# 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
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";
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";
}
'create' => function(&$field) {
$r = array(
'/datetime/i' => 'timestamp',
+ '/ COLLATE NOCASE/i' => '',
);
$field->type = preg_replace(array_keys($r),array_values($r),$field->type);
},
--- /dev/null
+-- 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 }