Commit 403017cee3a0a4c7828c8f059525f938f5b787cf

Authored by donald_jackson
1 parent 2e7dd711

"Licensing mechanism not active after a new install until the user does an 'Update' of the plugins."

KTC-648
Added connection specific last_insert_id() so all objects can register.

Committed by: Donald Jackson
Reviewed by: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/branches/RB_3.5.4a@9666 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/database/dbutil.inc
@@ -168,7 +168,7 @@ class DBUtil { @@ -168,7 +168,7 @@ class DBUtil {
168 if ($bNoId) 168 if ($bNoId)
169 return; 169 return;
170 else 170 else
171 - return mysql_insert_id(); 171 + return $db->getLastId();
172 } 172 }
173 if (PEAR::isError($res)) { 173 if (PEAR::isError($res)) {
174 DBUtil::logQueryError(DBUtil::lastQuery($db), $res); 174 DBUtil::logQueryError(DBUtil::lastQuery($db), $res);
thirdparty/pear/DB/common.php
@@ -2030,6 +2030,22 @@ class DB_common extends PEAR @@ -2030,6 +2030,22 @@ class DB_common extends PEAR
2030 } 2030 }
2031 2031
2032 // }}} 2032 // }}}
  2033 +
  2034 + // {{{ getLastId()
  2035 +
  2036 + /**
  2037 + * Returns the last insert ID
  2038 + *
  2039 + * @return int
  2040 + *
  2041 + * @access public
  2042 + */
  2043 + function getLastId()
  2044 + {
  2045 + return $this->_getLastId();
  2046 + }
  2047 +
  2048 + // }}}
