Update of /cvsroot/mxbb/core/includes/db In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv6068 Modified Files: firebird.php mssql.php mssql_odbc.php mysql.php mysql4.php mysqli.php oracle.php postgres.php sqlite.php Log Message: http://www.mx-publisher.com/phpBB2/viewtopic.php?p=65197#65197 Massive update. Index: mysqli.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/mysqli.php,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** mysqli.php 19 Aug 2008 02:46:22 -0000 1.20 --- mysqli.php 31 Oct 2008 18:53:49 -0000 1.21 *************** *** 37,41 **** { var $multi_insert = true; ! /** * Connect to server --- 37,41 ---- { var $multi_insert = true; ! /** * Connect to server *************** *** 56,63 **** // mysqli only supported by phpBB3 //if (UTF_STATUS === 'phpbb3') ! //{ @mysqli_query($this->db_connect_id, "SET NAMES 'utf8'"); // enforce strict mode on databases that support it ! //} if (mysqli_get_server_version($this->db_connect_id) >= 50002) { --- 56,63 ---- // mysqli only supported by phpBB3 //if (UTF_STATUS === 'phpbb3') ! //{ @mysqli_query($this->db_connect_id, "SET NAMES 'utf8'"); // enforce strict mode on databases that support it ! //} if (mysqli_get_server_version($this->db_connect_id) >= 50002) { *************** *** 283,286 **** --- 283,288 ---- function sql_rowseek($rownum, $query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 288,291 **** --- 290,298 ---- } + if (!is_object($query_id) && isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_rowseek($rownum, $query_id); + } + return ($query_id) ? @mysqli_data_seek($query_id, $rownum) : false; } *************** *** 304,307 **** --- 311,316 ---- function sql_freeresult($query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 309,319 **** } ! // Make sure it is not a cached query ! if (is_object($this->query_result)) { ! return @mysqli_free_result($query_id); } ! return false; } --- 318,327 ---- } ! if (!is_object($query_id) && isset($mx_cache->sql_rowset[$query_id])) { ! return $mx_cache->sql_freeresult($query_id); } ! return @mysqli_free_result($query_id); } Index: sqlite.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/sqlite.php,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** sqlite.php 7 Mar 2008 00:59:03 -0000 1.15 --- sqlite.php 31 Oct 2008 18:53:49 -0000 1.16 *************** *** 253,256 **** --- 253,258 ---- function sql_rowseek($rownum, $query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 258,261 **** --- 260,268 ---- } + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_rowseek($rownum, $query_id); + } + return ($query_id) ? @sqlite_seek($query_id, $rownum) : false; } *************** *** 274,277 **** --- 281,296 ---- function sql_freeresult($query_id = false) { + global $mx_cache; + + if ($query_id === false) + { + $query_id = $this->query_result; + } + + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_freeresult($query_id); + } + return true; } Index: postgres.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/postgres.php,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** postgres.php 20 Jul 2008 02:41:41 -0000 1.16 --- postgres.php 31 Oct 2008 18:53:49 -0000 1.17 *************** *** 66,70 **** $connect_string .= "host=$sqlserver "; } ! if ($port) { --- 66,70 ---- $connect_string .= "host=$sqlserver "; } ! if ($port) { *************** *** 323,326 **** --- 323,328 ---- function sql_rowseek($rownum, $query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 328,331 **** --- 330,338 ---- } + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_rowseek($rownum, $query_id); + } + return ($query_id) ? @pg_result_seek($query_id, $rownum) : false; } *************** *** 364,367 **** --- 371,376 ---- function sql_freeresult($query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 369,372 **** --- 378,386 ---- } + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_freeresult($query_id); + } + if (isset($this->open_queries[(int) $query_id])) { *************** *** 374,377 **** --- 388,392 ---- return @pg_free_result($query_id); } + return false; } Index: mysql4.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/mysql4.php,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** mysql4.php 19 Aug 2008 02:46:22 -0000 1.20 --- mysql4.php 31 Oct 2008 18:53:49 -0000 1.21 *************** *** 26,30 **** define('SQL_LAYER', 'mysql4'); include_once($mx_root_path . 'includes/db/dbal.' . $phpEx); ! $sql_db = 'dbal_' . $dbms; /** --- 26,30 ---- define('SQL_LAYER', 'mysql4'); include_once($mx_root_path . 'includes/db/dbal.' . $phpEx); ! $sql_db = 'dbal_' . $dbms; // Repopulated for multiple db connections /** *************** *** 40,46 **** var $mysql_version; var $multi_insert = true; ! /** ! * Connect to server ! */ /** * Connect to server --- 40,44 ---- var $mysql_version; var $multi_insert = true; ! /** * Connect to server *************** *** 54,57 **** --- 52,57 ---- $this->dbname = $database; + $this->sql_layer = 'mysql4'; + $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); *************** *** 65,72 **** if (version_compare($this->mysql_version, '4.1.3', '>=')) { - $this->sql_layer = 'mysql4'; - if (UTF_STATUS === 'phpbb3') ! { @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); // enforce strict mode on databases that support it --- 65,70 ---- if (version_compare($this->mysql_version, '4.1.3', '>=')) { if (UTF_STATUS === 'phpbb3') ! { @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); // enforce strict mode on databases that support it *************** *** 103,110 **** $this->sql_layer = 'mysql4'; } ! else //if (version_compare($this->mysql_version, '4.0.0', '<')) { $this->sql_layer = 'mysql'; ! } return $this->db_connect_id; --- 101,108 ---- $this->sql_layer = 'mysql4'; } ! else { $this->sql_layer = 'mysql'; ! } return $this->db_connect_id; *************** *** 114,118 **** return $this->sql_error(''); } ! /** * Version information about used database --- 112,116 ---- return $this->sql_error(''); } ! /** * Version information about used database *************** *** 312,315 **** --- 310,315 ---- function sql_rowseek($rownum, $query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 317,320 **** --- 317,325 ---- } + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_rowseek($rownum, $query_id); + } + return ($query_id) ? @mysql_data_seek($query_id, $rownum) : false; } *************** *** 333,336 **** --- 338,343 ---- function sql_freeresult($query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 338,341 **** --- 345,353 ---- } + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_freeresult($query_id); + } + if (isset($this->open_queries[(int) $query_id])) { Index: firebird.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/firebird.php,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** firebird.php 7 Mar 2008 00:59:02 -0000 1.15 --- firebird.php 31 Oct 2008 18:53:49 -0000 1.16 *************** *** 53,73 **** /** - * Connect to server - */ - function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) - { - $this->persistency = $persistency; - $this->user = $sqluser; - $this->server = $sqlserver . (($port) ? ':' . $port : ''); - $this->dbname = $database; - - $this->db_connect_id = ($this->persistency) ? @ibase_pconnect($this->server . ':' . $this->dbname, $this->user, $sqlpassword, false, false, 3) : @ibase_connect($this->server . ':' . $this->dbname, $this->user, $sqlpassword, false, false, 3); - - $this->service_handle = (function_exists('ibase_service_attach')) ? @ibase_service_attach($this->server, $this->user, $sqlpassword) : false; - - return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); - } - - /** * sql transaction */ --- 53,56 ---- Index: mssql.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/mssql.php,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** mssql.php 19 Aug 2008 02:46:22 -0000 1.17 --- mssql.php 31 Oct 2008 18:53:49 -0000 1.18 *************** *** 38,44 **** * Connect to server */ - /** - * Connect to server - */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { --- 38,41 ---- *************** *** 49,56 **** if (UTF_STATUS === 'phpbb3') ! { @ini_set('mssql.charset', 'UTF-8'); // enforce strict mode on databases that support it ! } @ini_set('mssql.textlimit', 2147483647); @ini_set('mssql.textsize', 2147483647); --- 46,53 ---- if (UTF_STATUS === 'phpbb3') ! { @ini_set('mssql.charset', 'UTF-8'); // enforce strict mode on databases that support it ! } @ini_set('mssql.textlimit', 2147483647); @ini_set('mssql.textsize', 2147483647); *************** *** 312,323 **** function sql_nextid() { ! $result_id = @mssql_query('SELECT @@IDENTITY', $this->db_connect_id); if ($result_id) { ! if (@mssql_fetch_assoc($result_id)) { - $id = @mssql_result($result_id, 1); @mssql_free_result($result_id); ! return $id; } @mssql_free_result($result_id); --- 309,320 ---- function sql_nextid() { ! $result_id = @mssql_query('SELECT SCOPE_IDENTITY()', $this->db_connect_id); if ($result_id) { ! if ($row = @mssql_fetch_assoc($result_id)) { @mssql_free_result($result_id); ! return $row['computed']; ! } @mssql_free_result($result_id); *************** *** 332,335 **** --- 329,334 ---- function sql_freeresult($query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 337,340 **** --- 336,344 ---- } + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_freeresult($query_id); + } + if (isset($this->open_queries[$query_id])) { Index: mysql.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/mysql.php,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** mysql.php 4 Oct 2008 17:30:23 -0000 1.22 --- mysql.php 31 Oct 2008 18:53:49 -0000 1.23 *************** *** 37,41 **** var $mysql_version; var $multi_insert = true; ! /** * Connect to server --- 37,41 ---- var $mysql_version; var $multi_insert = true; ! /** * Connect to server *************** *** 49,56 **** $this->dbname = $database; - $this->sql_layer = 'mysql4'; - $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); ! if ($this->db_connect_id && $this->dbname != '') { --- 49,54 ---- $this->dbname = $database; $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); ! if ($this->db_connect_id && $this->dbname != '') { *************** *** 59,70 **** // Determine what version we are using and if it natively supports UNICODE $this->mysql_version = mysql_get_server_info($this->db_connect_id); ! if (version_compare($this->mysql_version, '4.1.3', '>=')) { if (UTF_STATUS === 'phpbb3') ! { @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); // enforce strict mode on databases that support it } if (version_compare($this->mysql_version, '5.0.2', '>=')) { --- 57,71 ---- // Determine what version we are using and if it natively supports UNICODE $this->mysql_version = mysql_get_server_info($this->db_connect_id); ! if (version_compare($this->mysql_version, '4.1.3', '>=')) { + $this->sql_layer = 'mysql4'; + if (UTF_STATUS === 'phpbb3') ! { @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); // enforce strict mode on databases that support it } + if (version_compare($this->mysql_version, '5.0.2', '>=')) { *************** *** 92,96 **** } } ! else if (version_compare($this->mysql_version, '4.0.0', '<')) { $this->sql_layer = 'mysql'; --- 93,101 ---- } } ! else if (version_compare($this->mysql_version, '4.0.0', '>=')) ! { ! $this->sql_layer = 'mysql4'; ! } ! else { $this->sql_layer = 'mysql'; *************** *** 100,104 **** } } ! return $this->sql_error(); } --- 105,109 ---- } } ! return $this->sql_error(''); } *************** *** 212,216 **** if ($total == 0) { ! $total = -1; } --- 217,222 ---- if ($total == 0) { ! // Because MySQL 4.1+ no longer supports -1 in LIMIT queries we set it to the maximum value ! $total = '18446744073709551615'; } *************** *** 300,303 **** --- 306,311 ---- function sql_rowseek($rownum, $query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 305,308 **** --- 313,321 ---- } + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_rowseek($rownum, $query_id); + } + return ($query_id) ? @mysql_data_seek($query_id, $rownum) : false; } *************** *** 321,324 **** --- 334,339 ---- function sql_freeresult($query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 326,329 **** --- 341,349 ---- } + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_freeresult($query_id); + } + if (isset($this->open_queries[(int) $query_id])) { *************** *** 349,372 **** /** - * return sql error array - * @private - */ - function _sql_error() - { - if (!$this->db_connect_id) - { - return array( - 'message' => @mysql_error(), - 'code' => @mysql_errno() - ); - } - - return array( - 'message' => @mysql_error($this->db_connect_id), - 'code' => @mysql_errno($this->db_connect_id) - ); - } - - /** * Build LIKE expression * @access private --- 369,372 ---- *************** *** 394,397 **** --- 394,417 ---- /** + * return sql error array + * @private + */ + function _sql_error() + { + if (!$this->db_connect_id) + { + return array( + 'message' => @mysql_error(), + 'code' => @mysql_errno() + ); + } + + return array( + 'message' => @mysql_error($this->db_connect_id), + 'code' => @mysql_errno($this->db_connect_id) + ); + } + + /** * Close sql connection * @private Index: oracle.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/oracle.php,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** oracle.php 7 Mar 2008 00:59:03 -0000 1.15 --- oracle.php 31 Oct 2008 18:53:49 -0000 1.16 *************** *** 46,49 **** --- 46,59 ---- $this->dbname = $database; + // support for "easy connect naming" + if ($sqlserver !== '' && $sqlserver !== '/') + { + if (substr($sqlserver, -1, 1) == '/') + { + $sqlserver == substr($sqlserver, 0, -1); + } + $connect = $sqlserver . (($port) ? ':' . $port : '') . '/' . $database; + } + $this->db_connect_id = ($this->persistency) ? @ociplogon($this->user, $sqlpassword, $this->server) : @ocinlogon($this->user, $sqlpassword, $this->server); *************** *** 125,129 **** --- 135,224 ---- } + $array = array(); + + // We overcome Oracle's 4000 char limit by binding vars + if (strlen($query) > 4000) + { + if (preg_match('/^(INSERT INTO[^(]++)\\(([^()]+)\\) VALUES[^(]++\\((.*?)\\)$/s', $query, $regs)) + { + if (strlen($regs[3]) > 4000) + { + $cols = explode(', ', $regs[2]); + preg_match_all('/\'(?:[^\']++|\'\')*+\'|[\d-.]+/', $regs[3], $vals, PREG_PATTERN_ORDER); + + $inserts = $vals[0]; + unset($vals); + + foreach ($inserts as $key => $value) + { + if (!empty($value) && $value[0] === "'" && strlen($value) > 4002) // check to see if this thing is greater than the max + 'x2 + { + $inserts[$key] = ':' . strtoupper($cols[$key]); + $array[$inserts[$key]] = str_replace("''", "'", substr($value, 1, -1)); + } + } + + $query = $regs[1] . '(' . $regs[2] . ') VALUES (' . implode(', ', $inserts) . ')'; + } + } + else if (preg_match_all('/^(UPDATE [\\w_]++\\s+SET )([\\w_]++\\s*=\\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]+)(?:,\\s*[\\w_]++\\s*=\\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]+))*+)\\s+(WHERE.*)$/s', $query, $data, PREG_SET_ORDER)) + { + if (strlen($data[0][2]) > 4000) + { + $update = $data[0][1]; + $where = $data[0][3]; + preg_match_all('/([\\w_]++)\\s*=\\s*(\'(?:[^\']++|\'\')*+\'|[\d-.]++)/', $data[0][2], $temp, PREG_SET_ORDER); + unset($data); + + $cols = array(); + foreach ($temp as $value) + { + if (!empty($value[2]) && $value[2][0] === "'" && strlen($value[2]) > 4002) // check to see if this thing is greater than the max + 'x2 + { + $cols[] = $value[1] . '=:' . strtoupper($value[1]); + $array[$value[1]] = str_replace("''", "'", substr($value[2], 1, -1)); + } + else + { + $cols[] = $value[1] . '=' . $value[2]; + } + } + + $query = $update . implode(', ', $cols) . ' ' . $where; + unset($cols); + } + } + } + + switch (substr($query, 0, 6)) + { + case 'DELETE': + if (preg_match('/^(DELETE FROM [\w_]++ WHERE)((?:\s*(?:AND|OR)?\s*[\w_]+\s*(?:(?:=|<>)\s*(?>\'(?>[^\']++|\'\')*+\'|[\d-.]+)|(?:NOT )?IN\s*\((?>\'(?>[^\']++|\'\')*+\',? ?|[\d-.]+,? ?)*+\)))*+)$/', $query, $regs)) + { + $query = $regs[1] . $this->_rewrite_where($regs[2]); + unset($regs); + } + break; + + case 'UPDATE': + if (preg_match('/^(UPDATE [\\w_]++\\s+SET [\\w_]+\s*=\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]++|:\w++)(?:, [\\w_]+\s*=\s*(?:\'(?:[^\']++|\'\')*+\'|[\d-.]++|:\w++))*+\\s+WHERE)(.*)$/s', $query, $regs)) + { + $query = $regs[1] . $this->_rewrite_where($regs[2]); + unset($regs); + } + break; + + case 'SELECT': + $query = preg_replace_callback('/([\w_.]++)\s*(?:(=|<>)\s*(?>\'(?>[^\']++|\'\')*+\'|[\d-.]++|([\w_.]++))|(?:NOT )?IN\s*\((?>\'(?>[^\']++|\'\')*+\',? ?|[\d-.]++,? ?)*+\))/', array($this, '_rewrite_col_compare'), $query); + break; + } + $this->query_result = @ociparse($this->db_connect_id, $query); + + foreach ($array as $key => $value) + { + @ocibindbyname($this->query_result, $key, $array[$key], -1); + } + $success = @ociexecute($this->query_result, OCI_DEFAULT); *************** *** 287,290 **** --- 382,387 ---- function sql_rowseek($rownum, $query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 292,295 **** --- 389,397 ---- } + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_rowseek($rownum, $query_id); + } + if (!$query_id) { *************** *** 349,352 **** --- 451,456 ---- function sql_freeresult($query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 354,357 **** --- 458,466 ---- } + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_freeresult($query_id); + } + if (isset($this->open_queries[(int) $query_id])) { Index: mssql_odbc.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/mssql_odbc.php,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** mssql_odbc.php 7 Mar 2008 00:59:02 -0000 1.15 --- mssql_odbc.php 31 Oct 2008 18:53:49 -0000 1.16 *************** *** 48,51 **** --- 48,74 ---- $this->dbname = $database; + $max_size = @ini_get('odbc.defaultlrl'); + if (!empty($max_size)) + { + $unit = strtolower(substr($max_size, -1, 1)); + $max_size = (int) $max_size; + + if ($unit == 'k') + { + $max_size = floor($max_size / 1024); + } + else if ($unit == 'g') + { + $max_size *= 1024; + } + else if (is_numeric($unit)) + { + $max_size = floor((int) ($max_size . $unit) / 1048576); + } + $max_size = max(8, $max_size) . 'M'; + + @ini_set('odbc.defaultlrl', $max_size); + } + $this->db_connect_id = ($this->persistency) ? @odbc_pconnect($this->server, $this->user, $sqlpassword) : @odbc_connect($this->server, $this->user, $sqlpassword); *************** *** 268,271 **** --- 291,296 ---- function sql_rowseek($rownum, $query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 273,276 **** --- 298,311 ---- } + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_rowseek($rownum, $query_id); + } + + if (!$query_id) + { + return false; + } + $this->sql_freeresult($query_id); $query_id = $this->sql_query($this->last_query_text); *************** *** 319,322 **** --- 354,359 ---- function sql_freeresult($query_id = false) { + global $mx_cache; + if (!$query_id) { *************** *** 324,327 **** --- 361,369 ---- } + if (isset($mx_cache->sql_rowset[$query_id])) + { + return $mx_cache->sql_freeresult($query_id); + } + if (isset($this->open_queries[(int) $query_id])) { |