- store sql_layer directly within the layer itself

- new method sql_multi_insert to circumvent db-specific hacks
(hopefully not introduced any parsing errors)


git-svn-id: file:///svn/phpbb/trunk@6497 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2006-10-14 14:56:46 +00:00
parent 46922674ea
commit 4afaca12dc
38 changed files with 198 additions and 465 deletions

View file

@ -371,7 +371,7 @@ function mass_auth($ug_type, $forum_id, $ug_id, $acl_list, $setting)
switch ($sql_type) switch ($sql_type)
{ {
case 'insert': case 'insert':
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysql': case 'mysql':
case 'mysql4': case 'mysql4':

View file

@ -313,7 +313,7 @@ function make_post($new_topic_id, $forum_id, $user_id, $post_username, $text, $m
else else
{ {
// Rollback // Rollback
if(SQL_LAYER == "mysql") if($db->sql_layer == "mysql")
{ {
$sql = "DELETE FROM " . POSTS_TABLE . " $sql = "DELETE FROM " . POSTS_TABLE . "
WHERE post_id = $new_post_id"; WHERE post_id = $new_post_id";

View file

@ -12,7 +12,7 @@
// ------------------------------------------------------------- // -------------------------------------------------------------
define('IN_PHPBB', true); define('IN_PHPBB', true);
$phpbb_root_path = './'; $phpbb_root_path = './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1); $phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx); include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_admin.'.$phpEx); include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
@ -22,13 +22,13 @@ header('Expires: 0');
ignore_user_abort(true); ignore_user_abort(true);
// number of topics to create // number of topics to create
$num_topics = 5000000; $num_topics = 10000;
// number of topics to be generated per call // number of topics to be generated per call
$batch_size = 100000; $batch_size = 2000;
// max number of posts per topic // max number of posts per topic
$posts_per_topic = 500000; $posts_per_topic = 500;
// general vars // general vars
@ -40,7 +40,7 @@ switch ($mode)
case 'generate': case 'generate':
$user_ids = $forum_ids = $topic_rows = array(); $user_ids = $forum_ids = $topic_rows = array();
$sql = 'SELECT user_id FROM ' . USERS_TABLE; $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') OR user_id = ' . ANONYMOUS;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
@ -60,7 +60,7 @@ switch ($mode)
{ {
$db->sql_query('TRUNCATE TABLE ' . POSTS_TABLE); $db->sql_query('TRUNCATE TABLE ' . POSTS_TABLE);
$db->sql_query('TRUNCATE TABLE ' . TOPICS_TABLE); $db->sql_query('TRUNCATE TABLE ' . TOPICS_TABLE);
$db->sql_query('TRUNCATE TABLE ' . TOPICS_TABLE . '_prefetch'); // $db->sql_query('TRUNCATE TABLE ' . TOPICS_TABLE . '_prefetch');
} }
$db->sql_query('LOCK TABLES ' . POSTS_TABLE . ' WRITE, ' . TOPICS_TABLE . ' WRITE'); $db->sql_query('LOCK TABLES ' . POSTS_TABLE . ' WRITE, ' . TOPICS_TABLE . ' WRITE');
@ -86,7 +86,7 @@ switch ($mode)
$rows = array(); $rows = array();
$post_time = mt_rand(0, time()); $post_time = mt_rand(0, time());
$num_posts = mt_rand(1, $posts_per_topic); $num_posts = $posts_per_topic; //mt_rand(1, $posts_per_topic);
for ($i = 0; $i < $num_posts; ++$i) for ($i = 0; $i < $num_posts; ++$i)
{ {
$poster_id = $user_ids[array_rand($user_ids)]; $poster_id = $user_ids[array_rand($user_ids)];
@ -108,18 +108,20 @@ switch ($mode)
if ($topic_id >= $num_topics) if ($topic_id >= $num_topics)
{ {
echo '<meta http-equiv="refresh" content="0; url=fill.' . $phpEx . '?mode=sync&amp;' . time() . '">And now for something completely different...'; echo '<meta http-equiv="refresh" content="10; url=fill.' . $phpEx . '?mode=sync&amp;' . time() . '">And now for something completely different...';
$db->sql_query('ANALYZE TABLES ' . TOPICS_TABLE . ', ' . POSTS_TABLE); $db->sql_query('ANALYZE TABLES ' . TOPICS_TABLE . ', ' . POSTS_TABLE);
flush();
} }
else else
{ {
echo '<meta http-equiv="refresh" content="0; url=fill.' . $phpEx . '?start=' . $topic_id . '&amp;' . time() . '">To the next page... (' . $topic_id . '/' . $num_topics . ')'; echo '<meta http-equiv="refresh" content="10; url=fill.' . $phpEx . '?start=' . $topic_id . '&amp;' . time() . '">To the next page... (' . $topic_id . '/' . $num_topics . ')';
flush();
} }
break; break;
case 'sync': case 'sync':
error_reporting(E_ALL); /* error_reporting(E_ALL);
$sync_all = TRUE; $sync_all = TRUE;
if ($sync_all) if ($sync_all)
@ -158,8 +160,11 @@ switch ($mode)
{ {
trigger_error('Done'); trigger_error('Done');
} }
*/
} }
$db->sql_close();
function rndm_username() function rndm_username()
{ {
static $usernames; static $usernames;

View file

@ -48,7 +48,7 @@ $sql = "CREATE TABLE {$table_prefix}attachments
AND a.post_id = p.post_id"; AND a.post_id = p.post_id";
$db->sql_query($sql); $db->sql_query($sql);
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysql': case 'mysql':
case 'mysql4': case 'mysql4':

View file

@ -54,7 +54,7 @@ $sql = "CREATE TABLE {$table_prefix}posts
WHERE pt.post_id = p.post_id"; WHERE pt.post_id = p.post_id";
$db->sql_query($sql); $db->sql_query($sql);
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysql': case 'mysql':
case 'mysql4': case 'mysql4':
@ -150,7 +150,7 @@ while ($row = $db->sql_fetchrow($result))
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'oracle': case 'oracle':
$sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id

View file

@ -133,7 +133,7 @@ class acp_database
$sql_data .= "# DATE : " . gmdate("d-m-Y H:i:s", $time) . " GMT\n"; $sql_data .= "# DATE : " . gmdate("d-m-Y H:i:s", $time) . " GMT\n";
$sql_data .= "#\n"; $sql_data .= "#\n";
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'sqlite': case 'sqlite':
$sql_data .= "BEGIN TRANSACTION;\n"; $sql_data .= "BEGIN TRANSACTION;\n";
@ -151,7 +151,7 @@ class acp_database
break; break;
} }
if ($structure && SQL_LAYER == 'firebird') if ($structure && $db->sql_layer == 'firebird')
{ {
$sql = 'SELECT RDB$FUNCTION_NAME, RDB$DESCRIPTION $sql = 'SELECT RDB$FUNCTION_NAME, RDB$DESCRIPTION
FROM RDB$FUNCTIONS FROM RDB$FUNCTIONS
@ -181,7 +181,7 @@ class acp_database
// Get the table structure // Get the table structure
if ($structure) if ($structure)
{ {
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysqli': case 'mysqli':
case 'mysql4': case 'mysql4':
@ -224,27 +224,12 @@ class acp_database
} }
$sql_data .= $this->get_table_structure($table_name); $sql_data .= $this->get_table_structure($table_name);
} }
// We might wanna empty out all that junk :D
else else
{ {
switch (SQL_LAYER) // We might wanna empty out all that junk :D
{ $sql_data .= (($db->sql_layer == 'sqlite') ? 'DELETE FROM ' : 'TRUNCATE TABLE ') . $table_name . ";\n";
case 'mysqli':
case 'mysql4':
case 'mysql':
case 'mssql':
case 'mssql_odbc':
case 'oracle':
case 'postgres':
case 'firebird':
$sql_data .= 'TRUNCATE TABLE ' . $table_name . ";\n";
break;
case 'sqlite':
$sql_data .= 'DELETE FROM ' . $table_name . ";\n";
break;
}
} }
// Now write the data for the first time. :) // Now write the data for the first time. :)
if ($store == true) if ($store == true)
{ {
@ -270,7 +255,7 @@ class acp_database
{ {
$sql_data .= "\n"; $sql_data .= "\n";
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysqli': case 'mysqli':
@ -1016,7 +1001,7 @@ class acp_database
} }
} }
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'sqlite': case 'sqlite':
case 'postgres': case 'postgres':
@ -1056,7 +1041,7 @@ class acp_database
default: default:
$tables = array(); $tables = array();
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'sqlite': case 'sqlite':
$sql = "SELECT name $sql = "SELECT name
@ -1247,13 +1232,13 @@ class acp_database
remove_remarks($data); remove_remarks($data);
// SQLite gets improved performance when you shove all of these disk write queries at once :D // SQLite gets improved performance when you shove all of these disk write queries at once :D
if (SQL_LAYER == 'sqlite') if ($db->sql_layer == 'sqlite')
{ {
$db->sql_query($data); $db->sql_query($data);
} }
else else
{ {
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'firebird': case 'firebird':
$delim = ';;'; $delim = ';;';
@ -1351,7 +1336,7 @@ class acp_database
$sql_data = ''; $sql_data = '';
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysqli': case 'mysqli':
case 'mysql4': case 'mysql4':

View file

@ -210,34 +210,8 @@ class acp_forums
$db->sql_freeresult($result); $db->sql_freeresult($result);
// Now insert the data // Now insert the data
switch (SQL_LAYER) $db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary);
{ $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
case 'mysql':
case 'mysql4':
case 'mysqli':
if (sizeof($users_sql_ary))
{
$db->sql_query('INSERT INTO ' . ACL_USERS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $users_sql_ary));
}
if (sizeof($groups_sql_ary))
{
$db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $groups_sql_ary));
}
break;
default:
foreach ($users_sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . ACL_USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
foreach ($groups_sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
} }
$auth->acl_clear_prefetch(); $auth->acl_clear_prefetch();
@ -1408,7 +1382,7 @@ class acp_forums
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysql4': case 'mysql4':
case 'mysqli': case 'mysqli':

View file

@ -368,24 +368,7 @@ class acp_groups
$db->sql_freeresult($result); $db->sql_freeresult($result);
// Now insert the data // Now insert the data
if (sizeof($groups_sql_ary)) $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
{
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $groups_sql_ary));
break;
default:
foreach ($groups_sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
$auth->acl_clear_prefetch(); $auth->acl_clear_prefetch();
} }

View file

@ -311,7 +311,7 @@ class acp_icons
// The user has already selected a smilies_pak file // The user has already selected a smilies_pak file
if ($current == 'delete') if ($current == 'delete')
{ {
$db->sql_query(((SQL_LAYER != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . $table); $db->sql_query((($db->sql_layer != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . $table);
switch ($mode) switch ($mode)
{ {

View file

@ -149,7 +149,7 @@ class acp_main
break; break;
case 'db_track': case 'db_track':
$db->sql_query(((SQL_LAYER != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . TOPICS_POSTED_TABLE); $db->sql_query((($db->sql_layer != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . TOPICS_POSTED_TABLE);
// This can get really nasty... therefore we only do the last six months // This can get really nasty... therefore we only do the last six months
$get_from_time = time() - (6 * 4 * 7 * 24 * 60 * 60); $get_from_time = time() - (6 * 4 * 7 * 24 * 60 * 60);
@ -204,24 +204,7 @@ class acp_main
} }
unset($posted); unset($posted);
if (sizeof($sql_ary)) $db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
{
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary));
break;
default:
foreach ($sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
} }
add_log('admin', 'LOG_RESYNC_POST_MARKING'); add_log('admin', 'LOG_RESYNC_POST_MARKING');

View file

@ -107,7 +107,7 @@ class acp_profile
$db->sql_query('DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id"); $db->sql_query('DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id");
$db->sql_query('DELETE FROM ' . PROFILE_LANG_TABLE . " WHERE field_id = $field_id"); $db->sql_query('DELETE FROM ' . PROFILE_LANG_TABLE . " WHERE field_id = $field_id");
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'sqlite': case 'sqlite':
$sql = "SELECT sql $sql = "SELECT sql
@ -1236,7 +1236,7 @@ class acp_profile
{ {
global $db; global $db;
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysql': case 'mysql':
case 'mysql4': case 'mysql4':

View file

@ -202,7 +202,7 @@ class acp_reasons
$other_reason_id = (int) $db->sql_fetchfield('reason_id'); $other_reason_id = (int) $db->sql_fetchfield('reason_id');
$db->sql_freeresult($result); $db->sql_freeresult($result);
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
// The ugly one! // The ugly one!
case 'mysqli': case 'mysqli':

View file

@ -1040,7 +1040,7 @@ class acp_users
// Update Custom Fields // Update Custom Fields
if (sizeof($cp_data)) if (sizeof($cp_data))
{ {
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'oracle': case 'oracle':
case 'firebird': case 'firebird':
@ -1944,7 +1944,7 @@ class acp_users
FROM ' . ACL_OPTIONS_TABLE . " FROM ' . ACL_OPTIONS_TABLE . "
WHERE auth_option LIKE '%\_'"; WHERE auth_option LIKE '%\_'";
if (SQL_LAYER == 'mssql' || SQL_LAYER == 'mssql_odbc') if ($db->sql_layer == 'mssql' || $db->sql_layer == 'mssql_odbc')
{ {
$sql .= " ESCAPE '\\'"; $sql .= " ESCAPE '\\'";
} }
@ -1964,7 +1964,7 @@ class acp_users
FROM ' . ACL_OPTIONS_TABLE . " FROM ' . ACL_OPTIONS_TABLE . "
WHERE auth_option LIKE '%\_'"; WHERE auth_option LIKE '%\_'";
if (SQL_LAYER == 'mssql' || SQL_LAYER == 'mssql_odbc') if ($db->sql_layer == 'mssql' || $db->sql_layer == 'mssql_odbc')
{ {
$sql .= " ESCAPE '\\'"; $sql .= " ESCAPE '\\'";
} }

View file

@ -724,24 +724,7 @@ class auth_admin extends auth
} }
} }
if (sizeof($sql_ary)) $db->sql_multi_insert(ACL_OPTIONS_TABLE, $sql_ary);
{
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query('INSERT INTO ' . ACL_OPTIONS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary));
break;
default:
foreach ($sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . ACL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
$cache->destroy('acl_options'); $cache->destroy('acl_options');
$this->acl_clear_prefetch(); $this->acl_clear_prefetch();
@ -874,24 +857,7 @@ class auth_admin extends auth
} }
} }
if (sizeof($sql_ary)) $db->sql_multi_insert($table, $sql_ary);
{
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query("INSERT INTO $table " . $db->sql_build_array('MULTI_INSERT', $sql_ary));
break;
default:
foreach ($sql_ary as $ary)
{
$db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
if ($clear_prefetch) if ($clear_prefetch)
{ {
@ -956,21 +922,8 @@ class auth_admin extends auth
WHERE role_id = ' . $role_id; WHERE role_id = ' . $role_id;
$db->sql_query($sql); $db->sql_query($sql);
switch (SQL_LAYER) // Now insert the new values
{ $db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary);
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query('INSERT INTO ' . ACL_ROLES_DATA_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary));
break;
default:
foreach ($sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . ACL_ROLES_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
$this->acl_clear_prefetch(); $this->acl_clear_prefetch();
} }
@ -1010,7 +963,7 @@ class auth_admin extends auth
$sql = 'SELECT auth_option, auth_option_id $sql = 'SELECT auth_option, auth_option_id
FROM ' . ACL_OPTIONS_TABLE . " FROM ' . ACL_OPTIONS_TABLE . "
WHERE auth_option LIKE '" . $db->sql_escape(str_replace('_', "\_", $permission_type)) . "%'"; WHERE auth_option LIKE '" . $db->sql_escape(str_replace('_', "\_", $permission_type)) . "%'";
$sql .= (SQL_LAYER == 'mssql' || SQL_LAYER == 'mssql_odbc') ? " ESCAPE '\\'" : ''; $sql .= ($db->sql_layer == 'mssql' || $db->sql_layer == 'mssql_odbc') ? " ESCAPE '\\'" : '';
$result = $db->sql_query($sql); $result = $db->sql_query($sql);

View file

@ -802,7 +802,7 @@ class auth
if (strpos($auth_options, '_') !== false) if (strpos($auth_options, '_') !== false)
{ {
$sql_opts = "AND $key LIKE '" . $db->sql_escape(str_replace('_', "\_", $auth_options)) . "'"; $sql_opts = "AND $key LIKE '" . $db->sql_escape(str_replace('_', "\_", $auth_options)) . "'";
$sql_escape = (SQL_LAYER == 'mssql' || SQL_LAYER == 'mssql_odbc') ? " ESCAPE '\\'" : ''; $sql_escape = ($db->sql_layer == 'mssql' || $db->sql_layer == 'mssql_odbc') ? " ESCAPE '\\'" : '';
} }
else else
{ {
@ -848,7 +848,7 @@ class auth
if ($is_underline) if ($is_underline)
{ {
$sql_escape = (SQL_LAYER == 'mssql' || SQL_LAYER == 'mssql_odbc') ? " ESCAPE '\\'" : ''; $sql_escape = ($db->sql_layer == 'mssql' || $db->sql_layer == 'mssql_odbc') ? " ESCAPE '\\'" : '';
} }
} }
} }

View file

@ -266,7 +266,7 @@ class cache extends acm
{ {
global $db; global $db;
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mssql': case 'mssql':
case 'mssql_odbc': case 'mssql_odbc':

View file

@ -38,6 +38,11 @@ class dbal
// Holding the last sql query on sql error // Holding the last sql query on sql error
var $sql_error_sql = ''; var $sql_error_sql = '';
/**
* Current sql layer
*/
var $sql_layer = '';
/** /**
* Constructor * Constructor
*/ */
@ -48,6 +53,10 @@ class dbal
'normal' => 0, 'normal' => 0,
'total' => 0, 'total' => 0,
); );
// Fill default sql layer based on the class being called.
// This can be changed by the specified layer itself later if needed.
$this->sql_layer = substr(get_class($this), 5);
} }
/** /**
@ -243,6 +252,12 @@ class dbal
$ary = array(); $ary = array();
foreach ($assoc_ary as $id => $sql_ary) foreach ($assoc_ary as $id => $sql_ary)
{ {
// If by accident the sql array is only one-dimensional we build a normal insert statement
if (!is_array($sql_ary))
{
return $this->sql_build_array('INSERT', $assoc_ary);
}
$values = array(); $values = array();
foreach ($sql_ary as $key => $var) foreach ($sql_ary as $key => $var)
{ {
@ -266,6 +281,10 @@ class dbal
return $query; return $query;
} }
/**
* Build IN, NOT IN, = and <> sql comparison string.
* @access public
*/
function sql_in_set($field, $array, $negate = false) function sql_in_set($field, $array, $negate = false)
{ {
if (!sizeof($array)) if (!sizeof($array))
@ -295,6 +314,47 @@ class dbal
} }
} }
/**
* Run more than one insert statement.
*
* @param $sql_ary array multi-dimensional array holding the statement data.
* @param $table string table name to run the statements on
*
* @return bool false if no statements were executed.
* @access public
*/
function sql_multi_insert($table, &$sql_ary)
{
if (!sizeof($sql_ary))
{
return false;
}
switch ($this->sql_layer)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
case 'sqlite':
$this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('MULTI_INSERT', $sql_ary));
break;
default:
foreach ($sql_ary as $ary)
{
if (!is_array($ary))
{
return false;
}
$this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $ary));
}
break;
}
return true;
}
/** /**
* Function for validating values * Function for validating values
* @access private * @access private
@ -392,7 +452,7 @@ class dbal
if (!$this->return_on_error) if (!$this->return_on_error)
{ {
$message = '<u>SQL ERROR</u> [ ' . SQL_LAYER . ' ]<br /><br />' . $error['message'] . ' [' . $error['code'] . ']'; $message = '<u>SQL ERROR</u> [ ' . $db->sql_layer . ' ]<br /><br />' . $error['message'] . ' [' . $error['code'] . ']';
// Show complete SQL error and path to administrators only // Show complete SQL error and path to administrators only
// Additionally show complete error on installation or if extended debug mode is enabled // Additionally show complete error on installation or if extended debug mode is enabled
@ -491,7 +551,7 @@ class dbal
<br /> <br />
<p><b>Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries['normal']} queries" . (($this->num_queries['cached']) ? " + {$this->num_queries['cached']} " . (($this->num_queries['cached'] == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '</b></p> <p><b>Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries['normal']} queries" . (($this->num_queries['cached']) ? " + {$this->num_queries['cached']} " . (($this->num_queries['cached'] == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '</b></p>
<p>Time spent on ' . SQL_LAYER . ' queries: <b>' . round($this->sql_time, 5) . 's</b> | Time spent on PHP: <b>' . round($totaltime - $this->sql_time, 5) . 's</b></p> <p>Time spent on ' . $db->sql_layer . ' queries: <b>' . round($this->sql_time, 5) . 's</b> | Time spent on PHP: <b>' . round($totaltime - $this->sql_time, 5) . 's</b></p>
<br /><br /> <br /><br />
' . $this->sql_report . ' ' . $this->sql_report . '
@ -542,7 +602,7 @@ class dbal
else else
{ {
$error = $this->sql_error(); $error = $this->sql_error();
$this->sql_report .= '<b style="color: red">FAILED</b> - ' . SQL_LAYER . ' Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']); $this->sql_report .= '<b style="color: red">FAILED</b> - ' . $db->sql_layer . ' Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']);
} }
$this->sql_report .= '</p><br /><br />'; $this->sql_report .= '</p><br /><br />';

View file

@ -9,20 +9,14 @@
*/ */
/** /**
* @ignore
*/ */
if (!defined('IN_PHPBB')) if (!defined('IN_PHPBB'))
{ {
exit; exit;
} }
/** include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
* @ignore
*/
if (!defined('SQL_LAYER'))
{
define('SQL_LAYER', 'firebird');
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* Firebird/Interbase Database Abstraction Layer * Firebird/Interbase Database Abstraction Layer
@ -389,9 +383,6 @@ class dbal_firebird extends dbal
break; break;
} }
} }
} }
} // if ... define
?> ?>

