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;
}
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);
}
}
init_connection($link);
$op = $_REQUEST["op"];

View file

@ -28,4 +28,6 @@
official site for more information.");
$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);
if ($error_code != 0) {
@ -5843,4 +5847,16 @@
function feed_has_icon($id) {
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);
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);
}
}
init_connection($link);
login_sequence($link, true);

View file

@ -10,15 +10,7 @@
$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);

View file

@ -10,16 +10,7 @@
$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);
$owner_uid = $_SESSION["uid"];

View file

@ -10,16 +10,7 @@
$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);
$owner_uid = $_SESSION["uid"];

View file

@ -57,6 +57,8 @@
"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);
if (!$link) {
@ -67,16 +69,6 @@
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);
$last_purge = 0;

View file

@ -113,7 +113,6 @@
db_close($link);
while (true) {
// Since sleep is interupted by SIGCHLD, we need another way to
@ -155,15 +154,7 @@
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);
}
}
init_connection($link);
// We disable stamp file, since it is of no use in a multiprocess update.
// not really, tho for the time being -fox

View file

@ -54,15 +54,7 @@
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);
}
}
init_connection($link);
$last_purge = 0;

View file

@ -36,15 +36,7 @@
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);
}
}
init_connection($link);
// Purge all posts (random 30 feeds)
global_purge_old_posts($link, true, 30);

View file

@ -19,15 +19,7 @@
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);
}
}
init_connection($link);
function getVirtualFeeds($msg) {
global $link;