/usr/share/php/adodb/replicate/test-tnb.php is in libphp-adodb 5.20.3-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <?php
include_once('../adodb.inc.php');
include_once('adodb-replicate.inc.php');
set_time_limit(0);
function IndexFilter($dtable, $idxname,$flds,$options)
{
if (strlen($idxname) > 28) $idxname = substr($idxname,0,24).rand(1000,9999);
return $idxname;
}
function SelFilter($table, &$arr, $delfirst)
{
return true;
}
function updatefilter($table, $fld, $val)
{
return "nvl($fld, $val)";
}
function FieldFilter(&$fld,$mode)
{
$uf = strtoupper($fld);
switch($uf) {
case 'SIZEFLD':
return 'Size';
case 'GROUPFLD':
return 'Group';
case 'GROUP':
if ($mode == 'SELECT') $fld = '"Group"';
return 'GroupFld';
case 'SIZE':
if ($mode == 'SELECT') $fld = '"Size"';
return 'SizeFld';
}
return $fld;
}
function ParseTable(&$table, &$pkey)
{
$table = trim($table);
if (strlen($table) == 0) return false;
if (strpos($table, '#') !== false) {
$at = strpos($table, '#');
$table = trim(substr($table,0,$at));
if (strlen($table) == 0) return false;
}
$tabarr = explode(',',$table);
if (sizeof($tabarr) == 1) {
$table = $tabarr[0];
$pkey = '';
echo "No primary key for $table **** **** <br>";
} else {
$table = trim($tabarr[0]);
$pkey = trim($tabarr[1]);
if (strpos($pkey,' ') !== false) echo "Bad PKEY for $table $pkey<br>";
}
return true;
}
global $TARR;
function TableStats($rep, $table, $pkey)
{
global $TARR;
if (empty($TARR)) $TARR = array();
$cnt = $rep->connSrc->GetOne("select count(*) from $table");
if (isset($TARR[$table])) echo "<h1>Table $table repeated twice</h1>";
$TARR[$table] = $cnt;
if ($pkey) {
$ok = $rep->connSrc->SelectLimit("select $pkey from $table",1);
if (!$ok) echo "<h1>$table: $pkey does not exist</h1>";
} else
echo "<h1>$table: no primary key</h1>";
}
function CreateTable($rep, $table)
{
## CREATE TABLE
#$DB2->Execute("drop table $table");
$rep->execute = true;
$ok = $rep->CopyTableStruct($table);
if ($ok) echo "Table Created<br>\n";
else {
echo "<hr>Error: Cannot Create Table<hr>\n";
}
flush();@ob_flush();
}
function CopyData($rep, $table, $pkey)
{
$dtable = $table;
$rep->execute = true;
$rep->deleteFirst = true;
$secs = time();
$rows = $rep->ReplicateData($table,$dtable,array($pkey));
$secs = time() - $secs;
if (!$rows || !$rows[0] || !$rows[1] || $rows[1] != $rows[2]+$rows[3]) {
echo "<hr>Error: "; var_dump($rows); echo " (secs=$secs) <hr>\n";
} else
echo date('H:i:s'),': ',$rows[1]," record(s) copied, ",$rows[2]," inserted, ",$rows[3]," updated (secs=$secs)<br>\n";
flush();@ob_flush();
}
function MergeDataJohnTest($rep, $table, $pkey)
{
$rep->SwapDBs();
$dtable = $table;
$rep->oracleSequence = 'LGBSEQUENCE';
# $rep->MergeSrcSetup($table, array($pkey),'UpdatedOn','CopiedFlag');
if (strpos($rep->connDest->databaseType,'mssql') !== false) { # oracle ==> mssql
$ignoreflds = array($pkey);
$ignoreflds[] = 'MSSQL_ID';
$set = 'MSSQL_ID=nvl($INSERT_ID,MSSQL_ID)';
$pkeyarr = array(array($pkey),false,array('MSSQL_ID'));# array('MSSQL_ID', 'ORA_ID'));
} else { # mssql ==> oracle
$ignoreflds = array($pkey);
$ignoreflds[] = 'ORA_ID';
$set = '';
#$set = 'ORA_ID=isnull($INSERT_ID,ORA_ID)';
$pkeyarr = array(array($pkey),array('MSSQL_ID'));
}
$rep->execute = true;
#$rep->updateFirst = false;
$ok = $rep->Merge($table, $dtable, $pkeyarr, $ignoreflds, $set, 'UpdatedOn','CopiedFlag',array('Y','N','P','='), 'CopyDate');
var_dump($ok);
#$rep->connSrc->Execute("update JohnTest set name='Apple' where id=4");
}
$DB = ADONewConnection('odbtp');
#$ok = $DB->Connect('localhost','root','','northwind');
$ok = $DB->Connect('192.168.0.1','DRIVER={SQL Server};SERVER=(local);UID=sa;PWD=natsoft;DATABASE=OIR;','','');
$DB->_bindInputArray = false;
$DB2 = ADONewConnection('oci8');
$ok2 = $DB2->Connect('192.168.0.2','tnb','natsoft','RAPTOR','');
if (!$ok || !$ok2) die("Failed connection DB=$ok DB2=$ok2<br>");
$tables =
"
JohnTest,id
";
# net* are ERMS, need last updated field from LGBnet
# tblRep* are tables insert or update from Juris, need last updated field also
# The rest are lookup tables, can copy all from LGBnet
$tablesOrig =
"
SysVoltSubLevel,id
# Lookup table for Restoration Details screen
sysefi,ID # (not identity)
sysgenkva,ID #(not identity)
sysrestoredby,ID #(not identity)
# Sel* table added on 24 Oct
SELSGManufacturer,ID
SelABCCondSizeLV,ID
SelABCCondSizeMV,ID
SelArchingHornSize,ID
SelBallastSize,ID
SelBallastType,ID
SelBatteryType,ID #(not identity)
SelBreakerCapacity,ID
SelBreakerType,ID #(not identity)
SelCBreakerManuf,ID
SelCTRatio,ID #(not identity)
SelCableBrand,ID
SelCableSize,ID
SelCableSizeLV,ID # (not identity)
SelCapacitorSize,ID
SelCapacitorType,ID
SelColourCode,ID
SelCombineSealingChamberSize,ID
SelConductorBrand,ID
SelConductorSize4,ID
SelConductorSizeLV,ID
SelConductorSizeMV,ID
SelContactorSize,ID
SelContractor,ID
SelCoverType,ID
SelCraddleSize,ID
SelDeadEndClampBrand,ID
SelDeadEndClampSize,ID
SelDevTermination,ID
SelFPManuf,ID
SelFPillarRating,ID
SelFalseTrue,ID
SelFuseManuf,ID
SelFuseType,ID
SelIPCBrand,ID
SelIPCSize,ID
SelIgnitorSize,ID
SelIgnitorType,ID
SelInsulatorBrand,ID
SelJoint,ID
SelJointBrand,ID
SelJunctionBoxBrand,ID
SelLVBoardBrand,ID
SelLVBoardSize,ID
SelLVOHManuf,ID
SelLVVoltage,ID
SelLightningArresterBrand,ID
SelLightningShieldwireSize,ID
SelLineTapSize,ID
SelLocation,ID
SelMVVoltage,ID
SelMidSpanConnectorsSize,ID
SelMidSpanJointSize,ID
SelNERManuf,ID
SelNERType,ID
SelNLinkSize,ID
SelPVCCondSizeLV,ID
SelPoleBrand,ID
SelPoleConcreteSize,ID
SelPoleSize,ID
SelPoleSpunConcreteSize,ID
SelPoleSteelSize,ID
SelPoleType,ID
SelPoleWoodSize,ID
SelPorcelainFuseSize,ID
SelRatedFaultCurrentBreaker,ID
SelRatedVoltageSG,ID #(not identity)
SelRelayType,ID # (not identity)
SelResistanceValue,ID
SelSGEquipmentType,ID # (not identity)
SelSGInsulationType,ID # (not identity)
SelSGManufacturer,ID
SelStayInsulatorSize,ID
SelSuspensionClampBrand,ID
SelSuspensionClampSize,ID
SelTSwitchType,ID
SelTowerType,ID
SelTransformerCapacity,ID
SelTransformerManuf,ID
SelTransformerType,ID #(not identity)
SelTypeOfArchingHorn,ID
SelTypeOfCable,ID #(not identity)
SelTypeOfConductor,ID # (not identity)
SelTypeOfInsulationCB,ID # (not identity)
SelTypeOfMidSpanJoint,ID
SelTypeOfSTJoint,ID
SelTypeSTCable,ID
SelUGVoltage,ID # (not identity)
SelVoltageInOut,ID
SelWireSize,ID
SelWireType,ID
SelWonpieceBrand,ID
#
# Net* tables added on 24 Oct
NetArchingHorn,Idx
NetBatteryBank,Idx # identity, FunctLocation Pri
NetBiMetal,Idx
NetBoxFuse,Idx
NetCable,Idx # identity, FunctLocation Pri
NetCapacitorBank,Idx # identity, FunctLocation Pri
NetCircuitBreaker,Idx # identity, FunctLocation Pri
NetCombineSealingChamber,Idx
NetCommunication,Idx
NetCompInfras,Idx
NetControl,Idx
NetCraddle,Idx
NetDeadEndClamp,Idx
NetEarthing,Idx
NetFaultIndicator,Idx
NetFeederPillar,Idx # identity, FunctLocation Pri
NetGenCable,Idx # identity , FunctLocation Not Null
NetGenerator,Idx
NetGrid,Idx
NetHVOverhead,Idx #identity, FunctLocation Pri
NetHVUnderground,Idx #identity, FunctLocation Pri
NetIPC,Idx
NetInductorBank,Idx
NetInsulator,Idx
NetJoint,Idx
NetJunctionBox,Idx
NetLVDB,Idx #identity, FunctLocation Pri
NetLVOverhead,Idx
NetLVUnderground,Idx # identity, FunctLocation Not Null
NetLightningArrester,Idx
NetLineTap,Idx
NetMidSpanConnectors,Idx
NetMidSpanJoint,Idx
NetNER,Idx # identity , FunctLocation Pri
NetOilPump,Idx
NetOtherComponent,Idx
NetPole,Idx
NetRMU,Idx # identity, FunctLocation Pri
NetStreetLight,Idx
NetStrucSupp,Idx
NetSuspensionClamp,Idx
NetSwitchGear,Idx # identity, FunctLocation Pri
NetTermination,Idx
NetTransition,Idx
NetWonpiece,Idx
#
# comment1
SelMVFuseType,ID
selFuseSize,ID
netRelay,Idx # identity, FunctLocation Pri
SysListVolt,ID
sysVoltLevel,ID_SVL
sysRestoration,ID_SRE
sysRepairMethod,ID_SRM # (not identity)
sysInterruptionType,ID_SIN
netTransformer,Idx # identity, FunctLocation Pri
#
#
sysComponent,ID_SC
sysCodecibs #-- no idea, UpdatedOn(the only column is unique),Ermscode,Cibscode is unique but got null value
sysCodeno,id
sysProtection,ID_SP
sysEquipment,ID_SEQ
sysAddress #-- no idea, ID_SAD(might be auto gen No)
sysWeather,ID_SW
sysEnvironment,ID_SE
sysPhase,ID_SPH
sysFailureCause,ID_SFC
sysFailureMode,ID_SFM
SysSchOutageMode,ID_SSM
SysOutageType,ID_SOT
SysInstallation,ID_SI
SysInstallationCat,ID_SIC
SysInstallationType,ID_SIT
SysFaultCategory,ID_SF #(not identity)
SysResponsible,ID_SR
SysProtectionOperation,ID_SPO #(not identity)
netCodename,CodeNo #(not identity)
netSubstation,Idx #identity, FunctLocation Pri
netLvFeeder,Idx # identity, FunctLocation Pri
#
#
tblReport,ReportNo
tblRepRestoration,ID_RR
tblRepResdetail,ID_RRD
tblRepFailureMode,ID_RFM
tblRepFailureCause,ID_RFC
tblRepRepairMethod,ReportNo # (not identity)
tblInterruptionType,ID_TIN
tblProtType,ID_PT #--capital letter
tblRepProtection,ID_RP
tblRepComponent,ID_RC
tblRepWeather,ID_RW
tblRepEnvironment,ID_RE
tblRepSubstation,ID_RSS
tblInstallationType,ID_TIT
tblInstallationCat,ID_TIC
tblFailureCause,ID_TFC
tblFailureMode,ID_TFM
tblProtection,ID_TP
tblComponent,ID_TC
tblProtdetail,Id # (Id)--capital letter for I
tblInstallation,ID_TI
#
";
$tables = explode("\n",$tables);
$rep = new ADODB_Replicate($DB,$DB2);
$rep->fieldFilter = 'FieldFilter';
$rep->selFilter = 'SELFILTER';
$rep->indexFilter = 'IndexFilter';
if (1) {
$rep->debug = 1;
$DB->debug=1;
$DB2->debug=1;
}
# $rep->SwapDBs();
$cnt = sizeof($tables);
foreach($tables as $k => $table) {
$pkey = '';
if (!ParseTable($table, $pkey)) continue;
#######################
$kcnt = $k+1;
echo "<h1>($kcnt/$cnt) $table -- $pkey</h1>\n";
flush();@ob_flush();
CreateTable($rep,$table);
# COPY DATA
TableStats($rep, $table, $pkey);
if ($table == 'JohnTest') MergeDataJohnTest($rep, $table, $pkey);
else CopyData($rep, $table, $pkey);
}
if (!empty($TARR)) {
ksort($TARR);
adodb_pr($TARR);
asort($TARR);
adodb_pr($TARR);
}
echo "<hr>",date('H:i:s'),": Done</hr>";
|