]> git.nbdom.net Git - nb.git/commitdiff
out_sql
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 21 Mar 2016 18:50:35 +0000 (19:50 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 21 Mar 2016 18:50:35 +0000 (19:50 +0100)
lib/php/db/field.php
lib/php/db/table.php
lib/php/out.php

index 64cc34477b3b0bd789a5badd0411e0f3b66282f6..7ba2abadbc09070c0407ab811a1bc4fbfdf1e4ff 100644 (file)
@@ -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));
index e1be11844b376400d25dbc9d859aeedb86d7c34e..28e27744974b44c70f6d8ea3b9797f864874dd54 100644 (file)
@@ -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
   -----------------------------------------------------------------*/
index 201766ec2d3a7e44f6e85e5f869d00e891ca9a47..c9e175912bc1aa5311f12672c4af24dd61ded9de 100644 (file)
@@ -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;
   }