From: garvinhicking Date: Thu, 15 Sep 2005 10:08:57 +0000 (+0000) Subject: Fix crashing SQLite. Stupid ***$§*$"**"§$"§ X-Git-Tag: 0.9~142 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=bd83b005414340c74c2dfd0a591b169cc5d156f0;p=s9y.git Fix crashing SQLite. Stupid ***$§*$"**"§$"§ thing of a DB layer dies unexpectedly in simple WHERE x IN (...) queries. Also fix some HTTP Port issues, Cookie authentication and category ACL issues. Thanks a bunch to Mark Kubacki! --- diff --git a/include/db/mysql.inc.php b/include/db/mysql.inc.php index 51dc47b..3144143 100644 --- a/include/db/mysql.inc.php +++ b/include/db/mysql.inc.php @@ -14,6 +14,10 @@ function serendipity_db_end_transaction($commit){ } } +function serendipity_db_in_sql($col, &$search_ids) { + return $col . " IN (" . implode(', ', $search_ids) . ")"; +} + /* Issues a query to the underlying database; * returns: * false if there was an error, diff --git a/include/db/mysqli.inc.php b/include/db/mysqli.inc.php index f3549b3..e2f2441 100644 --- a/include/db/mysqli.inc.php +++ b/include/db/mysqli.inc.php @@ -14,6 +14,10 @@ function serendipity_db_end_transaction($commit){ } } +function serendipity_db_in_sql($col, &$search_ids) { + return $col . " IN (" . implode(', ', $search_ids) . ")"; +} + /* Issues a query to the underlying database; * returns: * false if there was an error, diff --git a/include/db/postgres.inc.php b/include/db/postgres.inc.php index b68fb0b..0c758f1 100644 --- a/include/db/postgres.inc.php +++ b/include/db/postgres.inc.php @@ -14,6 +14,10 @@ function serendipity_db_end_transaction($commit){ } } +function serendipity_db_in_sql($col, &$search_ids) { + return $col . " IN (" . implode(', ', $search_ids) . ")"; +} + function serendipity_db_connect() { global $serendipity; diff --git a/include/db/sqlite.inc.php b/include/db/sqlite.inc.php index 009d12f..fe3aa88 100644 --- a/include/db/sqlite.inc.php +++ b/include/db/sqlite.inc.php @@ -99,6 +99,20 @@ function serendipity_db_sqlite_fetch_array($res, $type = SQLITE_BOTH) return $row; } +function serendipity_db_in_sql($col, &$search_ids, $type = ' OR ') { + $sql = array(); + if (!is_array($search_ids)) { + return false; + } + + foreach($search_ids AS $id) { + $sql[] = $col . ' = ' . $id; + } + + $cond = '(' . implode($type, $sql) . ')'; + return $cond; +} + function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = true, $assocKey = false, $assocVal = false, $expectError = false) { global $serendipity; @@ -110,8 +124,13 @@ function &serendipity_db_query($sql, $single = false, $result_type = "both", $re static $debug = false; - if ($debug) $fp = @fopen('sqlite.log', 'a'); - + if ($debug) { + // Open file and write directly. In case of crashes, the pointer needs to be killed. + $fp = @fopen('sqlite.log', 'a'); + fwrite($fp, '[' . date('d.m.Y H:i') . '] SQLITE QUERY: ' . $sql . "\n\n"); + fclose($fp); + } + if ($reportErr && !$expectError) { $res = sqlite_query($sql, $serendipity['dbConn']); } else { @@ -124,11 +143,13 @@ function &serendipity_db_query($sql, $single = false, $result_type = "both", $re var_dump($sql); return "problem with query"; } - if ($debug) fwrite($fp, '[' . date('d.m.Y H:i') . '] [ERROR] SQLITE QUERY: ' . $sql . "\n\n"); + if ($debug) { + $fp = @fopen('sqlite.log', 'a'); + fwrite($fp, '[' . date('d.m.Y H:i') . '] [ERROR] ' . "\n\n"); + fclose($fp); + } return false; - } elseif ($debug) { - fwrite($fp, '[' . date('d.m.Y H:i') . '] SQLITE QUERY: ' . $sql . "\n\n"); } if ($res === true) { @@ -152,8 +173,11 @@ function &serendipity_db_query($sql, $single = false, $result_type = "both", $re } } - if ($debug) fwrite($fp, '[' . date('d.m.Y H:i') . '] SQLITE RESULT: ' . print_r($rows, true). "\n\n"); - if ($debug) fclose($fp); + if ($debug) { + $fp = @fopen('sqlite.log', 'a'); + fwrite($fp, '[' . date('d.m.Y H:i') . '] SQLITE RESULT: ' . print_r($rows, true). "\n\n"); + fclose($fp); + } if ($single && count($rows) == 1) { return $rows[0]; diff --git a/include/functions_config.inc.php b/include/functions_config.inc.php index 180284c..8de289d 100644 --- a/include/functions_config.inc.php +++ b/include/functions_config.inc.php @@ -219,7 +219,7 @@ function serendipity_login($use_external = true) { } } elseif ( isset($serendipity['COOKIE']['author_information']) ) { $cookie = unserialize(base64_decode($serendipity['COOKIE']['author_information'])); - if (serendipity_authenticate_author($cookie['username'], $cookie['password'], $use_external)) { + if (serendipity_authenticate_author($cookie['username'], $cookie['password'], false, $use_external)) { return true; } else { serendipity_deleteCookie('author_information'); @@ -1050,7 +1050,7 @@ function serendipity_ACL_SQL(&$cond, $append_category = false) { if (!isset($serendipity['enableACL']) || $serendipity['enableACL'] == true) { if ($_SESSION['serendipityAuthedUser'] === true) { $read_id = (int)$serendipity['authorid']; - $read_id_sql = 'acl_a.groupid'; + $read_id_sql = 'acl_a.groupid OR acl_acc.groupid = 0'; } else { // "0" as category property counts as "anonymous viewers" $read_id = 0; @@ -1084,7 +1084,7 @@ function serendipity_ACL_SQL(&$cond, $append_category = false) { // When in Admin-Mode, apply readership permissions. $cond['and'] .= " ( c.categoryid IS NULL - OR ( acl_acc.groupid = " . $read_id_sql . " ) + OR ( acl_acc.groupid = " . $read_id_sql . ") OR ( acl_acc.artifact_id IS NULL " . (isset($serendipity['GET']['adminModule']) && $serendipity['GET']['adminModule'] == 'entries' && diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php index 836b098..742ecba 100644 --- a/include/functions_entries.inc.php +++ b/include/functions_entries.inc.php @@ -270,6 +270,8 @@ function serendipity_fetchEntries($range = null, $full = true, $limit = '', $fet ORDER BY {$cond['orderby']} $limit"; + // DEBUG: + // die($query); $ret = serendipity_db_query($query); if (is_string($ret)) { @@ -305,7 +307,7 @@ function serendipity_fetchEntries($range = null, $full = true, $limit = '', $fet FROM {$serendipity['dbPrefix']}category AS c LEFT JOIN {$serendipity['dbPrefix']}entrycat AS ec ON ec.categoryid = c.categoryid - WHERE ec.entryid IN (" . implode(', ', $search_ids) . ")"; + WHERE " . serendipity_db_in_sql('ec.entryid', $search_ids); $search_ret = serendipity_db_query($query); diff --git a/serendipity_config.inc.php b/serendipity_config.inc.php index cddd680..22ffb0b 100644 --- a/serendipity_config.inc.php +++ b/serendipity_config.inc.php @@ -249,7 +249,7 @@ $serendipity['permissionLevels'] = array(USERLEVEL_EDITOR => USERLEVEL_EDITOR_DE if ( (isset($serendipity['autodetect_baseURL']) && serendipity_db_bool($serendipity['autodetect_baseURL'])) || (isset($serendipity['embed']) && serendipity_db_bool($serendipity['embed'])) ) { - $serendipity['baseURL'] = 'http' . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : '') . $serendipity['serendipityHTTPPath']; + $serendipity['baseURL'] = 'http' . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . (!strstr($_SERVER['HTTP_HOST'], ':') && !empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : '') . $serendipity['serendipityHTTPPath']; } /*