@@ -153,7 +153,7 @@ class Converter {
153
153
/**
154
154
* @var array
155
155
*/
156
- protected $ types =array ('small ' ,'int ' ,'long ' ,'float ' ,'coord ' ,'string ' );
156
+ protected $ types =array ('small ' ,'int ' ,'long ' ,'float ' ,'double ' ,'string ' );
157
157
158
158
/**
159
159
* @var array
@@ -233,13 +233,13 @@ public function setLicense($license) {
233
233
*
234
234
* @param string $name
235
235
* @param string $file
236
- * @param bool $ignoreFirstRow
236
+ * @param bool $ignoreFirstRows
237
237
* @param string $encoding
238
238
* @param string $delimiter
239
239
* @param string $enclosure
240
240
* @param string $escape
241
241
*/
242
- public function addCSV ($ name ,$ file ,$ ignoreFirstRow =true ,$ encoding ='UTF-8 ' ,$ delimiter =', ' ,$ enclosure ='" ' ,$ escape ='\\' ) {
242
+ public function addCSV ($ name ,$ file ,$ ignoreFirstRows =true ,$ encoding ='UTF-8 ' ,$ delimiter =', ' ,$ enclosure ='" ' ,$ escape ='\\' ) {
243
243
$ this ->iterator ['csv ' ]++;
244
244
$ srcId = 'CSV # ' .$ this ->iterator ['csv ' ];
245
245
if (!is_string ($ name ) || !preg_match ('/^[a-z0-9]+$/ui ' ,$ name )) {
@@ -267,7 +267,7 @@ public function addCSV($name,$file,$ignoreFirstRow=true,$encoding='UTF-8',$delim
267
267
}
268
268
if (!empty ($ this ->errors )) return ;
269
269
$ this ->csv [$ name ]['file ' ] = $ file ;
270
- $ this ->csv [$ name ]['ignoreFirstRow ' ] = empty ($ ignoreFirstRow )?0 :1 ;
270
+ $ this ->csv [$ name ]['ignoreFirstRows ' ] = empty ($ ignoreFirstRows )?0 :( int ) $ ignoreFirstRows ;
271
271
$ this ->csv [$ name ]['encoding ' ] = $ encoding ;
272
272
$ this ->csv [$ name ]['delimiter ' ] = $ delimiter ;
273
273
$ this ->csv [$ name ]['enclosure ' ] = $ enclosure ;
@@ -381,7 +381,7 @@ public function addNetworks($csv,$ipFormat,$firstIp,$lastIp,$registers) {
381
381
*/
382
382
public function create ($ file ) {
383
383
if (true ) {
384
- $ tmpDb = $ this ->temporaryDir . DIRECTORY_SEPARATOR . 'tmp.sqlite ' ;
384
+ $ tmpDb = $ this ->temporaryDir . DIRECTORY_SEPARATOR . uniqid (). 'tmp.sqlite ' ;
385
385
try {
386
386
$ this ->pdo = new PDO ('sqlite: ' . $ tmpDb );
387
387
$ this ->pdo ->exec ('PRAGMA foreign_keys = 1;PRAGMA encoding = \'UTF-8 \'; ' );
@@ -469,16 +469,18 @@ protected function createTmpDb() {
469
469
$ sql = 'CREATE TABLE ` ' . $ table . '` ( ' . implode (', ' , $ fields ) . ', CONSTRAINT `_pk` PRIMARY KEY (`_pk`) ON CONFLICT IGNORE); ' ;
470
470
$ sql .= 'CREATE INDEX `_used` ON ` ' .$ table .'` (`_used`); ' ;
471
471
$ this ->pdo ->exec ($ sql );
472
- $ sql = 'INSERT INTO ` ' .$ table .'` ( ' . implode (', ' , $ fields ) . ') VALUES ( ' . implode (', ' , $ params ) . ') ' ;
472
+ $ sql = 'INSERT INTO ` ' .$ table .'` ( ' . implode (', ' , $ fields ) . ') VALUES ( ' . implode (', ' , $ params ) . '); ' ;
473
473
$ prepare ['insert ' ][$ table ] = $ this ->pdo ->prepare ($ sql );
474
474
$ this ->pdo ->beginTransaction ();
475
475
$ file = $ this ->csv [$ register ['csv ' ]];
476
476
$ csv = fopen ($ file ['file ' ], 'r ' );
477
477
$ rowIterator = 0 ;
478
478
if ($ csv !== false ) {
479
- if (!empty ($ file ['ignoreFirstRow ' ])) {
480
- $ row = fgetcsv ($ csv , 4096 , $ file ['delimiter ' ], $ file ['enclosure ' ], $ file ['escape ' ]);
481
- unset($ row );
479
+ if (!empty ($ file ['ignoreFirstRows ' ])) {
480
+ for ($ ignore =0 ; $ ignore < $ file ['ignoreFirstRows ' ]; $ ignore ++) {
481
+ $ row = fgetcsv ($ csv , 4096 , $ file ['delimiter ' ], $ file ['enclosure ' ], $ file ['escape ' ]);
482
+ unset($ row );
483
+ }
482
484
}
483
485
while ($ row = fgetcsv ($ csv , 4096 , $ file ['delimiter ' ], $ file ['enclosure ' ], $ file ['escape ' ])) {
484
486
$ rowIterator ++;
@@ -519,9 +521,11 @@ protected function createTmpDb() {
519
521
$ file = $ this ->csv [$ network ['csv ' ]];
520
522
$ csv = fopen ($ file ['file ' ], 'r ' );
521
523
if ($ csv !== false ) {
522
- if (!empty ($ file ['ignoreFirstRow ' ])) {
523
- $ row = fgetcsv ($ csv , 4096 , $ file ['delimiter ' ], $ file ['enclosure ' ], $ file ['escape ' ]);
524
- unset($ row );
524
+ if (!empty ($ file ['ignoreFirstRows ' ])) {
525
+ for ($ ignore =0 ; $ ignore < $ file ['ignoreFirstRows ' ]; $ ignore ++) {
526
+ $ row = fgetcsv ($ csv , 4096 , $ file ['delimiter ' ], $ file ['enclosure ' ], $ file ['escape ' ]);
527
+ unset($ row );
528
+ }
525
529
}
526
530
$ this ->pdo ->beginTransaction ();
527
531
while ($ row = fgetcsv ($ csv , 4096 , $ file ['delimiter ' ], $ file ['enclosure ' ], $ file ['escape ' ])) {
@@ -625,23 +629,21 @@ protected function createTmpRegisters() {
625
629
$ format ['pack ' ][] = 'f ' ;
626
630
$ format ['unpack ' ][] = 'f ' .$ f ;
627
631
break ;
628
- case 'coord ' :
629
- $ format ['pack ' ][] = 'f ' ;
630
- $ format ['unpack ' ][] = 'f ' .$ f ;
632
+ case 'double ' :
633
+ $ format ['pack ' ][] = 'd ' ;
634
+ $ format ['unpack ' ][] = 'd ' .$ f ;
631
635
break ;
632
636
}
633
637
}
634
638
$ pack = implode ('' ,$ format ['pack ' ]);
635
639
$ bin = self ::packArray ($ pack ,$ empty );
636
640
$ this ->meta ['registers ' ][$ table ]['pack ' ] = implode ('/ ' ,$ format ['unpack ' ]);
637
- $ this ->meta ['registers ' ][$ table ]['items ' ] = 0 ;
638
641
$ this ->meta ['registers ' ][$ table ]['len ' ] = strlen ($ bin );
639
642
$ tmpFile = fopen ($ files [$ table ],'w ' );
640
643
$ data = $ this ->pdo ->query ('SELECT ' .implode (', ' ,$ fields ).' FROM ` ' .$ table .'` WHERE `_used` = \'1 \'' );
641
644
fwrite ($ tmpFile ,$ bin );
642
645
$ this ->pdo ->beginTransaction ();
643
646
while ($ row = $ data ->fetch ()) {
644
- $ this ->meta ['registers ' ][$ table ]['items ' ] ++;
645
647
$ rowId = $ row ['_pk ' ];
646
648
unset($ row ['_pk ' ]);
647
649
$ check = 0 ;
@@ -655,6 +657,7 @@ protected function createTmpRegisters() {
655
657
}
656
658
$ this ->pdo ->exec ('UPDATE `_ips` SET `offset` = \'' .($ check ?$ offset :0 ).'\' WHERE `parameter` = \'' .$ table .'\' AND `value`= \'' .$ rowId .'\'; ' );
657
659
}
660
+ $ this ->meta ['registers ' ][$ table ]['items ' ] = $ offset ;
658
661
$ this ->pdo ->commit ();
659
662
fclose ($ tmpFile );
660
663
}
0 commit comments