Update of /cvsroot/php-blog/serendipity/include/db
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15298/include/db
Modified Files:
db.inc.php mysql.inc.php mysqli.inc.php postgres.inc.php
sqlite.inc.php
Log Message:
PLEASE TEST, THIS IS IMPORTANT!
* Fix CSS not visible in upgrader (there must be a cleaner way to do
this, I admit I feel bad with this solution)
* Fix SQL index key creation, the parse_sql regexp didn't catch many
lines. Create those missing SQL keys for alpha10 upgrade
* Upgrader didn't emit SQL error messages
* serendipity_db_query is now able to expect errors (like for this
alpha10 upgrade)
PLEASE TEST, THIS IS IMPORTANT!
Index: db.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/db/db.inc.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- db.inc.php 19 Nov 2004 11:05:34 -0000 1.2
+++ db.inc.php 19 Jan 2005 10:22:13 -0000 1.3
@@ -1,9 +1,11 @@
<?php # $Id$
# Copyright (c) 2003-2004, Jannis Hermanns
# All rights reserved. See LICENSE file for licensing details
-@define('S9Y_DB_INCLUDED', TRUE);
-include_once(S9Y_INCLUDE_PATH . "include/db/{$serendipity['dbType']}.inc.php");
+
+if (@include_once(S9Y_INCLUDE_PATH . "include/db/{$serendipity['dbType']}.inc.php")) {
+ @define('S9Y_DB_INCLUDED', TRUE);
+}
function serendipity_db_update($table, $keys, $values)
{
Index: mysqli.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/db/mysqli.inc.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mysqli.inc.php 9 Jan 2005 10:32:36 -0000 1.8
+++ mysqli.inc.php 19 Jan 2005 10:22:13 -0000 1.9
@@ -19,18 +19,22 @@
* array of field values if it returned a single row and $single is true
* array of array of field values if it returned row(s)
*/
-function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr=false, $assocKey=false, $assocVal=false) {
+function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
global $serendipity;
$type_map = array('assoc' => MYSQLI_ASSOC, 'num' => MYSQLI_NUM, 'both' => MYSQLI_BOTH);
- $c = mysqli_query($serendipity['dbConn'], $sql);
+ if ($expectError) {
+ $c = @mysqli_query($serendipity['dbConn'], $sql);
+ } else {
+ $c = mysqli_query($serendipity['dbConn'], $sql);
+ }
- if ( mysqli_error($serendipity['dbConn']) != '' ) {
+ if (!$expectError && mysqli_error($serendipity['dbConn']) != '') {
return mysqli_error($serendipity['dbConn']);
}
if (!$c) {
- if (!$serendipity['production']) {
+ if (!$expectError && !$serendipity['production']) {
print mysqli_error($serendipity['dbConn']);
if (function_exists('debug_backtrace') && $reportErr == true) {
highlight_string(var_export(debug_backtrace(), 1));
@@ -39,6 +43,7 @@
return false;
}
+
if ($c === true) {
return true;
}
@@ -146,7 +151,13 @@
static $replace = array('int(11) not null auto_increment', 'primary key',
'unsigned' , 'FULLTEXT', 'FULLTEXT', 'enum (\'true\', \'false\') NOT NULL default \'true\'');
- return serendipity_db_query(str_replace($search, $replace, $query));
+ $query = trim(str_replace($search, $replace, $query));
+ if ($query{0} == '@') {
+ // Errors are expected to happen (like duplicate index creation)
+ return serendipity_db_query(substr($query, 1), false, 'both', false, false, false, true);
+ } else {
+ return serendipity_db_query($query);
+ }
}
/* probes the usability of the DB during installation */
Index: mysql.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/db/mysql.inc.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mysql.inc.php 9 Jan 2005 10:32:36 -0000 1.8
+++ mysql.inc.php 19 Jan 2005 10:22:13 -0000 1.9
@@ -19,7 +19,7 @@
* array of field values if it returned a single row and $single is true
* array of array of field values if it returned row(s)
*/
-function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr=false, $assocKey=false, $assocVal=false) {
+function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
global $serendipity;
static $type_map = array(
'assoc' => MYSQL_ASSOC,
@@ -29,13 +29,18 @@
// highlight_string(var_export($sql, 1));
- $c = mysql_query($sql, $serendipity['dbConn']);
+ if ($expectError) {
+ $c = @mysql_query($sql, $serendipity['dbConn']);
+ } else {
+ $c = mysql_query($sql, $serendipity['dbConn']);
+ }
- if (mysql_error($serendipity['dbConn']) != '') {
+ if (!$expectError && mysql_error($serendipity['dbConn']) != '') {
return '<pre>' . $sql . '</pre> / ' . mysql_error($serendipity['dbConn']);
}
+
if (!$c) {
- if (!$serendipity['production']) {
+ if (!$expectError && !$serendipity['production']) {
print '<pre>' . $sql . '</pre> / ' . mysql_error($serendipity['dbConn']);
if (function_exists('debug_backtrace') && $reportErr == true) {
highlight_string(var_export(debug_backtrace(), 1));
@@ -97,7 +102,7 @@
"/^[^0-9]+([0-9]+)[^0-9]+([0-9]+)[^0-9]+([0-9]+)/",
mysql_info(),
$arr);
- // mysql_affected_rows returns 0 if rows were matched but not changed.
+ // mysql_affected_rows returns 0 if rows were matched but not changed.
// mysql_info returns rows matched AND rows changed
return $arr[2];
}
@@ -109,7 +114,7 @@
"/^[^0-9]+([0-9]+)[^0-9]+([0-9]+)[^0-9]+([0-9]+)/",
mysql_info(),
$arr);
- // mysql_affected_rows returns 0 if rows were matched but not changed.
+ // mysql_affected_rows returns 0 if rows were matched but not changed.
// mysql_info returns rows matched AND rows changed
return $arr[1];
}
@@ -150,7 +155,13 @@
static $replace = array('int(11) not null auto_increment', 'primary key',
'unsigned' , 'FULLTEXT', 'FULLTEXT', 'enum (\'true\', \'false\') NOT NULL default \'true\'');
- return serendipity_db_query(str_replace($search, $replace, $query));
+ $query = trim(str_replace($search, $replace, $query));
+ if ($query{0} == '@') {
+ // Errors are expected to happen (like duplicate index creation)
+ return serendipity_db_query(substr($query, 1), false, 'both', false, false, false, true);
+ } else {
+ return serendipity_db_query($query);
+ }
}
/* probes the usability of the DB during installation */
Index: postgres.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/db/postgres.inc.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- postgres.inc.php 9 Jan 2005 10:32:36 -0000 1.8
+++ postgres.inc.php 19 Jan 2005 10:22:13 -0000 1.9
@@ -59,14 +59,14 @@
function serendipity_db_updated_rows() {
global $serendipity;
- // it is unknown whether pg_affected_rows returns number of rows
+ // it is unknown whether pg_affected_rows returns number of rows
// UPDATED or MATCHED on an UPDATE statement.
return pg_affected_rows($serendipity['dbLastResult']);
}
function serendipity_db_matched_rows() {
global $serendipity;
- // it is unknown whether pg_affected_rows returns number of rows
+ // it is unknown whether pg_affected_rows returns number of rows
// UPDATED or MATCHED on an UPDATE statement.
return pg_affected_rows($serendipity['dbLastResult']);
}
@@ -88,7 +88,7 @@
}
}
-function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr=false, $assocKey=false, $assocVal=false) {
+function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = false, $assocKey = false, $assocVal = false, $expectError = false) {
global $serendipity;
static $type_map = array(
'assoc' => PGSQL_ASSOC,
@@ -96,14 +96,14 @@
'both' => PGSQL_BOTH
);
- if ($reportErr || !$serendipity['production']) {
+ if (!$expectError && ($reportErr || !$serendipity['production'])) {
$serendipity['dbLastResult'] = pg_query($serendipity['dbConn'], $sql);
} else {
$serendipity['dbLastResult'] = @pg_query($serendipity['dbConn'], $sql);
}
if (!$serendipity['dbLastResult']) {
- if (!$serendipity['production']) {
+ if (!$expectError && !$serendipity['production']) {
print "Error in $sql<br/>\n";
print pg_last_error($serendipity['dbConn']) . "<BR/>\n";
if (function_exists('debug_backtrace')) {
@@ -157,7 +157,13 @@
return true;
}
- return serendipity_db_query(str_replace($search, $replace, $query));
+ $query = trim(str_replace($search, $replace, $query));
+ if ($query{0} == '@') {
+ // Errors are expected to happen (like duplicate index creation)
+ return serendipity_db_query(substr($query, 1), false, 'both', false, false, false, true);
+ } else {
+ return serendipity_db_query($query);
+ }
}
function serendipity_db_probe($hash, &$errs) {
Index: sqlite.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/db/sqlite.inc.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- sqlite.inc.php 9 Jan 2005 10:32:36 -0000 1.8
+++ sqlite.inc.php 19 Jan 2005 10:22:13 -0000 1.9
@@ -58,7 +58,7 @@
// It is unknown whether sqllite returns rows MATCHED or rows UPDATED
return sqlite_changes($serendipity['dbConn']);
}
-
+
function serendipity_db_matched_rows()
{
global $serendipity;
@@ -97,7 +97,7 @@
return $row;
}
-function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr=true, $assocKey=false, $assocVal=false)
+function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = true, $assocKey = false, $assocVal = false, $expectError = false)
{
global $serendipity;
static $type_map = array(
@@ -110,14 +110,14 @@
if ($debug) $fp = @fopen('sqlite.log', 'a');
- if ($reportErr) {
+ if ($reportErr && !$expectError) {
$res = sqlite_query($sql, $serendipity['dbConn']);
} else {
$res = @sqlite_query($sql, $serendipity['dbConn']);
}
if (!$res) {
- if (!$serendipity['production']) {
+ if (!$expectError && !$serendipity['production']) {
var_dump($res);
var_dump($sql);
return "problem with query";
@@ -191,7 +191,13 @@
return true;
}
- return serendipity_db_query(str_replace($search, $replace, $query));
+ $query = trim(str_replace($search, $replace, $query));
+ if ($query{0} == '@') {
+ // Errors are expected to happen (like duplicate index creation)
+ return serendipity_db_query(substr($query, 1), false, 'both', false, false, false, true);
+ } else {
+ return serendipity_db_query($query);
+ }
}
function serendipity_db_limit($start, $offset) {
|