2033 } 2049 }
2034 2050
2035 /* 2051 /*
thirdparty/pear/DB/mysql.php
@@ -45,63 +45,63 @@ require_once 'DB/common.php'; @@ -45,63 +45,63 @@ require_once 'DB/common.php';
45 */ 45 */
46 class DB_mysql extends DB_common 46 class DB_mysql extends DB_common
47 { 47 {
48 - // {{{ properties  
49 -  
50 - var $connection;  
51 - var $phptype, $dbsyntax;  
52 - var $prepare_tokens = array();  
53 - var $prepare_types = array();  
54 - var $num_rows = array();  
55 - var $transaction_opcount = 0;  
56 - var $autocommit = true;  
57 - var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */  
58 - var $_db = false;  
59 -  
60 - // }}}  
61 - // {{{ constructor  
62 -  
63 - /** 48 + // {{{ properties
  49 +
  50 + var $connection;
  51 + var $phptype, $dbsyntax;
  52 + var $prepare_tokens = array();
  53 + var $prepare_types = array();
  54 + var $num_rows = array();
  55 + var $transaction_opcount = 0;
  56 + var $autocommit = true;
  57 + var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */
  58 + var $_db = false;
  59 +
  60 + // }}}
  61 + // {{{ constructor
  62 +
  63 + /**
64 * DB_mysql constructor. 64 * DB_mysql constructor.
65 * 65 *
66 * @access public 66 * @access public
67 */ 67 */
68 - function DB_mysql()  
69 - {  
70 - $this->DB_common();  
71 - $this->phptype = 'mysql';  
72 - $this->dbsyntax = 'mysql';  
73 - $this->features = array(  
74 - 'prepare' => false,  
75 - 'pconnect' => true,  
76 - 'transactions' => true,  
77 - 'limit' => 'alter'  
78 - );  
79 - $this->errorcode_map = array(  
80 - 1004 => DB_ERROR_CANNOT_CREATE,  
81 - 1005 => DB_ERROR_CANNOT_CREATE,  
82 - 1006 => DB_ERROR_CANNOT_CREATE,  
83 - 1007 => DB_ERROR_ALREADY_EXISTS,  
84 - 1008 => DB_ERROR_CANNOT_DROP,  
85 - 1022 => DB_ERROR_ALREADY_EXISTS,  
86 - 1046 => DB_ERROR_NODBSELECTED,  
87 - 1048 => DB_ERROR_CONSTRAINT,  
88 - 1050 => DB_ERROR_ALREADY_EXISTS,  
89 - 1051 => DB_ERROR_NOSUCHTABLE,  
90 - 1054 => DB_ERROR_NOSUCHFIELD,  
91 - 1062 => DB_ERROR_ALREADY_EXISTS,  
92 - 1064 => DB_ERROR_SYNTAX,  
93 - 1100 => DB_ERROR_NOT_LOCKED,  
94 - 1136 => DB_ERROR_VALUE_COUNT_ON_ROW,  
95 - 1146 => DB_ERROR_NOSUCHTABLE,  
96 - 1216 => DB_ERROR_CONSTRAINT,  
97 - 1217 => DB_ERROR_CONSTRAINT,  
98 - );  
99 - }  
100 -  
101 - // }}}  
102 - // {{{ connect()  
103 -  
104 - /** 68 + function DB_mysql()
  69 + {
  70 + $this->DB_common();
  71 + $this->phptype = 'mysql';
  72 + $this->dbsyntax = 'mysql';
  73 + $this->features = array(
  74 + 'prepare' => false,
  75 + 'pconnect' => true,
  76 + 'transactions' => true,
  77 + 'limit' => 'alter'
  78 + );
  79 + $this->errorcode_map = array(
  80 + 1004 => DB_ERROR_CANNOT_CREATE,
  81 + 1005 => DB_ERROR_CANNOT_CREATE,
  82 + 1006 => DB_ERROR_CANNOT_CREATE,
  83 + 1007 => DB_ERROR_ALREADY_EXISTS,
  84 + 1008 => DB_ERROR_CANNOT_DROP,
  85 + 1022 => DB_ERROR_ALREADY_EXISTS,
  86 + 1046 => DB_ERROR_NODBSELECTED,
  87 + 1048 => DB_ERROR_CONSTRAINT,
  88 + 1050 => DB_ERROR_ALREADY_EXISTS,
  89 + 1051 => DB_ERROR_NOSUCHTABLE,
  90 + 1054 => DB_ERROR_NOSUCHFIELD,
  91 + 1062 => DB_ERROR_ALREADY_EXISTS,
  92 + 1064 => DB_ERROR_SYNTAX,
  93 + 1100 => DB_ERROR_NOT_LOCKED,
  94 + 1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
  95 + 1146 => DB_ERROR_NOSUCHTABLE,
  96 + 1216 => DB_ERROR_CONSTRAINT,
  97 + 1217 => DB_ERROR_CONSTRAINT,
  98 + );
  99 + }
  100 +
  101 + // }}}
  102 + // {{{ connect()
  103 +
  104 + /**
105 * Connect to a database and log in as the specified user. 105 * Connect to a database and log in as the specified user.
106 * 106 *
107 * @param $dsn the data source name (see DB::parseDSN for syntax) 107 * @param $dsn the data source name (see DB::parseDSN for syntax)
@@ -110,88 +110,88 @@ class DB_mysql extends DB_common @@ -110,88 +110,88 @@ class DB_mysql extends DB_common
110 * @access public 110 * @access public
111 * @return int DB_OK on success, a DB error on failure 111 * @return int DB_OK on success, a DB error on failure
112 */ 112 */
113 - function connect($dsninfo, $persistent = false)  
114 - {  
115 - if (!DB::assertExtension('mysql')) {  
116 - return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);  
117 - }  
118 - $this->dsn = $dsninfo;  
119 - if ($dsninfo['protocol'] && $dsninfo['protocol'] == 'unix') {  
120 - $dbhost = ':' . $dsninfo['socket'];  
121 - } else {  
122 - $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';  
123 - if ($dsninfo['port']) {  
124 - $dbhost .= ':' . $dsninfo['port'];  
125 - }  
126 - }  
127 -  
128 - $connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect';  
129 -  
130 - if ($dbhost && $dsninfo['username'] && isset($dsninfo['password'])) {  
131 - $conn = @$connect_function($dbhost, $dsninfo['username'],  
132 - $dsninfo['password']);  
133 - } elseif ($dbhost && $dsninfo['username']) {  
134 - $conn = @$connect_function($dbhost, $dsninfo['username']);  
135 - } elseif ($dbhost) {  
136 - $conn = @$connect_function($dbhost);  
137 - } else {  
138 - $conn = false;  
139 - }  
140 - if (!$conn) {  
141 - if (($err = @mysql_error()) != '') {  
142 - return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,  
143 - null, $err);  
144 - } elseif (empty($php_errormsg)) {  
145 - return $this->raiseError(DB_ERROR_CONNECT_FAILED);  
146 - } else {  
147 - return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,  
148 - null, $php_errormsg);  
149 - }  
150 - }  
151 -  
152 - if ($dsninfo['database']) {  
153 - if (!@mysql_select_db($dsninfo['database'], $conn)) {  
154 - switch(mysql_errno($conn)) {  
155 - case 1049:  
156 - return $this->raiseError(DB_ERROR_NOSUCHDB, null, null,  
157 - null, @mysql_error($conn));  
158 - case 1044:  
159 - return $this->raiseError(DB_ERROR_ACCESS_VIOLATION, null, null,  
160 - null, @mysql_error($conn));  
161 - default:  
162 - return $this->raiseError(DB_ERROR, null, null,  
163 - null, @mysql_error($conn));  
164 - }  
165 - }  
166 - // fix to allow calls to different databases in the same script  
167 - $this->_db = $dsninfo['database'];  
168 - }  
169 -  
170 - $this->connection = $conn;  
171 - return DB_OK;  
172 - }  
173 -  
174 - // }}}  
175 - // {{{ disconnect()  
176 -  
177 - /** 113 + function connect($dsninfo, $persistent = false)
  114 + {
  115 + if (!DB::assertExtension('mysql')) {
  116 + return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
  117 + }
  118 + $this->dsn = $dsninfo;
  119 + if ($dsninfo['protocol'] && $dsninfo['protocol'] == 'unix') {
  120 + $dbhost = ':' . $dsninfo['socket'];
  121 + } else {
  122 + $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
  123 + if ($dsninfo['port']) {
  124 + $dbhost .= ':' . $dsninfo['port'];
  125 + }
  126 + }
  127 +
  128 + $connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect';
  129 +
  130 + if ($dbhost && $dsninfo['username'] && isset($dsninfo['password'])) {
  131 + $conn = @$connect_function($dbhost, $dsninfo['username'],
  132 + $dsninfo['password']);
  133 + } elseif ($dbhost && $dsninfo['username']) {
  134 + $conn = @$connect_function($dbhost, $dsninfo['username']);
  135 + } elseif ($dbhost) {
  136 + $conn = @$connect_function($dbhost);
  137 + } else {
  138 + $conn = false;
  139 + }
  140 + if (!$conn) {
  141 + if (($err = @mysql_error()) != '') {
  142 + return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
  143 + null, $err);
  144 + } elseif (empty($php_errormsg)) {
  145 + return $this->raiseError(DB_ERROR_CONNECT_FAILED);
  146 + } else {
  147 + return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
  148 + null, $php_errormsg);
  149 + }
  150 + }
  151 +
  152 + if ($dsninfo['database']) {
  153 + if (!@mysql_select_db($dsninfo['database'], $conn)) {
  154 + switch(mysql_errno($conn)) {
  155 + case 1049:
  156 + return $this->raiseError(DB_ERROR_NOSUCHDB, null, null,
  157 + null, @mysql_error($conn));
  158 + case 1044:
  159 + return $this->raiseError(DB_ERROR_ACCESS_VIOLATION, null, null,
  160 + null, @mysql_error($conn));
  161 + default:
  162 + return $this->raiseError(DB_ERROR, null, null,
  163 + null, @mysql_error($conn));
  164 + }
  165 + }
  166 + // fix to allow calls to different databases in the same script
  167 + $this->_db = $dsninfo['database'];
  168 + }
  169 +
  170 + $this->connection = $conn;
  171 + return DB_OK;
  172 + }
  173 +
  174 + // }}}
  175 + // {{{ disconnect()
  176 +
  177 + /**
178 * Log out and disconnect from the database. 178 * Log out and disconnect from the database.
179 * 179 *
180 * @access public 180 * @access public
181 * 181 *
182 * @return bool true on success, false if not connected. 182 * @return bool true on success, false if not connected.
183 */ 183 */
184 - function disconnect()  
185 - {  
186 - $ret = @mysql_close($this->connection);  
187 - $this->connection = null;  
188 - return $ret;  
189 - } 184 + function disconnect()
  185 + {
  186 + $ret = @mysql_close($this->connection);
  187 + $this->connection = null;
  188 + return $ret;
  189 + }
190 190
191 - // }}}  
192 - // {{{ simpleQuery() 191 + // }}}
  192 + // {{{ simpleQuery()
