}
}
- #try {
- #foreach ($this->sql_pre() as $s) { $this->conn->exec($s); }
$this->method('connect');
- #} catch (PDOException $e) {
- #return false;
- #}
return true;
}
public function disconnect() {
if (empty($this->conn)) return null;
-# NB 19.12.16 foreach ((array)$this->method('sql.post') as $s) {
-# NB 19.12.16 $r = $this->conn->exec($s);
-# NB 19.12.16 }
$this->method('disconnect');
-# NB 09.09.16 return $this->conn->close();
}
function exec($sql) {
return str_replace(array_keys($replace),array_values($replace),$value);
}
-# NB 04.04.17 public function method($key=null,$args=null) {
public function method($key=null) {
$method = $this->conf_type($key);
if (is_callable($method)) return $this->unvar($method($this));
'format' => 'sql',
'db_type_from' => $type_from,
];
- # NB 10.01.18: Just create problems ! should be used ony for CREATE sql
-# NB 10.01.18 if ($fct = $this->conf_type('table.sql.create')) {
-# NB 10.01.18 $row_opt['fct'] = $fct;
-# NB 10.01.18 }
# SQL_PRE
- $i = 0; foreach ($this->sql_pre() as $s) {
- if (($i++) == 0) echo "\n-- SQL_PRE\n";
- echo rtrim($s,';').";\n";
- }
- $i = 0; foreach ((array)$this->method('sql.pre') as $s) {
+ $i = 0; foreach ((array)$this->method('schema.pre') as $s) {
if (($i++) == 0) echo "\n-- SQL.PRE\n";
echo rtrim($s,';').";\n";
}
$create = rtrim($t->create(false),';');
$create = str_replace(';CREATE',";\nCREATE",$create);
- if (!($drop = $t->unvar($this->method('sql.drop')))) $drop =
+ if (!($drop = $this->method('sql.drop'))) $drop =
'DROP '.strtoupper($t->type).' IF EXISTS '.$t->sql_name()
;
# INSERT
if ($insert and $t->type == 'table') {
-# NB 04.12.17: Use instead "cleaner" option db_type_from
-# NB 04.12.17 if ($type_from) $this->type = $type_from;
$o = $row_opt;
$t->rows($o);
-# NB 04.12.17 if ($type_to) $this->type = $type_to;
}
}
- $i = 0; foreach ((array)$this->method('sql.post') as $s) {
+ $i = 0; foreach ((array)$this->method('schema.post') as $s) {
if (($i++) == 0) echo "\n-- SQL.POST\n";
echo rtrim($s,';').";\n";
}
public function sql_pre() {
$return = [];
+ foreach ((array)$this->conf_type('sql_pre') as $s) {
+ if (!empty($s)) $return[] = $s;
+ }
+
if (!empty($this->sql_pre)) {
foreach ((array)$this->sql_pre as $s) {
if (!empty($s)) $return[] = $s;
}
}
- foreach ((array)$this->conf_type('sql_pre') as $s) {
+ return $return;
+ }
+
+ public function sql_post() {
+ $return = [];
+
+ foreach ((array)$this->conf_type('sql_post') as $s) {
if (!empty($s)) $return[] = $s;
}
+ if (!empty($this->sql_post)) {
+ foreach ((array)$this->sql_post as $s) {
+ if (!empty($s)) $return[] = $s;
+ }
+ }
+
return $return;
}
<?php
$DB_TYPES['pgsql'] = array (
-'sql.pre' => [
+'schema.pre' => [
'BEGIN TRANSACTION',
],
-'sql.post' => [
+'schema.post' => [
'COMMIT',
],
+'sql.drop' => 'DROP <T.TYPE> IF EXISTS "<T.NAME>" CASCADE',
'delete_no_limit' => true,
'replace_insert' => function(&$sql,&$table,$fields=[]) {
$keys = $table->fields_keys($others);
'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 <T.TYPE> IF EXISTS "<T.NAME>" CASCADE',
# NB 10.01.18 '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 = 'public'",
'tables' => "SELECT table_name as name,LOWER(CASE table_type WHEN 'BASE TABLE' THEN 'TABLE' ELSE table_type END) as type FROM information_schema.tables WHERE table_type in('BASE TABLE','VIEW') AND table_schema = 'public'",