|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @package dbal
|
|
|
4c79b5 |
* @version $Id: firebird.php 8967 2008-10-02 12:04:12Z acydburn $
|
|
|
4c79b5 |
* @copyright (c) 2005 phpBB Group
|
|
|
4c79b5 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* @ignore
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
if (!defined('IN_PHPBB'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
exit;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Firebird/Interbase Database Abstraction Layer
|
|
|
4c79b5 |
* Minimum Requirement is Firebird 2.0
|
|
|
4c79b5 |
* @package dbal
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
class dbal_firebird extends dbal
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var $last_query_text = '';
|
|
|
4c79b5 |
var $service_handle = false;
|
|
|
4c79b5 |
var $affected_rows = 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Connect to server
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->persistency = $persistency;
|
|
|
4c79b5 |
$this->user = $sqluser;
|
|
|
4c79b5 |
$this->server = $sqlserver . (($port) ? ':' . $port : '');
|
|
|
4c79b5 |
$this->dbname = str_replace('\\', '/', $database);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// There are three possibilities to connect to an interbase db
|
|
|
4c79b5 |
if (!$this->server)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$use_database = $this->dbname;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (strpos($this->server, '//') === 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$use_database = $this->server . $this->dbname;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$use_database = $this->server . ':' . $this->dbname;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->db_connect_id = ($this->persistency) ? @ibase_pconnect($use_database, $this->user, $sqlpassword, false, false, 3) : @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->service_handle = (function_exists('ibase_service_attach') && $this->server) ? @ibase_service_attach($this->server, $this->user, $sqlpassword) : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Version information about used database
|
|
|
4c79b5 |
* @param bool $raw if true, only return the fetched sql_server_version
|
|
|
4c79b5 |
* @return string sql server version
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_server_info($raw = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($this->service_handle !== false && function_exists('ibase_server_info'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return @ibase_server_info($this->service_handle, IBASE_SVC_SERVER_VERSION);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return ($raw) ? '2.0' : 'Firebird/Interbase';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* SQL Transaction
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function _sql_transaction($status = 'begin')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($status)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'begin':
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'commit':
|
|
|
4c79b5 |
return @ibase_commit();
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'rollback':
|
|
|
4c79b5 |
return @ibase_rollback();
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Base query method
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @param string $query Contains the SQL query which shall be executed
|
|
|
4c79b5 |
* @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
|
|
|
4c79b5 |
* @return mixed When casted to bool the returned value returns true on success and false on failure
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @access public
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_query($query = '', $cache_ttl = 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($query != '')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $cache;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// EXPLAIN only in extra debug mode
|
|
|
4c79b5 |
if (defined('DEBUG_EXTRA'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->sql_report('start', $query);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->last_query_text = $query;
|
|
|
4c79b5 |
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
|
|
|
4c79b5 |
$this->sql_add_num_queries($this->query_result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($this->query_result === false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$array = array();
|
|
|
4c79b5 |
// We overcome Firebird's 32767 char limit by binding vars
|
|
|
4c79b5 |
if (strlen($query) > 32767)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (preg_match('/^(INSERT INTO[^(]++)\\(([^()]+)\\) VALUES[^(]++\\((.*?)\\)$/s', $query, $regs))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (strlen($regs[3]) > 32767)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
preg_match_all('/\'(?:[^\']++|\'\')*+\'|[\d-.]+/', $regs[3], $vals, PREG_PATTERN_ORDER);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$inserts = $vals[0];
|
|
|
4c79b5 |
unset($vals);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($inserts as $key => $value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!empty($value) && $value[0] === "'" && strlen($value) > 32769) // check to see if this thing is greater than the max + 'x2
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$inserts[$key] = '?';
|
|
|
4c79b5 |
$array[] = str_replace("''", "'", substr($value, 1, -1));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$query = $regs[1] . '(' . $regs[2] . ') VALUES (' . implode(', ', $inserts) . ')';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (preg_match('/^(UPDATE ([\\w_]++)\\s+SET )([\\w_]++\\s*=\\s*(?:\'(?:[^\']++|\'\')*+\'|\\d+)(?:,\\s*[\\w_]++\\s*=\\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]+))*+)\\s+(WHERE.*)$/s', $query, $data))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (strlen($data[3]) > 32767)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$update = $data[1];
|
|
|
4c79b5 |
$where = $data[4];
|
|
|
4c79b5 |
preg_match_all('/(\\w++)\\s*=\\s*(\'(?:[^\']++|\'\')*+\'|[\d-.]++)/', $data[3], $temp, PREG_SET_ORDER);
|
|
|
4c79b5 |
unset($data);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cols = array();
|
|
|
4c79b5 |
foreach ($temp as $value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!empty($value[2]) && $value[2][0] === "'" && strlen($value[2]) > 32769) // check to see if this thing is greater than the max + 'x2
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$array[] = str_replace("''", "'", substr($value[2], 1, -1));
|
|
|
4c79b5 |
$cols[] = $value[1] . '=?';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cols[] = $value[1] . '=' . $value[2];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$query = $update . implode(', ', $cols) . ' ' . $where;
|
|
|
4c79b5 |
unset($cols);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!function_exists('ibase_affected_rows') && (preg_match('/^UPDATE ([\w_]++)\s+SET [\w_]++\s*=\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]+)(?:,\s*[\w_]++\s*=\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]+))*+\s+(WHERE.*)?$/s', $query, $regs) || preg_match('/^DELETE FROM ([\w_]++)\s*(WHERE\s*.*)?$/s', $query, $regs)))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$affected_sql = 'SELECT COUNT(*) as num_rows_affected FROM ' . $regs[1];
|
|
|
4c79b5 |
if (!empty($regs[2]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$affected_sql .= ' ' . $regs[2];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!($temp_q_id = @ibase_query($this->db_connect_id, $affected_sql)))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$temp_result = @ibase_fetch_assoc($temp_q_id);
|
|
|
4c79b5 |
@ibase_free_result($temp_q_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->affected_rows = ($temp_result) ? $temp_result['NUM_ROWS_AFFECTED'] : false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($array))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$p_query = @ibase_prepare($this->db_connect_id, $query);
|
|
|
4c79b5 |
array_unshift($array, $p_query);
|
|
|
4c79b5 |
$this->query_result = call_user_func_array('ibase_execute', $array);
|
|
|
4c79b5 |
unset($array);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($this->query_result === false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->sql_error($query);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (($this->query_result = @ibase_query($this->db_connect_id, $query)) === false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->sql_error($query);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (defined('DEBUG_EXTRA'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->sql_report('stop', $query);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$this->transaction)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (function_exists('ibase_commit_ret'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
@ibase_commit_ret();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// way cooler than ibase_commit_ret :D
|
|
|
4c79b5 |
@ibase_query('COMMIT RETAIN;');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($cache_ttl && method_exists($cache, 'sql_save'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
|
|
4c79b5 |
$cache->sql_save($query, $this->query_result, $cache_ttl);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (defined('DEBUG_EXTRA'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->sql_report('fromcache', $query);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $this->query_result;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Build LIMIT query
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->query_result = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$query = 'SELECT FIRST ' . $total . ((!empty($offset)) ? ' SKIP ' . $offset : '') . substr($query, 6);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $this->sql_query($query, $cache_ttl);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Return number of affected rows
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_affectedrows()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// PHP 5+ function
|
|
|
4c79b5 |
if (function_exists('ibase_affected_rows'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return ($this->db_connect_id) ? @ibase_affected_rows($this->db_connect_id) : false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $this->affected_rows;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Fetch current row
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_fetchrow($query_id = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $cache;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($query_id === false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$query_id = $this->query_result;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($cache->sql_rowset[$query_id]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $cache->sql_fetchrow($query_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($query_id === false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$row = array();
|
|
|
4c79b5 |
$cur_row = @ibase_fetch_object($query_id, IBASE_TEXT);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$cur_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach (get_object_vars($cur_row) as $key => $value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$row[strtolower($key)] = (is_string($value)) ? trim(str_replace(array("\\0", "\\n"), array("\0", "\n"), $value)) : $value;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return (sizeof($row)) ? $row : false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Seek to given row number
|
|
|
4c79b5 |
* rownum is zero-based
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_rowseek($rownum, &$query_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $cache;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($query_id === false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$query_id = $this->query_result;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($cache->sql_rowset[$query_id]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $cache->sql_rowseek($rownum, $query_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($query_id === false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->sql_freeresult($query_id);
|
|
|
4c79b5 |
$query_id = $this->sql_query($this->last_query_text);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($query_id === false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// We do not fetch the row for rownum == 0 because then the next resultset would be the second row
|
|
|
4c79b5 |
for ($i = 0; $i < $rownum; $i++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!$this->sql_fetchrow($query_id))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get last inserted id after insert statement
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_nextid()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$query_id = $this->query_result;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($query_id !== false && $this->last_query_text != '')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($this->query_result && preg_match('#^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)#i', $this->last_query_text, $tablename))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT GEN_ID(' . $tablename[1] . '_gen, 0) AS new_id FROM RDB$DATABASE';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!($temp_q_id = @ibase_query($this->db_connect_id, $sql)))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$temp_result = @ibase_fetch_assoc($temp_q_id);
|
|
|
4c79b5 |
@ibase_free_result($temp_q_id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return ($temp_result) ? $temp_result['NEW_ID'] : false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Free sql result
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_freeresult($query_id = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $cache;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($query_id === false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$query_id = $this->query_result;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($cache->sql_rowset[$query_id]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $cache->sql_freeresult($query_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($this->open_queries[(int) $query_id]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
unset($this->open_queries[(int) $query_id]);
|
|
|
4c79b5 |
return @ibase_free_result($query_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Escape string used in sql query
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_escape($msg)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return str_replace(array("'", "\0"), array("''", ''), $msg);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Build LIKE expression
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function _sql_like_expression($expression)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $expression . " ESCAPE '\\'";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Build db-specific query data
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function _sql_custom_build($stage, $data)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $data;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* return sql error array
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function _sql_error()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return array(
|
|
|
4c79b5 |
'message' => @ibase_errmsg(),
|
|
|
4c79b5 |
'code' => (@function_exists('ibase_errcode') ? @ibase_errcode() : '')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Close sql connection
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function _sql_close()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($this->service_handle !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
@ibase_service_detach($this->service_handle);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return @ibase_close($this->db_connect_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Build db-specific report
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function _sql_report($mode, $query = '')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'start':
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'fromcache':
|
|
|
4c79b5 |
$endtime = explode(' ', microtime());
|
|
|
4c79b5 |
$endtime = $endtime[0] + $endtime[1];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$result = @ibase_query($this->db_connect_id, $query);
|
|
|
4c79b5 |
while ($void = @ibase_fetch_object($result, IBASE_TEXT))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Take the time spent on parsing rows into account
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
@ibase_free_result($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$splittime = explode(' ', microtime());
|
|
|
4c79b5 |
$splittime = $splittime[0] + $splittime[1];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->sql_report('record_fromcache', $query, $endtime, $splittime);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|