193 193
194 - /** 194 + /**
195 * Send a query to MySQL and return the results as a MySQL resource 195 * Send a query to MySQL and return the results as a MySQL resource
196 * identifier. 196 * identifier.
197 * 197 *
@@ -203,45 +203,45 @@ class DB_mysql extends DB_common @@ -203,45 +203,45 @@ class DB_mysql extends DB_common
203 * queries, DB_OK for other successful queries. A DB error is 203 * queries, DB_OK for other successful queries. A DB error is
204 * returned on failure. 204 * returned on failure.
205 */ 205 */
206 - function simpleQuery($query)  
207 - {  
208 - $ismanip = DB::isManip($query);  
209 - $this->last_query = $query;  
210 - $query = $this->modifyQuery($query);  
211 - if ($this->_db) {  
212 - if (!@mysql_select_db($this->_db, $this->connection)) {  
213 - return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);  
214 - }  
215 - }  
216 - if (!$this->autocommit && $ismanip) {  
217 - if ($this->transaction_opcount == 0) {  
218 - $result = @mysql_query('SET AUTOCOMMIT=0', $this->connection);  
219 - $result = @mysql_query('BEGIN', $this->connection);  
220 - if (!$result) {  
221 - return $this->mysqlRaiseError();  
222 - }  
223 - }  
224 - $this->transaction_opcount++;  
225 - }  
226 - $result = @mysql_query($query, $this->connection);  
227 - if (!$result) {  
228 - return $this->mysqlRaiseError();  
229 - }  
230 - if (is_resource($result)) {  
231 - $numrows = $this->numrows($result);  
232 - if (is_object($numrows)) {  
233 - return $numrows;  
234 - }  
235 - $this->num_rows[(int)$result] = $numrows;  
236 - return $result;  
237 - }  
238 - return DB_OK;  
239 - }  
240 -  
241 - // }}}  
242 - // {{{ nextResult()  
243 -  
244 - /** 206 + function simpleQuery($query)
  207 + {
  208 + $ismanip = DB::isManip($query);
  209 + $this->last_query = $query;
  210 + $query = $this->modifyQuery($query);
  211 + if ($this->_db) {
  212 + if (!@mysql_select_db($this->_db, $this->connection)) {
  213 + return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
  214 + }
  215 + }
  216 + if (!$this->autocommit && $ismanip) {
  217 + if ($this->transaction_opcount == 0) {
  218 + $result = @mysql_query('SET AUTOCOMMIT=0', $this->connection);
  219 + $result = @mysql_query('BEGIN', $this->connection);
  220 + if (!$result) {
  221 + return $this->mysqlRaiseError();
  222 + }
  223 + }
  224 + $this->transaction_opcount++;
  225 + }
  226 + $result = @mysql_query($query, $this->connection);
  227 + if (!$result) {
  228 + return $this->mysqlRaiseError();
  229 + }
  230 + if (is_resource($result)) {
  231 + $numrows = $this->numrows($result);
  232 + if (is_object($numrows)) {
  233 + return $numrows;
  234 + }
  235 + $this->num_rows[(int)$result] = $numrows;
  236 + return $result;
  237 + }
  238 + return DB_OK;
  239 + }
  240 +
  241 + // }}}
  242 + // {{{ nextResult()
  243 +
  244 + /**
245 * Move the internal mysql result pointer to the next available result 245 * Move the internal mysql result pointer to the next available result
246 * 246 *
247 * This method has not been implemented yet. 247 * This method has not been implemented yet.
@@ -252,15 +252,15 @@ class DB_mysql extends DB_common @@ -252,15 +252,15 @@ class DB_mysql extends DB_common
252 * 252 *
253 * @return false 253 * @return false
254 */ 254 */
255 - function nextResult($result)  
256 - {  
257 - return false;  
258 - } 255 + function nextResult($result)
  256 + {
  257 + return false;
  258 + }
259 259
260 - // }}}  
261 - // {{{ fetchInto() 260 + // }}}
  261 + // {{{ fetchInto()
262 262
263 - /** 263 + /**
264 * Fetch a row and insert the data into an existing array. 264 * Fetch a row and insert the data into an existing array.
265 * 265 *
266 * Formating of the array and the data therein are configurable. 266 * Formating of the array and the data therein are configurable.
@@ -278,51 +278,51 @@ class DB_mysql extends DB_common @@ -278,51 +278,51 @@ class DB_mysql extends DB_common
278 * @see DB_result::fetchInto() 278 * @see DB_result::fetchInto()
279 * @access private 279 * @access private
280 */ 280 */
281 - function fetchInto($result, &$arr, $fetchmode, $rownum=null)  
282 - {  
283 - if ($rownum !== null) {  
284 - if (!@mysql_data_seek($result, $rownum)) {  
285 - return null;  
286 - }  
287 - }  
288 - if ($fetchmode & DB_FETCHMODE_ASSOC) {  
289 - $arr = @mysql_fetch_array($result, MYSQL_ASSOC);  
290 - if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {  
291 - $arr = array_change_key_case($arr, CASE_LOWER);  
292 - }  
293 - } else {  
294 - $arr = @mysql_fetch_row($result);  
295 - }  
296 - if (!$arr) {  
297 - // See: http://bugs.php.net/bug.php?id=22328  
298 - // for why we can't check errors on fetching  
299 - return null;  
300 - /*  
301 - $errno = @mysql_errno($this->connection);  
302 - if (!$errno) {  
303 - return null;  
304 - }  
305 - return $this->mysqlRaiseError($errno);  
306 - */  
307 - }  
308 - if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {  
309 - /*  
310 - * Even though this DBMS already trims output, we do this because  
311 - * a field might have intentional whitespace at the end that  
312 - * gets removed by DB_PORTABILITY_RTRIM under another driver.  
313 - */  
314 - $this->_rtrimArrayValues($arr);  
315 - }  
316 - if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {  
317 - $this->_convertNullArrayValuesToEmpty($arr);  
318 - }  
319 - return DB_OK;  
320 - }  
321 -  
322 - // }}}  
323 - // {{{ freeResult()  
324 -  
325 - /** 281 + function fetchInto($result, &$arr, $fetchmode, $rownum=null)
  282 + {
  283 + if ($rownum !== null) {
  284 + if (!@mysql_data_seek($result, $rownum)) {
  285 + return null;
  286 + }
  287 + }
  288 + if ($fetchmode & DB_FETCHMODE_ASSOC) {
  289 + $arr = @mysql_fetch_array($result, MYSQL_ASSOC);
  290 + if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
  291 + $arr = array_change_key_case($arr, CASE_LOWER);
  292 + }
  293 + } else {
  294 + $arr = @mysql_fetch_row($result);
  295 + }
  296 + if (!$arr) {
  297 + // See: http://bugs.php.net/bug.php?id=22328
  298 + // for why we can't check errors on fetching
  299 + return null;
  300 + /*
  301 + $errno = @mysql_errno($this->connection);
  302 + if (!$errno) {
  303 + return null;
  304 + }
  305 + return $this->mysqlRaiseError($errno);
  306 + */
  307 + }
  308 + if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
  309 + /*
  310 + * Even though this DBMS already trims output, we do this because
  311 + * a field might have intentional whitespace at the end that
  312 + * gets removed by DB_PORTABILITY_RTRIM under another driver.
  313 + */
  314 + $this->_rtrimArrayValues($arr);
  315 + }
  316 + if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
  317 + $this->_convertNullArrayValuesToEmpty($arr);
  318 + }
  319 + return DB_OK;
  320 + }
  321 +
  322 + // }}}
  323 + // {{{ freeResult()
  324 +
  325 + /**
326 * Free the internal resources associated with $result. 326 * Free the internal resources associated with $result.
327 * 327 *
328 * @param $result MySQL result identifier 328 * @param $result MySQL result identifier
@@ -331,16 +331,16 @@ class DB_mysql extends DB_common @@ -331,16 +331,16 @@ class DB_mysql extends DB_common
331 * 331 *
332 * @return bool true on success, false if $result is invalid 332 * @return bool true on success, false if $result is invalid
333 */ 333 */
334 - function freeResult($result)  
335 - {  
336 - unset($this->num_rows[(int)$result]);  
337 - return @mysql_free_result($result);  
338 - } 334 + function freeResult($result)
  335 + {
  336 + unset($this->num_rows[(int)$result]);
  337 + return @mysql_free_result($result);
  338 + }
339 339
340 - // }}}  
341 - // {{{ numCols() 340 + // }}}
  341 + // {{{ numCols()