View file

@ -9,20 +9,14 @@
*/ */
/** /**
* @ignore
*/ */
if (!defined('IN_PHPBB')) if (!defined('IN_PHPBB'))
{ {
exit; exit;
} }
/** include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
* @ignore
*/
if (!defined('SQL_LAYER'))
{
define('SQL_LAYER', 'mssql');
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* MSSQL Database Abstraction Layer * MSSQL Database Abstraction Layer
@ -437,9 +431,6 @@ class dbal_mssql extends dbal
break; break;
} }
} }
} }
} // if ... define
?> ?>

View file

@ -9,20 +9,14 @@
*/ */
/** /**
* @ignore
*/ */
if (!defined('IN_PHPBB')) if (!defined('IN_PHPBB'))
{ {
exit; exit;
} }
/** include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
* @ignore
*/
if (!defined('SQL_LAYER'))
{
define('SQL_LAYER', 'mssql_odbc');
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* Unified ODBC functions * Unified ODBC functions
@ -417,9 +411,6 @@ class dbal_mssql_odbc extends dbal
break; break;
} }
} }
} }
} // if ... define
?> ?>

View file

@ -9,18 +9,14 @@
*/ */
/** /**
* @ignore
*/ */
if (!defined('IN_PHPBB')) if (!defined('IN_PHPBB'))
{ {
exit; exit;
} }
/** include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
* @ignore
*/
if (!defined('SQL_LAYER'))
{
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* MySQL4 Database Abstraction Layer * MySQL4 Database Abstraction Layer
@ -57,16 +53,11 @@ class dbal_mysql extends dbal
if (version_compare($this->mysql_version, '4.1.3', '>=')) if (version_compare($this->mysql_version, '4.1.3', '>='))
{ {
define('SQL_LAYER', 'mysql4');
@mysql_query("SET NAMES 'utf8'", $this->db_connect_id); @mysql_query("SET NAMES 'utf8'", $this->db_connect_id);
} }
else if (version_compare($this->mysql_version, '4.0.0', '>=')) else if (version_compare($this->mysql_version, '4.0.0', '<'))
{ {
define('SQL_LAYER', 'mysql4'); $this->sql_layer = 'mysql';
}
else
{
define('SQL_LAYER', 'mysql');
} }
return $this->db_connect_id; return $this->db_connect_id;
@ -394,9 +385,6 @@ class dbal_mysql extends dbal
break; break;
} }
} }
} }
} // if ... define
?> ?>

