From 76d477c6837818a111b234f2e6e1df0233c6bc21 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 2 Aug 2016 16:56:36 +0100 Subject: [PATCH] sql.drop --- etc/dbs/ui.php | 7 +++++++ lib/php/db.php | 9 ++++++++- lib/php/db/types/pgsql.php | 21 +++++++++++++++------ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/etc/dbs/ui.php b/etc/dbs/ui.php index ce6a69e6..26b0426b 100644 --- a/etc/dbs/ui.php +++ b/etc/dbs/ui.php @@ -165,6 +165,13 @@ $CONF['_ui'] = array( $CONF['ui'] = array( '_import' => array('_ui'), ); +$CONF['ui-pgsql'] = array( + 'host' => 'ui.semantico.net', + 'type' => 'pgsql', + 'name' => 'ui', + 'pdo' => '', + '_import' => array('_ui','_semadm'), +); $CONF['ui-mysql'] = array( 'host' => 'ui.semantico.net', 'type' => 'mysql', diff --git a/lib/php/db.php b/lib/php/db.php index 003ce194..0269eea2 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -662,7 +662,14 @@ return; $sql = rtrim($t->create(),';'); $sql = str_replace(';CREATE',";\nCREATE",$sql); - $t->sql_create = 'DROP '.strtoupper($t->type).' IF EXISTS '.$t->sql_name().';'.NB_EOL + + if ($drop = $this->type('sql.drop')) { + $drop = str_replace('',$t->name,$drop); + $drop = str_replace('',strtoupper($t->type),$drop); + } else { + $drop = 'DROP '.strtoupper($t->type).' IF EXISTS '.$t->sql_name(); + } + $t->sql_create = $drop.';'.NB_EOL .$sql.';'.NB_EOL ; diff --git a/lib/php/db/types/pgsql.php b/lib/php/db/types/pgsql.php index 44dbeaf6..1a6e31e3 100644 --- a/lib/php/db/types/pgsql.php +++ b/lib/php/db/types/pgsql.php @@ -23,18 +23,27 @@ 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', +'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')", -'create' => function(&$field) { +# NB 02.08.16 'create' => function(&$field) { +# NB 02.08.16 $r = array( +# NB 02.08.16 '/datetime/i' => 'timestamp', +# NB 02.08.16 '/float/i' => 'numeric', +# NB 02.08.16 '/ COLLATE NOCASE/i' => '', +# NB 02.08.16 ); +# NB 02.08.16 $field->type = preg_replace(array_keys($r),array_values($r),$field->type); +# NB 02.08.16 }, + +'sql.replace' => function($sql) { + $sql = preg_replace('/ESCAPE \'.*?\'/','',$sql); $r = array( '/datetime/i' => 'timestamp', + '/float\(/i' => 'numeric(', + '/\w*int\(/i' => 'numeric(', '/ COLLATE NOCASE/i' => '', ); - $field->type = preg_replace(array_keys($r),array_values($r),$field->type); -}, - -'sql.replace' => function($sql) { - $sql = preg_replace('/ESCAPE \'.*?\'/','',$sql); + $sql= preg_replace(array_keys($r),array_values($r),$sql); return $sql; }, -- 2.47.3