342 342
343 - /** 343 + /**
344 * Get the number of columns in a result set. 344 * Get the number of columns in a result set.
345 * 345 *
346 * @param $result MySQL result identifier 346 * @param $result MySQL result identifier
@@ -349,21 +349,21 @@ class DB_mysql extends DB_common @@ -349,21 +349,21 @@ class DB_mysql extends DB_common
349 * 349 *
350 * @return int the number of columns per row in $result 350 * @return int the number of columns per row in $result
351 */ 351 */
352 - function numCols($result)  
353 - {  
354 - $cols = @mysql_num_fields($result); 352 + function numCols($result)
  353 + {
  354 + $cols = @mysql_num_fields($result);
355 355
356 - if (!$cols) {  
357 - return $this->mysqlRaiseError();  
358 - } 356 + if (!$cols) {
  357 + return $this->mysqlRaiseError();
  358 + }
359 359
360 - return $cols;  
361 - } 360 + return $cols;
  361 + }
362 362
363 - // }}}  
364 - // {{{ numRows() 363 + // }}}
  364 + // {{{ numRows()
365 365
366 - /** 366 + /**
367 * Get the number of rows in a result set. 367 * Get the number of rows in a result set.
368 * 368 *
369 * @param $result MySQL result identifier 369 * @param $result MySQL result identifier
@@ -372,99 +372,99 @@ class DB_mysql extends DB_common @@ -372,99 +372,99 @@ class DB_mysql extends DB_common
372 * 372 *
373 * @return int the number of rows in $result 373 * @return int the number of rows in $result
374 */ 374 */
375 - function numRows($result)  
376 - {  
377 - $rows = @mysql_num_rows($result);  
378 - if ($rows === null) {  
379 - return $this->mysqlRaiseError();  
380 - }  
381 - return $rows;  
382 - }  
383 -  
384 - // }}}  
385 - // {{{ autoCommit()  
386 -  
387 - /** 375 + function numRows($result)
  376 + {
  377 + $rows = @mysql_num_rows($result);
  378 + if ($rows === null) {
  379 + return $this->mysqlRaiseError();
  380 + }
  381 + return $rows;
  382 + }
  383 +
  384 + // }}}
  385 + // {{{ autoCommit()
  386 +
  387 + /**
388 * Enable/disable automatic commits 388 * Enable/disable automatic commits
389 */ 389 */
390 - function autoCommit($onoff = false)  
391 - {  
392 - // XXX if $this->transaction_opcount > 0, we should probably  
393 - // issue a warning here.  
394 - $this->autocommit = $onoff ? true : false;  
395 - return DB_OK;  
396 - }  
397 -  
398 - // }}}  
399 - // {{{ commit()  
400 -  
401 - /** 390 + function autoCommit($onoff = false)
  391 + {
  392 + // XXX if $this->transaction_opcount > 0, we should probably
  393 + // issue a warning here.
  394 + $this->autocommit = $onoff ? true : false;
  395 + return DB_OK;
  396 + }
  397 +
  398 + // }}}
  399 + // {{{ commit()
  400 +
  401 + /**
402 * Commit the current transaction. 402 * Commit the current transaction.
403 */ 403 */
404 - function commit()  
405 - {  
406 - if ($this->transaction_opcount > 0) {  
407 - if ($this->_db) {  
408 - if (!@mysql_select_db($this->_db, $this->connection)) {  
409 - return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);  
410 - }  
411 - }  
412 - $result = @mysql_query('COMMIT', $this->connection);  
413 - $result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);  
414 - $this->transaction_opcount = 0;  
415 - if (!$result) {  
416 - return $this->mysqlRaiseError();  
417 - }  
418 - }  
419 - return DB_OK;  
420 - }  
421 -  
422 - // }}}  
423 - // {{{ rollback()  
424 -  
425 - /** 404 + function commit()
  405 + {
  406 + if ($this->transaction_opcount > 0) {
  407 + if ($this->_db) {
  408 + if (!@mysql_select_db($this->_db, $this->connection)) {
  409 + return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
  410 + }
  411 + }
  412 + $result = @mysql_query('COMMIT', $this->connection);
  413 + $result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);
  414 + $this->transaction_opcount = 0;
  415 + if (!$result) {
  416 + return $this->mysqlRaiseError();
  417 + }
  418 + }
  419 + return DB_OK;
  420 + }
  421 +
  422 + // }}}
  423 + // {{{ rollback()
  424 +
  425 + /**
426 * Roll back (undo) the current transaction. 426 * Roll back (undo) the current transaction.
427 */ 427 */
428 - function rollback()  
429 - {  
430 - if ($this->transaction_opcount > 0) {  
431 - if ($this->_db) {  
432 - if (!@mysql_select_db($this->_db, $this->connection)) {  
433 - return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);  
434 - }  
435 - }  
436 - $result = @mysql_query('ROLLBACK', $this->connection);  
437 - $result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);  
438 - $this->transaction_opcount = 0;  
439 - if (!$result) {  
440 - return $this->mysqlRaiseError();  
441 - }  
442 - }  
443 - return DB_OK;  
444 - }  
445 -  
446 - // }}}  
447 - // {{{ affectedRows()  
448 -  
449 - /** 428 + function rollback()
  429 + {
  430 + if ($this->transaction_opcount > 0) {
  431 + if ($this->_db) {
  432 + if (!@mysql_select_db($this->_db, $this->connection)) {
  433 + return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
  434 + }
  435 + }
  436 + $result = @mysql_query('ROLLBACK', $this->connection);
  437 + $result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);
  438 + $this->transaction_opcount = 0;
  439 + if (!$result) {
  440 + return $this->mysqlRaiseError();
  441 + }
  442 + }
  443 + return DB_OK;
  444 + }
  445 +
  446 + // }}}
  447 + // {{{ affectedRows()
  448 +
  449 + /**
450 * Gets the number of rows affected by the data manipulation 450 * Gets the number of rows affected by the data manipulation
451 * query. For other queries, this function returns 0. 451 * query. For other queries, this function returns 0.
452 * 452 *
453 * @return number of rows affected by the last query 453 * @return number of rows affected by the last query
454 */ 454 */
455 - function affectedRows()  
456 - {  
457 - if (DB::isManip($this->last_query)) {  
458 - return @mysql_affected_rows($this->connection);  
459 - } else {  
460 - return 0;  
461 - }  
462 - }  
463 -  
464 - // }}}  
465 - // {{{ errorNative()  
466 -  
467 - /** 455 + function affectedRows()
  456 + {
  457 + if (DB::isManip($this->last_query)) {
  458 + return @mysql_affected_rows($this->connection);
  459 + } else {
  460 + return 0;
  461 + }
  462 + }
  463 +
  464 + // }}}
  465 + // {{{ errorNative()
  466 +
  467 + /**
468 * Get the native error code of the last error (if any) that 468 * Get the native error code of the last error (if any) that
469 * occured on the current connection. 469 * occured on the current connection.
470 * 470 *
@@ -472,15 +472,15 @@ class DB_mysql extends DB_common @@ -472,15 +472,15 @@ class DB_mysql extends DB_common
472 * 472 *
473 * @return int native MySQL error code 473 * @return int native MySQL error code
474 */ 474 */
475 - function errorNative()  
476 - {  
477 - return @mysql_errno($this->connection);  
478 - } 475 + function errorNative()
  476 + {
  477 + return @mysql_errno($this->connection);
  478 + }
