22 include_once (
'Class.Application.php');
26 $usage->setDefinitionText(
"Update the SQL structure of a table of a DbObj Object");
30 return sprintf(
"Multiple values for '%s' not allowed.", $name);
32 if (strpos(
$value, DIRECTORY_SEPARATOR) !==
false) {
33 return sprintf(
"Value for '%s' must not contain directory separator chars ('%s').", $name, DIRECTORY_SEPARATOR);
41 return sprintf(
"Multiple values for '%s' not allowed.", $name);
43 if (!preg_match(
'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/',
$value)) {
44 return sprintf(
"Invalid class name '%s' for '%s'.",
$value, $name, DIRECTORY_SEPARATOR);
65 $commonColumns = array_intersect(
$o->fields, $columns);
67 $oldTableName = sprintf(
"%s_old",
$o->dbtable);
68 $sql[] = sprintf(
"ALTER TABLE public.%s RENAME TO %s", pg_escape_identifier(
$o->dbtable) , pg_escape_identifier($oldTableName));
70 $sqlCommands = explode(
";", str_replace(
"\n",
" ",
$o->sqlcreate));
71 foreach ($sqlCommands as $k => $sqlQuery) {
74 if (preg_match(
'/CREATE\s+ (?:UNIQUE\s+)? INDEX\s+ (?:CONCURRENTLY\s+)? (?:IF\s+NOT\s+EXISTS\s+)? (?P<indexName>[a-z0-9_]+)/xi', $sqlQuery, $m)) {
76 if (in_array($m[
'indexName'], $tableIndexes)) {
77 $sql[] = sprintf(
"DROP INDEX public.%s", pg_escape_identifier($m[
'indexName']));
80 if (chop($sqlQuery) !=
"")
$sql[] = $sqlQuery;
83 $sql[] = sprintf(
"INSERT INTO public.%s (%s) SELECT %s FROM public.%s", pg_escape_identifier(
$o->dbtable) , implode(
", ", array_map(
'pg_escape_identifier', $commonColumns)) , implode(
", ", array_map(
'pg_escape_identifier', $commonColumns)) , pg_escape_identifier($oldTableName));
85 $sql[] = sprintf(
"DROP TABLE public.%s", pg_escape_identifier($oldTableName));
93 print sprintf(
"Updating existing table '%s'...\n",
$o->dbtable);
94 foreach (
$sql as $k => $v) {
95 if (preg_match(
'/CREATE\s+ SEQUENCE\s+ (?:IF\s+NOT\s+EXISTS\s+)? (?P<seqName>[a-z0-9_]+)/xi', $v, $m)) {
97 print sprintf(
"[+] (%d/%d) Skipping sequence '%s'.\n", $m[
'seqName'], $k + 1, count(
$sql));
100 print sprintf(
"[+] (%d/%d) Executing SQL:\n", $k + 1, count(
$sql));
102 print "\t" . str_replace(
"\n",
"\n\t", $v) .
"\n";
108 print sprintf(
"Creating table '%s'...\n",
$o->dbtable);
if($updateExistingTable) $point
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
if($file) if($subject==""&&$file) if($subject=="") $err
Verify arguments for wsh programs.