]> git.nbdom.net Git - nb.git/commitdiff
postgres indexes
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 9 Sep 2016 09:17:07 +0000 (11:17 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 9 Sep 2016 09:17:07 +0000 (11:17 +0200)
lib/php/db.php
lib/php/db/types/pgsql.php
lib/php/db/types/sqlite.php
lib/php/page.php

index 2bfc6531201798a71d427c6aeb0c8f4e01be2307..682d27ac5b1f1237a11c22214bcd8ba3b9642208 100644 (file)
@@ -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;
   }
 
index e5623185e7b392bd2f78ff06239ab534d0083aa5..67d12d167eaca237d37b4749e34aeb7da1ca36a8 100644 (file)
@@ -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 <TYPE> IF EXISTS "<NAME>" 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 = '<NAME>')
   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;',
index 4c4763d127932fee9cab2d29ff2bf43e31d02b5c..b67a350e7fee078cb0231396930f02561ab26702 100644 (file)
@@ -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");
index 44a4de13caa137bb40266fd5e378c71c3e85db01..3b52600b13216eaa9038252e839df4eba1cdd7a5 100644 (file)
@@ -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 .= '<meta name="viewport" content="width=device-width, initial-scale=1" />'.NB_EOL;
 
-      foreach (self::to_array($this->css) as $v) {
+      foreach ((array)($this->css) as $v) {
         $head .= '<link type="text/css" rel="stylesheet" href="' . $v . '" />'.NB_EOL;
       }
 
@@ -379,7 +375,7 @@ class Page extends nb {
         . ' --></style>' . NB_EOL
       ;
 
-      foreach ($this->to_array($this->js) as $v) {
+      foreach ((array)($this->js) as $v) {
         $head .= '<script src="' . $v . '" type="text/javascript"></script>' . 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 = '<head>'.NB_EOL.$head.'</head>'.NB_EOL;