479 479
480 - // }}}  
481 - // {{{ nextId() 480 + // }}}
  481 + // {{{ nextId()
482 482
483 - /** 483 + /**
484 * Returns the next free id in a sequence 484 * Returns the next free id in a sequence
485 * 485 *
486 * @param string $seq_name name of the sequence 486 * @param string $seq_name name of the sequence
@@ -493,78 +493,78 @@ class DB_mysql extends DB_common @@ -493,78 +493,78 @@ class DB_mysql extends DB_common
493 * @see DB_common::nextID() 493 * @see DB_common::nextID()
494 * @access public 494 * @access public
495 */ 495 */
496 - function nextId($seq_name, $ondemand = true)  
497 - {  
498 - $seqname = $this->getSequenceName($seq_name);  
499 - do {  
500 - $repeat = 0;  
501 - $this->pushErrorHandling(PEAR_ERROR_RETURN);  
502 - $result = $this->query("UPDATE ${seqname} ".  
503 - 'SET id=LAST_INSERT_ID(id+1)');  
504 - $this->popErrorHandling();  
505 - if ($result === DB_OK) {  
506 - /** COMMON CASE **/  
507 - $id = @mysql_insert_id($this->connection);  
508 - if ($id != 0) {  
509 - return $id;  
510 - }  
511 - /** EMPTY SEQ TABLE **/  
512 - // Sequence table must be empty for some reason, so fill it and return 1  
513 - // Obtain a user-level lock  
514 - $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");  
515 - if (DB::isError($result)) {  
516 - return $this->raiseError($result);  
517 - }  
518 - if ($result == 0) {  
519 - // Failed to get the lock, bail with a DB_ERROR_NOT_LOCKED error  
520 - return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED);  
521 - }  
522 -  
523 - // add the default value  
524 - $result = $this->query("REPLACE INTO ${seqname} (id) VALUES (0)");  
525 - if (DB::isError($result)) {  
526 - return $this->raiseError($result);  
527 - }  
528 -  
529 - // Release the lock  
530 - $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");  
531 - if (DB::isError($result)) {  
532 - return $this->raiseError($result);  
533 - }  
534 - // We know what the result will be, so no need to try again  
535 - return 1;  
536 -  
537 - /** ONDEMAND TABLE CREATION **/  
538 - } elseif ($ondemand && DB::isError($result) &&  
539 - $result->getCode() == DB_ERROR_NOSUCHTABLE)  
540 - {  
541 - $result = $this->createSequence($seq_name);  
542 - if (DB::isError($result)) {  
543 - return $this->raiseError($result);  
544 - } else {  
545 - $repeat = 1;  
546 - }  
547 -  
548 - /** BACKWARDS COMPAT **/  
549 - } elseif (DB::isError($result) &&  
550 - $result->getCode() == DB_ERROR_ALREADY_EXISTS)  
551 - {  
552 - // see _BCsequence() comment  
553 - $result = $this->_BCsequence($seqname);  
554 - if (DB::isError($result)) {  
555 - return $this->raiseError($result);  
556 - }  
557 - $repeat = 1;  
558 - }  
559 - } while ($repeat);  
560 -  
561 - return $this->raiseError($result);  
562 - }  
563 -  
564 - // }}}  
565 - // {{{ createSequence()  
566 -  
567 - /** 496 + function nextId($seq_name, $ondemand = true)
  497 + {
  498 + $seqname = $this->getSequenceName($seq_name);
  499 + do {
  500 + $repeat = 0;
  501 + $this->pushErrorHandling(PEAR_ERROR_RETURN);
  502 + $result = $this->query("UPDATE ${seqname} ".
  503 + 'SET id=LAST_INSERT_ID(id+1)');
  504 + $this->popErrorHandling();
  505 + if ($result === DB_OK) {
  506 + /** COMMON CASE **/
  507 + $id = @mysql_insert_id($this->connection);
  508 + if ($id != 0) {
  509 + return $id;
  510 + }
  511 + /** EMPTY SEQ TABLE **/
  512 + // Sequence table must be empty for some reason, so fill it and return 1
  513 + // Obtain a user-level lock
  514 + $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");
  515 + if (DB::isError($result)) {
  516 + return $this->raiseError($result);
  517 + }
  518 + if ($result == 0) {
  519 + // Failed to get the lock, bail with a DB_ERROR_NOT_LOCKED error
  520 + return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED);
  521 + }
  522 +
  523 + // add the default value
  524 + $result = $this->query("REPLACE INTO ${seqname} (id) VALUES (0)");
  525 + if (DB::isError($result)) {
  526 + return $this->raiseError($result);
  527 + }
  528 +
  529 + // Release the lock
  530 + $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");
  531 + if (DB::isError($result)) {
  532 + return $this->raiseError($result);
  533 + }
  534 + // We know what the result will be, so no need to try again
  535 + return 1;
  536 +
  537 + /** ONDEMAND TABLE CREATION **/
  538 + } elseif ($ondemand && DB::isError($result) &&
  539 + $result->getCode() == DB_ERROR_NOSUCHTABLE)
  540 + {
  541 + $result = $this->createSequence($seq_name);
  542 + if (DB::isError($result)) {
  543 + return $this->raiseError($result);
  544 + } else {
  545 + $repeat = 1;
  546 + }
  547 +
  548 + /** BACKWARDS COMPAT **/
  549 + } elseif (DB::isError($result) &&
  550 + $result->getCode() == DB_ERROR_ALREADY_EXISTS)
  551 + {
  552 + // see _BCsequence() comment
  553 + $result = $this->_BCsequence($seqname);
  554 + if (DB::isError($result)) {
  555 + return $this->raiseError($result);
  556 + }
  557 + $repeat = 1;
  558 + }
  559 + } while ($repeat);
  560 +
  561 + return $this->raiseError($result);
  562 + }
  563 +
  564 + // }}}
  565 + // {{{ createSequence()
  566 +
  567 + /**
568 * Creates a new sequence 568 * Creates a new sequence
569 * 569 *
570 * @param string $seq_name name of the new sequence 570 * @param string $seq_name name of the new sequence
@@ -576,28 +576,28 @@ class DB_mysql extends DB_common @@ -576,28 +576,28 @@ class DB_mysql extends DB_common
576 * @see DB_common::createSequence() 576 * @see DB_common::createSequence()
577 * @access public 577 * @access public
578 */ 578 */
579 - function createSequence($seq_name)  
580 - {  
581 - $seqname = $this->getSequenceName($seq_name);  
582 - $res = $this->query("CREATE TABLE ${seqname} ".  
583 - '(id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'.  
584 - ' PRIMARY KEY(id))');  
585 - if (DB::isError($res)) {  
586 - return $res;  
587 - }  
588 - // insert yields value 1, nextId call will generate ID 2  
589 - $res = $this->query("INSERT INTO ${seqname} (id) VALUES (0)");  
590 - if (DB::isError($res)) {  
591 - return $res;  
592 - }  
593 - // so reset to zero  
594 - return $this->query("UPDATE ${seqname} SET id = 0;");  
595 - }  
596 -  
597 - // }}}  
598 - // {{{ dropSequence()  
599 -  
600 - /** 579 + function createSequence($seq_name)
  580 + {
  581 + $seqname = $this->getSequenceName($seq_name);
  582 + $res = $this->query("CREATE TABLE ${seqname} ".
  583 + '(id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'.
  584 + ' PRIMARY KEY(id))');
  585 + if (DB::isError($res)) {
  586 + return $res;
  587 + }
  588 + // insert yields value 1, nextId call will generate ID 2
  589 + $res = $this->query("INSERT INTO ${seqname} (id) VALUES (0)");
  590 + if (DB::isError($res)) {
  591 + return $res;
  592 + }
  593 + // so reset to zero
  594 + return $this->query("UPDATE ${seqname} SET id = 0;");
  595 + }
  596 +
  597 + // }}}
  598 + // {{{ dropSequence()
  599 +
  600 + /**
601 * Deletes a sequence 601 * Deletes a sequence
602 * 602 *
603 * @param string $seq_name name of the sequence to be deleted 603 * @param string $seq_name name of the sequence to be deleted
@@ -608,62 +608,62 @@ class DB_mysql extends DB_common @@ -608,62 +608,62 @@ class DB_mysql extends DB_common
608 * @see DB_common::dropSequence() 608 * @see DB_common::dropSequence()
609 * @access public 609 * @access public
610 */ 610 */
611 - function dropSequence($seq_name)  
612 - {  
613 - return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));  
614 - } 611 + function dropSequence($seq_name)
  612 + {
  613 + return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
  614 + }
