From c14b5eed754443a835d2df9fd05b99a52691a1e4 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 21 Jun 2016 10:33:07 +0100 Subject: [PATCH] psql dump --- lib/php/db.php | 20 +++++++++++++------- lib/php/db/types/pgsql.php | 1 + lib/postgres/functions.sql | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 lib/postgres/functions.sql diff --git a/lib/php/db.php b/lib/php/db.php index b584459b..12b21890 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -587,13 +587,13 @@ class Db extends nb { # Tables param filter $tables = $this->tables(); - if ($table=self::p('table')) { - $new = array(); - foreach (explode(',',$table) as $t) { - $new[$t] = $tables[$t]; - } - $tables = $new; - } +# NB 21.06.16 if ($table=self::p('table')) { +# NB 21.06.16 $new = array(); +# NB 21.06.16 foreach (explode(',',$table) as $t) { +# NB 21.06.16 $new[$t] = $tables[$t]; +# NB 21.06.16 } +# NB 21.06.16 $tables = $new; +# NB 21.06.16 } #if (NB_EOL == "\n") # Cache before changing db type @@ -615,6 +615,9 @@ class Db extends nb { echo "-- Type : ".self::p('db.type')."\n"; } + $type = self::p('type',''); + $name = self::p('name',''); + if ($sql = $this->type('exec')) { foreach ((is_array($sql) ? $sql : array($sql)) as $sql) { echo rtrim($sql,';').";\n"; @@ -623,6 +626,9 @@ class Db extends nb { foreach ($tables as $t) { if (!empty($tables) and empty($tables[$t->name])) continue; + if (!empty($type) and strpos($t->type,$type) === false) continue; + if (!empty($name) and strpos($t->name,$name) === false) continue; + if ($insert) { echo "\n-- Table: ".$t->name."\n"; } diff --git a/lib/php/db/types/pgsql.php b/lib/php/db/types/pgsql.php index bd3221c0..3be9a54e 100644 --- a/lib/php/db/types/pgsql.php +++ b/lib/php/db/types/pgsql.php @@ -9,6 +9,7 @@ $DB_TYPES['pgsql'] = array ( 'create' => function(&$field) { $r = array( '/datetime/i' => 'timestamp', + '/ COLLATE NOCASE/i' => '', ); $field->type = preg_replace(array_keys($r),array_values($r),$field->type); }, diff --git a/lib/postgres/functions.sql b/lib/postgres/functions.sql new file mode 100644 index 00000000..3dec9b36 --- /dev/null +++ b/lib/postgres/functions.sql @@ -0,0 +1,33 @@ +-- NB 21.06.16 CREATE AGGREGATE array_agg (anyelement) +-- NB 21.06.16 ( +-- NB 21.06.16 sfunc = array_append, +-- NB 21.06.16 stype = anyarray, +-- NB 21.06.16 initcond = '{}' +-- NB 21.06.16 ); + +DROP AGGREGATE IF EXISTS CONCAT(text); +CREATE AGGREGATE CONCAT( + basetype = text, + sfunc = textcat, + stype = text, + initcond = '' + +); + +CREATE OR REPLACE FUNCTION GROUP_CONCAT(anyarray, sep text DEFAULT ',', nullstr text DEFAULT '') +RETURNS text AS $$ +SELECT array_to_string( ARRAY( SELECT coalesce(v::text, $3) FROM unnest($1) g(v) ), $2 ) +$$ LANGUAGE sql; + +DROP FUNCTION IF EXISTS CIDR_RANGE(cidr text, ip text); +CREATE OR REPLACE FUNCTION CIDR_RANGE(cidr text, ip text) +RETURNS bool AS $$ +SELECT ip::inet << cidr::cidr +$$ LANGUAGE sql; + +-- NB 21.06.16 CREATE AGGREGATE GROUP_CONCAT(field,sep=',') +-- NB 21.06.16 sfunc = array_append, +-- NB 21.06.16 stype = anyarray, +-- NB 21.06.16 initcond = '{}' +-- NB 21.06.16 -- return array_to_string(array_agg(field),sep) +-- NB 21.06.16 } -- 2.47.3