-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmodel-mysql.php
More file actions
executable file
·582 lines (487 loc) · 19.1 KB
/
Copy pathmodel-mysql.php
File metadata and controls
executable file
·582 lines (487 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<?php
require_once('fileutils.php');
require_once('dbutils.php');
require_once('model-common.php');
require_once('config.php');
//****************************
//Model Storage
//****************************
class OsmDatabaseMysql extends OsmDatabaseCommon
{
function __construct()
{
$this->inTransaction = false;
try {
/* print_r( */
/* 'mysql CONNECT :mysql:dbname='.MYSQL_DB_NAME.';host='. */
/* MYSQL_SERVER.';' . MYSQL_USER . MYSQL_PASSWORD . "\n"); */
$this->dbh = new PDO('mysql://dbname='.MYSQL_DB_NAME.';host='.MYSQL_SERVER.';', MYSQL_USER, MYSQL_PASSWORD);
} catch (PDOException $e) {
throw new Exception ('Connection failed: ' . $e->getMessage());
}
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->InitialiseSchema();
}
function __destruct()
{
if ($this->inTransaction) {$this->dbh->commit(); $this->inTransaction = false;}
}
//******************
//Utility functions
//******************
function CheckPermissions()
{
return 1;
}
function InitialiseSchema()
{
//mysql_select_db
$sql = "CREATE TABLE IF NOT EXISTS ".MYSQL_DB_NAME.".meta (intid BIGINT PRIMARY KEY AUTO_INCREMENT, type INTEGER, id BIGINT, ver BIGINT, changeset BIGINT, user TEXT, uid BIGINT, timestamp INTEGER, visible INTEGER, INDEX(id,ver)) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin ENGINE=MyISAM;";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$sql = "CREATE TABLE IF NOT EXISTS ".MYSQL_DB_NAME.".geom (intid BIGINT PRIMARY KEY, g GEOMETRY NOT NULL, SPATIAL INDEX(g), type INTEGER, id BIGINT, ver BIGINT, INDEX(id,ver)) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin ENGINE=MyISAM;";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$sql = "CREATE TABLE IF NOT EXISTS ".MYSQL_DB_NAME.".tags (intid BIGINT PRIMARY KEY, type INTEGER, id BIGINT, ver BIGINT, tags BLOB, INDEX(id,ver)) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin ENGINE=MyISAM;";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$sql = "CREATE TABLE IF NOT EXISTS ".MYSQL_DB_NAME.".members (linkid BIGINT PRIMARY KEY AUTO_INCREMENT, ptype INTEGER, pid BIGINT, pver BIGINT, ctype INTEGER, cid BIGINT, role TEXT, ord INTEGER, INDEX(pid,pver), INDEX(cid)) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin ENGINE=MyISAM;";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$sql = "CREATE TABLE IF NOT EXISTS ".MYSQL_DB_NAME.".current (rowid BIGINT PRIMARY KEY AUTO_INCREMENT, type INTEGER, id BIGINT, currentver BIGINT, visible INTEGER, intid BIGINT, INDEX(id,type)) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin ENGINE=MyISAM;";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
}
function TypeToCode($ty)
{
if($ty=="node") return 0;
if($ty=="way") return 1;
if($ty=="relation") return 2;
throw new Exception("Type ".$ty." not recognised");
}
function CodeToType($code)
{
if($code==0) return "node";
if($code==1) return "way";
if($code==2) return "relation";
throw new Exception("Code ".$code." not recognised");
}
function InsertMembersIntoDatabase($el, $id, $mems, $ptype)
{
$ver = $this->dbh->quote($el->attr['version']);
$count = 0;
foreach($mems as $e)
{
$sql = "INSERT INTO ".MYSQL_DB_NAME.".members (ptype, pid, pver, ctype, cid, role, ord) VALUES (".
$this->dbh->quote($this->TypeToCode($ptype)).",".
$this->dbh->quote($id).",".$ver.",".
$this->dbh->quote($this->TypeToCode($e[0])).",".
$this->dbh->quote($e[1]).",".
$this->dbh->quote($e[2]).",".
$this->dbh->quote($count).
");";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$count ++;
}
}
function PointStrToLatLon($pt)
{
$nums = explode(" ",substr($pt,6,strlen($pt)-7));
return array((float)$nums[0],(float)$nums[1]);
}
function IntIdToObj($intid)
{
//Return requested version, first get the meta data
$out = null;
$type = null;
$id = null;
$version = null;
$sql = "SELECT * FROM ".MYSQL_DB_NAME.".meta WHERE intid = ".$this->dbh->quote($intid).";";
//echo $sql."\n";
$ret = $this->dbh->query($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
foreach ($ret as $row) {
//print_r($row);
$out = OsmElementFactory($this->CodeToType($row['type']));
$out->attr['id'] = $row['id'];
$out->attr['version'] = $row['ver'];
$out->attr['changeset'] = $row['changeset'];
$out->attr['user'] = $row['user'];
$out->attr['uid'] = $row['uid'];
$out->attr['timestamp'] = date('c',(int)$row['timestamp']);
if($row['visible']) $out->attr['visible'] = "true";
else $out->attr['visible'] = "false";
//$intid = $row['intid'];
$type = $this->CodeToType($row['type']);
$id = $row['id'];
$version = $row['ver'];
}
if($out == null) return 0;
//If node, get exact position
if($type=="node")
{
$sql = "SELECT AsText(g) FROM ".MYSQL_DB_NAME.".geom WHERE intid = ".$this->dbh->quote($intid).";";
$ret = $this->dbh->query($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
foreach ($ret as $row) {
//print_r($this->PointStrToLatLon($row['AsText(g)']));
list($lat,$lon) = $this->PointStrToLatLon($row['AsText(g)']);
$out->attr['lat'] = $lat;
$out->attr['lon'] = $lon;
}
}
//Get tags
$sql = "SELECT tags FROM ".MYSQL_DB_NAME.".tags WHERE intid = ".$this->dbh->quote($intid).";";
$ret = $this->dbh->query($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
foreach ($ret as $row) {
$out->tags = array();
foreach(json_decode($row['tags']) as $t => $v)
$out->tags[$t] = $v;
}
//Get members
$sql = "SELECT ctype,cid,role FROM ".MYSQL_DB_NAME.".members WHERE ptype = ".$this->dbh->quote($this->TypeToCode($type))." AND pid = ".
$this->dbh->quote($id)." AND pver = ".$this->dbh->quote($version)." ORDER BY ord;";
//echo $sql."\n";
$ret = $this->dbh->query($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
foreach ($ret as $row) {
//print_r($row);
$ctype = $this->CodeToType($row['ctype']);
array_push($out->members,array($ctype,$row['cid'],$row['role']));
}
return $out;
}
public function GetHighestVersionNum($type,$id)
{
if (0) //Uncached version, direct from meta table
{
$maxVer = null;
$maxIntId = null;
$maxVisible = null;
$sql = "SELECT ver,intid,visible FROM ".MYSQL_DB_NAME.".meta WHERE type = ".$this->dbh->quote($this->TypeToCode($type))." AND id = ".$this->dbh->quote($id).";";
//echo $sql."\n";
$ret = $this->dbh->query($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
foreach ($ret as $row) {
//print_r($row);
//return array($row['intid'],$row['MAX(ver)'],$row['visible']);
if($maxVer === null or $row['ver'] > $maxVer)
{
$maxVer = $row['ver'];
$maxIntId = $row['intid'];
$maxVisible = $row['visible'];
}
}
if($maxVer === null) return 0; //Not found
return array($maxIntId,$maxVer,$maxVisible);
}
//Retrieve latest version from current table
$sql = "SELECT * FROM ".MYSQL_DB_NAME.".current WHERE id = ".$this->dbh->quote($id)." AND type = ".$this->dbh->quote($this->TypeToCode($type)).";";
//echo $sql."\n";
$ret = $this->dbh->query($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
foreach ($ret as $row) {
//print_r($row);
return array($row['intid'],$row['currentver'],$row['visible']);
}
return 0; //Not found
}
public function UpdateLatestVersionFromMeta($type,$id)
{
$maxVer = null;
$maxIntId = null;
$maxVisible = null;
$sql = "SELECT ver,intid,visible FROM ".MYSQL_DB_NAME.".meta WHERE type = ".$this->dbh->quote($this->TypeToCode($type))." AND id = ".$this->dbh->quote($id).";";
//echo $sql."\n";
$ret = $this->dbh->query($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
foreach ($ret as $row) {
//print_r($row);
//return array($row['intid'],$row['MAX(ver)'],$row['visible']);
if($maxVer === null or $row['ver'] > $maxVer)
{
$maxVer = $row['ver'];
$maxIntId = $row['intid'];
$maxVisible = $row['visible'];
}
}
if($maxVer === null) return 0; //Not found
//echo $maxVer."\n";
//Try to update current table, see how many rows are affected
$sql = "UPDATE ".MYSQL_DB_NAME.".current SET currentver=".$this->dbh->quote($maxVer).", visible=".$this->dbh->quote($maxVisible).
", intid=".$this->dbh->quote($maxIntId)." WHERE id=".$this->dbh->quote($id).
" AND type=".$this->dbh->quote($this->TypeToCode($type)).";";
$stat = $this->dbh->prepare($sql);
$ret = $stat->execute();
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$affected = $stat->rowCount();
//echo $affected."\n";
//If the record is not in the table, insert a fresh row
if($affected == 0)
{
$sql = "INSERT INTO ".MYSQL_DB_NAME.".current (currentver, visible, intid, id, type) VALUES (".
$this->dbh->quote($maxVer).",".
$this->dbh->quote($maxVisible).",".
$this->dbh->quote($maxIntId).",".
$this->dbh->quote($id).",".
$this->dbh->quote($this->TypeToCode($type)).");";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
}
//return array($maxIntId,$maxVer,$maxVisible);
}
public function GetParentsByType(&$els,$type)
{
$parentIds = array();
//Find all parent ways
foreach($els as $el)
{
$id = $el->attr['id'];
//ptype INTEGER, pid INTEGER, pver INTEGER, ctype INTEGER, cid
$sql = "SELECT * FROM ".MYSQL_DB_NAME.".members WHERE ptype = ".$this->dbh->quote($this->TypeToCode($type)).
" AND ctype = ".$this->dbh->quote($this->TypeToCode($el->GetType())).
" AND cid = ".$this->dbh->quote($id).";";
//echo $sql."\n"; die();
$ret = $this->dbh->query($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
foreach ($ret as $row) {
//print_r($row);
$parentId = $row['pid'];
$parentVer = $row['pver'];
//Keep the highest version num
if (!isset($parentIds[$parentId]))
$parentIds[$parentId] = $parentVer;
if($parentVer > $parentIds[$parentId])
$parentIds[$parentId] = $parentVer;
}
}
//print_r($parentIds);
//Check if each way is still an active object (and ignore the non-current objects)
$highVerParents = array();
foreach ($parentIds as $parentId=>$ver)
{
list($intid,$highestVer,$visible) = $this->GetHighestVersionNum($type,$parentId);
//echo $type." ".$parentId." ".$intid." ".$highestVer."\n";
if ($highestVer == $ver) $highVerParents[$parentId] = $intid;
//echo "\n";
}
//print_r($highVerWays);
//exit(0);
///Check if object has been deleted
//Get parent objects
$out = array();
foreach ($highVerParents as $parentId=>$intid)
{
$obj = $this->IntIdToObj($intid);
if(!is_numeric($obj))
array_push($out,$obj);
}
//exit(0);
return $out;
}
//**********************
//General main query
//**********************
public function GetNodesInBbox($bbox)
{
$startTime = microtime(TRUE);
$sql = "SELECT ".MYSQL_DB_NAME.".geom.intid, meta.type, meta.id, meta.ver FROM ".MYSQL_DB_NAME.".geom INNER JOIN ".MYSQL_DB_NAME.".meta ON ".MYSQL_DB_NAME.".geom.intid = ".MYSQL_DB_NAME.".meta.intid".
" WHERE Contains(GeomFromText('Polygon((".
$bbox[1]." ".$bbox[0].",".$bbox[3]." ".$bbox[0].",".$bbox[3]." ".
$bbox[2].",".$bbox[1]." ".$bbox[0].",".$bbox[1]." ".$bbox[0]."))'),geom.g) AND meta.visible = 1;";
//echo $sql."\n"; exit(0);
$ret = $this->dbh->query($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$hits = array();
foreach ($ret as $row) {
//print_r($row);
$intid = $row['intid'];
array_push($hits,array($intid,$this->CodeToType($row['type']),$row['id'],$row['ver']));
}
//print "Fetched nodes in bbox in ".(microtime(TRUE) - $startTime)."\n";
//Check if this is the latest version
$currentHits = array();
foreach ($hits as $hit) {
$startTime = microtime(TRUE);
list($intid,$type,$id,$version) = $hit;
list($maxIntId,$maxVer,$maxVisible) = $this->GetHighestVersionNum($type,$id);
if($version == $maxVer)
{
array_push($currentHits, $hit);
}
//print "Fetched current ver in ".(microtime(TRUE) - $startTime)."\n";
}
//Get objects
$out = array();
foreach ($currentHits as $hit) {
$startTime = microtime(TRUE);
list($intid,$type,$id,$version) = $hit;
$obj = $this->IntIdToObj($intid);
if(!is_numeric($obj))
array_push($out,$obj);
//print "Fetched final obj in ".(microtime(TRUE) - $startTime)."\n";
}
return $out;
}
public function GetParentWaysOfNodes(&$nodes)
{
return $this->GetParentsByType($nodes,"way");
}
public function GetParentRelations(&$els)
{
return $this->GetParentsByType($els,"relation");
}
//**********************************
//Get specific info from database
//**********************************
public function GetElementById($type,$id,$version=null)
{
$intid = Null;
if($version == null)
{
//Automatically determine latest version
$ret = $this->GetHighestVersionNum($type,$id);
if($ret===0) return 0; //Not found
list($intid,$version,$visible) = $ret;
//Check if deleted (return -2, if so)
if($visible == 0) return -2;
}
if($intid == Null)
{
//Return requested version, first the intid of the object
$out = null;
$sql = "SELECT intid FROM ".MYSQL_DB_NAME.".meta WHERE type = ".$this->dbh->quote($this->TypeToCode($type))." AND id = ".
$this->dbh->quote($id)." AND ver = ".$this->dbh->quote($version).";";
//echo $sql."\n";
$ret = $this->dbh->query($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
foreach ($ret as $row) {
$intid = $row['intid'];
}
}
//Return object
return $this->IntIdToObj($intid);
}
public function GetElementFullHistory($type,$id)
{
//Find all version numbers
$vers = array();
$sql = "SELECT ver FROM ".MYSQL_DB_NAME.".meta WHERE type = ".$this->dbh->quote($this->TypeToCode($type))." AND id = ".$this->dbh->quote($id).";";
$ret = $this->dbh->query($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
foreach ($ret as $row) {
//print_r($row);
array_push($vers,$row['ver']);
}
if (count($vers)==0) return 0; //Not found
$out = array();
foreach($vers as $ver)
{
$obj = $this->GetElementById($type,$id,$ver);
array_push($out,$obj);
}
return $out;
}
public function Dump($callback)
{
//Dump current version of the database to a callback function
//Dump types
$tys = array('node','way','relation');
foreach($tys as $ty)
{
$sql = "SELECT * FROM ".MYSQL_DB_NAME.".current WHERE type = ".$this->dbh->quote($this->TypeToCode($ty)).";";
$ret = $this->dbh->query($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
foreach ($ret as $row) {$obj = $this->IntIdToObj($row['intid']);$callback($obj);}
}
}
//***********************
//Modification functions
//***********************
/*public function GetInternalTable($type)
{
}*/
public function CreateElement($type,$id,$el)
{
return $this->ModifyElement($type,$id,$el);
}
public function ModifyElement($type,$id,$el)
{
//if ($type=="way")
//print_r($el);
//Start transaction if we have not already
if (!$this->inTransaction) {$this->dbh->beginTransaction(); $this->inTransaction = true;}
//Insert into internal id table
$ver = $this->dbh->quote($el->attr['version']);
$changeset = $this->dbh->quote($el->attr['changeset']);
$user = "NULL";
if (isset($el->attr['user']))
$user = $this->dbh->quote($el->attr['user']);
$uid = "NULL";
if (isset($el->attr['uid']))
$uid = $this->dbh->quote($el->attr['uid']);
$timestamp = 0;
if (isset($el->attr['timestamp']))
$timestamp = $this->dbh->quote((int)strtotime($el->attr['timestamp']));
$visible = "NULL";
if (isset($el->attr['visible']) and $el->attr['visible'] == "true") $visible = 1;
if (isset($el->attr['visible']) and $el->attr['visible'] == "false") $visible = 0;
if (!isset($el->attr['visible'])) $visible = 1;
$sql ="INSERT INTO ".MYSQL_DB_NAME.".meta (type, id, ver, changeset, user, uid, timestamp, visible) VALUES (".$this->dbh->quote($this->TypeToCode($type)).",".
$this->dbh->quote($id).",".$ver.",".$changeset.",".$user.",".$uid.",".$timestamp.",".$visible.")";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$intid = $this->dbh->lastInsertId();
//Store nodes in geometry optimised table too
if($type == "node")
{
$lat = $el->attr['lat'];
$lon = $el->attr['lon'];
$sql = "INSERT INTO ".MYSQL_DB_NAME.".geom (intid, g, type, id, ver) VALUES (".$intid.",GeomFromText('POINT(".$lat." ".$lon.")'),".
$this->dbh->quote($this->TypeToCode($type)).",".
$this->dbh->quote($id).",".$ver.");";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
}
//Store, tags if any
if(count($el->tags)>0)
{
$tagser = $this->dbh->quote(json_encode($el->tags));
$sql = "INSERT INTO ".MYSQL_DB_NAME.".tags (intid, type, id, ver, tags) VALUES (".$intid.",".
$this->dbh->quote($this->TypeToCode($type)).",".
$this->dbh->quote($id).",".$ver.",".$tagser.");";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
}
//Store the references to child objects
$this->InsertMembersIntoDatabase($el,$id,$el->members,$type);
//Check if this is the latest version and update the "current" version table
$this->UpdateLatestVersionFromMeta($type,$id);
}
public function DeleteElement($type,$id,$el)
{
return $this->ModifyElement($type,$id,$el);
}
public function Purge()
{
$sql = "DROP TABLE IF EXISTS ".MYSQL_DB_NAME.".geom;";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$sql = "DROP TABLE IF EXISTS ".MYSQL_DB_NAME.".meta;";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$sql = "DROP TABLE IF EXISTS ".MYSQL_DB_NAME.".tags;";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$sql = "DROP TABLE IF EXISTS ".MYSQL_DB_NAME.".members;";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$sql = "DROP TABLE IF EXISTS ".MYSQL_DB_NAME.".current;";
$ret = $this->dbh->exec($sql);
if($ret===false) {$err= $this->dbh->errorInfo();throw new Exception($sql.",".$err[2]);}
$this->InitialiseSchema();
}
}
?>