[geeklog-cvs] geeklog: Some Postgres improvements, committed on behalf of Stan
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sun Mar 21 15:58:23 EDT 2010
changeset 7823:553b381de147
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/553b381de147
user: Dirk Haun <dirk at haun-online.de>
date: Sun Mar 21 20:58:16 2010 +0100
description:
Some Postgres improvements, committed on behalf of Stan
diffstat:
public_html/usersettings.php | 4 +-
system/databases/pgsql.class.php | 74 +++++++++++++++++++++++++++++++-----
2 files changed, 65 insertions(+), 13 deletions(-)
diffs (137 lines):
diff -r 1c21fd923607 -r 553b381de147 public_html/usersettings.php
--- a/public_html/usersettings.php Sun Mar 21 20:26:33 2010 +0100
+++ b/public_html/usersettings.php Sun Mar 21 20:58:16 2010 +0100
@@ -542,13 +542,13 @@
$preferences->set_var('timezone_selector', $selection);
$preferences->set_var('lang_timezone', $LANG04[158]);
- if ($A['noicons'] == '1') {
+ if (isset ($A['noicons']) && $A['noicons'] == '1') {
$preferences->set_var ('noicons_checked', 'checked="checked"');
} else {
$preferences->set_var ('noicons_checked', '');
}
- if ($A['noboxes'] == 1) {
+ if (isset ($A['noboxes']) && $A['noboxes'] == '1') {
$preferences->set_var ('noboxes_checked', 'checked="checked"');
} else {
$preferences->set_var ('noboxes_checked', '');
diff -r 1c21fd923607 -r 553b381de147 system/databases/pgsql.class.php
--- a/system/databases/pgsql.class.php Sun Mar 21 20:26:33 2010 +0100
+++ b/system/databases/pgsql.class.php Sun Mar 21 20:58:16 2010 +0100
@@ -419,8 +419,51 @@
$key = array_search($row[0][0],$fields_array);
if($key!==FALSE) //$fields contains the primary key already
{
- $sql = "DELETE FROM $table WHERE {$row[0][0]}='{$values_array[$key]}'";
- $result = $this->dbQuery($sql);
+ $validKey=false;
+ $sql = "DELETE FROM $table WHERE ";
+ if(strlen($values_array[$key])>0 && $values_array[$key]!='UNIX_TIMESTAMP()')
+ {
+ $sql.="{$row[0][0]}={$values_array[$key]} AND ";
+ $validKey = true;
+ }
+ $fieldno = count($fields_array);
+ if($fieldno>1)
+ {
+ for($i=0;$i<$fieldno;$i++)
+ {
+ if($fields_array[$i]!=$fields_array[$key] && strlen($values_array[$i])>0 && $values_array[$i] !='-')
+ {
+ if($values_array[$i]== "'0000-00-00 00:00:00'" || $values_array[$i]=="'-'"
+ || $fields_array[$i]=='maxstories' || $fields_array[$i]=='commentorder'
+ || $values_array[$i]=='NOW()' || $values_array[$i]=='UNIX_TIMESTAMP()'
+ || strlen($values_array[$i])==0) //annoying things
+ $n = 'NULL';
+ else if($values_array[$i][0]=="'")
+ {
+ $sql.=$fields_array[$i]." = ".$values_array[$i];
+ if($i!=$fieldno-1)
+ $sql.=' AND ';
+ }
+
+ else if($values_array[$i][0]==" " && $values_array[$i][1]=="'") //check for whitespace in first char
+ {
+ $sql.=$fields_array[$i]." = ".substr($values_array[$i],1);
+ if($i!=$fieldno-1)
+ $sql.=' AND ';
+ }
+ else
+ {
+ $sql.=$fields_array[$i]." = '".$values_array[$i]."'";
+ if($i!=$fieldno-1)
+ $sql.=' AND ';
+ }
+ }
+ }
+ }
+ if($fieldno>0 && $validKey)
+ $result = $this->dbQuery($sql);
+
+ $sql="INSERT INTO $table($fields) VALUES($values)";
}
elseif($counter>1) //we will search for unique fields and see if they are getting duplicates
{
@@ -430,16 +473,20 @@
$key = array_search($row[$x][0],$fields_array);
if($key!==FALSE)
{
+ if(!empty($where_clause))
+ $where_clause.=' AND ';
+
$values_array[$key] = str_replace('\'','',$values_array[$key]);
- $values_array[$key] = str_replace('"','',$values_array[$key]);
- if($x==$counter-1){$where_clause .="{$row[$x][0]} ='{$values_array[$key]}'"; }
- else{$where_clause .="{$row[$x][0]} ='{$values_array[$key]}' AND ";}
+ $where_clause .="{$row[$x][0]} ='{$values_array[$key]}'";
}
}
- $sql="SELECT COUNT(*) FROM $table WHERE $where_clause";
+ echo $sql="SELECT COUNT(*) FROM $table WHERE $where_clause";
$result = $this->dbQuery($sql);
$row2 = pg_fetch_row($result);
- if($row2[0]!=0){$sql = "DELETE FROM $table WHERE $where_clause'";}
+ if($row2[0]!=0){
+ $sql = "DELETE FROM $table WHERE $where_clause";
+ $result = $this->dbQuery($sql);
+ }
$sql="INSERT INTO $table ($fields) VALUES ($values)";
}
@@ -450,7 +497,7 @@
}
else //no keys to worry about
{
- $sql="INSERT INTO $table ($fields) VALUES ($values)";
+ $sql="INSERT INTO $table ($fields) VALUES ($values)";
}
}
@@ -489,9 +536,15 @@
$sql .= ' WHERE ';
for ($i = 1; $i <= $num_ids; $i++) {
if ($i == $num_ids) {
- $sql .= current($id) . " = '" . current($value) . "'";
+ if($value[0]=="'")
+ $sql .= current($id) . " = " . current($value);
+ else
+ $sql .= current($id) . " = '" . current($value) . "'";
} else {
- $sql .= current($id) . " = '" . current($value) . "' AND ";
+ if($value[0]=="'")
+ $sql .= current($id) . " = " . current($value) . " AND ";
+ else
+ $sql .= current($id) . " = '" . current($value) . "' AND ";
}
next($id);
next($value);
@@ -507,7 +560,6 @@
$sql .= " WHERE $id = '$value'";
}
}
-
$this->dbQuery($sql);
if ($this->isVerbose()) {
More information about the geeklog-cvs
mailing list