]> git.nbdom.net Git - nb.git/commitdiff
dump sql_replace per db
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Thu, 30 Jun 2016 10:29:25 +0000 (11:29 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Thu, 30 Jun 2016 10:29:25 +0000 (11:29 +0100)
etc/dbs/ui.php
lib/mysql/functions.sql
lib/php/db.php
lib/php/db/table.php
lib/php/db/types/mysql.php

index b2c4518cc13a6eba33a278983965022447c6f033..575d2a8788a89e3e62bef24f49c37baeb6790ae4 100644 (file)
@@ -3,6 +3,16 @@ $CONF['_ui'] = array(
   'title' => 'Semantico UI',
   'pdo' => 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db',
   'default_table' => 'node',
+
+  'sql_replace' => function($sql) {
+    $r = [];
+
+    $r["CAST(started as char(30)),duration||' seconds'"] = "from_unixtime(UNIX_TIMESTAMP(started)+duration)";
+
+    $sql = str_replace(array_keys($r),$r,$sql);
+    return $sql;
+  },
+
   'tables' => array(
 
     'aws_az' => array(
index 90b96a4f30dc7129d38cb220300699cfdf15dd1a..29a7d17f9e102a1a34a002925e59378607272bce 100644 (file)
@@ -1,4 +1,17 @@
 DELIMITER $$
+
+DROP FUNCTION IF EXISTS strftime$$
+CREATE FUNCTION strftime (f text,str text)
+RETURNS text DETERMINISTIC
+BEGIN
+  IF  ( f = '%s' )
+  THEN
+    RETURN UNIX_TIMESTAMP(str);
+  ELSE
+    RETURN DATE_FORMAT(str,f);
+  END IF;
+END$$
+
 DROP FUNCTION IF EXISTS to_char$$
 CREATE FUNCTION to_char (f text,s text)
 RETURNS text DETERMINISTIC
index c12a3635deb22c7bf269829ce06f9c8d68e001d9..00edc87fed96d4a3520a16126c7a7ce2fb258185 100644 (file)
@@ -631,7 +631,7 @@ class Db extends nb {
       if (!empty($name) and !preg_match('/'.$name.'/',$t->name)) continue;
 
       if ($insert) {
-        echo "\n-- Table: ".$t->name."\n";
+        echo "\n-- ".strtoupper($t->type).": ".$t->name."\n";
       }
       #echo 'DROP TABLE IF EXISTS '.$t->sql_name().';'.NB_EOL;
       echo 'DROP '.strtoupper($t->type).' IF EXISTS '.$t->sql_name().';'.NB_EOL;
index 6165a7a091a391b216c8b6e966e5979baacd1895..63855767c33b244e80c9425c2c0f3be8c4b431fd 100644 (file)
@@ -123,7 +123,9 @@ Class Table extends nb {
 
     // String replace function
     $sql_replace_fct = $this->db()->type('sql.replace',false);
-    $sql_replace = function($sql) use ($sql_replace_fct) {
+    $db_sql_replace_fct = empty($this->db()->sql_replace) ? '' : $this->db()->sql_replace;
+    $sql_replace = function($sql) use ($sql_replace_fct,$db_sql_replace_fct) {
+      if ($db_sql_replace_fct) $sql = $db_sql_replace_fct($sql);
       return $sql_replace_fct ? $sql_replace_fct($sql) : $sql;
     };
 
index 9dd85f6a77baa460e7050029701f00d4c252d6a2..27de89515e7cea2e1fed83a4868e00ff4d71583d 100644 (file)
@@ -6,7 +6,7 @@ $DB_TYPES['mysql'] = array (
 
 'exec' => [
   'SET NAMES '.str_replace('utf-8','utf8',strtolower(Db::$encoding)),
-  (Db::p('db.type') ? 'SET sql_mode=PIPES_AS_CONCAT' : null),
+  (Db::p('db.type') ? 'SET SESSION sql_mode=PIPES_AS_CONCAT' : null),
 ],
 'extra_where' => 'having',