projects
/
iserv-mod-error-reporter.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
53f4eed
)
database update: db.inc works here now, no crappy psql -c needed anymore
author
Roland Hieber
<devnull@localhost>
Mon, 8 Mar 2010 02:36:43 +0000
(
03:36
+0100)
committer
Roland Hieber
<devnull@localhost>
Mon, 8 Mar 2010 02:36:43 +0000
(
03:36
+0100)
maint/update-database.php
patch
|
blob
|
history
diff --git
a/maint/update-database.php
b/maint/update-database.php
index
2669c3f
..
b392ee5
100755
(executable)
--- a/
maint/update-database.php
+++ b/
maint/update-database.php
@@
-31,20
+31,18
@@
require_once("/usr/share/iserv/www/inc/quote.inc");
require_once("/usr/share/iserv/www/inc/db.inc");
require_once("/usr/share/iserv/www/inc/quote.inc");
require_once("/usr/share/iserv/www/inc/db.inc");
-function doSql($cmd, $quiet = false) {
- $i = 0;
- $a = array();
- $cmd = "psql -c ".qs($cmd);
- $cmd = ($quiet) ? $cmd . ">/dev/null 2>&1" : $cmd;
- exec($cmd, $a, $i);
- return ($i == 0);
+function table_exists($table) {
+ return pg_num_rows(db_query("SELECT * FROM information_schema.tables WHERE ".
+ "table_catalog = 'iserv' AND table_name = ".qdb($table).";")) > 0;
}
}
-function printSql($cmd) { echo $cmd."\n"; return doSql($cmd); }
-function tableExists($table) {
- return doSql("SELECT * FROM $table", tnue);
+function column_exists($table, $column) {
+ return table_exists($table) && pg_num_rows(db_query("SELECT * FROM ".
+ "information_schema.columns WHERE table_name = ".qdb($table)." AND ".
+ "column_name = ".qdb($column).";")) > 0;
}
}
-function columnExists($table, $col) {
- return (doSql("SELECT $col FROM $table", true) and tableExists($table));
+function print_sql($cmd) {
+ echo $cmd."\n";
+ db_query($cmd);
}
if(isset($_SERVER["REMOTE_ADDR"])) {
}
if(isset($_SERVER["REMOTE_ADDR"])) {
@@
-55,24
+53,24
@@
if(isset($_SERVER["REMOTE_ADDR"])) {
echo "updating database schema... \n";
/** table from pre-3.0 **/
echo "updating database schema... \n";
/** table from pre-3.0 **/
-if(table
Exists("errors") and !columnE
xists("errors", "pclabel")) {
- print
S
ql("ALTER TABLE errors RENAME COLUMN pc_number TO pclabel;");
+if(table
_exists("errors") and !column_e
xists("errors", "pclabel")) {
+ print
_s
ql("ALTER TABLE errors RENAME COLUMN pc_number TO pclabel;");
}
/** table from 3.0 **/
}
/** table from 3.0 **/
-if(table
Exists("errors") and !columnE
xists("errors", "pclabel")) {
- print
S
ql("INSERT INTO mod_errorreporter (er_date,er_act,er_machine,er_text,".
+if(table
_exists("errors") and !column_e
xists("errors", "pclabel")) {
+ print
_s
ql("INSERT INTO mod_errorreporter (er_date,er_act,er_machine,er_text,".
"er_comment,er_commentact,er_hidden) SELECT date,name,pclabel,text,".
"comment,commentby,hidden FROM errors;");
"er_comment,er_commentact,er_hidden) SELECT date,name,pclabel,text,".
"comment,commentby,hidden FROM errors;");
- print
S
ql("DROP TABLE errors;");
+ print
_s
ql("DROP TABLE errors;");
}
/** table from 4.0 **/
}
/** table from 4.0 **/
-if(table
E
xists("errorreports")) {
- print
S
ql("INSERT INTO mod_errorreporter (er_date,er_act,er_machine,er_text,".
+if(table
_e
xists("errorreports")) {
+ print
_s
ql("INSERT INTO mod_errorreporter (er_date,er_act,er_machine,er_text,".
"er_comment,er_commentact,er_hidden) SELECT er_date,er_act,er_machine,".
"er_text,er_comment,er_commentact,er_hidden FROM errorreports;");
"er_comment,er_commentact,er_hidden) SELECT er_date,er_act,er_machine,".
"er_text,er_comment,er_commentact,er_hidden FROM errorreports;");
- print
S
ql("DROP TABLE errorreports;");
+ print
_s
ql("DROP TABLE errorreports;");
}
echo "done.\n";
}
echo "done.\n";
This page took
0.027129 seconds
and
4
git commands to generate.