diff options
| author | Meik Sievertsen <acydburn@phpbb.com> | 2006-10-14 14:56:46 +0000 |
|---|---|---|
| committer | Meik Sievertsen <acydburn@phpbb.com> | 2006-10-14 14:56:46 +0000 |
| commit | 4afaca12dc55b076293e9ef8ac28332d22730df0 (patch) | |
| tree | 944b15618d8a0bed05fafb942e27322a739b2d3d /phpBB/includes/db | |
| parent | 46922674ea1b5ecf96d14c0edfdbcf6af3743051 (diff) | |
| download | forums-4afaca12dc55b076293e9ef8ac28332d22730df0.tar forums-4afaca12dc55b076293e9ef8ac28332d22730df0.tar.gz forums-4afaca12dc55b076293e9ef8ac28332d22730df0.tar.bz2 forums-4afaca12dc55b076293e9ef8ac28332d22730df0.tar.xz forums-4afaca12dc55b076293e9ef8ac28332d22730df0.zip | |
- 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
Diffstat (limited to 'phpBB/includes/db')
| -rw-r--r-- | phpBB/includes/db/dbal.php | 66 | ||||
| -rw-r--r-- | phpBB/includes/db/firebird.php | 13 | ||||
| -rw-r--r-- | phpBB/includes/db/mssql.php | 13 | ||||
| -rw-r--r-- | phpBB/includes/db/mssql_odbc.php | 13 | ||||
| -rw-r--r-- | phpBB/includes/db/mysql.php | 20 | ||||
| -rw-r--r-- | phpBB/includes/db/mysqli.php | 12 | ||||
| -rw-r--r-- | phpBB/includes/db/oracle.php | 14 | ||||
| -rw-r--r-- | phpBB/includes/db/postgres.php | 13 | ||||
| -rw-r--r-- | phpBB/includes/db/sqlite.php | 13 |
9 files changed, 81 insertions, 96 deletions
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 732ecdfed6..cbeb3dca24 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -39,6 +39,11 @@ class dbal var $sql_error_sql = ''; /** + * Current sql layer + */ + var $sql_layer = ''; + + /** * Constructor */ function dbal() @@ -48,6 +53,10 @@ class dbal 'normal' => 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(); 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) { @@ -266,6 +281,10 @@ class dbal return $query; } + /** + * Build IN, NOT IN, = and <> sql comparison string. + * @access public + */ function sql_in_set($field, $array, $negate = false) { if (!sizeof($array)) @@ -296,6 +315,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 * @access private */ @@ -392,7 +452,7 @@ class dbal 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 // Additionally show complete error on installation or if extended debug mode is enabled @@ -491,7 +551,7 @@ class dbal <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>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 /> ' . $this->sql_report . ' @@ -542,7 +602,7 @@ class dbal else { $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 />'; diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 922a647eeb..82ff453a4c 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -9,20 +9,14 @@ */ /** +* @ignore */ if (!defined('IN_PHPBB')) { exit; } -/** -* @ignore -*/ -if (!defined('SQL_LAYER')) -{ - - define('SQL_LAYER', 'firebird'); - include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); +include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); /** * Firebird/Interbase Database Abstraction Layer @@ -389,9 +383,6 @@ class dbal_firebird extends dbal break; } } - } -} // if ... define - ?>
\ No newline at end of file diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index 19bc3709d6..f95f99969c 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -9,20 +9,14 @@ */ /** +* @ignore */ if (!defined('IN_PHPBB')) { exit; } -/** -* @ignore -*/ -if (!defined('SQL_LAYER')) -{ - - define('SQL_LAYER', 'mssql'); - include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); +include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); /** * MSSQL Database Abstraction Layer @@ -437,9 +431,6 @@ class dbal_mssql extends dbal break; } } - } -} // if ... define - ?>
\ No newline at end of file diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 718bd113de..12e3ca686e 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -9,20 +9,14 @@ */ /** +* @ignore */ if (!defined('IN_PHPBB')) { exit; } -/** -* @ignore -*/ -if (!defined('SQL_LAYER')) -{ - - define('SQL_LAYER', 'mssql_odbc'); - include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); +include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); /** * Unified ODBC functions @@ -417,9 +411,6 @@ class dbal_mssql_odbc extends dbal break; } } - } -} // if ... define - ?>
\ No newline at end of file diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index de92fd679f..56d8a419c8 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -9,18 +9,14 @@ */ /** +* @ignore */ if (!defined('IN_PHPBB')) { exit; } -/** -* @ignore -*/ -if (!defined('SQL_LAYER')) -{ - include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); +include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); /** * MySQL4 Database Abstraction Layer @@ -57,16 +53,11 @@ class dbal_mysql extends dbal if (version_compare($this->mysql_version, '4.1.3', '>=')) { - define('SQL_LAYER', 'mysql4'); @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'); - } - else - { - define('SQL_LAYER', 'mysql'); + $this->sql_layer = 'mysql'; } return $this->db_connect_id; @@ -394,9 +385,6 @@ class dbal_mysql extends dbal break; } } - } -} // if ... define - ?>
\ No newline at end of file diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index 5f4c0c80e5..86700744fb 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -9,20 +9,14 @@ */ /** +* @ignore */ if (!defined('IN_PHPBB')) { exit; } -/** -* @ignore -*/ -if (!defined('SQL_LAYER')) -{ - - define('SQL_LAYER', 'mysqli'); - include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); +include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); /** * MySQLi Database Abstraction Layer @@ -363,6 +357,4 @@ class dbal_mysqli extends dbal } } -} // if ... define - ?>
\ No newline at end of file diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 0a16ca1b1e..e8a0ce3605 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -9,20 +9,14 @@ */ /** +* @ignore */ if (!defined('IN_PHPBB')) { exit; } -/** -* @ignore -*/ -if(!defined('SQL_LAYER')) -{ - - define('SQL_LAYER', 'oracle'); - include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); +include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); /** * Oracle Database Abstraction Layer @@ -507,10 +501,6 @@ class dbal_oracle extends dbal break; } } - - } -} // if ... define - ?>
\ No newline at end of file diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index c74adbf150..c06786a795 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -9,20 +9,14 @@ */ /** +* @ignore */ if (!defined('IN_PHPBB')) { exit; } -/** -* @ignore -*/ -if (!defined('SQL_LAYER')) -{ - - define('SQL_LAYER', 'postgres'); - include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); +include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); /** * PostgreSQL Database Abstraction Layer @@ -414,9 +408,6 @@ class dbal_postgres extends dbal break; } } - } -} // if ... defined - ?>
\ No newline at end of file diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index 4155d35929..708376881c 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -9,20 +9,14 @@ */ /** +* @ignore */ if (!defined('IN_PHPBB')) { exit; } -/** -* @ignore -*/ -if (!defined('SQL_LAYER')) -{ - - define('SQL_LAYER', 'sqlite'); - include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); +include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); /** * Sqlite Database Abstraction Layer @@ -313,9 +307,6 @@ class dbal_sqlite extends dbal break; } } - } -} // if ... define - ?>
\ No newline at end of file |
