3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2002 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Author: Stig Bakken <ssb@fast.no> |
17 // +----------------------------------------------------------------------+
19 // Based on DB 1.3 from the pear.php.net repository.
20 // The only modifications made have been modification of the include paths.
22 rcs_id('$Id: common.php,v 1.2 2002-09-12 11:45:33 rurban Exp $');
23 rcs_id('From Pear CVS: Id: common.php,v 1.8 2002/06/12 15:03:16 fab Exp');
25 // Base class for DB implementations.
29 * DB_common is a base class for DB implementations, and must be
30 * inherited by all such.
33 class DB_common extends PEAR
37 * assoc of capabilities for this DB implementation
38 * $features['limit'] => 'emulate' => emulate with fetch row by number
39 * 'alter' => alter the query
46 * assoc mapping native error codes to DB ones
52 * DB type (mysql, oci8, odbc etc.)
70 var $prepared_queries;
75 var $prepare_maxstmt = 0;
85 var $fetchmode = DB_FETCHMODE_ORDERED;
90 var $fetchmode_object_class = 'stdClass';
93 * $options["persistent"] -> boolean persistent connection true|false?
94 * $options["optimize"] -> string 'performance' or 'portability'
95 * $options["debug"] -> integer numeric debug level
99 'persistent' => false,
100 'optimize' => 'performance',
102 'seqname_format' => '%s_seq',
115 * String conversation
122 $info = get_class($this);
123 $info .= ": (phptype=" . $this->phptype .
124 ", dbsyntax=" . $this->dbsyntax .
127 if ($this->connection) {
128 $info .= " [connected]";
141 $this->PEAR('DB_Error');
142 $this->features = array();
143 $this->errorcode_map = array();
144 $this->fetchmode = DB_FETCHMODE_ORDERED;
151 * Quotes a string so it can be safely used within string delimiters
152 * in a query (preserved for compatibility issues, quote() is preffered).
154 * @return string quoted string
158 function quoteString($string)
160 $string = $this->quote($string);
161 if ($string{0} == "'") {
162 return substr($string, 1, -1);
168 * Quotes a string so it can be safely used in a query. It will return
169 * the string with single quotes around. Other backend quote styles
170 * should override this method.
172 * @param string $string the input string to quote
174 * @return string The NULL string or the string quotes
175 * in magic_quote_sybase style
177 function quote($string)
179 return ($string === null) ? 'NULL' : "'".str_replace("'", "''", $string)."'";
186 * Tell whether a DB implementation or its backend extension
187 * supports a given feature.
189 * @param array $feature name of the feature (see the DB class doc)
190 * @return bool whether this DB implementation supports $feature
194 function provides($feature)
196 return $this->features[$feature];
203 * Map native error codes to DB's portable ones. Requires that
204 * the DB implementation's constructor fills in the $errorcode_map
207 * @param mixed $nativecode the native error code, as returned by the backend
208 * database extension (string or integer)
210 * @return int a portable DB error code, or FALSE if this DB
211 * implementation has no mapping for the given error code.
216 function errorCode($nativecode)
218 if (isset($this->errorcode_map[$nativecode])) {
219 return $this->errorcode_map[$nativecode];
221 // Fall back to DB_ERROR if there was no mapping.
226 // {{{ errorMessage()
229 * Map a DB error code to a textual message. This is actually
230 * just a wrapper for DB::errorMessage().
232 * @param integer $dbcode the DB error code
234 * @return string the corresponding error message, of FALSE
235 * if the error code was unknown
240 function errorMessage($dbcode)
242 return DB::errorMessage($this->errorcode_map[$dbcode]);
249 * This method is used to communicate an error and invoke error
250 * callbacks etc. Basically a wrapper for PEAR::raiseError
251 * without the message string.
253 * @param mixed integer error code, or a PEAR error object (all
254 * other parameters are ignored if this parameter is
257 * @param int error mode, see PEAR_Error docs
259 * @param mixed If error mode is PEAR_ERROR_TRIGGER, this is the
260 * error level (E_USER_NOTICE etc). If error mode is
261 * PEAR_ERROR_CALLBACK, this is the callback function,
262 * either as a function name, or as an array of an
263 * object and method name. For other error modes this
264 * parameter is ignored.
266 * @param string Extra debug information. Defaults to the last
267 * query and native error code.
269 * @param mixed Native error code, integer or string depending the
272 * @return object a PEAR error object
277 function &raiseError($code = DB_ERROR, $mode = null, $options = null,
278 $userinfo = null, $nativecode = null)
280 // The error is yet a DB error object
281 if (is_object($code)) {
282 // because we the static PEAR::raiseError, our global
283 // handler should be used if it is set
284 if ($mode === null && !empty($this->_default_error_mode)) {
285 $mode = $this->_default_error_mode;
286 $options = $this->_default_error_options;
288 return PEAR::raiseError($code, null, $mode, $options, null, null, true);
291 if ($userinfo === null) {
292 $userinfo = $this->last_query;
296 $userinfo .= " [nativecode=$nativecode]";
299 return PEAR::raiseError(null, $code, $mode, $options, $userinfo,
304 // {{{ setFetchMode()
307 * Sets which fetch mode should be used by default on queries
308 * on this connection.
310 * @param integer $fetchmode DB_FETCHMODE_ORDERED or
311 * DB_FETCHMODE_ASSOC, possibly bit-wise OR'ed with
312 * DB_FETCHMODE_FLIPPED.
314 * @param string $object_class The class of the object
315 * to be returned by the fetch methods when
316 * the DB_FETCHMODE_OBJECT mode is selected.
317 * If no class is specified by default a cast
318 * to object from the assoc array row will be done.
319 * There is also the posibility to use and extend the
322 * @see DB_FETCHMODE_ORDERED
323 * @see DB_FETCHMODE_ASSOC
324 * @see DB_FETCHMODE_FLIPPED
325 * @see DB_FETCHMODE_OBJECT
326 * @see DB_Row::DB_Row()
330 function setFetchMode($fetchmode, $object_class = null)
332 switch ($fetchmode) {
333 case DB_FETCHMODE_OBJECT:
335 $this->fetchmode_object_class = $object_class;
337 case DB_FETCHMODE_ORDERED:
338 case DB_FETCHMODE_ASSOC:
339 $this->fetchmode = $fetchmode;
342 return $this->raiseError('invalid fetchmode mode');
349 * set the option for the db class
351 * @param string $option option name
352 * @param mixed $value value for the option
354 * @return mixed DB_OK or DB_Error
356 function setOption($option, $value)
358 if (isset($this->options[$option])) {
359 $this->options[$option] = $value;
362 return $this->raiseError("unknown option $option");
368 * returns the value of an option
370 * @param string $option option name
372 * @return mixed the option value
374 function getOption($option)
376 if (isset($this->options[$option])) {
377 return $this->options[$option];
379 return $this->raiseError("unknown option $option");
386 * Prepares a query for multiple execution with execute().
387 * With some database backends, this is emulated.
388 * prepare() requires a generic query as string like
389 * "INSERT INTO numbers VALUES(?,?,?)". The ? are wildcards.
390 * Types of wildcards:
391 * ? - a quoted scalar value, i.e. strings, integers
392 * & - requires a file name, the content of the file
393 * insert into the query (i.e. saving binary data
395 * ! - value is inserted 'as is'
397 * @param string the query to prepare
399 * @return resource handle for the query
405 function prepare($query)
407 $tokens = split("[\&\?\!]", $query);
411 for ($i = 0; $i < strlen($query); $i++) {
412 switch ($query[$i]) {
414 $types[$token++] = DB_PARAM_SCALAR;
417 $types[$token++] = DB_PARAM_OPAQUE;
420 $types[$token++] = DB_PARAM_MISC;
425 $this->prepare_tokens[] = &$tokens;
426 end($this->prepare_tokens);
428 $k = key($this->prepare_tokens);
429 $this->prepare_types[$k] = $types;
430 $this->prepared_queries[$k] = &$query;
439 * Make automaticaly an insert or update query and call prepare() with it
441 * @param string $table name of the table
442 * @param array $table_fields ordered array containing the fields names
443 * @param int $mode type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE)
444 * @param string $where in case of update queries, this string will be put after the sql WHERE statement
445 * @return resource handle for the query
449 function autoPrepare($table, $table_fields, $mode = DB_AUTOQUERY_INSERT, $where = false)
451 $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
452 return $this->prepare($query);
459 * Make automaticaly an insert or update query and call prepare() and execute() with it
461 * @param string $table name of the table
462 * @param array $fields_values assoc ($key=>$value) where $key is a field name and $value its value
463 * @param int $mode type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE)
464 * @param string $where in case of update queries, this string will be put after the sql WHERE statement
465 * @return mixed a new DB_Result or a DB_Error when fail
470 function autoExecute($table, $fields_values, $mode = DB_AUTOQUERY_INSERT, $where = false)
472 $sth = $this->autoPrepare($table, array_keys($fields_values), $mode, $where);
473 return $this->execute($sth, array_values($fields_values));
478 // }}} buildManipSQL()
481 * Make automaticaly an sql query for prepare()
483 * Example : buildManipSQL('table_sql', array('field1', 'field2', 'field3'), DB_AUTOQUERY_INSERT)
484 * will return the string : INSERT INTO table_sql (field1,field2,field3) VALUES (?,?,?)
485 * NB : - This belongs more to a SQL Builder class, but this is a simple facility
486 * - Be carefull ! If you don't give a $where param with an UPDATE query, all
487 * the records of the table will be updated !
489 * @param string $table name of the table
490 * @param array $table_fields ordered array containing the fields names
491 * @param int $mode type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE)
492 * @param string $where in case of update queries, this string will be put after the sql WHERE statement
493 * @return string sql query for prepare()
496 function buildManipSQL($table, $table_fields, $mode, $where = false)
498 if (count($table_fields)==0) {
499 $this->raiseError(DB_ERROR_NEED_MORE_DATA);
503 case DB_AUTOQUERY_INSERT:
506 while (list(, $value) = each($table_fields)) {
516 return "INSERT INTO $table ($names) VALUES ($values)";
518 case DB_AUTOQUERY_UPDATE:
520 while (list(, $value) = each($table_fields)) {
526 $set .= "$value = ?";
528 $sql = "UPDATE $table SET $set";
530 $sql .= " WHERE $sql";
535 $this->raiseError(DB_ERROR_SYNTAX);
542 * Executes a prepared SQL query
543 * With execute() the generic query of prepare is
544 * assigned with the given data array. The values
545 * of the array inserted into the query in the same
546 * order like the array order
548 * @param resource $stmt query handle from prepare()
549 * @param array $data numeric array containing the
550 * data to insert into the query
552 * @return mixed a new DB_Result or a DB_Error when fail
557 function execute($stmt, $data = false)
559 $realquery = $this->executeEmulateQuery($stmt, $data);
560 if (DB::isError($realquery)) {
563 $result = $this->simpleQuery($realquery);
564 if (DB::isError($result) || $result === DB_OK) {
567 return new DB_result($this, $result);
572 // {{{ executeEmulateQuery()
575 * Emulates the execute statement, when not supported
577 * @param resource $stmt query handle from prepare()
578 * @param array $data numeric array containing the
579 * data to insert into the query
581 * @return mixed a string containing the real query run when emulating
582 * prepare/execute. A DB error code is returned on failure.
588 function executeEmulateQuery($stmt, $data = false)
590 $p = &$this->prepare_tokens;
592 if (!isset($this->prepare_tokens[$stmt]) ||
593 !is_array($this->prepare_tokens[$stmt]) ||
594 !sizeof($this->prepare_tokens[$stmt]))
596 return $this->raiseError(DB_ERROR_INVALID);
599 $qq = &$this->prepare_tokens[$stmt];
600 $qp = sizeof($qq) - 1;
602 if ((!$data && $qp > 0) ||
603 (!is_array($data) && $qp > 1) ||
604 (is_array($data) && $qp > sizeof($data)))
606 $this->last_query = $this->prepared_queries[$stmt];
607 return $this->raiseError(DB_ERROR_NEED_MORE_DATA);
611 for ($i = 0; $i < $qp; $i++) {
612 $type = $this->prepare_types[$stmt][$i];
613 if ($type == DB_PARAM_OPAQUE) {
614 if (is_array($data)) {
615 $fp = fopen($data[$i], 'r');
617 $fp = fopen($data, 'r');
623 while (($buf = fread($fp, 4096)) != false) {
628 if (is_array($data)) {
635 $realquery .= ($type != DB_PARAM_MISC) ? $this->quote($pdata) : $pdata;
636 $realquery .= $qq[$i + 1];
643 // {{{ executeMultiple()
646 * This function does several execute() calls on the same
647 * statement handle. $data must be an array indexed numerically
648 * from 0, one execute call is done for every "row" in the array.
650 * If an error occurs during execute(), executeMultiple() does not
651 * execute the unfinished rows, but rather returns that error.
653 * @param resource $stmt query handle from prepare()
654 * @param array $data numeric array containing the
655 * data to insert into the query
657 * @return mixed DB_OK or DB_Error
660 * @see prepare(), execute()
663 function executeMultiple( $stmt, &$data )
665 for($i = 0; $i < sizeof( $data ); $i++) {
666 $res = $this->execute($stmt, $data[$i]);
667 if (DB::isError($res)) {
678 * This method is used by backends to alter queries for various
679 * reasons. It is defined here to assure that all implementations
680 * have this method defined.
682 * @param string $query query to modify
684 * @return the new (modified) query
688 function modifyQuery($query) {
693 // {{{ modifyLimitQuery()
695 * This method is used by backends to alter limited queries
697 * @param string $query query to modify
698 * @param integer $from the row to start to fetching
699 * @param integer $count the numbers of rows to fetch
701 * @return the new (modified) query
706 function modifyLimitQuery($query, $from, $count)
715 * Send a query to the database and return any results with a
720 * @param string $query the SQL query or the statement to prepare
721 * @param string $params the data to be added to the query
722 * @return mixed a DB_result object or DB_OK on success, a DB
726 * @see DB_common::prepare
727 * @see DB_common::execute
729 function &query($query, $params = array()) {
730 if (sizeof($params) > 0) {
731 $sth = $this->prepare($query);
732 if (DB::isError($sth)) {
735 return $this->execute($sth, $params);
737 $result = $this->simpleQuery($query);
738 if (DB::isError($result) || $result === DB_OK) {
741 return new DB_result($this, $result);
749 * Generates a limited query
752 * @param string $query query
753 * @param integer $from the row to start to fetching
754 * @param integer $count the numbers of rows to fetch
756 * @return mixed a DB_Result object or a DB_Error
760 function &limitQuery($query, $from, $count)
762 $query = $this->modifyLimitQuery($query, $from, $count);
763 $result = $this->simpleQuery($query);
764 if (DB::isError($result) || $result === DB_OK) {
767 $options['limit_from'] = $from;
768 $options['limit_count'] = $count;
769 return new DB_result($this, $result, $options);
777 * Fetch the first column of the first row of data returned from
778 * a query. Takes care of doing the query and freeing the results
781 * @param string $query the SQL query
782 * @param array $params if supplied, prepare/execute will be used
783 * with this array as execute parameters
785 * @return mixed DB_Error or the returned value of the query
790 function &getOne($query, $params = array())
792 settype($params, "array");
793 if (sizeof($params) > 0) {
794 $sth = $this->prepare($query);
795 if (DB::isError($sth)) {
798 $res = $this->execute($sth, $params);
800 $res = $this->query($query);
803 if (DB::isError($res)) {
807 $err = $res->fetchInto($row, DB_FETCHMODE_ORDERED);
808 if ($err !== DB_OK) {
815 $this->freeResult($sth);
825 * Fetch the first row of data returned from a query. Takes care
826 * of doing the query and freeing the results when finished.
828 * @param string $query the SQL query
829 * @param integer $fetchmode the fetch mode to use
830 * @param array $params array if supplied, prepare/execute will be used
831 * with this array as execute parameters
833 * @return array the first row of results as an array indexed from
834 * 0, or a DB error code.
837 function &getRow($query,
839 $fetchmode = DB_FETCHMODE_DEFAULT)
841 // compat check, the params and fetchmode parameters used to
842 // have the opposite order
843 if (!is_array($params)) {
844 if (is_array($fetchmode)) {
846 $params = $fetchmode;
848 } elseif ($params !== null) {
849 $fetchmode = $params;
853 $params = (empty($params)) ? array() : $params;
854 $fetchmode = (empty($fetchmode)) ? DB_FETCHMODE_DEFAULT : $fetchmode;
855 settype($params, 'array');
856 if (sizeof($params) > 0) {
857 $sth = $this->prepare($query);
858 if (DB::isError($sth)) {
861 $res = $this->execute($sth, $params);
863 $res = $this->query($query);
866 if (DB::isError($res)) {
870 $err = $res->fetchInto($row, $fetchmode);
872 if ($err !== DB_OK) {
878 $this->freeResult($sth);
888 * Fetch a single column from a result set and return it as an
891 * @param string $query the SQL query
893 * @param mixed $col which column to return (integer [column number,
894 * starting at 0] or string [column name])
896 * @param array $params array if supplied, prepare/execute will be used
897 * with this array as execute parameters
900 * @return array an indexed array with the data from the first
901 * row at index 0, or a DB error code.
904 function &getCol($query, $col = 0, $params = array())
906 settype($params, "array");
907 if (sizeof($params) > 0) {
908 $sth = $this->prepare($query);
910 if (DB::isError($sth)) {
914 $res = $this->execute($sth, $params);
916 $res = $this->query($query);
919 if (DB::isError($res)) {
923 $fetchmode = is_int($col) ? DB_FETCHMODE_ORDERED : DB_FETCHMODE_ASSOC;
926 while (is_array($row = $res->fetchRow($fetchmode))) {
929 if (DB::isError($row)) {
935 $this->freeResult($sth);
945 * Fetch the entire result set of a query and return it as an
946 * associative array using the first column as the key.
948 * If the result set contains more than two columns, the value
949 * will be an array of the values from column 2-n. If the result
950 * set contains only two columns, the returned value will be a
951 * scalar with the value of the second column (unless forced to an
952 * array with the $force_array parameter). A DB error code is
953 * returned on errors. If the result set contains fewer than two
954 * columns, a DB_ERROR_TRUNCATED error is returned.
956 * For example, if the table "mytable" contains:
959 * --------------------------------
962 * 3 'three' 944679408
964 * Then the call getAssoc('SELECT id,text FROM mytable') returns:
971 * ...while the call getAssoc('SELECT id,text,date FROM mytable') returns:
973 * '1' => array('one', '944679408'),
974 * '2' => array('two', '944679408'),
975 * '3' => array('three', '944679408')
978 * If the more than one row occurs with the same value in the
979 * first column, the last row overwrites all previous ones by
980 * default. Use the $group parameter if you don't want to
981 * overwrite like this. Example:
983 * getAssoc('SELECT category,id,name FROM mytable', false, null,
984 * DB_FETCHMODE_ASSOC, true) returns:
986 * '1' => array(array('id' => '4', 'name' => 'number four'),
987 * array('id' => '6', 'name' => 'number six')
989 * '9' => array(array('id' => '4', 'name' => 'number four'),
990 * array('id' => '6', 'name' => 'number six')
994 * Keep in mind that database functions in PHP usually return string
995 * values for results regardless of the database's internal type.
997 * @param string $query the SQL query
999 * @param boolean $force_array used only when the query returns
1000 * exactly two columns. If true, the values of the returned array
1001 * will be one-element arrays instead of scalars.
1003 * @param array $params array if supplied, prepare/execute will be used
1004 * with this array as execute parameters
1006 * @param boolean $group if true, the values of the returned array
1007 * is wrapped in another array. If the same
1008 * key value (in the first column) repeats
1009 * itself, the values will be appended to
1010 * this array instead of overwriting the
1015 * @return array associative array with results from the query.
1018 function &getAssoc($query, $force_array = false, $params = array(),
1019 $fetchmode = DB_FETCHMODE_ORDERED, $group = false)
1021 settype($params, "array");
1022 if (sizeof($params) > 0) {
1023 $sth = $this->prepare($query);
1025 if (DB::isError($sth)) {
1029 $res = $this->execute($sth, $params);
1031 $res = $this->query($query);
1034 if (DB::isError($res)) {
1038 $cols = $res->numCols();
1041 return $this->raiseError(DB_ERROR_TRUNCATED);
1046 if ($cols > 2 || $force_array) {
1047 // return array values
1048 // XXX this part can be optimized
1049 if ($fetchmode == DB_FETCHMODE_ASSOC) {
1050 while (is_array($row = $res->fetchRow(DB_FETCHMODE_ASSOC))) {
1052 $key = current($row);
1053 unset($row[key($row)]);
1055 $results[$key][] = $row;
1057 $results[$key] = $row;
1061 while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) {
1062 // we shift away the first element to get
1063 // indices running from 0 again
1064 $key = array_shift($row);
1066 $results[$key][] = $row;
1068 $results[$key] = $row;
1072 if (DB::isError($row)) {
1076 // return scalar values
1077 while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) {
1079 $results[$row[0]][] = $row[1];
1081 $results[$row[0]] = $row[1];
1084 if (DB::isError($row)) {
1092 $this->freeResult($sth);
1102 * Fetch all the rows returned from a query.
1104 * @param string $query the SQL query
1106 * @param array $params array if supplied, prepare/execute will be used
1107 * with this array as execute parameters
1108 * @param integer $fetchmode the fetch mode to use
1111 * @return array an nested array, or a DB error
1114 function &getAll($query,
1116 $fetchmode = DB_FETCHMODE_DEFAULT)
1118 // compat check, the params and fetchmode parameters used to
1119 // have the opposite order
1120 if (!is_array($params)) {
1121 if (is_array($fetchmode)) {
1123 $params = $fetchmode;
1125 } elseif ($params !== null) {
1126 $fetchmode = $params;
1130 $params = (empty($params)) ? array() : $params;
1131 $fetchmode = (empty($fetchmode)) ? DB_FETCHMODE_DEFAULT : $fetchmode;
1132 settype($params, "array");
1133 if (sizeof($params) > 0) {
1134 $sth = $this->prepare($query);
1136 if (DB::isError($sth)) {
1140 $res = $this->execute($sth, $params);
1142 $res = $this->query($query);
1145 if (DB::isError($res)) {
1150 $this->pushErrorHandling(PEAR_ERROR_RETURN);
1151 while (DB_OK === $res->fetchInto($row, $fetchmode)) {
1152 if ($fetchmode & DB_FETCHMODE_FLIPPED) {
1153 foreach ($row as $key => $val) {
1154 $results[$key][] = $val;
1160 $this->popErrorHandling();
1165 $this->freeResult($sth);
1167 if (DB::isError($row)) {
1168 return $this->raiseError($row);
1176 * enable automatic Commit
1178 * @param boolean $onoff
1179 * @return mixed DB_Error
1183 function autoCommit($onoff=false)
1185 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1193 * @return mixed DB_Error
1199 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1207 * @return mixed DB_Error
1213 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1219 * returns the number of rows in a result object
1221 * @param object DB_Result the result object to check
1223 * @return mixed DB_Error or the number of rows
1227 function numRows($result)
1229 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1233 // {{{ affectedRows()
1235 * returns the affected rows of a query
1237 * @return mixed DB_Error or number of rows
1241 function affectedRows()
1243 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1247 // {{{ errorNative()
1249 * returns an errormessage, provides by the database
1251 * @return mixed DB_Error or message
1255 function errorNative()
1257 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1263 * returns the next free id of a sequence
1265 * @param string $seq_name name of the sequence
1266 * @param boolean $ondemand when true the seqence is
1267 * automatic created, if it
1270 * @return mixed DB_Error or id
1272 function nextId($seq_name, $ondemand = true)
1274 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1278 // {{{ createSequence()
1280 * creates a new sequence
1282 * @param string $seq_name name of the new sequence
1284 * @return mixed DB_Error
1288 function createSequence($seq_name)
1290 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1294 // {{{ dropSequence()
1296 * deletes a sequence
1298 * @param string $seq_name name of the sequence
1300 * @return mixed DB_Error
1304 function dropSequence($seq_name)
1306 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1312 * returns meta data about the result set
1314 * @param object DB_Result $result the result object to analyse
1315 * @param mixed $mode depends on implementation
1317 * @return mixed DB_Error
1321 function tableInfo($result, $mode = null)
1323 return $this->raiseError(DB_ERROR_NOT_CAPABLE);
1331 function getTables()
1333 return $this->getListOf('tables');
1339 * list internal DB info
1340 * valid values for $type are db dependent,
1341 * often: databases, users, view, functions
1343 * @param string $type type of requested info
1345 * @return mixed DB_Error or the requested data
1349 function getListOf($type)
1351 $sql = $this->getSpecialQuery($type);
1352 if ($sql === null) { // No support
1353 return $this->raiseError(DB_ERROR_UNSUPPORTED);
1354 } elseif (is_int($sql) || DB::isError($sql)) { // Previous error
1355 return $this->raiseError($sql);
1356 } elseif (is_array($sql)) { // Already the result
1359 return $this->getCol($sql); // Launch this query
1362 // {{{ getSequenceName()
1364 function getSequenceName($sqn)
1366 return sprintf($this->getOption("seqname_format"),
1367 preg_replace('/[^a-z0-9_]/i', '_', $sqn));
1373 // Used by many drivers
1374 if (!function_exists('array_change_key_case')) {
1375 define('CASE_UPPER', 1);
1376 define('CASE_LOWER', 0);
1377 function &array_change_key_case(&$array, $case) {
1378 $casefunc = ($case == CASE_LOWER) ? 'strtolower' : 'strtoupper';
1380 foreach ($array as $key => $value) {
1381 $ret[$casefunc($key)] = $value;