From b8c165569d10fe15d4991fda892a2ca2c11d30aa Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Fri, 9 Sep 2016 11:17:07 +0200 Subject: [PATCH] postgres indexes --- lib/php/db.php | 13 +++++++++++-- lib/php/db/types/pgsql.php | 8 +++++--- lib/php/db/types/sqlite.php | 6 +++++- lib/php/page.php | 12 ++++-------- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 2bfc6531..682d27ac 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -778,12 +778,16 @@ class Db extends nb { #return; # EXEC - $i = 0; - foreach ($this->sql_exec() as $s) { + $i = 0; foreach ($this->sql_exec() as $s) { if (($i++) == 0) echo "\n-- EXEC\n"; echo rtrim($s,';').";\n"; } + $i = 0; foreach ((array)$this->method('sql.pre') as $s) { + if (($i++) == 0) echo "\n-- SQL.PRE\n"; + echo rtrim($s,';').";\n"; + } + # DUMP foreach ($tables as $t) { @@ -796,6 +800,11 @@ class Db extends nb { } } + $i = 0; foreach ((array)$this->method('sql.post') as $s) { + if (($i++) == 0) echo "\n-- SQL.POST\n"; + echo rtrim($s,';').";\n"; + } + return true; } diff --git a/lib/php/db/types/pgsql.php b/lib/php/db/types/pgsql.php index e5623185..67d12d16 100644 --- a/lib/php/db/types/pgsql.php +++ b/lib/php/db/types/pgsql.php @@ -8,7 +8,7 @@ $DB_TYPES['pgsql'] = array ( /* 'databases' => "SELECT d.datname as 'Name', pg_catalog.pg_get_userbyid(d.datdba) as 'Owner', - pg_catalog.pg_encoding_to_char(d.encoding) as 'Encoding', + pg_catalog.pg_encoding_d.encoding) as 'Encoding', d.datcollate as 'Collate', d.datctype as 'Ctype', pg_catalog.array_to_string(d.datacl, E'\n') AS 'Access privileges', @@ -22,7 +22,7 @@ FROM pg_catalog.pg_database d JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid ORDER BY 1", */ -'databases' => 'SELECT datname as name,pg_catalog.pg_get_userbyid(datdba) as owner,pg_catalog.pg_encoding_to_char(encoding) as encoding, datcollate as "collate",datctype as "Ctype" FROM pg_catalog.pg_database', +'databases' => 'SELECT datname as name,pg_catalog.pg_get_userbyid(datdba) as owner,pg_catalog.pg_encoding_encoding) as encoding, datcollate as "collate",datctype as "Ctype" FROM pg_catalog.pg_database', 'sql.drop' => 'DROP IF EXISTS "" CASCADE', 'tables' => "SELECT table_name as name,LOWER(CASE table_type WHEN 'BASE TABLE' THEN 'TABLE' ELSE table_type END) as type,table_type FROM information_schema.tables WHERE table_type in('BASE TABLE','VIEW') AND table_schema NOT IN ('pg_catalog', 'information_schema')", @@ -52,7 +52,7 @@ ORDER BY 1", 'table.sql.index' => [ "SELECT c.relname as name - ,a.attname as field + ,array_to_string(array_agg(coalesce(a.attname,'')),',') as field ,(CASE indisunique WHEN 't' THEN 1 ELSE 0 END) as unique FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace @@ -61,9 +61,11 @@ FROM pg_catalog.pg_class c WHERE NOT indisprimary AND c.relkind IN ('i','s','') AND n.nspname !~ '^pg_toast' AND EXISTS (SELECT 1 FROM pg_catalog.pg_class c2 WHERE i.indrelid = c2.oid AND c2.relname = '') AND pg_catalog.pg_table_is_visible(c.oid) +GROUP BY i.indrelid,c.relname,indisunique ORDER BY i.indrelid " ], + 'table.fields' => array ( 'fct' => create_function('&$r',join('',array( 'if (!isset($r["pg_default"])) return;', diff --git a/lib/php/db/types/sqlite.php b/lib/php/db/types/sqlite.php index 4c4763d1..b67a350e 100644 --- a/lib/php/db/types/sqlite.php +++ b/lib/php/db/types/sqlite.php @@ -4,8 +4,12 @@ if (!class_exists('Db')) { exit; } $DB_TYPES['sqlite'] = array ( -'dump.pre' => [ +'sql.pre' => [ 'PRAGMA foreign_keys=OFF', + 'BEGIN TRANSACTION', +], +'sql.post' => [ + 'COMMIT', ], '_disconnect' => function($db) { #$table->db()->exec("COMMIT"); diff --git a/lib/php/page.php b/lib/php/page.php index 44a4de13..3b52600b 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -75,7 +75,7 @@ class Page extends nb { if ( empty($this->h1) ) $this->h1 = !empty($nav) ? join($this->sep,$nav) : $this->title; // Call - foreach ($this->to_array($this->call) as $call) { + foreach ((array)($this->call) as $call) { if (is_scalar($call)) { $this->$call(); @@ -102,10 +102,6 @@ class Page extends nb { echo $v; } - public static function to_array($v) { - return (is_array($v) ? $v : [$v]); - } - public static function title2filename($title,$content_type='') { $ext = $content_type ? self::mime2ext($content_type) : ''; $title = self::no_accent($title); @@ -369,7 +365,7 @@ class Page extends nb { $head .= ''.NB_EOL; - foreach (self::to_array($this->css) as $v) { + foreach ((array)($this->css) as $v) { $head .= ''.NB_EOL; } @@ -379,7 +375,7 @@ class Page extends nb { . ' -->' . NB_EOL ; - foreach ($this->to_array($this->js) as $v) { + foreach ((array)($this->js) as $v) { $head .= '' . NB_EOL; } if ($this->js_code) $head .= '' @@ -391,7 +387,7 @@ class Page extends nb { } - foreach ($this->to_array($this->head) as $h) $head .= $h.NB_EOL; + foreach ((array)($this->head) as $h) $head .= $h.NB_EOL; if ($head) { $head = ''.NB_EOL.$head.''.NB_EOL; -- 2.47.3