예제 #1
0
 public function loadTable($name)
 {
     $ext = $this->checkFormat($name);
     if ($ext === "sqlite") {
         $sql = $this->io->openSqliteDatabase($name);
         if ($sql === null) {
             $this->io->writeStderr("! Cannot open database, aborting\n");
             return null;
         }
         $tab = new coopy_SqlTables($sql, $this->flags);
         return $tab;
     }
     $txt = $this->io->getContent($name);
     if ($ext === "ndjson") {
         $t = new coopy_SimpleTable(0, 0);
         $ndjson = new coopy_Ndjson($t);
         $ndjson->parse($txt);
         return $t;
     }
     if ($ext === "json" || $ext === "") {
         try {
             $json = _hx_deref(new haxe_format_JsonParser($txt))->parseRec();
             $this->format_preference = "json";
             $t1 = $this->jsonToTables($json);
             if ($t1 === null) {
                 throw new HException("JSON failed");
             }
             return $t1;
         } catch (Exception $__hx__e) {
             $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
             $e = $_ex_;
             if ($ext === "json") {
                 throw new HException($e);
             }
         }
     }
     $this->format_preference = "csv";
     $csv = new coopy_Csv($this->delim_preference);
     $output = new coopy_SimpleTable(0, 0);
     $csv->parseTable($txt, $output);
     if ($output !== null) {
         $output->trimBlank();
     }
     return $output;
 }
예제 #2
0
 public function loadTable($name)
 {
     $ext = $this->checkFormat($name);
     if ($ext === "sqlite") {
         $sql = $this->io->openSqliteDatabase($name);
         if ($sql === null) {
             $this->io->writeStderr("! Cannot open database, aborting\n");
             return null;
         }
         $helper = new coopy_SqliteHelper();
         $name1 = "";
         if ($this->flags === null || $this->flags->tables === null || $this->flags->tables->length === 0) {
             $names = $helper->getTableNames($sql);
             if ($names === null) {
                 $this->io->writeStderr("! Cannot find database tables, aborting\n");
                 return null;
             }
             if ($names->length === 0) {
                 $this->io->writeStderr("! No tables in database, aborting\n");
                 return null;
             }
             $name1 = $names[0];
         } else {
             $name1 = $this->flags->tables[0];
             if ($this->flags->tables->length > 1) {
                 $this->io->writeStderr("! Cannot compare more than one table yet\n");
             }
         }
         $tab = new coopy_SqlTable($sql, new coopy_SqlTableName($name1, null), $helper);
         $this->strategy = "sql";
         return $tab;
     }
     $txt = $this->io->getContent($name);
     if ($ext === "ndjson") {
         $t = new coopy_SimpleTable(0, 0);
         $ndjson = new coopy_Ndjson($t);
         $ndjson->parse($txt);
         return $t;
     }
     if ($ext === "json" || $ext === "") {
         try {
             $json = _hx_deref(new haxe_format_JsonParser($txt))->parseRec();
             $this->format_preference = "json";
             $t1 = coopy_Coopy::jsonToTable($json);
             if ($t1 === null) {
                 throw new HException("JSON failed");
             }
             return $t1;
         } catch (Exception $__hx__e) {
             $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
             $e = $_ex_;
             if ($ext === "json") {
                 throw new HException($e);
             }
         }
     }
     $this->format_preference = "csv";
     $csv = new coopy_Csv($this->delim_preference);
     $output = new coopy_SimpleTable(0, 0);
     $csv->parseTable($txt, $output);
     if ($output !== null) {
         $output->trimBlank();
     }
     return $output;
 }