C:/lib/adodb/replicate/test-tnb.php Quellcode

test-tnb.php
gehe zur Dokumentation dieser Datei
1 <?php
2 include_once('../adodb.inc.php');
3 include_once('adodb-replicate.inc.php');
4 
5 set_time_limit(0);
6 
7 function IndexFilter($dtable, $idxname,$flds,$options)
8 {
9  if (strlen($idxname) > 28) $idxname = substr($idxname,0,24).rand(1000,9999);
10  return $idxname;
11 }
12 
13 function SelFilter($table, &$arr, $delfirst)
14 {
15  return true;
16 }
17 
18 function updatefilter($table, $fld, $val)
19 {
20  return "nvl($fld, $val)";
21 }
22 
23 
24 function FieldFilter(&$fld,$mode)
25 {
26  $uf = strtoupper($fld);
27  switch($uf) {
28  case 'SIZEFLD':
29  return 'Size';
30 
31  case 'GROUPFLD':
32  return 'Group';
33 
34  case 'GROUP':
35  if ($mode == 'SELECT') $fld = '"Group"';
36  return 'GroupFld';
37  case 'SIZE':
38  if ($mode == 'SELECT') $fld = '"Size"';
39  return 'SizeFld';
40  }
41  return $fld;
42 }
43 
44 function ParseTable(&$table, &$pkey)
45 {
46  $table = trim($table);
47  if (strlen($table) == 0) return false;
48  if (strpos($table, '#') !== false) {
49  $at = strpos($table, '#');
50  $table = trim(substr($table,0,$at));
51  if (strlen($table) == 0) return false;
52  }
53 
54  $tabarr = explode(',',$table);
55  if (sizeof($tabarr) == 1) {
56  $table = $tabarr[0];
57  $pkey = '';
58  echo "No primary key for $table **** **** <br>";
59  } else {
60  $table = trim($tabarr[0]);
61  $pkey = trim($tabarr[1]);
62  if (strpos($pkey,' ') !== false) echo "Bad PKEY for $table $pkey<br>";
63  }
64 
65  return true;
66 }
67 
68 global $TARR;
69 
70 function TableStats($rep, $table, $pkey)
71 {
72 global $TARR;
73 
74  if (empty($TARR)) $TARR = array();
75  $cnt = $rep->connSrc->GetOne("select count(*) from $table");
76  if (isset($TARR[$table])) echo "<h1>Table $table repeated twice</h1>";
77  $TARR[$table] = $cnt;
78 
79  if ($pkey) {
80  $ok = $rep->connSrc->SelectLimit("select $pkey from $table",1);
81  if (!$ok) echo "<h1>$table: $pkey does not exist</h1>";
82  } else
83  echo "<h1>$table: no primary key</h1>";
84 }
85 
86 function CreateTable($rep, $table)
87 {
88 ## CREATE TABLE
89  #$DB2->Execute("drop table $table");
90 
91  $rep->execute = true;
92  $ok = $rep->CopyTableStruct($table);
93  if ($ok) echo "Table Created<br>\n";
94  else {
95  echo "<hr>Error: Cannot Create Table<hr>\n";
96  }
97  flush();@ob_flush();
98 }
99 
100 function CopyData($rep, $table, $pkey)
101 {
102  $dtable = $table;
103 
104  $rep->execute = true;
105  $rep->deleteFirst = true;
106 
107  $secs = time();
108  $rows = $rep->ReplicateData($table,$dtable,array($pkey));
109  $secs = time() - $secs;
110  if (!$rows || !$rows[0] || !$rows[1] || $rows[1] != $rows[2]+$rows[3]) {
111  echo "<hr>Error: "; var_dump($rows); echo " (secs=$secs) <hr>\n";
112  } else
113  echo date('H:i:s'),': ',$rows[1]," record(s) copied, ",$rows[2]," inserted, ",$rows[3]," updated (secs=$secs)<br>\n";
114  flush();@ob_flush();
115 }
116 
117 function MergeDataJohnTest($rep, $table, $pkey)
118 {
119  $rep->SwapDBs();
120 
121  $dtable = $table;
122  $rep->oracleSequence = 'LGBSEQUENCE';
123 
124 # $rep->MergeSrcSetup($table, array($pkey),'UpdatedOn','CopiedFlag');
125  if (strpos($rep->connDest->databaseType,'mssql') !== false) { # oracle ==> mssql
126  $ignoreflds = array($pkey);
127  $ignoreflds[] = 'MSSQL_ID';
128  $set = 'MSSQL_ID=nvl($INSERT_ID,MSSQL_ID)';
129  $pkeyarr = array(array($pkey),false,array('MSSQL_ID'));# array('MSSQL_ID', 'ORA_ID'));
130  } else { # mssql ==> oracle
131  $ignoreflds = array($pkey);
132  $ignoreflds[] = 'ORA_ID';
133  $set = '';
134  #$set = 'ORA_ID=isnull($INSERT_ID,ORA_ID)';
135  $pkeyarr = array(array($pkey),array('MSSQL_ID'));
136  }
137  $rep->execute = true;
138  #$rep->updateFirst = false;
139  $ok = $rep->Merge($table, $dtable, $pkeyarr, $ignoreflds, $set, 'UpdatedOn','CopiedFlag',array('Y','N','P','='), 'CopyDate');
140  var_dump($ok);
141 
142  #$rep->connSrc->Execute("update JohnTest set name='Apple' where id=4");
143 }
144 
145 $DB = ADONewConnection('odbtp');
146 #$ok = $DB->Connect('localhost','root','','northwind');
147 $ok = $DB->Connect('192.168.0.1','DRIVER={SQL Server};SERVER=(local);UID=sa;PWD=natsoft;DATABASE=OIR;','','');
148 $DB->_bindInputArray = false;
149 
150 $DB2 = ADONewConnection('oci8');
151 $ok2 = $DB2->Connect('192.168.0.2','tnb','natsoft','RAPTOR','');
152 
153 if (!$ok || !$ok2) die("Failed connection DB=$ok DB2=$ok2<br>");
154 
155 $tables =
156 "
157 JohnTest,id
158 ";
159 
160 # net* are ERMS, need last updated field from LGBnet
161 # tblRep* are tables insert or update from Juris, need last updated field also
162 # The rest are lookup tables, can copy all from LGBnet
163 
165 "
166 SysVoltSubLevel,id
167 # Lookup table for Restoration Details screen
168 sysefi,ID # (not identity)
169 sysgenkva,ID #(not identity)
170 sysrestoredby,ID #(not identity)
171 # Sel* table added on 24 Oct
172 SELSGManufacturer,ID
173 SelABCCondSizeLV,ID
174 SelABCCondSizeMV,ID
175 SelArchingHornSize,ID
176 SelBallastSize,ID
177 SelBallastType,ID
178 SelBatteryType,ID #(not identity)
179 SelBreakerCapacity,ID
180 SelBreakerType,ID #(not identity)
181 SelCBreakerManuf,ID
182 SelCTRatio,ID #(not identity)
183 SelCableBrand,ID
184 SelCableSize,ID
185 SelCableSizeLV,ID # (not identity)
186 SelCapacitorSize,ID
187 SelCapacitorType,ID
188 SelColourCode,ID
189 SelCombineSealingChamberSize,ID
190 SelConductorBrand,ID
191 SelConductorSize4,ID
192 SelConductorSizeLV,ID
193 SelConductorSizeMV,ID
194 SelContactorSize,ID
195 SelContractor,ID
196 SelCoverType,ID
197 SelCraddleSize,ID
198 SelDeadEndClampBrand,ID
199 SelDeadEndClampSize,ID
200 SelDevTermination,ID
201 SelFPManuf,ID
202 SelFPillarRating,ID
203 SelFalseTrue,ID
204 SelFuseManuf,ID
205 SelFuseType,ID
206 SelIPCBrand,ID
207 SelIPCSize,ID
208 SelIgnitorSize,ID
209 SelIgnitorType,ID
210 SelInsulatorBrand,ID
211 SelJoint,ID
212 SelJointBrand,ID
213 SelJunctionBoxBrand,ID
214 SelLVBoardBrand,ID
215 SelLVBoardSize,ID
216 SelLVOHManuf,ID
217 SelLVVoltage,ID
218 SelLightningArresterBrand,ID
219 SelLightningShieldwireSize,ID
220 SelLineTapSize,ID
221 SelLocation,ID
222 SelMVVoltage,ID
223 SelMidSpanConnectorsSize,ID
224 SelMidSpanJointSize,ID
225 SelNERManuf,ID
226 SelNERType,ID
227 SelNLinkSize,ID
228 SelPVCCondSizeLV,ID
229 SelPoleBrand,ID
230 SelPoleConcreteSize,ID
231 SelPoleSize,ID
232 SelPoleSpunConcreteSize,ID
233 SelPoleSteelSize,ID
234 SelPoleType,ID
235 SelPoleWoodSize,ID
236 SelPorcelainFuseSize,ID
237 SelRatedFaultCurrentBreaker,ID
238 SelRatedVoltageSG,ID #(not identity)
239 SelRelayType,ID # (not identity)
240 SelResistanceValue,ID
241 SelSGEquipmentType,ID # (not identity)
242 SelSGInsulationType,ID # (not identity)
243 SelSGManufacturer,ID
244 SelStayInsulatorSize,ID
245 SelSuspensionClampBrand,ID
246 SelSuspensionClampSize,ID
247 SelTSwitchType,ID
248 SelTowerType,ID
249 SelTransformerCapacity,ID
250 SelTransformerManuf,ID
251 SelTransformerType,ID #(not identity)
252 SelTypeOfArchingHorn,ID
253 SelTypeOfCable,ID #(not identity)
254 SelTypeOfConductor,ID # (not identity)
255 SelTypeOfInsulationCB,ID # (not identity)
256 SelTypeOfMidSpanJoint,ID
257 SelTypeOfSTJoint,ID
258 SelTypeSTCable,ID
259 SelUGVoltage,ID # (not identity)
260 SelVoltageInOut,ID
261 SelWireSize,ID
262 SelWireType,ID
263 SelWonpieceBrand,ID
264 #
265 # Net* tables added on 24 Oct
266 NetArchingHorn,Idx
267 NetBatteryBank,Idx # identity, FunctLocation Pri
268 NetBiMetal,Idx
269 NetBoxFuse,Idx
270 NetCable,Idx # identity, FunctLocation Pri
271 NetCapacitorBank,Idx # identity, FunctLocation Pri
272 NetCircuitBreaker,Idx # identity, FunctLocation Pri
273 NetCombineSealingChamber,Idx
274 NetCommunication,Idx
275 NetCompInfras,Idx
276 NetControl,Idx
277 NetCraddle,Idx
278 NetDeadEndClamp,Idx
279 NetEarthing,Idx
280 NetFaultIndicator,Idx
281 NetFeederPillar,Idx # identity, FunctLocation Pri
282 NetGenCable,Idx # identity , FunctLocation Not Null
283 NetGenerator,Idx
284 NetGrid,Idx
285 NetHVOverhead,Idx #identity, FunctLocation Pri
286 NetHVUnderground,Idx #identity, FunctLocation Pri
287 NetIPC,Idx
288 NetInductorBank,Idx
289 NetInsulator,Idx
290 NetJoint,Idx
291 NetJunctionBox,Idx
292 NetLVDB,Idx #identity, FunctLocation Pri
293 NetLVOverhead,Idx
294 NetLVUnderground,Idx # identity, FunctLocation Not Null
295 NetLightningArrester,Idx
296 NetLineTap,Idx
297 NetMidSpanConnectors,Idx
298 NetMidSpanJoint,Idx
299 NetNER,Idx # identity , FunctLocation Pri
300 NetOilPump,Idx
301 NetOtherComponent,Idx
302 NetPole,Idx
303 NetRMU,Idx # identity, FunctLocation Pri
304 NetStreetLight,Idx
305 NetStrucSupp,Idx
306 NetSuspensionClamp,Idx
307 NetSwitchGear,Idx # identity, FunctLocation Pri
308 NetTermination,Idx
309 NetTransition,Idx
310 NetWonpiece,Idx
311 #
312 # comment1
313 SelMVFuseType,ID
314 selFuseSize,ID
315 netRelay,Idx # identity, FunctLocation Pri
316 SysListVolt,ID
317 sysVoltLevel,ID_SVL
318 sysRestoration,ID_SRE
319 sysRepairMethod,ID_SRM # (not identity)
320 
321 sysInterruptionType,ID_SIN
322 netTransformer,Idx # identity, FunctLocation Pri
323 #
324 #
325 sysComponent,ID_SC
326 sysCodecibs #-- no idea, UpdatedOn(the only column is unique),Ermscode,Cibscode is unique but got null value
327 sysCodeno,id
328 sysProtection,ID_SP
329 sysEquipment,ID_SEQ
330 sysAddress #-- no idea, ID_SAD(might be auto gen No)
331 sysWeather,ID_SW
332 sysEnvironment,ID_SE
333 sysPhase,ID_SPH
334 sysFailureCause,ID_SFC
335 sysFailureMode,ID_SFM
336 SysSchOutageMode,ID_SSM
337 SysOutageType,ID_SOT
338 SysInstallation,ID_SI
339 SysInstallationCat,ID_SIC
340 SysInstallationType,ID_SIT
341 SysFaultCategory,ID_SF #(not identity)
342 SysResponsible,ID_SR
343 SysProtectionOperation,ID_SPO #(not identity)
344 netCodename,CodeNo #(not identity)
345 netSubstation,Idx #identity, FunctLocation Pri
346 netLvFeeder,Idx # identity, FunctLocation Pri
347 #
348 #
349 tblReport,ReportNo
350 tblRepRestoration,ID_RR
351 tblRepResdetail,ID_RRD
352 tblRepFailureMode,ID_RFM
353 tblRepFailureCause,ID_RFC
354 tblRepRepairMethod,ReportNo # (not identity)
355 tblInterruptionType,ID_TIN
356 tblProtType,ID_PT #--capital letter
357 tblRepProtection,ID_RP
358 tblRepComponent,ID_RC
359 tblRepWeather,ID_RW
360 tblRepEnvironment,ID_RE
361 tblRepSubstation,ID_RSS
362 tblInstallationType,ID_TIT
363 tblInstallationCat,ID_TIC
364 tblFailureCause,ID_TFC
365 tblFailureMode,ID_TFM
366 tblProtection,ID_TP
367 tblComponent,ID_TC
368 tblProtdetail,Id # (Id)--capital letter for I
369 tblInstallation,ID_TI
370 #
371 ";
372 
373 
374 $tables = explode("\n",$tables);
375 
377 $rep->fieldFilter = 'FieldFilter';
378 $rep->selFilter = 'SELFILTER';
379 $rep->indexFilter = 'IndexFilter';
380 
381 if (1) {
382  $rep->debug = 1;
383  $DB->debug=1;
384  $DB2->debug=1;
385 }
386 
387 # $rep->SwapDBs();
388 
389 $cnt = sizeof($tables);
390 foreach($tables as $k => $table) {
391  $pkey = '';
392  if (!ParseTable($table, $pkey)) continue;
393 
394  #######################
395 
396  $kcnt = $k+1;
397  echo "<h1>($kcnt/$cnt) $table -- $pkey</h1>\n";
398  flush();@ob_flush();
399 
400  CreateTable($rep,$table);
401 
402 
403  # COPY DATA
404 
405 
406  TableStats($rep, $table, $pkey);
407 
408  if ($table == 'JohnTest') MergeDataJohnTest($rep, $table, $pkey);
409  else CopyData($rep, $table, $pkey);
410 
411 }
412 
413 
414 if (!empty($TARR)) {
415  ksort($TARR);
416  adodb_pr($TARR);
417  asort($TARR);
418  adodb_pr($TARR);
419 }
420 
421 echo "<hr>",date('H:i:s'),": Done</hr>";
422 ?>




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.