]> git.nbdom.net Git - nb.git/commitdiff
www/dbq/dbq.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 12 Dec 2017 23:13:01 +0000 (23:13 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 12 Dec 2017 23:13:01 +0000 (23:13 +0000)
etc/profile.d/nb.sh
lib/php/db.php
lib/php/db/field.php
lib/php/db/table.php
lib/php/db/types/pgsql.php
share/sql/host_info.sql
www/dbq/etc/nginx.conf

index 67da5cda54232d5c4e0588ba15b480bdf745d7b2..4dd598c98f2e2b4f10c2c00a643f1f1cfa0c828d 100644 (file)
@@ -92,10 +92,8 @@ nb_api_post() {
 
 nb_post_sys_infos() {
 (
-  sys_infos | while IFS=$'\t' read -r -a i; do
-    #eval "nb_api_post host_info \"key=${i[0]}\" \"val=${i[1]}\""
-    nb_api_post host_info "key=${i[0]}" "val=${i[1]}"
+  sys_infos | while IFS=$'\t' read -r key val; do
+    nb_api_post host_info "key=$key" "val=$val"
   done
 ) | sed 's/^/nb_post_sys_infos: /'
 }
-
index 4bbc159e76f76c82ee98f4256dab42b4ba659c9b..c3e23b04fca0a3ddca925465af42059e0483a1c8 100644 (file)
@@ -14,7 +14,7 @@ $DB_TYPES = []; # See db/types/*.php
 #$arr = ['rent'=>'Rent','nb'=>'Nb'];
 #if (!empty($argv) and $argv[1] == 'zaza') bye($arr);
 
-if (defined('PRODUCTION')) {
+if (defined('PRODUCTION') and PRODUCTION) {
   define('DB_DEFAUL_ERRMODE',PDO::ERRMODE_SILENT);
 } else {
   define('DB_DEFAUL_ERRMODE',PDO::ERRMODE_EXCEPTION);
index 4424078cac07427626a68bcb47b127ea61fb21da..e7ed0087124a3c47914ea95510cac995058b0e8a 100644 (file)
@@ -39,6 +39,11 @@ class field extends nb {
     if (is_scalar($attr)) $attr = ['name'=>$attr];
     foreach ($attr as $k => $v) { $this->$k = $v; }
     if ($this->default == "''") $this->default = '';
+# NB 12.12.17     if (strtoupper($this->default) == "NULL") $this->default = null;
+    #if (strtoupper($this->default) == "NOW()") $this->default = null;
+    if (strtoupper($this->default) == "NOW()") $this->default = date("Y-m-d H:i:s.u");
+    if (strtoupper($this->default) == "CURRENT_TIMESTAMP)") $this->default = date("Y-m-d H:i:s.u");
+    if (strtoupper($this->default) == "CURRENT_DATE)") $this->default = date("Y-m-d");
   }
 
   public function autoincrement() {
index 4abbeb2455363b5227378b636c21b79acafe8a5f..5c5b27d03965d916862bbb3f40fc049e25c808fc 100644 (file)
@@ -239,7 +239,6 @@ Class Table extends nb {
 
       // Default
       return $field->sql_name().' '.$field->type
-# NB 27.10.16         .($field->null ? ' NULL' : ' NOT NULL')
         .($field->null ? '' : ' NOT NULL')
         .($field->default !== null ? ' DEFAULT '.$field->quote($field->default,true) : '')
         .($field->key ? ' PRIMARY KEY' : '')
@@ -1645,6 +1644,7 @@ Class Table extends nb {
     $sql_names = $fields = $values = [];
 
     foreach ($this->fields() as $name => $field) {
+      #if (!isset($post[$this->field_preff.$name]) and isset($field->default)) 
       if (!isset($post[$this->field_preff.$name])) continue;
       if ($field->key and $field->autoincrement()) continue;
 
@@ -1662,7 +1662,7 @@ Class Table extends nb {
 
                if (!empty($info['sql_fct'])) {
                        $fct = $info['sql_fct'];
-                       $fct($sql,$this);
+                       $fct($sql,$this,$fields);
                }
     $info['sql'] = $sql;
 
@@ -1715,12 +1715,12 @@ Class Table extends nb {
           continue;
         }
 
-        $_value = isset($post[$this->key_preff.$name]) ? $post[$this->key_preff.$name] : null;
+# NB 12.12.17         $_value = isset($post[$this->key_preff.$name]) ? $post[$this->key_preff.$name] : null;
 
-        if ($_value) {
+        if (isset($post[$this->key_preff.$name])) {
           $fields[] = $name;
-          $fields_values[] = $value;
-          $keys_values[] = $_value;
+          $fields_values[] = $post[$this->key_preff.$name];
+          $keys_values[] = $post[$this->key_preff.$name];
 
         } else {
           $keys_values[] = $value;
index 4f423aa5107afcf6ede09c58facd278e8bda404c..d9cb1508e15fd4bb4d9c003e94401827673e82df 100644 (file)
@@ -1,11 +1,12 @@
 <?php
 $DB_TYPES['pgsql'] = array (
 'delete_no_limit' => true,
-'replace_insert' => function(&$sql,&$table) {
+'replace_insert' => function(&$sql,&$table,$fields=[]) {
        $keys = $table->fields_keys($others);
        #if ($table->p('debug')) {
-       $sql .= ' ON CONFLICT ('.join(',',array_keys($keys)).') DO UPDATE ';
-  $sql .= ' SET '   . join(',',$table->ar_map('"$a=:$a"',array_keys($others)));
+       if (!empty($fields)) $others = $fields;
+       $sql .= ' ON CONFLICT ('.join(',',array_keys($keys)).') DO UPDATE';
+  $sql .= ' SET ' . join(',',$table->ar_map('"$a=:$a"',array_keys($others)));
        #$info['debug'] = [$keys,$others];
 },
 'extra_where' => 'denorm',
index 62aeb0190766eda6e9d459a4012ad31c68a023a5..318e43a175fd2891246e98610ef07467f3cf93a4 100644 (file)
@@ -3,11 +3,12 @@ CREATE TABLE host_info (
        host VARCHAR(200),      
        key VARCHAR(100) NOT NULL,      
        val VARCHAR(500) NOT NULL,      
-       created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
-       PRIMARY KEY (host,key,created)
+       updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+       -- PRIMARY KEY (host,key,updated)
+       PRIMARY KEY (host,key)
 );
 CREATE INDEX IF NOT EXISTS host_info_host ON host_info USING btree (host);
 CREATE INDEX IF NOT EXISTS host_info_key ON host_info USING btree (key);
 CREATE INDEX IF NOT EXISTS host_info_val ON host_info USING btree (val);
-CREATE INDEX IF NOT EXISTS host_info_created ON host_info USING btree (created);
+CREATE INDEX IF NOT EXISTS host_info_updated ON host_info USING btree (updated);
 GRANT ALL ON host_info TO www;
index 67475373a298446cef7e50995a56ccdb2cd66b43..002c55bd90bc43b44da14099d5e0f5e068ed23d7 100644 (file)
@@ -39,8 +39,10 @@ location ~ /index\.php$ {
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
 
-       if ($DBQ_CONF_FILE = "") { set $DBQ_CONF_FILE $document_root/../../../etc/dbq/000-local.php; }
        fastcgi_param DBQ_TITLE $DBQ_TITLE;
+       if ($DBQ_CONF_FILE = "") { set $DBQ_CONF_FILE $document_root/../../../etc/dbq/000-local.php; }
        fastcgi_param DBQ_CONF_FILE $DBQ_CONF_FILE;
        fastcgi_param DBQ_PERM $DBQ_PERM;
+       if ($DBQ_PROD = "") { set $DBQ_PROD ""; }
+       fastcgi_param PRODUCTION $DBQ_PROD;
 }