From: Nicolas Boisselier Date: Mon, 21 Mar 2016 18:50:35 +0000 (+0100) Subject: out_sql X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=56375abfa0fc3c634d6e5ae1ce57648448a46c4b;p=nb.git out_sql --- diff --git a/lib/php/db/field.php b/lib/php/db/field.php index 64cc3447..7ba2abad 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -99,7 +99,7 @@ class field { } // Text - if (!$this->num() or !preg_match('/^\d+(\.\d*)?$/',$v)) { # text criteria value + if (!$this->numeric() or !preg_match('/^\d+(\.\d*)?$/',$v)) { # text criteria value if (strtolower($v)=='null') $v = ''; return $this->name.' '.($not ? 'NOT ' : '').'LIKE '.$this->db()->quote(str_replace('*','%',$v)); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index e1be1184..28e27744 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -644,7 +644,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. # Use the module out when format unknow $out_conf = null; if ($this->p('out') or !preg_match('/^('.join('|', - array( 'table','div','csv','xml','json','yaml' ) + array( 'table','div','csv','xml','json','yaml','sql' ) ).')$/',$format)) { @@ -762,6 +762,28 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. return $count; } + /*----------------------------------------------------------------- + Sql + -----------------------------------------------------------------*/ + public function rows_begin_sql() { + return ''; + } + + public function rows_rec_sql(&$row) { + $values = array(); + + foreach ($row as $k=>$v) { + $f = $this->fields($k); + $values[] = $f->quote($v); + } + + return "INSERT INTO ".$this->sql_name()." (".join(',',array_keys($row)).") VALUE(".join(',',array_values($values)).");\n"; + } + + public function rows_end_sql() { + return ''; + } + /*----------------------------------------------------------------- Text -----------------------------------------------------------------*/ diff --git a/lib/php/out.php b/lib/php/out.php index 201766ec..c9e17591 100644 --- a/lib/php/out.php +++ b/lib/php/out.php @@ -54,7 +54,7 @@ class Out extends Nb { ), 'json' => array( 'enclose' => array('['.NB_EOL,NB_EOL.']'), - 'function.ext' => 'json_encode', + 'function' => 'json_encode', 'eol' => NB_EOL, 'rec' => ',', ), @@ -85,17 +85,10 @@ class Out extends Nb { public static function row($o,&$row) { - #if (isset($o['eol'])) $row = rtrim($row,$o['eol']); - #bye($o['function']); - if (isset($o['function.ext'])) { - echo $o['function.ext']($row); - return true; - } if (isset($o['function'])) { echo $o['function']($row,$o); return true; } - #if (!isset($o['sep'])) $o['sep'] = "\t"; out_csv($row,$o); out_tag($row,$o); return false; }