comparison managedb.php @ 1104:0a2117349f46

s/true/TRUE/g; s/false/FALSE/g;
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 14 May 2019 14:45:36 +0300
parents 48e16e856646
children 24e6915fc0fb
comparison
equal deleted inserted replaced
1103:1fe7df7c77fb 1104:0a2117349f46
93 { 93 {
94 $status = TRUE; 94 $status = TRUE;
95 95
96 foreach ($settings as $key => $data) 96 foreach ($settings as $key => $data)
97 { 97 {
98 $sql = false; 98 $sql = FALSE;
99 99
100 // Get setting type 100 // Get setting type
101 switch ($data[0]) 101 switch ($data[0])
102 { 102 {
103 case VT_TEXT: $type = "%s"; $var = "vtext"; break; 103 case VT_TEXT: $type = "%s"; $var = "vtext"; break;
128 $sql = stDBPrepareSQL($outDB, $sqlFmt, 128 $sql = stDBPrepareSQL($outDB, $sqlFmt,
129 $key, $data[0], $res[$var], $data[2], $group); 129 $key, $data[0], $res[$var], $data[2], $group);
130 } 130 }
131 } 131 }
132 132
133 if ($sql === false) 133 if ($sql === FALSE)
134 { 134 {
135 // Normal insertion of default data 135 // Normal insertion of default data
136 $sql = stDBPrepareSQL($outDB, $sqlFmt, 136 $sql = stDBPrepareSQL($outDB, $sqlFmt,
137 $key, $data[0], $data[1], $data[2], $group); 137 $key, $data[0], $data[1], $data[2], $group);
138 } 138 }
163 echo " - Group '".$groupID."' -> ".$groupData[$groupID][1]."."; 163 echo " - Group '".$groupID."' -> ".$groupData[$groupID][1].".";
164 $sql = stDBPrepareSQL($outDB, 164 $sql = stDBPrepareSQL($outDB,
165 "INSERT INTO ".$groupTable." (name,description) VALUES (%s,%s)", 165 "INSERT INTO ".$groupTable." (name,description) VALUES (%s,%s)",
166 $groupData[$groupID][0], $groupData[$groupID][1]); 166 $groupData[$groupID][0], $groupData[$groupID][1]);
167 167
168 if (($gid = stDBExecSQLInsert($outDB, $sql)) === false) 168 if (($gid = stDBExecSQLInsert($outDB, $sql)) === FALSE)
169 { 169 {
170 echo "\nFailed to add group '".$groupID."'\n"; 170 echo "\nFailed to add group '".$groupID."'\n";
171 return FALSE; 171 return FALSE;
172 } 172 }
173 173
174 // Add settings to the group 174 // Add settings to the group
175 stDBBeginTransaction($outDB); 175 stDBBeginTransaction($outDB);
176 if (stDoAddSettings($inDB, $outDB, $settings, $table, $upgrade, $gid) === false) 176 if (stDoAddSettings($inDB, $outDB, $settings, $table, $upgrade, $gid) === FALSE)
177 { 177 {
178 echo "\nFailed to add settings to group '".$groupID."'\n"; 178 echo "\nFailed to add settings to group '".$groupID."'\n";
179 return FALSE; 179 return FALSE;
180 } 180 }
181 stDBCommitTransaction($outDB); 181 stDBCommitTransaction($outDB);
217 $arr = array_merge( 217 $arr = array_merge(
218 array($outDB, "INSERT INTO ".$table." (".$data[0].") VALUES (".$data[1].")"), 218 array($outDB, "INSERT INTO ".$table." (".$data[0].") VALUES (".$data[1].")"),
219 $data[$n]); 219 $data[$n]);
220 220
221 $sql = call_user_func_array('stDBPrepareSQL', $arr); 221 $sql = call_user_func_array('stDBPrepareSQL', $arr);
222 if (stDBExecSQL($outDB, $sql) === false) 222 if (stDBExecSQL($outDB, $sql) === FALSE)
223 { 223 {
224 $status = false; 224 $status = FALSE;
225 break; 225 break;
226 } 226 }
227 } 227 }
228 } 228 }
229 else 229 else
297 if (in_array("AUTOINCREMENT", $col)) 297 if (in_array("AUTOINCREMENT", $col))
298 $sequences[] = $col[0]; 298 $sequences[] = $col[0];
299 } 299 }
300 300
301 $sql = "INSERT INTO ".$table." (".implode(",", $acols).") VALUES (".implode(",", $avals).")"; 301 $sql = "INSERT INTO ".$table." (".implode(",", $acols).") VALUES (".implode(",", $avals).")";
302 if (stDBExecSQL($outDB, $sql) === false) 302 if (stDBExecSQL($outDB, $sql) === FALSE)
303 { 303 {
304 $status = FALSE; 304 $status = FALSE;
305 break; 305 break;
306 } 306 }
307 echo "."; 307 echo ".";
312 { 312 {
313 case "pgsql": 313 case "pgsql":
314 // For PostgreSQL we need to update sequences 314 // For PostgreSQL we need to update sequences
315 foreach ($sequences as $seq) 315 foreach ($sequences as $seq)
316 { 316 {
317 if (($max_id = stDBFetchSQLColumn($outDB, "SELECT MAX(".$seq.") FROM ".$table)) !== false && 317 if (($max_id = stDBFetchSQLColumn($outDB, "SELECT MAX(".$seq.") FROM ".$table)) !== FALSE &&
318 ($seq_id = stDBFetchSQLColumn($outDB, "SELECT nextval('".$table."_".$seq."_seq')")) !== false && 318 ($seq_id = stDBFetchSQLColumn($outDB, "SELECT nextval('".$table."_".$seq."_seq')")) !== FALSE &&
319 ($seq_id <= $max_id)) 319 ($seq_id <= $max_id))
320 { 320 {
321 echo "SEQFIX"; 321 echo "SEQFIX";
322 stDBExecSQL($outDB, "SELECT setval('".$table."_".$seq."_seq', ".$max_id.")"); 322 stDBExecSQL($outDB, "SELECT setval('".$table."_".$seq."_seq', ".$max_id.")");
323 } 323 }
416 case "test": 416 case "test":
417 $addTestData = TRUE; 417 $addTestData = TRUE;
418 418
419 case "new": 419 case "new":
420 // Try to connect to database 420 // Try to connect to database
421 if (($inSpec = stCArg(2)) === false) 421 if (($inSpec = stCArg(2)) === FALSE)
422 die("No PDO database spec specified.\n"); 422 die("No PDO database spec specified.\n");
423 423
424 if (($inDB = stConnectSQLDBSpec($inSpec)) === false) 424 if (($inDB = stConnectSQLDBSpec($inSpec)) === FALSE)
425 die("Could not connect to SQL database '".$inSpec."'.\n"); 425 die("Could not connect to SQL database '".$inSpec."'.\n");
426 426
427 echo "Using database spec '".$inSpec."'.\n"; 427 echo "Using database spec '".$inSpec."'.\n";
428 428
429 // Create tables, add defaults 429 // Create tables, add defaults
457 if ($outSpec == $inSpec) 457 if ($outSpec == $inSpec)
458 die("The input and output databases CAN NOT BE SAME.\nBe VERY CAREFUL to not accidentally specify same db!\n"); 458 die("The input and output databases CAN NOT BE SAME.\nBe VERY CAREFUL to not accidentally specify same db!\n");
459 459
460 echo "Using INPUT database spec '".$inSpec."'.\n"; 460 echo "Using INPUT database spec '".$inSpec."'.\n";
461 461
462 if (($inDB = stConnectSQLDBSpec($inSpec)) === false) 462 if (($inDB = stConnectSQLDBSpec($inSpec)) === FALSE)
463 die("Could not connect to SQL database '".$inSpec."'.\n"); 463 die("Could not connect to SQL database '".$inSpec."'.\n");
464 464
465 // Check the current version first ... 465 // Check the current version first ...
466 if (($currVersion = stGetDBMeta($inDB, "dbVersion")) === FALSE) 466 if (($currVersion = stGetDBMeta($inDB, "dbVersion")) === FALSE)
467 $currVersion = -1; 467 $currVersion = -1;
471 echo "Database is already version ".$dbVersion.", no upgrading needed.\n"; 471 echo "Database is already version ".$dbVersion.", no upgrading needed.\n";
472 } 472 }
473 else 473 else
474 { 474 {
475 // Okay, we shall create an upgraded version .. 475 // Okay, we shall create an upgraded version ..
476 if (($outDB = stConnectSQLDBSpec($outSpec)) === false) 476 if (($outDB = stConnectSQLDBSpec($outSpec)) === FALSE)
477 die("Could not connect to SQL database '".$outSpec."'.\n"); 477 die("Could not connect to SQL database '".$outSpec."'.\n");
478 478
479 echo "Database at version ".$currVersion.", upgrading to ".$dbVersion."\n"; 479 echo "Database at version ".$currVersion.", upgrading to ".$dbVersion."\n";
480 echo "Using OUTPUT database spec '".$outSpec."'.\n"; 480 echo "Using OUTPUT database spec '".$outSpec."'.\n";
481 481