From 9979c8b100bd9406132f110d554b2b63e922416a Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 5 Jul 2016 12:01:39 +0100 Subject: [PATCH] sql_exec --- etc/dbs/ui.php | 4 ++++ lib/php/db.php | 32 +++++++++++++++++++++++--------- lib/php/db/types/mysql.php | 1 - 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/etc/dbs/ui.php b/etc/dbs/ui.php index 1a07cbf0..8ede2185 100644 --- a/etc/dbs/ui.php +++ b/etc/dbs/ui.php @@ -4,6 +4,10 @@ $CONF['_ui'] = array( 'pdo' => 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db', 'default_table' => 'node', + 'sql_exec' => [ + 'SET SESSION sql_mode=PIPES_AS_CONCAT', + ], + 'sql_replace' => function($sql) { if (!Db::p('db.type')) return $sql; $r = []; diff --git a/lib/php/db.php b/lib/php/db.php index 99c5ae01..23420257 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -170,11 +170,8 @@ class Db extends nb { if (empty($this->conn)) return false; # Type queries - if ($sql = $this->type('exec')) { - if (is_scalar($sql)) $sql = array($sql); - foreach ($sql as $s) { - if (!empty($s)) $this->conn->exec($s); - } + foreach ($this->sql_exec() as $s) { + $this->conn->exec($s); } # Create functions @@ -642,10 +639,8 @@ class Db extends nb { $type = self::p('type',''); $name = self::p('name',''); - if ($sql = $this->type('exec')) { - foreach ((is_array($sql) ? $sql : array($sql)) as $sql) { - if ($sql) echo rtrim($sql,';').";\n"; - } + foreach ($this->sql_exec() as $s) { + echo rtrim($s,';').";\n"; } foreach ($tables as $t) { @@ -749,6 +744,25 @@ class Db extends nb { return $fields; } + public function sql_exec() { + $return = []; + + if ($sql = $this->type('exec')) { + if (is_scalar($sql)) $sql = array($sql); + foreach ($sql as $s) { + if (!empty($s)) $return[] = $s; + } + } + + if (!empty($this->sql_exec) and ($sql = $this->sql_exec)) { + if (is_scalar($sql)) $sql = array($sql); + foreach ($sql as $s) { + if (!empty($s)) $return[] = $s; + } + } + + return $return; + } } # < Class ?> diff --git a/lib/php/db/types/mysql.php b/lib/php/db/types/mysql.php index bb464a5c..a1d46587 100644 --- a/lib/php/db/types/mysql.php +++ b/lib/php/db/types/mysql.php @@ -13,7 +13,6 @@ $DB_TYPES['mysql'] = array ( 'SET NAMES '.str_replace('utf-8','utf8',strtolower(Db::$encoding)), ], (Db::p('db.type') ? [ - 'SET SESSION sql_mode=PIPES_AS_CONCAT', "/*!40103 SET TIME_ZONE='+00:00' */", '/*!40014 SET @@UNIQUE_CHECKS=0 */', '/*!40014 SET @@FOREIGN_KEY_CHECKS=0 */', -- 2.47.3