code cleanup, test for db_escape() crazyness in DB sanity check

This commit is contained in:
Andrew Dolgov 2008-11-10 06:29:19 +01:00
parent d2bf48f90a
commit f29ba1484f
12 changed files with 30 additions and 95 deletions

View File

@ -46,15 +46,7 @@
return; return;
} }
if (DB_TYPE == "pgsql") { init_connection($link);
pg_query("set client_encoding = 'UTF-8'");
pg_set_client_encoding("UNICODE");
} else {
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
db_query($link, "SET NAMES " . MYSQL_CHARSET);
// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
}
}
$op = $_REQUEST["op"]; $op = $_REQUEST["op"];

View File

@ -28,4 +28,6 @@
official site for more information."); official site for more information.");
$ERRORS[11] = "[This error is not returned by server]"; $ERRORS[11] = "[This error is not returned by server]";
$ERRORS[12] = __("SQL escaping test failed, check your database and PHP configuration");
?> ?>

View File

@ -1980,6 +1980,10 @@
} }
} }
if (db_escape_string("testTEST") != "testTEST") {
$error_code = 12;
}
error_reporting (DEFAULT_ERROR_LEVEL); error_reporting (DEFAULT_ERROR_LEVEL);
if ($error_code != 0) { if ($error_code != 0) {
@ -5843,4 +5847,16 @@
function feed_has_icon($id) { function feed_has_icon($id) {
return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0; return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0;
} }
function init_connection($link) {
if (DB_TYPE == "pgsql") {
pg_query("set client_encoding = 'UTF-8'");
pg_set_client_encoding("UNICODE");
} else {
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
db_query($link, "SET NAMES " . MYSQL_CHARSET);
// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
}
}
}
?> ?>

View File

@ -13,15 +13,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (DB_TYPE == "pgsql") { init_connection($link);
pg_query("set client_encoding = 'UTF-8'");
pg_set_client_encoding("UNICODE");
} else {
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
db_query($link, "SET NAMES " . MYSQL_CHARSET);
// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
}
}
login_sequence($link, true); login_sequence($link, true);

View File

@ -9,16 +9,8 @@
require_once "db.php"; require_once "db.php";
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (DB_TYPE == "pgsql") { init_connection($link);
pg_query($link, "set client_encoding = 'utf-8'");
pg_set_client_encoding("UNICODE");
} else {
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
db_query($link, "SET NAMES " . MYSQL_CHARSET);
// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
}
}
login_sequence($link); login_sequence($link);

View File

@ -10,16 +10,7 @@
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (DB_TYPE == "pgsql") { init_connection($link);
pg_query($link, "set client_encoding = 'utf-8'");
pg_set_client_encoding("UNICODE");
} else {
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
db_query($link, "SET NAMES " . MYSQL_CHARSET);
// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
}
}
login_sequence($link); login_sequence($link);
$owner_uid = $_SESSION["uid"]; $owner_uid = $_SESSION["uid"];

View File

@ -9,17 +9,8 @@
require_once "db.php"; require_once "db.php";
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (DB_TYPE == "pgsql") {
pg_query($link, "set client_encoding = 'utf-8'");
pg_set_client_encoding("UNICODE");
} else {
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
db_query($link, "SET NAMES " . MYSQL_CHARSET);
// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
}
}
init_connection($link);
login_sequence($link); login_sequence($link);
$owner_uid = $_SESSION["uid"]; $owner_uid = $_SESSION["uid"];

View File

@ -57,6 +57,8 @@
"Maybe another daemon is already running.\n"); "Maybe another daemon is already running.\n");
} }
// Testing database connection.
// It is unnecessary to start the fork loop if database is not ok.
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!$link) { if (!$link) {
@ -67,16 +69,6 @@
return; return;
} }
if (DB_TYPE == "pgsql") {
pg_query("set client_encoding = 'utf-8'");
pg_set_client_encoding("UNICODE");
} else {
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
db_query($link, "SET NAMES " . MYSQL_CHARSET);
// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
}
}
db_close($link); db_close($link);
$last_purge = 0; $last_purge = 0;

View File

@ -113,7 +113,6 @@
db_close($link); db_close($link);
while (true) { while (true) {
// Since sleep is interupted by SIGCHLD, we need another way to // Since sleep is interupted by SIGCHLD, we need another way to
@ -155,15 +154,7 @@
return; return;
} }
if (DB_TYPE == "pgsql") { init_connection($link);
pg_query("set client_encoding = 'utf-8'");
pg_set_client_encoding("UNICODE");
} else {
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
db_query($link, "SET NAMES " . MYSQL_CHARSET);
// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
}
}
// We disable stamp file, since it is of no use in a multiprocess update. // We disable stamp file, since it is of no use in a multiprocess update.
// not really, tho for the time being -fox // not really, tho for the time being -fox

View File

@ -54,15 +54,7 @@
return; return;
} }
if (DB_TYPE == "pgsql") { init_connection($link);
pg_query("set client_encoding = 'utf-8'");
pg_set_client_encoding("UNICODE");
} else {
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
db_query($link, "SET NAMES " . MYSQL_CHARSET);
// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
}
}
$last_purge = 0; $last_purge = 0;

View File

@ -36,15 +36,7 @@
return; return;
} }
if (DB_TYPE == "pgsql") { init_connection($link);
pg_query("set client_encoding = 'utf-8'");
pg_set_client_encoding("UNICODE");
} else {
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
db_query($link, "SET NAMES " . MYSQL_CHARSET);
// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
}
}
// Purge all posts (random 30 feeds) // Purge all posts (random 30 feeds)
global_purge_old_posts($link, true, 30); global_purge_old_posts($link, true, 30);

View File

@ -19,15 +19,7 @@
return; return;
} }
if (DB_TYPE == "pgsql") { init_connection($link);
pg_query("set client_encoding = 'utf-8'");
pg_set_client_encoding("UNICODE");
} else {
if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
db_query($link, "SET NAMES " . MYSQL_CHARSET);
// db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
}
}
function getVirtualFeeds($msg) { function getVirtualFeeds($msg) {
global $link; global $link;