615 615
616 - // }}}  
617 - // {{{ _BCsequence() 616 + // }}}
  617 + // {{{ _BCsequence()
618 618
619 - /** 619 + /**
620 * Backwards compatibility with old sequence emulation implementation 620 * Backwards compatibility with old sequence emulation implementation
621 * (clean up the dupes) 621 * (clean up the dupes)
622 * 622 *
623 * @param string $seqname The sequence name to clean up 623 * @param string $seqname The sequence name to clean up
624 * @return mixed DB_Error or true 624 * @return mixed DB_Error or true
625 */ 625 */
626 - function _BCsequence($seqname)  
627 - {  
628 - // Obtain a user-level lock... this will release any previous  
629 - // application locks, but unlike LOCK TABLES, it does not abort  
630 - // the current transaction and is much less frequently used.  
631 - $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");  
632 - if (DB::isError($result)) {  
633 - return $result;  
634 - }  
635 - if ($result == 0) {  
636 - // Failed to get the lock, can't do the conversion, bail  
637 - // with a DB_ERROR_NOT_LOCKED error  
638 - return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED);  
639 - }  
640 -  
641 - $highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}");  
642 - if (DB::isError($highest_id)) {  
643 - return $highest_id;  
644 - }  
645 - // This should kill all rows except the highest  
646 - // We should probably do something if $highest_id isn't  
647 - // numeric, but I'm at a loss as how to handle that...  
648 - $result = $this->query("DELETE FROM ${seqname} WHERE id <> $highest_id");  
649 - if (DB::isError($result)) {  
650 - return $result;  
651 - }  
652 -  
653 - // If another thread has been waiting for this lock,  
654 - // it will go thru the above procedure, but will have no  
655 - // real effect  
656 - $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");  
657 - if (DB::isError($result)) {  
658 - return $result;  
659 - }  
660 - return true;  
661 - }  
662 -  
663 - // }}}  
664 - // {{{ quoteIdentifier()  
665 -  
666 - /** 626 + function _BCsequence($seqname)
  627 + {
  628 + // Obtain a user-level lock... this will release any previous
  629 + // application locks, but unlike LOCK TABLES, it does not abort
  630 + // the current transaction and is much less frequently used.
  631 + $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");
  632 + if (DB::isError($result)) {
  633 + return $result;
  634 + }
  635 + if ($result == 0) {
  636 + // Failed to get the lock, can't do the conversion, bail
  637 + // with a DB_ERROR_NOT_LOCKED error
  638 + return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED);
  639 + }
  640 +
  641 + $highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}");
  642 + if (DB::isError($highest_id)) {
  643 + return $highest_id;
  644 + }
  645 + // This should kill all rows except the highest
  646 + // We should probably do something if $highest_id isn't
  647 + // numeric, but I'm at a loss as how to handle that...
  648 + $result = $this->query("DELETE FROM ${seqname} WHERE id <> $highest_id");
  649 + if (DB::isError($result)) {
  650 + return $result;
  651 + }
  652 +
  653 + // If another thread has been waiting for this lock,
  654 + // it will go thru the above procedure, but will have no
  655 + // real effect
  656 + $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");
  657 + if (DB::isError($result)) {
  658 + return $result;
  659 + }
  660 + return true;
  661 + }
  662 +
  663 + // }}}
  664 + // {{{ quoteIdentifier()
  665 +
  666 + /**
667 * Quote a string so it can be safely used as a table or column name 667 * Quote a string so it can be safely used as a table or column name
668 * 668 *
669 * Quoting style depends on which database driver is being used. 669 * Quoting style depends on which database driver is being used.
@@ -679,26 +679,26 @@ class DB_mysql extends DB_common @@ -679,26 +679,26 @@ class DB_mysql extends DB_common
679 * @access public 679 * @access public
680 * @internal 680 * @internal
681 */ 681 */
682 - function quoteIdentifier($str)  
683 - {  
684 - return '`' . $str . '`';  
685 - } 682 + function quoteIdentifier($str)
  683 + {
  684 + return '`' . $str . '`';
  685 + }
686 686
687 - // }}}  
688 - // {{{ quote() 687 + // }}}
  688 + // {{{ quote()
689 689
690 - /** 690 + /**
691 * @deprecated Deprecated in release 1.6.0 691 * @deprecated Deprecated in release 1.6.0
692 * @internal 692 * @internal
693 */ 693 */
694 - function quote($str) {  
695 - return $this->quoteSmart($str);  
696 - } 694 + function quote($str) {
  695 + return $this->quoteSmart($str);
  696 + }
697 697
698 - // }}}  
699 - // {{{ escapeSimple() 698 + // }}}
  699 + // {{{ escapeSimple()
