@@ -153,7 +153,7 @@ class Converter {
153153 /**
154154 * @var array
155155 */
156- protected $ types =array ('small ' ,'int ' ,'long ' ,'float ' ,'coord ' ,'string ' );
156+ protected $ types =array ('small ' ,'int ' ,'long ' ,'float ' ,'double ' ,'string ' );
157157
158158 /**
159159 * @var array
@@ -233,13 +233,13 @@ public function setLicense($license) {
233233 *
234234 * @param string $name
235235 * @param string $file
236- * @param bool $ignoreFirstRow
236+ * @param bool $ignoreFirstRows
237237 * @param string $encoding
238238 * @param string $delimiter
239239 * @param string $enclosure
240240 * @param string $escape
241241 */
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 ='\\' ) {
243243 $ this ->iterator ['csv ' ]++;
244244 $ srcId = 'CSV # ' .$ this ->iterator ['csv ' ];
245245 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
267267 }
268268 if (!empty ($ this ->errors )) return ;
269269 $ this ->csv [$ name ]['file ' ] = $ file ;
270- $ this ->csv [$ name ]['ignoreFirstRow ' ] = empty ($ ignoreFirstRow )?0 :1 ;
270+ $ this ->csv [$ name ]['ignoreFirstRows ' ] = empty ($ ignoreFirstRows )?0 :( int ) $ ignoreFirstRows ;
271271 $ this ->csv [$ name ]['encoding ' ] = $ encoding ;
272272 $ this ->csv [$ name ]['delimiter ' ] = $ delimiter ;
273273 $ this ->csv [$ name ]['enclosure ' ] = $ enclosure ;
@@ -381,7 +381,7 @@ public function addNetworks($csv,$ipFormat,$firstIp,$lastIp,$registers) {
381381 */
382382 public function create ($ file ) {
383383 if (true ) {
384- $ tmpDb = $ this ->temporaryDir . DIRECTORY_SEPARATOR . 'tmp.sqlite ' ;
384+ $ tmpDb = $ this ->temporaryDir . DIRECTORY_SEPARATOR . uniqid (). 'tmp.sqlite ' ;
385385 try {
386386 $ this ->pdo = new PDO ('sqlite: ' . $ tmpDb );
387387 $ this ->pdo ->exec ('PRAGMA foreign_keys = 1;PRAGMA encoding = \'UTF-8 \'; ' );
@@ -469,16 +469,18 @@ protected function createTmpDb() {
469469 $ sql = 'CREATE TABLE ` ' . $ table . '` ( ' . implode (', ' , $ fields ) . ', CONSTRAINT `_pk` PRIMARY KEY (`_pk`) ON CONFLICT IGNORE); ' ;
470470 $ sql .= 'CREATE INDEX `_used` ON ` ' .$ table .'` (`_used`); ' ;
471471 $ this ->pdo ->exec ($ sql );
472- $ sql = 'INSERT INTO ` ' .$ table .'` ( ' . implode (', ' , $ fields ) . ') VALUES ( ' . implode (', ' , $ params ) . ') ' ;
472+ $ sql = 'INSERT INTO ` ' .$ table .'` ( ' . implode (', ' , $ fields ) . ') VALUES ( ' . implode (', ' , $ params ) . '); ' ;
473473 $ prepare ['insert ' ][$ table ] = $ this ->pdo ->prepare ($ sql );
474474 $ this ->pdo ->beginTransaction ();
475475 $ file = $ this ->csv [$ register ['csv ' ]];
476476 $ csv = fopen ($ file ['file ' ], 'r ' );
477477 $ rowIterator = 0 ;
478478 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+ }
482484 }
483485 while ($ row = fgetcsv ($ csv , 4096 , $ file ['delimiter ' ], $ file ['enclosure ' ], $ file ['escape ' ])) {
484486 $ rowIterator ++;
@@ -519,9 +521,11 @@ protected function createTmpDb() {
519521 $ file = $ this ->csv [$ network ['csv ' ]];
520522 $ csv = fopen ($ file ['file ' ], 'r ' );
521523 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+ }
525529 }
526530 $ this ->pdo ->beginTransaction ();
527531 while ($ row = fgetcsv ($ csv , 4096 , $ file ['delimiter ' ], $ file ['enclosure ' ], $ file ['escape ' ])) {
@@ -625,23 +629,21 @@ protected function createTmpRegisters() {
625629 $ format ['pack ' ][] = 'f ' ;
626630 $ format ['unpack ' ][] = 'f ' .$ f ;
627631 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 ;
631635 break ;
632636 }
633637 }
634638 $ pack = implode ('' ,$ format ['pack ' ]);
635639 $ bin = self ::packArray ($ pack ,$ empty );
636640 $ this ->meta ['registers ' ][$ table ]['pack ' ] = implode ('/ ' ,$ format ['unpack ' ]);
637- $ this ->meta ['registers ' ][$ table ]['items ' ] = 0 ;
638641 $ this ->meta ['registers ' ][$ table ]['len ' ] = strlen ($ bin );
639642 $ tmpFile = fopen ($ files [$ table ],'w ' );
640643 $ data = $ this ->pdo ->query ('SELECT ' .implode (', ' ,$ fields ).' FROM ` ' .$ table .'` WHERE `_used` = \'1 \'' );
641644 fwrite ($ tmpFile ,$ bin );
642645 $ this ->pdo ->beginTransaction ();
643646 while ($ row = $ data ->fetch ()) {
644- $ this ->meta ['registers ' ][$ table ]['items ' ] ++;
645647 $ rowId = $ row ['_pk ' ];
646648 unset($ row ['_pk ' ]);
647649 $ check = 0 ;
@@ -655,6 +657,7 @@ protected function createTmpRegisters() {
655657 }
656658 $ this ->pdo ->exec ('UPDATE `_ips` SET `offset` = \'' .($ check ?$ offset :0 ).'\' WHERE `parameter` = \'' .$ table .'\' AND `value`= \'' .$ rowId .'\'; ' );
657659 }
660+ $ this ->meta ['registers ' ][$ table ]['items ' ] = $ offset ;
658661 $ this ->pdo ->commit ();
659662 fclose ($ tmpFile );
660663 }
0 commit comments