Line 64 | Line 64 |
---|
*/ var $any_char; var $one_char;
|
*/ var $any_char; var $one_char;
|
| /** * Exact version of the DBAL, directly queried */ var $sql_server_version = false;
|
/** * Constructor
| /** * Constructor
|
Line 138 | Line 143 |
---|
$this->sql_freeresult($query_id); }
|
$this->sql_freeresult($query_id); }
|
return $this->_sql_close();
| // Connection closed correctly. Set db_connect_id to false to prevent errors if ($result = $this->_sql_close()) { $this->db_connect_id = false; }
return $result;
|
}
/**
| }
/**
|
Line 181 | Line 192 |
---|
} return false;
|
} return false;
|
| }
/** * Seek to given row number * rownum is zero-based */ function sql_rowseek($rownum, &$query_id) { global $cache;
if ($query_id === false) { $query_id = $this->query_result; }
if (isset($cache->sql_rowset[$query_id])) { return $cache->sql_rowseek($rownum, $query_id); }
if ($query_id === false) { return false; }
$this->sql_freeresult($query_id); $query_id = $this->sql_query($this->last_query_text);
if ($query_id === false) { return false; }
// We do not fetch the row for rownum == 0 because then the next resultset would be the second row for ($i = 0; $i < $rownum; $i++) { if (!$this->sql_fetchrow($query_id)) { return false; } }
return true;
|
}
/**
| }
/**
|
Line 224 | Line 278 |
---|
*/ function sql_like_expression($expression) {
|
*/ function sql_like_expression($expression) {
|
$expression = str_replace(array('_', '%'), array("\_", "\%"), $expression); $expression = str_replace(array(chr(0) . "\_", chr(0) . "\%"), array('_', '%'), $expression);
| $expression = utf8_str_replace(array('_', '%'), array("\_", "\%"), $expression); $expression = utf8_str_replace(array(chr(0) . "\_", chr(0) . "\%"), array('_', '%'), $expression);
|
return $this->_sql_like_expression('LIKE \'' . $this->sql_escape($expression) . '\'');
|
return $this->_sql_like_expression('LIKE \'' . $this->sql_escape($expression) . '\'');
|
| }
/** * Returns whether results of a query need to be buffered to run a transaction while iterating over them. * * @return bool Whether buffering is required. */ function sql_buffer_nested_transactions() { return false;
|
}
/**
| }
/**
|
Line 300 | Line 364 |
---|
* Build sql statement from array for insert/update/select statements * * Idea for this from Ikonboard
|
* Build sql statement from array for insert/update/select statements * * Idea for this from Ikonboard
|
* Possible query values: INSERT, INSERT_SELECT, MULTI_INSERT, UPDATE, SELECT
| * Possible query values: INSERT, INSERT_SELECT, UPDATE, SELECT
|
* */ function sql_build_array($query, $assoc_ary = false)
| * */ function sql_build_array($query, $assoc_ary = false)
|
Line 333 | Line 397 |
---|
} else if ($query == 'MULTI_INSERT') {
|
} else if ($query == 'MULTI_INSERT') {
|
$ary = array(); 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(); foreach ($sql_ary as $key => $var) { $values[] = $this->_sql_validate_value($var); } $ary[] = '(' . implode(', ', $values) . ')'; }
$query = ' (' . implode(', ', array_keys($assoc_ary[0])) . ') VALUES ' . implode(', ', $ary);
| trigger_error('The MULTI_INSERT query value is no longer supported. Please use sql_multi_insert() instead.', E_USER_ERROR);
|
} else if ($query == 'UPDATE' || $query == 'SELECT') {
| } else if ($query == 'UPDATE' || $query == 'SELECT') {
|
Line 415 | Line 462 |
---|
{ return $field . ($negate ? ' NOT IN ' : ' IN ') . '(' . implode(', ', array_map(array($this, '_sql_validate_value'), $array)) . ')'; }
|
{ return $field . ($negate ? ' NOT IN ' : ' IN ') . '(' . implode(', ', array_map(array($this, '_sql_validate_value'), $array)) . ')'; }
|
| }
/** * Run binary AND operator on DB column. * Results in sql statement: "{$column_name} & (1 << {$bit}) {$compare}" * * @param string $column_name The column name to use * @param int $bit The value to use for the AND operator, will be converted to (1 << $bit). Is used by options, using the number schema... 0, 1, 2...29 * @param string $compare Any custom SQL code after the check (for example "= 0") */ function sql_bit_and($column_name, $bit, $compare = '') { if (method_exists($this, '_sql_bit_and')) { return $this->_sql_bit_and($column_name, $bit, $compare); }
return $column_name . ' & ' . (1 << $bit) . (($compare) ? ' ' . $compare : ''); }
/** * Run binary OR operator on DB column. * Results in sql statement: "{$column_name} | (1 << {$bit}) {$compare}" * * @param string $column_name The column name to use * @param int $bit The value to use for the OR operator, will be converted to (1 << $bit). Is used by options, using the number schema... 0, 1, 2...29 * @param string $compare Any custom SQL code after the check (for example "= 0") */ function sql_bit_or($column_name, $bit, $compare = '') { if (method_exists($this, '_sql_bit_or')) { return $this->_sql_bit_or($column_name, $bit, $compare); }
return $column_name . ' | ' . (1 << $bit) . (($compare) ? ' ' . $compare : ''); }
/** * Run LOWER() on DB column of type text (i.e. neither varchar nor char). * * @param string $column_name The column name to use * * @return string A SQL statement like "LOWER($column_name)" */ function sql_lower_text($column_name) { return "LOWER($column_name)";
|
}
/**
| }
/**
|
Line 435 | Line 530 |
---|
if ($this->multi_insert) {
|
if ($this->multi_insert) {
|
$this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('MULTI_INSERT', $sql_ary));
| $ary = array(); foreach ($sql_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_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $sql_ary)); }
$values = array(); foreach ($_sql_ary as $key => $var) { $values[] = $this->_sql_validate_value($var); } $ary[] = '(' . implode(', ', $values) . ')'; }
return $this->sql_query('INSERT INTO ' . $table . ' ' . ' (' . implode(', ', array_keys($sql_ary[0])) . ') VALUES ' . implode(', ', $ary));
|
} else {
| } else {
|
Line 446 | Line 558 |
---|
return false; }
|
return false; }
|
$this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $ary));
| $result = $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $ary));
if (!$result) { return false; }
|
} }
| } }
|
Line 488 | Line 605 |
---|
$sql = str_replace('_', ' ', $query) . ' ' . $array['SELECT'] . ' FROM ';
|
$sql = str_replace('_', ' ', $query) . ' ' . $array['SELECT'] . ' FROM ';
|
$table_array = array();
| // Build table array. We also build an alias array for later checks. $table_array = $aliases = array(); $used_multi_alias = false;
|
foreach ($array['FROM'] as $table_name => $alias) { if (is_array($alias)) {
|
foreach ($array['FROM'] as $table_name => $alias) { if (is_array($alias)) {
|
| $used_multi_alias = true;
|
foreach ($alias as $multi_alias) { $table_array[] = $table_name . ' ' . $multi_alias;
|
foreach ($alias as $multi_alias) { $table_array[] = $table_name . ' ' . $multi_alias;
|
| $aliases[] = $multi_alias;
|
} } else { $table_array[] = $table_name . ' ' . $alias;
|
} } else { $table_array[] = $table_name . ' ' . $alias;
|
| $aliases[] = $alias; } }
// We run the following code to determine if we need to re-order the table array. ;) // The reason for this is that for multi-aliased tables (two equal tables) in the FROM statement the last table need to match the first comparison. // DBMS who rely on this: Oracle, PostgreSQL and MSSQL. For all other DBMS it makes absolutely no difference in which order the table is. if (!empty($array['LEFT_JOIN']) && sizeof($array['FROM']) > 1 && $used_multi_alias !== false) { // Take first LEFT JOIN $join = current($array['LEFT_JOIN']);
// Determine the table used there (even if there are more than one used, we only want to have one preg_match('/(' . implode('|', $aliases) . ')\.[^\s]+/U', str_replace(array('(', ')', 'AND', 'OR', ' '), '', $join['ON']), $matches);
// If there is a first join match, we need to make sure the table order is correct if (!empty($matches[1])) { $first_join_match = trim($matches[1]); $table_array = $last = array();
foreach ($array['FROM'] as $table_name => $alias) { if (is_array($alias)) { foreach ($alias as $multi_alias) { ($multi_alias === $first_join_match) ? $last[] = $table_name . ' ' . $multi_alias : $table_array[] = $table_name . ' ' . $multi_alias; } } else { ($alias === $first_join_match) ? $last[] = $table_name . ' ' . $alias : $table_array[] = $table_name . ' ' . $alias; } }
$table_array = array_merge($table_array, $last);
|
} }
|
} }
|
$sql .= $this->_sql_custom_build('FROM', implode(', ', $table_array));
| $sql .= $this->_sql_custom_build('FROM', implode(' CROSS JOIN ', $table_array));
|
if (!empty($array['LEFT_JOIN'])) {
| if (!empty($array['LEFT_JOIN'])) {
|
Line 557 | Line 717 |
---|
// The DEBUG_EXTRA constant is for development only! if ((isset($auth) && $auth->acl_get('a_')) || defined('IN_INSTALL') || defined('DEBUG_EXTRA')) {
|
// The DEBUG_EXTRA constant is for development only! if ((isset($auth) && $auth->acl_get('a_')) || defined('IN_INSTALL') || defined('DEBUG_EXTRA')) {
|
// Print out a nice backtrace... $backtrace = get_backtrace();
| |
$message .= ($sql) ? '<br /><br />SQL<br /><br />' . htmlspecialchars($sql) : '';
|
$message .= ($sql) ? '<br /><br />SQL<br /><br />' . htmlspecialchars($sql) : '';
|
$message .= ($backtrace) ? '<br /><br />BACKTRACE<br />' . $backtrace : ''; $message .= '<br />';
| |
} else {
| } else {
|
Line 672 | Line 827 |
---|
</div> </div> <div id="page-footer">
|
</div> </div> <div id="page-footer">
|
Powered by phpBB © 2000, 2002, 2005, 2007 <a href="http://www.phpbb.com/">phpBB Group</a>
| Powered by <a href="https://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Group
|
</div> </div> </body>
| </div> </div> </body>
|
Line 799 | Line 954 |
---|
}
return true;
|
}
return true;
|
| }
/** * Gets the estimated number of rows in a specified table. * * @param string $table_name Table name * * @return string Number of rows in $table_name. * Prefixed with ~ if estimated (otherwise exact). * * @access public */ function get_estimated_row_count($table_name) { return $this->get_row_count($table_name); }
/** * Gets the exact number of rows in a specified table. * * @param string $table_name Table name * * @return string Exact number of rows in $table_name. * * @access public */ function get_row_count($table_name) { $sql = 'SELECT COUNT(*) AS rows_total FROM ' . $this->sql_escape($table_name); $result = $this->sql_query($sql); $rows_total = $this->sql_fetchfield('rows_total'); $this->sql_freeresult($result);
return $rows_total;
|
} }
| } }
|