700 700
701 - /** 701 + /**
702 * Escape a string according to the current DBMS's standards 702 * Escape a string according to the current DBMS's standards
703 * 703 *
704 * @param string $str the string to be escaped 704 * @param string $str the string to be escaped
@@ -707,46 +707,46 @@ class DB_mysql extends DB_common @@ -707,46 +707,46 @@ class DB_mysql extends DB_common
707 * 707 *
708 * @internal 708 * @internal
709 */ 709 */
710 - function escapeSimple($str) {  
711 - if (function_exists('mysql_real_escape_string')) {  
712 - return @mysql_real_escape_string($str, $this->connection);  
713 - } else {  
714 - return @mysql_escape_string($str);  
715 - }  
716 - }  
717 -  
718 - // }}}  
719 - // {{{ modifyQuery()  
720 -  
721 - function modifyQuery($query)  
722 - {  
723 - if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {  
724 - // "DELETE FROM table" gives 0 affected rows in MySQL.  
725 - // This little hack lets you know how many rows were deleted.  
726 - if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {  
727 - $query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/',  
728 - 'DELETE FROM \1 WHERE 1=1', $query);  
729 - }  
730 - }  
731 - return $query;  
732 - }  
733 -  
734 - // }}}  
735 - // {{{ modifyLimitQuery()  
736 -  
737 - function modifyLimitQuery($query, $from, $count, $params = array())  
738 - {  
739 - if (DB::isManip($query)) {  
740 - return $query . " LIMIT $count";  
741 - } else {  
742 - return $query . " LIMIT $from, $count";  
743 - }  
744 - }  
745 -  
746 - // }}}  
747 - // {{{ mysqlRaiseError()  
748 -  
749 - /** 710 + function escapeSimple($str) {
  711 + if (function_exists('mysql_real_escape_string')) {
  712 + return @mysql_real_escape_string($str, $this->connection);
  713 + } else {
  714 + return @mysql_escape_string($str);
  715 + }
  716 + }
  717 +
  718 + // }}}
  719 + // {{{ modifyQuery()
  720 +
  721 + function modifyQuery($query)
  722 + {
  723 + if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {
  724 + // "DELETE FROM table" gives 0 affected rows in MySQL.
  725 + // This little hack lets you know how many rows were deleted.
  726 + if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
  727 + $query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
  728 + 'DELETE FROM \1 WHERE 1=1', $query);
  729 + }
  730 + }
  731 + return $query;
  732 + }
  733 +
  734 + // }}}
  735 + // {{{ modifyLimitQuery()
  736 +
  737 + function modifyLimitQuery($query, $from, $count, $params = array())
  738 + {
  739 + if (DB::isManip($query)) {
  740 + return $query . " LIMIT $count";
  741 + } else {
  742 + return $query . " LIMIT $from, $count";
  743 + }
  744 + }
  745 +
  746 + // }}}
  747 + // {{{ mysqlRaiseError()
  748 +
  749 + /**
750 * Gather information about an error, then use that info to create a 750 * Gather information about an error, then use that info to create a
751 * DB error object and finally return that object. 751 * DB error object and finally return that object.
752 * 752 *
@@ -756,30 +756,30 @@ class DB_mysql extends DB_common @@ -756,30 +756,30 @@ class DB_mysql extends DB_common
756 * @see DB_common::errorCode() 756 * @see DB_common::errorCode()
757 * @see DB_common::raiseError() 757 * @see DB_common::raiseError()
758 */ 758 */
759 - function mysqlRaiseError($errno = null)  
760 - {  
761 - if ($errno === null) {  
762 - if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {  
763 - $this->errorcode_map[1022] = DB_ERROR_CONSTRAINT;  
764 - $this->errorcode_map[1048] = DB_ERROR_CONSTRAINT_NOT_NULL;  
765 - $this->errorcode_map[1062] = DB_ERROR_CONSTRAINT;  
766 - } else {  
767 - // Doing this in case mode changes during runtime.  
768 - $this->errorcode_map[1022] = DB_ERROR_ALREADY_EXISTS;  
769 - $this->errorcode_map[1048] = DB_ERROR_CONSTRAINT;  
770 - $this->errorcode_map[1062] = DB_ERROR_ALREADY_EXISTS;  
771 - }  
772 - $errno = $this->errorCode(mysql_errno($this->connection));  
773 - }  
774 - return $this->raiseError($errno, null, null, null,  
775 - @mysql_errno($this->connection) . ' ** ' .  
776 - @mysql_error($this->connection));  
777 - }  
778 -  
779 - // }}}  
780 - // {{{ tableInfo()  
781 -  
782 - /** 759 + function mysqlRaiseError($errno = null)
  760 + {
  761 + if ($errno === null) {
  762 + if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
  763 + $this->errorcode_map[1022] = DB_ERROR_CONSTRAINT;
  764 + $this->errorcode_map[1048] = DB_ERROR_CONSTRAINT_NOT_NULL;
  765 + $this->errorcode_map[1062] = DB_ERROR_CONSTRAINT;
  766 + } else {
  767 + // Doing this in case mode changes during runtime.
  768 + $this->errorcode_map[1022] = DB_ERROR_ALREADY_EXISTS;
  769 + $this->errorcode_map[1048] = DB_ERROR_CONSTRAINT;
  770 + $this->errorcode_map[1062] = DB_ERROR_ALREADY_EXISTS;
  771 + }
  772 + $errno = $this->errorCode(mysql_errno($this->connection));
  773 + }
  774 + return $this->raiseError($errno, null, null, null,
  775 + @mysql_errno($this->connection) . ' ** ' .
  776 + @mysql_error($this->connection));
  777 + }
  778 +
  779 + // }}}
  780 + // {{{ tableInfo()
  781 +
  782 + /**
783 * Returns information about a table or a result set. 783 * Returns information about a table or a result set.
784 * 784 *
785 * @param object|string $result DB_result object from a query or a 785 * @param object|string $result DB_result object from a query or a
@@ -791,126 +791,142 @@ class DB_mysql extends DB_common @@ -791,126 +791,142 @@ class DB_mysql extends DB_common
791 * @internal 791 * @internal
792 * @see DB_common::tableInfo() 792 * @see DB_common::tableInfo()
793 */ 793 */
794 - function tableInfo($result, $mode = null) {  
795 - if (isset($result->result)) {  
796 - /*  
797 - * Probably received a result object.  
798 - * Extract the result resource identifier.  
799 - */  
800 - $id = $result->result;  
801 - $got_string = false;  
802 - } elseif (is_string($result)) {  
803 - /*  
804 - * Probably received a table name.  
805 - * Create a result resource identifier.  
806 - */  
807 - $id = @mysql_list_fields($this->dsn['database'],  
808 - $result, $this->connection);  
809 - $got_string = true;  
810 - } else {  
811 - /*  
812 - * Probably received a result resource identifier.  
813 - * Copy it.  
814 - * Deprecated. Here for compatibility only.  
815 - */  
816 - $id = $result;  
817 - $got_string = false;  
818 - }  
819 -  
820 - if (!is_resource($id)) {  
821 - return $this->mysqlRaiseError(DB_ERROR_NEED_MORE_DATA);  
822 - }  
823 -  
824 - if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {  
825 - $case_func = 'strtolower';  
826 - } else {  
827 - $case_func = 'strval';  
828 - }  
829 -  
830 - $count = @mysql_num_fields($id);  
831 -  
832 - // made this IF due to performance (one if is faster than $count if's)  
833 - if (!$mode) {  
834 - for ($i=0; $i<$count; $i++) {  
835 - $res[$i]['table'] = $case_func(@mysql_field_table($id, $i));  
836 - $res[$i]['name'] = $case_func(@mysql_field_name($id, $i));  
837 - $res[$i]['type'] = @mysql_field_type($id, $i);  
838 - $res[$i]['len'] = @mysql_field_len($id, $i);  
839 - $res[$i]['flags'] = @mysql_field_flags($id, $i);  
840 - }  
841 - } else { // full  
842 - $res['num_fields']= $count;  
843 -  
844 - for ($i=0; $i<$count; $i++) {  
845 - $res[$i]['table'] = $case_func(@mysql_field_table($id, $i));  
846 - $res[$i]['name'] = $case_func(@mysql_field_name($id, $i));  
847 - $res[$i]['type'] = @mysql_field_type($id, $i);  
848 - $res[$i]['len'] = @mysql_field_len($id, $i);  
849 - $res[$i]['flags'] = @mysql_field_flags($id, $i);  
850 -  
851 - if ($mode & DB_TABLEINFO_ORDER) {  
852 - $res['order'][$res[$i]['name']] = $i;  
853 - }  
854 - if ($mode & DB_TABLEINFO_ORDERTABLE) {  
855 - $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;  
856 - }  
857 - }  
858 - }  
859 -  
860 - // free the result only if we were called on a table  
861 - if ($got_string) {  
862 - @mysql_free_result($id);  
863 - }  
864 - return $res;  
865 - }  
866 -  
867 - // }}}  
868 - // {{{ getSpecialQuery()  
869 -  
870 - /** 794 + function tableInfo($result, $mode = null) {
  795 + if (isset($result->result)) {
  796 + /*
  797 + * Probably received a result object.
  798 + * Extract the result resource identifier.
  799 + */
  800 + $id = $result->result;
  801 + $got_string = false;
  802 + } elseif (is_string($result)) {
  803 + /*
  804 + * Probably received a table name.
  805 + * Create a result resource identifier.
  806 + */
  807 + $id = @mysql_list_fields($this->dsn['database'],
  808 + $result, $this->connection);
  809 + $got_string = true;
  810 + } else {
  811 + /*
  812 + * Probably received a result resource identifier.
  813 + * Copy it.
  814 + * Deprecated. Here for compatibility only.
  815 + */
  816 + $id = $result;
  817 + $got_string = false;
  818 + }
  819 +
  820 + if (!is_resource($id)) {
  821 + return $this->mysqlRaiseError(DB_ERROR_NEED_MORE_DATA);
  822 + }
  823 +
  824 + if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
  825 + $case_func = 'strtolower';
  826 + } else {
  827 + $case_func = 'strval';
  828 + }
  829 +
  830 + $count = @mysql_num_fields($id);
  831 +
  832 + // made this IF due to performance (one if is faster than $count if's)
  833 + if (!$mode) {
  834 + for ($i=0; $i<$count; $i++) {
  835 + $res[$i]['table'] = $case_func(@mysql_field_table($id, $i));
  836 + $res[$i]['name'] = $case_func(@mysql_field_name($id, $i));
  837 + $res[$i]['type'] = @mysql_field_type($id, $i);
  838 + $res[$i]['len'] = @mysql_field_len($id, $i);
  839 + $res[$i]['flags'] = @mysql_field_flags($id, $i);
  840 + }
  841 + } else { // full
  842 + $res['num_fields']= $count;
  843 +
  844 + for ($i=0; $i<$count; $i++) {
  845 + $res[$i]['table'] = $case_func(@mysql_field_table($id, $i));
  846 + $res[$i]['name'] = $case_func(@mysql_field_name($id, $i));
  847 + $res[$i]['type'] = @mysql_field_type($id, $i);
  848 + $res[$i]['len'] = @mysql_field_len($id, $i);
  849 + $res[$i]['flags'] = @mysql_field_flags($id, $i);
  850 +
  851 + if ($mode & DB_TABLEINFO_ORDER) {
  852 + $res['order'][$res[$i]['name']] = $i;
  853 + }
  854 + if ($mode & DB_TABLEINFO_ORDERTABLE) {
  855 + $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
  856 + }
  857 + }
  858 + }
  859 +
  860 + // free the result only if we were called on a table
  861 + if ($got_string) {
  862 + @mysql_free_result($id);
  863 + }
  864 + return $res;
  865 + }
  866 +
  867 + // }}}
  868 + // {{{ getSpecialQuery()
  869 +
  870 + /**
871 * Returns the query needed to get some backend info 871 * Returns the query needed to get some backend info
872 * @param string $type What kind of info you want to retrieve 872 * @param string $type What kind of info you want to retrieve
873 * @return string The SQL query string 873 * @return string The SQL query string
874 */ 874 */
875 - function getSpecialQuery($type)  
876 - {  
877 - switch ($type) {  
878 - case 'tables':  
879 - return 'SHOW TABLES';  
880 - case 'views':  
881 - return DB_ERROR_NOT_CAPABLE;  
882 - case 'users':  
883 - $sql = 'select distinct User from user';  
884 - if ($this->dsn['database'] != 'mysql') {  
885 - $dsn = $this->dsn;  
886 - $dsn['database'] = 'mysql';  
887 - if (DB::isError($db = DB::connect($dsn))) {  
888 - return $db;  
889 - }  
890 - $sql = $db->getCol($sql);  
891 - $db->disconnect();  
892 - // XXX Fixme the mysql driver should take care of this  
893 - if (!@mysql_select_db($this->dsn['database'], $this->connection)) {  
894 - return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);  
895 - }  
896 - }  
897 - return $sql;  
898 - case 'databases':  
899 - return 'SHOW DATABASES';  
900 - default:  
901 - return null;  
902 - }  
903 - }  
904 -  
905 - // }}} 875 + function getSpecialQuery($type)
  876 + {
  877 + switch ($type) {
  878 + case 'tables':
  879 + return 'SHOW TABLES';
  880 + case 'views':
  881 + return DB_ERROR_NOT_CAPABLE;
  882 + case 'users':
  883 + $sql = 'select distinct User from user';
  884 + if ($this->dsn['database'] != 'mysql') {
  885 + $dsn = $this->dsn;
  886 + $dsn['database'] = 'mysql';
  887 + if (DB::isError($db = DB::connect($dsn))) {
  888 + return $db;
  889 + }
  890 + $sql = $db->getCol($sql);
  891 + $db->disconnect();
  892 + // XXX Fixme the mysql driver should take care of this
  893 + if (!@mysql_select_db($this->dsn['database'], $this->connection)) {
  894 + return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
  895 + }
  896 + }
  897 + return $sql;
  898 + case 'databases':
  899 + return 'SHOW DATABASES';
  900 + default:
  901 + return null;
  902 + }
  903 + }
  904 +
  905 + // }}}
  906 +
  907 + // {{{ _getLastId()
  908 +
  909 + /**
  910 + * Returns the last insert ID
  911 + *
  912 + * @return int
  913 + *
  914 + * @access private
  915 + */
  916 + function _getLastId()
  917 + {
  918 + return mysql_insert_id($this->connection);
  919 + }
  920 +
  921 + // }}}
906 922
907 } 923 }
908 924
909 /* 925 /*
910 - * Local variables:  
911 - * tab-width: 4  
912 - * c-basic-offset: 4  
913 - * End:  
914 - */ 926 +* Local variables:
  927 +* tab-width: 4
  928 +* c-basic-offset: 4
  929 +* End:
  930 +*/
915 931
916 ?> 932 ?>