View file

@ -9,20 +9,14 @@
*/ */
/** /**
* @ignore
*/ */
if (!defined('IN_PHPBB')) if (!defined('IN_PHPBB'))
{ {
exit; exit;
} }
/** include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
* @ignore
*/
if (!defined('SQL_LAYER'))
{
define('SQL_LAYER', 'mysqli');
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* MySQLi Database Abstraction Layer * MySQLi Database Abstraction Layer
@ -363,6 +357,4 @@ class dbal_mysqli extends dbal
} }
} }
} // if ... define
?> ?>

View file

@ -9,20 +9,14 @@
*/ */
/** /**
* @ignore
*/ */
if (!defined('IN_PHPBB')) if (!defined('IN_PHPBB'))
{ {
exit; exit;
} }
/** include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
* @ignore
*/
if(!defined('SQL_LAYER'))
{
define('SQL_LAYER', 'oracle');
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* Oracle Database Abstraction Layer * Oracle Database Abstraction Layer
@ -507,10 +501,6 @@ class dbal_oracle extends dbal
break; break;
} }
} }
} }
} // if ... define
?> ?>

View file

@ -9,20 +9,14 @@
*/ */
/** /**
* @ignore
*/ */
if (!defined('IN_PHPBB')) if (!defined('IN_PHPBB'))
{ {
exit; exit;
} }
/** include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
* @ignore
*/
if (!defined('SQL_LAYER'))
{
define('SQL_LAYER', 'postgres');
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* PostgreSQL Database Abstraction Layer * PostgreSQL Database Abstraction Layer
@ -414,9 +408,6 @@ class dbal_postgres extends dbal
break; break;
} }
} }
} }
} // if ... defined
?> ?>

View file

@ -9,20 +9,14 @@
*/ */
/** /**
* @ignore
*/ */
if (!defined('IN_PHPBB')) if (!defined('IN_PHPBB'))
{ {
exit; exit;
} }
/** include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
* @ignore
*/
if (!defined('SQL_LAYER'))
{
define('SQL_LAYER', 'sqlite');
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
/** /**
* Sqlite Database Abstraction Layer * Sqlite Database Abstraction Layer
@ -313,9 +307,6 @@ class dbal_sqlite extends dbal
break; break;
} }
} }
} }
} // if ... define
?> ?>

View file

@ -783,24 +783,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
); );
} }
if (sizeof($sql_ary)) $db->sql_multi_insert(FORUMS_TRACK_TABLE, $sql_ary);
{
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query('INSERT INTO ' . FORUMS_TRACK_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary));
break;
default:
foreach ($sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . FORUMS_TRACK_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
} }
} }
else if ($config['load_anon_lastread'] || $user->data['is_registered']) else if ($config['load_anon_lastread'] || $user->data['is_registered'])
@ -3010,7 +2993,7 @@ function page_header($page_title = '', $display_online_list = true)
$reading_sql = " AND s.session_page LIKE '%\_f\_={$f}x%'"; $reading_sql = " AND s.session_page LIKE '%\_f\_={$f}x%'";
// Specify escape character for MSSQL // Specify escape character for MSSQL
if (SQL_LAYER == 'mssql' || SQL_LAYER == 'mssql_odbc') if ($db->sql_layer == 'mssql' || $db->sql_layer == 'mssql_odbc')
{ {
$reading_sql .= " ESCAPE '\\'"; $reading_sql .= " ESCAPE '\\'";
} }

View file

@ -880,7 +880,7 @@ function delete_topic_shadows($max_age, $forum_id = '', $auto_sync = true)
{ {
$where = (is_array($forum_id)) ? 'AND ' . $db->sql_in_set('t.forum_id', array_map('intval', $forum_id)) : (($forum_id) ? 'AND t.forum_id = ' . (int) $forum_id : ''); $where = (is_array($forum_id)) ? 'AND ' . $db->sql_in_set('t.forum_id', array_map('intval', $forum_id)) : (($forum_id) ? 'AND t.forum_id = ' . (int) $forum_id : '');
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysql4': case 'mysql4':
case 'mysqli': case 'mysqli':
@ -971,24 +971,7 @@ function update_posted_info(&$topic_ids)
} }
unset($posted); unset($posted);
if (sizeof($sql_ary)) $db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
{
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary));
break;
default:
foreach ($sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
} }
/** /**
@ -1082,7 +1065,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
switch ($mode) switch ($mode)
{ {
case 'topic_moved': case 'topic_moved':
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysql4': case 'mysql4':
case 'mysqli': case 'mysqli':
@ -1121,7 +1104,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
break; break;
case 'topic_approved': case 'topic_approved':
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysql4': case 'mysql4':
case 'mysqli': case 'mysqli':
@ -1956,7 +1939,7 @@ function cache_moderators()
$cache->destroy('sql', MODERATOR_CACHE_TABLE); $cache->destroy('sql', MODERATOR_CACHE_TABLE);
// Clear table // Clear table
$db->sql_query(((SQL_LAYER != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . MODERATOR_CACHE_TABLE); $db->sql_query((($db->sql_layer != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . MODERATOR_CACHE_TABLE);
// We add moderators who have forum moderator permissions without an explicit ACL_NEVER setting // We add moderators who have forum moderator permissions without an explicit ACL_NEVER setting
$hold_ary = $ug_id_ary = $sql_ary = array(); $hold_ary = $ug_id_ary = $sql_ary = array();
@ -1994,7 +1977,7 @@ function cache_moderators()
AND ' . $db->sql_in_set('ug.user_id', $ug_id_ary) . " AND ' . $db->sql_in_set('ug.user_id', $ug_id_ary) . "
AND ug.user_pending = 0 AND ug.user_pending = 0
AND o.auth_option LIKE 'm\_%'" . AND o.auth_option LIKE 'm\_%'" .
((SQL_LAYER == 'mssql' || SQL_LAYER == 'mssql_odbc') ? " ESCAPE '\\'" : ''), (($db->sql_layer == 'mssql' || $db->sql_layer == 'mssql_odbc') ? " ESCAPE '\\'" : ''),
)); ));
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -2093,24 +2076,7 @@ function cache_moderators()
} }
} }
if (sizeof($sql_ary)) $db->sql_multi_insert(MODERATOR_CACHE_TABLE, $sql_ary);
{
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query('INSERT INTO ' . MODERATOR_CACHE_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary));
break;
default:
foreach ($sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . MODERATOR_CACHE_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
} }
/** /**
@ -2422,7 +2388,7 @@ function get_database_size()
$database_size = false; $database_size = false;
// This code is heavily influenced by a similar routine in phpMyAdmin 2.2.0 // This code is heavily influenced by a similar routine in phpMyAdmin 2.2.0
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysql': case 'mysql':
case 'mysql4': case 'mysql4':

View file

@ -1708,24 +1708,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
} }
} }
if (sizeof($sql_insert_ary)) $db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary);
{
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_insert_ary));
break;
default:
foreach ($sql_insert_ary as $ary)
{
$db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
if (sizeof($poll['poll_options']) < sizeof($cur_poll_options)) if (sizeof($poll['poll_options']) < sizeof($cur_poll_options))
{ {

View file

@ -1389,24 +1389,7 @@ function submit_pm($mode, $subject, &$data, $update_message, $put_in_outbox = tr
); );
} }
if (sizeof($sql_ary)) $db->sql_multi_insert(PRIVMSGS_TO_TABLE, $sql_ary);
{
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query('INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary));
break;
default:
foreach ($sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
$sql = 'UPDATE ' . USERS_TABLE . ' $sql = 'UPDATE ' . USERS_TABLE . '
SET user_new_privmsg = user_new_privmsg + 1, user_unread_privmsg = user_unread_privmsg + 1, user_last_privmsg = ' . time() . ' SET user_new_privmsg = user_new_privmsg + 1, user_unread_privmsg = user_unread_privmsg + 1, user_last_privmsg = ' . time() . '

View file

@ -808,24 +808,7 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas
); );
} }
if (sizeof($sql_ary)) $db->sql_multi_insert(BANLIST_TABLE, $sql_ary);
{
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query('INSERT INTO ' . BANLIST_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary));
break;
default:
foreach ($sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . BANLIST_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
// If we are banning we want to logout anyone matching the ban // If we are banning we want to logout anyone matching the ban
if (!$ban_exclude) if (!$ban_exclude)
@ -1719,11 +1702,11 @@ function group_user_add($group_id, $user_id_ary = false, $username_ary = false,
$add_id_ary = $update_id_ary = array(); $add_id_ary = $update_id_ary = array();
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$add_id_ary[] = $row['user_id']; $add_id_ary[] = (int) $row['user_id'];
if ($leader && !$row['group_leader']) if ($leader && !$row['group_leader'])
{ {
$update_id_ary[] = $row['user_id']; $update_id_ary[] = (int) $row['user_id'];
} }
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -1739,29 +1722,22 @@ function group_user_add($group_id, $user_id_ary = false, $username_ary = false,
$db->sql_transaction('begin'); $db->sql_transaction('begin');
// Insert the new users
if (sizeof($add_id_ary)) if (sizeof($add_id_ary))
{ {
// Insert the new users $sql_ary = array();
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
case 'sqlite':
$sql = 'INSERT INTO ' . USER_GROUP_TABLE . " (user_id, group_id, group_leader, user_pending)
VALUES " . implode(', ', preg_replace('#^([0-9]+)$#', "(\\1, $group_id, $leader, $pending)", $add_id_ary));
$db->sql_query($sql);
break;
default: foreach ($add_id_ary as $user_id)
foreach ($add_id_ary as $user_id) {
{ $sql_ary[] = array(
$sql = 'INSERT INTO ' . USER_GROUP_TABLE . " (user_id, group_id, group_leader, user_pending) 'user_id' => $user_id,
VALUES ($user_id, $group_id, $leader, $pending)"; 'group_id' => $group_id,
$db->sql_query($sql); 'group_leader' => $leader,
} 'user_pending' => $pending,
break; );
} }
$db->sql_multi_insert(USER_GROUP_TABLE, $sql_ary);
} }
if (sizeof($update_id_ary)) if (sizeof($update_id_ary))

View file

@ -1078,7 +1078,7 @@ class parse_message extends bbcode_firstpass
// NOTE: obtain_* function? chaching the table contents? // NOTE: obtain_* function? chaching the table contents?
// For now setting the ttl to 10 minutes // For now setting the ttl to 10 minutes
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mssql': case 'mssql':
case 'mssql_odbc': case 'mssql_odbc':

View file

@ -49,7 +49,7 @@ class fulltext_mysql extends search_backend
{ {
global $db, $user; global $db, $user;
if (strpos(SQL_LAYER, 'mysql') === false) if (strpos($db->sql_layer, 'mysql') === false)
{ {
return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_VERSION']; return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_VERSION'];
} }
@ -732,7 +732,7 @@ class fulltext_mysql extends search_backend
{ {
global $db; global $db;
if (strpos(SQL_LAYER, 'mysql') === false) if (strpos($db->sql_layer, 'mysql') === false)
{ {
$this->stats = array(); $this->stats = array();
return; return;

View file

@ -596,27 +596,25 @@ class fulltext_native extends search_backend
$sql = ''; $sql = '';
$sql_array_count = $sql_array; $sql_array_count = $sql_array;
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysql':
case 'mysql4': case 'mysql4':
case 'mysqli': case 'mysqli':
// 3.x does not support SQL_CALC_FOUND_ROWS // 3.x does not support SQL_CALC_FOUND_ROWS
if (SQL_LAYER != 'mysql' || $db->sql_server_info[6] != '3') $sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT'];
{ $is_mysql = true;
$sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT'];
$is_mysql = true;
// that's everything for MySQL >= 4.0 break;
break;
}
// no break for MySQL 3.x
case 'mysql':
case 'sqlite': case 'sqlite':
$sql_array_count['SELECT'] = ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id'; $sql_array_count['SELECT'] = ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id';
$sql = 'SELECT COUNT(' . (($type == 'posts') ? 'post_id' : 'topic_id') . ') as total_results $sql = 'SELECT COUNT(' . (($type == 'posts') ? 'post_id' : 'topic_id') . ') as total_results
FROM (' . $db->sql_build_query('SELECT', $sql_array_count) . ')'; FROM (' . $db->sql_build_query('SELECT', $sql_array_count) . ')';
// no break // no break
default: default:
$sql_array_count['SELECT'] = ($type == 'posts') ? 'COUNT(DISTINCT p.post_id) AS total_results' : 'COUNT(DISTINCT p.topic_id) AS total_results'; $sql_array_count['SELECT'] = ($type == 'posts') ? 'COUNT(DISTINCT p.post_id) AS total_results' : 'COUNT(DISTINCT p.topic_id) AS total_results';
$sql = (!$sql) ? $db->sql_build_query('SELECT', $sql_array_count) : $sql; $sql = (!$sql) ? $db->sql_build_query('SELECT', $sql_array_count) : $sql;
@ -798,9 +796,8 @@ class fulltext_native extends search_backend
// If the cache was completely empty count the results // If the cache was completely empty count the results
if (!$total_results) if (!$total_results)
{ {
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysql':
case 'mysql4': case 'mysql4':
case 'mysqli': case 'mysqli':
$select = 'SQL_CALC_FOUND_ROWS ' . $select; $select = 'SQL_CALC_FOUND_ROWS ' . $select;
@ -820,7 +817,7 @@ class fulltext_native extends search_backend
} }
else else
{ {
if (SQL_LAYER == 'sqlite') if ($db->sql_layer == 'sqlite')
{ {
$sql = 'SELECT COUNT(topic_id) as total_results $sql = 'SELECT COUNT(topic_id) as total_results
FROM (SELECT DISTINCT t.topic_id'; FROM (SELECT DISTINCT t.topic_id';
@ -836,7 +833,7 @@ class fulltext_native extends search_backend
$m_approve_fid_sql $m_approve_fid_sql
$sql_fora $sql_fora
AND t.topic_id = p.topic_id AND t.topic_id = p.topic_id
$sql_time" . ((SQL_LAYER == 'sqlite') ? ')' : ''); $sql_time" . (($db->sql_layer == 'sqlite') ? ')' : '');
} }
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -1086,26 +1083,16 @@ class fulltext_native extends search_backend
if (sizeof($new_words)) if (sizeof($new_words))
{ {
switch (SQL_LAYER) $sql_ary = array();
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$sql = 'INSERT INTO ' . SEARCH_WORDLIST_TABLE . " (word_text)
VALUES ('" . implode("'),('", array_map(array(&$db, 'sql_escape'), $new_words)) . "')";
$db->sql_query($sql);
break;
default: foreach ($new_words as $word)
foreach ($new_words as $word) {
{ $sql_ary[] = array('word_text' => $word);
$sql = 'INSERT INTO ' . SEARCH_WORDLIST_TABLE . " (word_text)
VALUES ('" . $db->sql_escape($word) . "')";
$db->sql_query($sql);
}
} }
$db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary);
} }
unset($new_words); unset($new_words, $sql_ary);
} }
// now update the search match table, remove links to removed words and add links to new words // now update the search match table, remove links to removed words and add links to new words
@ -1246,9 +1233,9 @@ class fulltext_native extends search_backend
{ {
global $db; global $db;
$db->sql_query(((SQL_LAYER != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . SEARCH_WORDLIST_TABLE); $db->sql_query((($db->sql_layer != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . SEARCH_WORDLIST_TABLE);
$db->sql_query(((SQL_LAYER != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . SEARCH_WORDMATCH_TABLE); $db->sql_query((($db->sql_layer != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . SEARCH_WORDMATCH_TABLE);
$db->sql_query(((SQL_LAYER != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . SEARCH_RESULTS_TABLE); $db->sql_query((($db->sql_layer != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . SEARCH_RESULTS_TABLE);
} }
/** /**

View file

@ -159,24 +159,7 @@ class ucp_zebra
); );
} }
if (sizeof($sql_ary)) $db->sql_multi_insert(ZEBRA_TABLE, $sql_ary);
{
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
case 'mysqli':
$db->sql_query('INSERT INTO ' . ZEBRA_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary));
break;
default:
foreach ($sql_ary as $ary)
{
$db->sql_query('INSERT INTO ' . ZEBRA_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
}
break;
}
}
$updated = true; $updated = true;
} }

View file

@ -304,9 +304,7 @@ $database_update_info = array(
); );
// Determine mapping database type // Determine mapping database type
$map_dbms = SQL_LAYER; switch ($db->sql_layer)
switch (SQL_LAYER)
{ {
case 'mysql': case 'mysql':
$map_dbms = 'mysql_40'; $map_dbms = 'mysql_40';
@ -321,6 +319,10 @@ switch (SQL_LAYER)
case 'mssql_odbc': case 'mssql_odbc':
$map_dbms = 'mssql'; $map_dbms = 'mssql';
break; break;
default:
$map_dbms = $db->sql_layer;
break;
} }
$error_ary = array(); $error_ary = array();
@ -356,7 +358,7 @@ $errored = false;
<br /> <br />
<p><?php echo $lang['DATABASE_TYPE']; ?> :: <strong><?php echo SQL_LAYER; ?></strong><br /> <p><?php echo $lang['DATABASE_TYPE']; ?> :: <strong><?php echo $db->sql_layer; ?></strong><br />
<?php <?php
$sql = "SELECT config_value $sql = "SELECT config_value
@ -490,9 +492,10 @@ _sql($sql, $errored, $error_ary);
// Optimize/vacuum analyze the tables where appropriate // Optimize/vacuum analyze the tables where appropriate
// this should be done for each version in future along with // this should be done for each version in future along with
// the version number update // the version number update
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mysql': case 'mysql':
case 'mysqli':
case 'mysql4': case 'mysql4':
$sql = 'OPTIMIZE TABLE ' . $table_prefix . 'auth_access, ' . $table_prefix . 'banlist, ' . $table_prefix . 'categories, ' . $table_prefix . 'config, ' . $table_prefix . 'disallow, ' . $table_prefix . 'forum_prune, ' . $table_prefix . 'forums, ' . $table_prefix . 'groups, ' . $table_prefix . 'posts, ' . $table_prefix . 'posts_text, ' . $table_prefix . 'privmsgs, ' . $table_prefix . 'privmsgs_text, ' . $table_prefix . 'ranks, ' . $table_prefix . 'search_results, ' . $table_prefix . 'search_wordlist, ' . $table_prefix . 'search_wordmatch, ' . $table_prefix . 'sessions_keys' . $table_prefix . 'smilies, ' . $table_prefix . 'themes, ' . $table_prefix . 'themes_name, ' . $table_prefix . 'topics, ' . $table_prefix . 'topics_watch, ' . $table_prefix . 'user_group, ' . $table_prefix . 'users, ' . $table_prefix . 'vote_desc, ' . $table_prefix . 'vote_results, ' . $table_prefix . 'vote_voters, ' . $table_prefix . 'words'; $sql = 'OPTIMIZE TABLE ' . $table_prefix . 'auth_access, ' . $table_prefix . 'banlist, ' . $table_prefix . 'categories, ' . $table_prefix . 'config, ' . $table_prefix . 'disallow, ' . $table_prefix . 'forum_prune, ' . $table_prefix . 'forums, ' . $table_prefix . 'groups, ' . $table_prefix . 'posts, ' . $table_prefix . 'posts_text, ' . $table_prefix . 'privmsgs, ' . $table_prefix . 'privmsgs_text, ' . $table_prefix . 'ranks, ' . $table_prefix . 'search_results, ' . $table_prefix . 'search_wordlist, ' . $table_prefix . 'search_wordmatch, ' . $table_prefix . 'sessions_keys' . $table_prefix . 'smilies, ' . $table_prefix . 'themes, ' . $table_prefix . 'themes_name, ' . $table_prefix . 'topics, ' . $table_prefix . 'topics_watch, ' . $table_prefix . 'user_group, ' . $table_prefix . 'users, ' . $table_prefix . 'vote_desc, ' . $table_prefix . 'vote_results, ' . $table_prefix . 'vote_voters, ' . $table_prefix . 'words';
_sql($sql, $errored, $error_ary); _sql($sql, $errored, $error_ary);

View file

@ -997,7 +997,7 @@ class install_install extends module
// If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;) // If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;)
if ($dbms == 'mysql') if ($dbms == 'mysql')
{ {
if (SQL_LAYER == 'mysql4' && version_compare($db->mysql_version, '4.1.3', '>=')) if ($db->sql_layer == 'mysql4' && version_compare($db->mysql_version, '4.1.3', '>='))
{ {
$this->available_dbms[$dbms]['SCHEMA'] .= '_41'; $this->available_dbms[$dbms]['SCHEMA'] .= '_41';
} }

View file

@ -970,7 +970,7 @@ $template->assign_vars(array(
); );
// Can't do comparisons w/ TEXT on MSSQL, CAST is good enough // Can't do comparisons w/ TEXT on MSSQL, CAST is good enough
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'mssql': case 'mssql':
case 'mssql_odbc': case 'mssql_odbc':

View file

@ -87,7 +87,7 @@ $guest_counter = 0;
// Get number of online guests (if we do not display them) // Get number of online guests (if we do not display them)
if (!$show_guests) if (!$show_guests)
{ {
switch (SQL_LAYER) switch ($db->sql_layer)
{ {
case 'sqlite': case 'sqlite':
$sql = 'SELECT COUNT(session_ip) as num_guests $sql = 'SELECT COUNT(session_ip) as num_guests
@ -104,6 +104,7 @@ if (!$show_guests)
FROM ' . SESSIONS_TABLE . ' FROM ' . SESSIONS_TABLE . '
WHERE session_user_id = ' . ANONYMOUS . ' WHERE session_user_id = ' . ANONYMOUS . '
AND session_time >= ' . (time() - ($config['load_online_time'] * 60)); AND session_time >= ' . (time() - ($config['load_online_time'] * 60));
break;
} }
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$guest_counter = (int) $db->sql_fetchfield('num_guests'); $guest_counter = (int) $db->sql_fetchfield('num_guests');