56set_include_path(
"./Services/Database/lib/PEAR" . PATH_SEPARATOR . ini_get(
'include_path'));
57if (!class_exists(
'PEAR')) {
58 require_once
'PEAR.php';
72define(
'MDB2_OK',
true);
73define(
'MDB2_ERROR', -1);
74define(
'MDB2_ERROR_SYNTAX', -2);
75define(
'MDB2_ERROR_CONSTRAINT', -3);
76define(
'MDB2_ERROR_NOT_FOUND', -4);
77define(
'MDB2_ERROR_ALREADY_EXISTS', -5);
78define(
'MDB2_ERROR_UNSUPPORTED', -6);
79define(
'MDB2_ERROR_MISMATCH', -7);
80define(
'MDB2_ERROR_INVALID', -8);
81define(
'MDB2_ERROR_NOT_CAPABLE', -9);
82define(
'MDB2_ERROR_TRUNCATED', -10);
83define(
'MDB2_ERROR_INVALID_NUMBER', -11);
84define(
'MDB2_ERROR_INVALID_DATE', -12);
85define(
'MDB2_ERROR_DIVZERO', -13);
86define(
'MDB2_ERROR_NODBSELECTED', -14);
87define(
'MDB2_ERROR_CANNOT_CREATE', -15);
88define(
'MDB2_ERROR_CANNOT_DELETE', -16);
89define(
'MDB2_ERROR_CANNOT_DROP', -17);
90define(
'MDB2_ERROR_NOSUCHTABLE', -18);
91define(
'MDB2_ERROR_NOSUCHFIELD', -19);
92define(
'MDB2_ERROR_NEED_MORE_DATA', -20);
93define(
'MDB2_ERROR_NOT_LOCKED', -21);
94define(
'MDB2_ERROR_VALUE_COUNT_ON_ROW', -22);
95define(
'MDB2_ERROR_INVALID_DSN', -23);
96define(
'MDB2_ERROR_CONNECT_FAILED', -24);
97define(
'MDB2_ERROR_EXTENSION_NOT_FOUND',-25);
98define(
'MDB2_ERROR_NOSUCHDB', -26);
99define(
'MDB2_ERROR_ACCESS_VIOLATION', -27);
100define(
'MDB2_ERROR_CANNOT_REPLACE', -28);
101define(
'MDB2_ERROR_CONSTRAINT_NOT_NULL',-29);
102define(
'MDB2_ERROR_DEADLOCK', -30);
103define(
'MDB2_ERROR_CANNOT_ALTER', -31);
104define(
'MDB2_ERROR_MANAGER', -32);
105define(
'MDB2_ERROR_MANAGER_PARSE', -33);
106define(
'MDB2_ERROR_LOADMODULE', -34);
107define(
'MDB2_ERROR_INSUFFICIENT_DATA', -35);
114define(
'MDB2_PREPARE_MANIP',
false);
115define(
'MDB2_PREPARE_RESULT',
null);
124define(
'MDB2_FETCHMODE_DEFAULT', 0);
129define(
'MDB2_FETCHMODE_ORDERED', 1);
134define(
'MDB2_FETCHMODE_ASSOC', 2);
139define(
'MDB2_FETCHMODE_OBJECT', 3);
147define(
'MDB2_FETCHMODE_FLIPPED', 4);
156define(
'MDB2_PORTABILITY_NONE', 0);
163define(
'MDB2_PORTABILITY_FIX_CASE', 1);
169define(
'MDB2_PORTABILITY_RTRIM', 2);
175define(
'MDB2_PORTABILITY_DELETE_COUNT', 4);
181define(
'MDB2_PORTABILITY_NUMROWS', 8);
196define(
'MDB2_PORTABILITY_ERRORS', 16);
203define(
'MDB2_PORTABILITY_EMPTY_TO_NULL', 32);
209define(
'MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES', 64);
215define(
'MDB2_PORTABILITY_ALL', 127);
287 foreach (
$options as $option => $value) {
288 $test = $db->setOption($option, $value);
311 if (version_compare(phpversion(),
"5.0",
">=")) {
312 return class_exists($classname,
false);
314 return class_exists($classname);
333 $file_name = str_replace(
'_', DIRECTORY_SEPARATOR, $class_name).
'.php';
335 $include = include_once($file_name);
337 $include = @include_once($file_name);
341 $msg =
"unable to find package '$class_name' file '$file_name'";
343 $msg =
"unable to load class '$class_name' from file '$file_name'";
382 if (empty($dsninfo[
'phptype'])) {
384 null,
null,
'no RDBMS driver specified');
387 $class_name =
'MDB2_Driver_'.$dsninfo[
'phptype'];
389 $debug = (!empty(
$options[
'debug']));
395 $db =
new $class_name();
396 $db->setDSN($dsninfo);
443 $err = $db->connect();
445 $dsn = $db->getDSN(
'string',
'xxx');
447 $err->addUserInfo($dsn);
490 $dsninfo = array_merge(
$GLOBALS[
'_MDB2_dsninfo_default'], $dsninfo);
491 $keys = array_keys(
$GLOBALS[
'_MDB2_databases']);
492 for ($i=0, $j=count($keys); $i<$j; ++$i) {
493 if (isset(
$GLOBALS[
'_MDB2_databases'][$keys[$i]])) {
494 $tmp_dsn =
$GLOBALS[
'_MDB2_databases'][$keys[$i]]->getDSN(
'array');
495 if (count(array_diff_assoc($tmp_dsn, $dsninfo)) == 0) {
497 return $GLOBALS[
'_MDB2_databases'][$keys[$i]];
501 } elseif (is_array(
$GLOBALS[
'_MDB2_databases']) && reset(
$GLOBALS[
'_MDB2_databases'])) {
523 $file_name =
'MDB2'.DIRECTORY_SEPARATOR.$file.
'.php';
526 'unable to find: '.$file_name);
528 if (!include_once($file_name)) {
530 'unable to load driver class: '.$file_name);
601 if (is_a(
$data,
'MDB2_Error')) {
602 if (is_null(
$code)) {
604 } elseif (is_string(
$code)) {
628 return is_a($value,
'MDB2_Driver_Common');
645 return is_a($value,
'MDB2_Result');
662 return is_a($value,
'MDB2_Result_Common');
679 return is_a($value,
'MDB2_Statement');
699 static $errorMessages;
701 if (is_array($value)) {
702 $errorMessages = $value;
706 if (!isset($errorMessages)) {
707 $errorMessages = array(
744 if (is_null($value)) {
745 return $errorMessages;
749 $value = $value->getCode();
752 return isset($errorMessages[$value]) ?
753 $errorMessages[$value] : $errorMessages[
MDB2_ERROR];
798 $parsed =
$GLOBALS[
'_MDB2_dsninfo_default'];
800 if (is_array($dsn)) {
801 $dsn = array_merge($parsed, $dsn);
802 if (!$dsn[
'dbsyntax']) {
803 $dsn[
'dbsyntax'] = $dsn[
'phptype'];
809 if (($pos = strpos($dsn,
'://')) !==
false) {
810 $str = substr($dsn, 0, $pos);
811 $dsn = substr($dsn, $pos + 3);
819 if (preg_match(
'|^(.+?)\((.*?)\)$|', $str, $arr)) {
820 $parsed[
'phptype'] = $arr[1];
821 $parsed[
'dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
823 $parsed[
'phptype'] = $str;
824 $parsed[
'dbsyntax'] = $str;
833 if (($at = strrpos($dsn,
'@')) !==
false) {
834 $str = substr($dsn, 0, $at);
835 $dsn = substr($dsn, $at + 1);
836 if (($pos = strpos($str,
':')) !==
false) {
837 $parsed[
'username'] = rawurldecode(substr($str, 0, $pos));
838 $parsed[
'password'] = rawurldecode(substr($str, $pos + 1));
840 $parsed[
'username'] = rawurldecode($str);
847 if (preg_match(
'|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
849 $proto_opts = $match[2] ? $match[2] :
false;
854 if (strpos($dsn,
'+') !==
false) {
855 list($proto, $dsn) = explode(
'+', $dsn, 2);
857 if ( strpos($dsn,
'//') === 0
858 && strpos($dsn,
'/', 2) !==
false
859 && $parsed[
'phptype'] ==
'oci8'
866 } elseif (strpos($dsn,
'/') !==
false) {
867 list($proto_opts, $dsn) = explode(
'/', $dsn, 2);
875 $parsed[
'protocol'] = (!empty($proto)) ? $proto :
'tcp';
876 $proto_opts = rawurldecode($proto_opts);
877 if (strpos($proto_opts,
':') !==
false) {
878 list($proto_opts, $parsed[
'port']) = explode(
':', $proto_opts);
880 if ($parsed[
'protocol'] ==
'tcp') {
881 $parsed[
'hostspec'] = $proto_opts;
882 } elseif ($parsed[
'protocol'] ==
'unix') {
883 $parsed[
'socket'] = $proto_opts;
890 if (($pos = strpos($dsn,
'?')) ===
false) {
891 $parsed[
'database'] = $dsn;
894 $parsed[
'database'] = substr($dsn, 0, $pos);
895 $dsn = substr($dsn, $pos + 1);
896 if (strpos($dsn,
'&') !==
false) {
897 $opts = explode(
'&', $dsn);
901 foreach ($opts as $opt) {
902 list($key, $value) = explode(
'=', $opt);
903 if (!isset($parsed[$key])) {
905 $parsed[$key] = rawurldecode($value);
929 if (!@ini_get(
'safe_mode')) {
930 $dirs = explode(PATH_SEPARATOR, ini_get(
'include_path'));
931 foreach ($dirs as $dir) {
932 if (@is_readable($dir . DIRECTORY_SEPARATOR .
$file)) {
937 $fp = @fopen(
$file,
'r',
true);
938 if (is_resource($fp)) {
972 $level = E_USER_NOTICE, $debuginfo =
null)
974 if (is_null(
$code)) {
1060 'sequences' =>
false,
1062 'affected_rows' =>
false,
1063 'summary_functions' =>
false,
1064 'order_by_text' =>
false,
1065 'transactions' =>
false,
1066 'savepoints' =>
false,
1067 'current_id' =>
false,
1068 'limit_queries' =>
false,
1071 'sub_selects' =>
false,
1072 'auto_increment' =>
false,
1073 'primary_key' =>
false,
1074 'result_introspection' =>
false,
1075 'prepared_statements' =>
false,
1076 'identifier_quoting' =>
false,
1077 'pattern_escaping' =>
false,
1078 'new_link' =>
false,
1129 'field_case' => CASE_LOWER,
1130 'disable_query' =>
false,
1131 'result_class' =>
'MDB2_Result_%s',
1132 'buffered_result_class' =>
'MDB2_BufferedResult_%s',
1133 'result_wrap_class' =>
false,
1134 'result_buffering' =>
true,
1135 'fetch_class' =>
'stdClass',
1136 'persistent' =>
false,
1138 'debug_handler' =>
'MDB2_defaultDebugOutput',
1139 'debug_expanded_output' =>
false,
1140 'default_text_field_length' => 4096,
1141 'lob_buffer_length' => 8192,
1142 'log_line_break' =>
"\n",
1143 'idxname_format' =>
'%s_idx',
1144 'seqname_format' =>
'%s_seq',
1145 'savepoint_format' =>
'MDB2_SAVEPOINT_%s',
1146 'statement_format' =>
'MDB2_STATEMENT_%1$s_%2$s',
1147 'seqcol_name' =>
'sequence',
1148 'quote_identifier' =>
false,
1149 'use_transactions' =>
true,
1150 'decimal_places' => 2,
1160 'emulate_prepared' =>
false,
1161 'datatype_map' => array(),
1162 'datatype_map_callback' => array(),
1163 'nativetype_map_callback' => array(),
1171 var
$string_quoting = array(
'start' =>
"'",
'end' =>
"'",
'escape' =>
false,
'escape_pattern' =>
false);
1186 array(
'start' =>
'--',
'end' =>
"\n",
'escape' =>
false),
1187 array(
'start' =>
'/*',
'end' =>
'*/',
'escape' =>
false),
1317 $this->destructor_registered =
false;
1344 unset(
$GLOBALS[
'_MDB2_databases'][$this->db_index]);
1345 unset($this->db_index);
1361 $info = get_class($this);
1362 $info.=
': (phptype = '.$this->phptype.
', dbsyntax = '.$this->dbsyntax.
')';
1363 if ($this->connection) {
1364 $info.=
' [connected]';
1383 return array(
$error,
null,
null);
1414 $userinfo =
"[Error message: $userinfo]\n";
1419 if (is_null($mode) && !empty($this->_default_error_mode)) {
1423 if (is_null($userinfo)) {
1424 $userinfo =
$code->getUserinfo();
1430 } elseif (isset($this->connection)) {
1431 if (!empty($this->last_query)) {
1432 $userinfo.=
"[Last executed query: {$this->last_query}]\n";
1434 $native_errno = $native_msg =
null;
1436 if (!is_null($native_errno) && $native_errno !==
'') {
1437 $userinfo.=
"[Native code: $native_errno]\n";
1439 if (!is_null($native_msg) && $native_msg !==
'') {
1440 $userinfo.=
"[Native message: ". strip_tags($native_msg) .
"]\n";
1442 if (!is_null($method)) {
1443 $userinfo = $method.
': '.$userinfo;
1449 && isset($this->nested_transaction_counter) && !$this->has_transaction_error) {
1450 $this->has_transaction_error =& $err;
1467 $this->warnings = array();
1484 return array_reverse($this->warnings);
1513 $this->options[
'fetch_class'] = $object_class;
1520 'invalid fetchmode mode', __FUNCTION__);
1541 if (array_key_exists($option, $this->options)) {
1542 $this->options[$option] = $value;
1546 "unknown option $option", __FUNCTION__);
1563 if (array_key_exists($option, $this->options)) {
1564 return $this->options[$option];
1567 "unknown option $option", __FUNCTION__);
1587 function debug($message, $scope =
'', $context = array())
1589 if ($this->options[
'debug'] && $this->options[
'debug_handler']) {
1590 if (!$this->options[
'debug_expanded_output']) {
1591 if (!empty($context[
'when']) && $context[
'when'] !==
'pre') {
1594 $context = empty($context[
'is_manip']) ? false : $context[
'is_manip'];
1596 return call_user_func_array($this->options[
'debug_handler'], array(&$this, $scope, $message, $context));
1632 if ($escape_wildcards) {
1636 $text = str_replace($this->string_quoting[
'end'], $this->string_quoting[
'escape'] . $this->string_quoting[
'end'],
$text);
1659 if ($this->string_quoting[
'escape_pattern']) {
1660 $text = str_replace($this->string_quoting[
'escape_pattern'], $this->string_quoting[
'escape_pattern'] . $this->string_quoting[
'escape_pattern'],
$text);
1661 foreach ($this->wildcards as $wildcard) {
1662 $text = str_replace($wildcard, $this->string_quoting[
'escape_pattern'] . $wildcard,
$text);
1707 if ($check_option && !$this->options[
'quote_identifier']) {
1710 $str = str_replace($this->identifier_quoting[
'end'], $this->identifier_quoting[
'escape'] . $this->identifier_quoting[
'end'], $str);
1711 return $this->identifier_quoting[
'start'] . $str . $this->identifier_quoting[
'end'];
1764 foreach (
$row as $key => $value) {
1765 if ($value ===
'') {
1771 foreach (
$row as $key => $value) {
1772 if (is_string($value)) {
1773 $row[$key] = rtrim($value);
1779 foreach (
$row as $key => $value) {
1780 $tmp_row[preg_replace(
'/^(?:.*\.)?([^.]+)$/',
'\\1', $key)] = $value;
1785 foreach (
$row as $key => $value) {
1786 if ($value ===
'') {
1788 } elseif (is_string($value)) {
1789 $row[$key] = rtrim($value);
1795 foreach (
$row as $key => $value) {
1796 if (is_string($value)) {
1797 $value = rtrim($value);
1799 $tmp_row[preg_replace(
'/^(?:.*\.)?([^.]+)$/',
'\\1', $key)] = $value;
1805 foreach (
$row as $key => $value) {
1806 if ($value ===
'') {
1809 $tmp_row[preg_replace(
'/^(?:.*\.)?([^.]+)$/',
'\\1', $key)] = $value;
1815 foreach (
$row as $key => $value) {
1816 if ($value ===
'') {
1818 } elseif (is_string($value)) {
1819 $value = rtrim($value);
1821 $tmp_row[preg_replace(
'/^(?:.*\.)?([^.]+)$/',
'\\1', $key)] = $value;
1845 function &
loadModule($module, $property =
null, $phptype_specific =
null)
1848 $property = strtolower($module);
1851 if (!isset($this->{$property})) {
1853 if ($phptype_specific !==
false) {
1856 $file_name = str_replace(
'_', DIRECTORY_SEPARATOR, $class_name).
'.php';
1858 if ($phptype_specific ===
false
1862 $class_name =
'MDB2_'.$module;
1863 $file_name = str_replace(
'_', DIRECTORY_SEPARATOR, $class_name).
'.php';
1873 if (method_exists($class_name,
'getClassName')) {
1874 $class_name_new = call_user_func(array($class_name,
'getClassName'), $this->db_index);
1875 if ($class_name != $class_name_new) {
1876 $class_name = $class_name_new;
1887 "unable to load module '$module' into property '$property'", __FUNCTION__);
1890 $this->{$property} =
new $class_name($this->db_index);
1891 $this->modules[$module] =& $this->{$property};
1896 $this->loaded_version_modules[] = $property;
1900 return $this->{$property};
1917 if (preg_match(
'/^([a-z]+)([A-Z])(.*)$/', $method, $match)
1918 && isset($this->options[
'modules'][$match[1]])
1920 $module = $this->options[
'modules'][$match[1]];
1921 $method = strtolower($match[2]).$match[3];
1922 if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) {
1929 foreach ($this->modules as $key => $foo) {
1930 if (is_object($this->modules[$key])
1931 && method_exists($this->modules[$key], $method)
1938 if (!is_null($module)) {
1939 return call_user_func_array(array(&$this->modules[$module], $method),
$params);
1941 trigger_error(
sprintf(
'Call to undefined function: %s::%s().', get_class($this), $method), E_USER_ERROR);
1957 $this->
debug(
'Starting transaction', __FUNCTION__, array(
'is_manip' =>
true,
'savepoint' => $savepoint));
1959 'transactions are not supported', __FUNCTION__);
1978 $this->
debug(
'Committing transaction/savepoint', __FUNCTION__, array(
'is_manip' =>
true,
'savepoint' => $savepoint));
1980 'commiting transactions is not supported', __FUNCTION__);
1999 $this->
debug(
'Rolling back transaction/savepoint', __FUNCTION__, array(
'is_manip' =>
true,
'savepoint' => $savepoint));
2001 'rolling back transactions is not supported', __FUNCTION__);
2020 if (!$ignore_nested && isset($this->nested_transaction_counter)) {
2047 $this->
debug(
'Setting transaction isolation level', __FUNCTION__, array(
'is_manip' =>
true));
2049 'isolation level setting is not supported', __FUNCTION__);
2070 if ($this->in_transaction) {
2072 $savepoint =
sprintf($this->options[
'savepoint_format'], $this->nested_transaction_counter);
2073 if ($this->
supports(
'savepoints') && $savepoint) {
2078 $this->has_transaction_error =
false;
2080 $this->nested_transaction_counter = 1;
2106 if ($this->nested_transaction_counter > 1) {
2107 $savepoint =
sprintf($this->options[
'savepoint_format'], $this->nested_transaction_counter);
2108 if ($this->
supports(
'savepoints') && $savepoint) {
2109 if ($force_rollback || $this->has_transaction_error) {
2113 $this->has_transaction_error =
false;
2125 $this->nested_transaction_counter =
null;
2129 if ($this->in_transaction) {
2130 if ($force_rollback || $this->has_transaction_error) {
2139 $this->has_transaction_error =
false;
2164 $error = $this->has_transaction_error ? $this->has_transaction_error :
true;
2168 $this->has_transaction_error =
$error;
2169 if (!$immediately) {
2207 'method not implemented', __FUNCTION__);
2224 'method not implemented', __FUNCTION__);
2243 $this->connection = 0;
2244 $this->connected_dsn = array();
2245 $this->connected_database_name =
'';
2246 $this->opened_persistent =
null;
2247 $this->connected_server_info =
'';
2248 $this->in_transaction =
null;
2249 $this->nested_transaction_counter =
null;
2267 $previous_database_name = (isset($this->database_name)) ? $this->database_name :
'';
2268 $this->database_name = $name;
2270 return $previous_database_name;
2302 $dsn_default =
$GLOBALS[
'_MDB2_dsninfo_default'];
2304 if (array_key_exists(
'database',
$dsn)) {
2305 $this->database_name =
$dsn[
'database'];
2306 unset(
$dsn[
'database']);
2308 $this->dsn = array_merge($dsn_default,
$dsn);
2325 function getDSN($type =
'string', $hidepw =
false)
2327 $dsn = array_merge(
$GLOBALS[
'_MDB2_dsninfo_default'], $this->dsn);
2331 $dsn[
'password'] = $hidepw;
2337 (
$dsn[
'dbsyntax'] ? (
'('.$dsn[
'dbsyntax'].
')') :
'').
2338 '://'.
$dsn[
'username'].
':'.
2339 $dsn[
'password'].
'@'.
$dsn[
'hostspec'].
2340 (
$dsn[
'port'] ? (
':'.
$dsn[
'port']) :
'').
2341 '/'.
$dsn[
'database'];
2369 $this->offset = $this->limit = 0;
2384 return $affected_rows;
2426 $this->last_query =
$query;
2427 $result = $this->
debug(
$query,
'query', array(
'is_manip' => $is_manip,
'when' =>
'pre'));
2435 'method not implemented', __FUNCTION__);
2455 'method not implemented', __FUNCTION__);
2474 $this->offset = $this->limit = 0;
2488 return $affectedRows;
2507 function &
query(
$query, $types =
null, $result_class =
true, $result_wrap_class =
false)
2511 $this->offset = $this->limit = 0;
2549 if ($types ===
true) {
2550 if ($this->
supports(
'result_introspection')) {
2552 $tableInfo = $this->reverse->tableInfo(
$result);
2557 foreach ($tableInfo as $field) {
2558 $types[] = $field[
'mdb2type'];
2565 if ($result_class ===
true) {
2566 $result_class = $this->options[
'result_buffering']
2567 ? $this->options[
'buffered_result_class'] : $this->options[
'result_class'];
2570 if ($result_class) {
2571 $class_name =
sprintf($result_class, $this->phptype);
2574 'result class does not exist '.$class_name, __FUNCTION__);
2580 'result class is not extended from MDB2_Result_Common', __FUNCTION__);
2583 if (!empty($types)) {
2584 $err =
$result->setResultTypes($types);
2591 if ($result_wrap_class ===
true) {
2592 $result_wrap_class = $this->options[
'result_wrap_class'];
2594 if ($result_wrap_class) {
2597 'result wrap class does not exist '.$result_wrap_class, __FUNCTION__);
2620 'method not implemented', __FUNCTION__);
2638 if (!$this->
supports(
'limit_queries')) {
2640 'limit is not supported by this driver', __FUNCTION__);
2645 'it was not specified a valid selected range row limit', __FUNCTION__);
2652 'it was not specified a valid first selected range row', __FUNCTION__);
2676 if ($this->
supports(
'sub_selects') ===
true) {
2680 if (!$this->
supports(
'sub_selects')) {
2682 'method not implemented', __FUNCTION__);
2689 if (!is_array($col) || count($col) == 0) {
2694 return $this->datatype->implodeArray($col, $type);
2696 return implode(
', ', $col);
2769 'replace query is not supported', __FUNCTION__);
2771 $count = count($fields);
2772 $condition = $values = array();
2773 for ($colnum = 0, reset($fields); $colnum < $count; next($fields), $colnum++) {
2774 $name = key($fields);
2775 if (isset($fields[$name][
'null']) && $fields[$name][
'null']) {
2778 $type = isset($fields[$name][
'type']) ? $fields[$name][
'type'] :
null;
2779 $value = $this->
quote($fields[$name][
'value'], $type);
2781 $values[$name] = $value;
2782 if (isset($fields[$name][
'key']) && $fields[$name][
'key']) {
2783 if ($value ===
'NULL') {
2785 'key value '.$name.
' may not be NULL', __FUNCTION__);
2787 $condition[] = $name .
'=' . $value;
2790 if (empty($condition)) {
2792 'not specified which fields are keys', __FUNCTION__);
2806 $condition =
' WHERE '.implode(
' AND ', $condition);
2807 $query =
"DELETE FROM $table$condition";
2811 $insert = implode(
', ', array_keys($values));
2812 $values = implode(
', ', $values);
2813 $query =
"INSERT INTO $table ($insert) VALUES ($values)";
2832 return $affected_rows;
2865 $this->offset = $this->limit = 0;
2866 $result = $this->
debug(
$query, __FUNCTION__, array(
'is_manip' => $is_manip,
'when' =>
'pre'));
2873 $placeholder_type_guess = $placeholder_type =
null;
2876 $positions = array();
2881 while ($position < strlen(
$query)) {
2882 $q_position = strpos(
$query, $question, $position);
2883 $c_position = strpos(
$query, $colon, $position);
2884 if ($q_position && $c_position) {
2885 $p_position = min($q_position, $c_position);
2886 } elseif ($q_position) {
2887 $p_position = $q_position;
2888 } elseif ($c_position) {
2889 $p_position = $c_position;
2893 if (is_null($placeholder_type)) {
2894 $placeholder_type_guess =
$query[$p_position];
2901 if ($new_pos != $position) {
2902 $position = $new_pos;
2906 if (
$query[$position] == $placeholder_type_guess) {
2907 if (is_null($placeholder_type)) {
2908 $placeholder_type =
$query[$p_position];
2909 $question = $colon = $placeholder_type;
2910 if (!empty($types) && is_array($types)) {
2911 if ($placeholder_type ==
':') {
2912 if (is_int(key($types))) {
2913 $types_tmp = $types;
2918 $types = array_values($types);
2922 if ($placeholder_type ==
':') {
2923 $parameter = preg_replace(
'/^.{'.($position+1).
'}([a-z0-9_]+).*$/si',
'\\1',
$query);
2924 if ($parameter ===
'') {
2926 'named parameter with an empty name', __FUNCTION__);
2929 $positions[$p_position] = $parameter;
2930 $query = substr_replace(
$query,
'?', $position, strlen($parameter)+1);
2932 if (isset($count) && isset($types_tmp[++$count])) {
2933 $types[$parameter] = $types_tmp[$count];
2936 $positions[$p_position] = count($positions);
2938 $position = $p_position + 1;
2940 $position = $p_position;
2943 $class_name =
'MDB2_Statement_'.$this->phptype;
2945 $obj =
new $class_name($this, $statement, $positions,
$query, $types, $result_types, $is_manip,
$limit,
$offset);
2946 $this->
debug(
$query, __FUNCTION__, array(
'is_manip' => $is_manip,
'when' =>
'post',
'result' => $obj));
2974 foreach ($ignores as
$ignore) {
2975 if (!empty(
$ignore[
'start'])) {
2976 if (is_int($start_quote = strpos(
$query,
$ignore[
'start'], $position)) && $start_quote < $p_position) {
2977 $end_quote = $start_quote;
2979 if (!is_int($end_quote = strpos(
$query,
$ignore[
'end'], $end_quote + 1))) {
2980 if (
$ignore[
'end'] ===
"\n") {
2981 $end_quote = strlen(
$query) - 1;
2984 'query with an unterminated text string specified', __FUNCTION__);
2989 $position = $end_quote + 1;
3014 function quote($value, $type =
null, $quote =
true, $escape_wildcards =
false)
3021 return $this->datatype->quote($value, $type, $quote, $escape_wildcards);
3046 return $this->datatype->getDeclaration($type, $name, $field);
3068 return $this->datatype->compareDefinition($current, $previous);
3088 if (array_key_exists($feature, $this->supported)) {
3089 return $this->supported[$feature];
3092 "unknown support feature $feature", __FUNCTION__);
3109 return sprintf($this->options[
'seqname_format'],
3110 preg_replace(
'/[^a-z0-9_\$.]/i',
'_', $sqn));
3127 return sprintf($this->options[
'idxname_format'],
3128 preg_replace(
'/[^a-z0-9_\$]/i',
'_', $idx));
3147 'method not implemented', __FUNCTION__);
3167 'method not implemented', __FUNCTION__);
3184 $this->warnings[] =
'database does not support getting current
3185 sequence value, the sequence value was incremented';
3186 return $this->
nextID($seq_name);
3215 $one =
$result->fetchOne($colnum);
3276 $col =
$result->fetchCol($colnum);
3309 $rekey =
false, $force_array =
false, $group =
false)
3340require_once(
'./Services/Database/interfaces/interface.ilDBStatement.php');
3373 $this->limit = max(0,
$limit - 1);
3378 return $this->
fetchRow($fetch_mode);
3428 $load = $this->db->loadModule(
'Datatype',
null,
true);
3432 $types = $this->db->datatype->checkResultTypes(
$types);
3455 if ($this->rownum > $target_rownum) {
3457 'seeking to previous rows not implemented', __FUNCTION__);
3459 while ($this->rownum < $target_rownum) {
3481 'method not implemented', __FUNCTION__);
3505 if (!array_key_exists($colnum,
$row)) {
3507 'column is not defined in the result set: '.$colnum, __FUNCTION__);
3509 return $row[$colnum];
3529 if (is_array(
$row)) {
3530 if (!array_key_exists($colnum,
$row)) {
3532 'column is not defined in the result set: '.$colnum, __FUNCTION__);
3536 }
while (is_array(
$row = $this->
fetchRow($fetchmode)));
3571 $force_array =
false, $group =
false)
3581 $shift_array = $rekey ? false :
null;
3582 if (!is_null($shift_array)) {
3583 if (is_object(
$row)) {
3584 $colnum = count(get_object_vars(
$row));
3586 $colnum = count(
$row);
3590 'rekey feature requires atleast 2 column', __FUNCTION__);
3592 $shift_array = (!$force_array && $colnum == 2);
3597 if (is_object(
$row)) {
3598 $arr = get_object_vars(
$row);
3600 unset(
$row->{$key});
3606 $key = array_shift(
$row);
3613 $all[$key][] =
$row;
3620 foreach (
$row as $key => $val) {
3621 $all[$key][] = $val;
3643 return $this->rownum + 1;
3659 'method not implemented', __FUNCTION__);
3675 'method not implemented', __FUNCTION__);
3696 if (!isset($this->column_names)) {
3697 $result = $this->_getColumnNames();
3701 $this->column_names =
$result;
3704 return array_flip($this->column_names);
3706 return $this->column_names;
3725 'method not implemented', __FUNCTION__);
3742 'method not implemented', __FUNCTION__);
3777 $column_names = $this->getColumnNames();
3779 if ($this->db->options[
'field_case'] == CASE_LOWER) {
3787 $this->values[
$column] =& $value;
3788 if (!is_null($type)) {
3789 $this->types[
$column] = $type;
3810 if (array_key_exists(
$column, $this->values)) {
3811 $this->values[
$column] = $value;
3829 $this->result =
false;
3840 $res = $this->result->execute($a_data);
3842 throw new ilDatabaseException(
"There was an MDB2 error executing the prepared query: ".$this->result->getMessage());
3869 foreach (
$row as $key => $value) {
3870 $this->$key = &
$row[$key];
3924 $this->positions = $positions;
3926 $this->types = (array)
$types;
3962 if (!is_numeric($parameter)) {
3963 $parameter = preg_replace(
'/^:(.*)$/',
'\\1', $parameter);
3965 if (!in_array($parameter, $this->positions)) {
3967 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
3969 $this->values[$parameter] = $value;
3970 if (!is_null($type)) {
3971 $this->types[$parameter] = $type;
3995 $parameters = array_keys(
$values);
3996 foreach ($parameters as $key => $parameter) {
4023 if (!is_numeric($parameter)) {
4024 $parameter = preg_replace(
'/^:(.*)$/',
'\\1', $parameter);
4026 if (!in_array($parameter, $this->positions)) {
4028 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
4030 $this->values[$parameter] =& $value;
4031 if (!is_null($type)) {
4032 $this->types[$parameter] = $type;
4056 $parameters = array_keys(
$values);
4057 foreach ($parameters as $key => $parameter) {
4084 if (is_null($this->positions)) {
4085 return $this->db->raiseError(
MDB2_ERROR,
null,
null,
4086 'Prepared statement has already been freed', __FUNCTION__);
4093 return $this->db->raiseError(
MDB2_ERROR,
null,
null,
4094 'Binding Values failed with message: ' . $err->getMessage(), __FUNCTION__);
4114 function &
_execute($result_class =
true, $result_wrap_class =
false)
4119 foreach ($this->positions as $current_position => $parameter) {
4120 if (!array_key_exists($parameter, $this->values)) {
4122 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
4124 $value = $this->values[$parameter];
4125 $query.= substr($this->query, $last_position, $current_position - $last_position);
4126 if (!isset($value)) {
4127 $value_quoted =
'NULL';
4129 $type = !empty($this->types[$parameter]) ? $this->types[$parameter] :
null;
4130 $value_quoted = $this->db->quote($value, $type);
4132 return $value_quoted;
4136 $last_position = $current_position + 1;
4138 $query.= substr($this->query, $last_position);
4142 if ($this->is_manip) {
4145 $result =& $this->db->query(
$query, $this->result_types, $result_class, $result_wrap_class);
4162 if (is_null($this->positions)) {
4163 return $this->db->raiseError(
MDB2_ERROR,
null,
null,
4164 'Prepared statement has already been freed', __FUNCTION__);
4167 $this->statement =
null;
4168 $this->positions =
null;
4169 $this->query =
null;
4170 $this->types =
null;
4171 $this->result_types =
null;
4172 $this->limit =
null;
4173 $this->is_manip =
null;
4174 $this->offset =
null;
4175 $this->values =
null;
4240 if (isset(
$GLOBALS[
'_MDB2_databases'][$this->db_index])) {
4244 'could not find MDB2 instance');
4265 reset(
$GLOBALS[
'_MDB2_databases']);
4266 while (next(
$GLOBALS[
'_MDB2_databases'])) {
4267 $key = key(
$GLOBALS[
'_MDB2_databases']);
4268 if (
$GLOBALS[
'_MDB2_databases'][$key]->opened_persistent
4269 &&
$GLOBALS[
'_MDB2_databases'][$key]->in_transaction
4271 $GLOBALS[
'_MDB2_databases'][$key]->rollback();
4297 $db->debug_output.= $scope.
'('.$db->db_index.
'): ';
4298 $db->debug_output.= $message.$db->getOption(
'log_line_break');
sprintf('%.4f', $callTime)
MDB2_defaultDebugOutput(&$db, $scope, $message, $context=array())
default debug output handler
const MDB2_ERROR_ACCESS_VIOLATION
const MDB2_FETCHMODE_FLIPPED
For multi-dimensional results: normally the first level of arrays is the row number,...
const MDB2_ERROR_UNSUPPORTED
const MDB2_PORTABILITY_ALL
Portability: turn on all portability features.
const MDB2_ERROR_NODBSELECTED
const MDB2_PORTABILITY_RTRIM
Portability: right trim the data output by query*() and fetch*().
const MDB2_ERROR_DEADLOCK
const MDB2_ERROR_INVALID_DATE
const MDB2_FETCHMODE_DEFAULT
This is a special constant that tells MDB2 the user hasn't specified any particular get mode,...
const MDB2_ERROR_CANNOT_DELETE
const MDB2_ERROR_CONSTRAINT_NOT_NULL
const MDB2_PORTABILITY_FIX_CASE
Portability: convert names of tables and fields to case defined in the "field_case" option when using...
const MDB2_ERROR_MISMATCH
const MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES
Portability: removes database/table qualifiers from associative indexes.
const MDB2_ERROR_NOT_LOCKED
const MDB2_ERROR_NOT_FOUND
const MDB2_ERROR_VALUE_COUNT_ON_ROW
const MDB2_ERROR_CANNOT_CREATE
const MDB2_ERROR_INVALID_NUMBER
const MDB2_ERROR_EXTENSION_NOT_FOUND
const MDB2_ERROR_LOADMODULE
const MDB2_ERROR_INVALID_DSN
$GLOBALS['_MDB2_databases']
These are global variables that are used to track the various class instances.
const MDB2_OK(!class_exists('PEAR'))
The method mapErrorCode in each MDB2_dbtype implementation maps native error codes to one of these.
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare()
const MDB2_ERROR_NOT_CAPABLE
const MDB2_ERROR_ALREADY_EXISTS
const MDB2_PORTABILITY_EMPTY_TO_NULL
Portability: convert empty values to null strings in data output by query*() and fetch*().
const MDB2_ERROR_CONSTRAINT
const MDB2_FETCHMODE_OBJECT
Column data as object properties.
const MDB2_FETCHMODE_ORDERED
Column data indexed by numbers, ordered from 0 and up.
const MDB2_ERROR_NOSUCHFIELD
const MDB2_ERROR_CANNOT_ALTER
const MDB2_ERROR_TRUNCATED
const MDB2_ERROR_NEED_MORE_DATA
const MDB2_ERROR_NOSUCHTABLE
const MDB2_ERROR_CONNECT_FAILED
const MDB2_ERROR_NOSUCHDB
const MDB2_ERROR_CANNOT_REPLACE
MDB2_closeOpenTransactions()
Close any open transactions form persistent connections.
const MDB2_FETCHMODE_ASSOC
Column data indexed by column names.
const MDB2_ERROR_CANNOT_DROP
const PEAR_ERROR_RETURN
#+ ERROR constants
while(false !==($line=fgets($in))) if(! $columns) $ignore
An exception for terminatinating execution or to throw for unit testing.
disconnect($force=true)
Log out and disconnect from the database.
setTransactionIsolation($isolation, $options=array())
Set the transacton isolation level.
__call($method, $params)
Calls a module method using the __call magic method.
inTransaction($ignore_nested=false)
If a transaction is currently open.
getConnection()
Returns a native connection.
& standaloneQuery($query, $types=null, $is_manip=false)
execute a query as database administrator
subSelect($query, $type=false)
simple subselect emulation: leaves the query untouched for all RDBMS that support subselects
getNestedTransactionError()
The first error that occured since the transaction start.
queryAll($query, $types=null, $fetchmode=MDB2_FETCHMODE_DEFAULT, $rekey=false, $force_array=false, $group=false)
Execute the specified query, fetch all the rows of the result set into a two dimensional array and th...
resetWarnings()
reset the warning array
debug($message, $scope='', $context=array())
set a debug message
queryOne($query, $type=null, $colnum=0)
Execute the specified query, fetch the value from the first column of the first row of the result set...
getDatabase()
Get the current database.
escape($text, $escape_wildcards=false)
Quotes a string so it can be safely used in a query.
compareDefinition($current, $previous)
Obtain an array of changes that may need to applied.
completeNestedTransaction($force_rollback=false)
Finish a nested transaction by rolling back if an error occured or committing otherwise.
getSequenceName($sqn)
adds sequence name formatting to a sequence name
& query($query, $types=null, $result_class=true, $result_wrap_class=false)
Send a query to the database and return any results.
lastInsertID($table=null, $field=null)
Returns the autoincrement ID if supported or $id or fetches the current ID in a sequence called: $tab...
_affectedRows($connection, $result=null)
Returns the number of rows affected.
& _wrapResult($result, $types=array(), $result_class=true, $result_wrap_class=false, $limit=null, $offset=null)
wrap a result set into the correct class
& _doQuery($query, $is_manip=false, $connection=null, $database_name=null)
Execute a query.
replace($table, $fields)
Execute a SQL REPLACE query.
errorInfo($error=null)
This method is used to collect information about an error.
rollback($savepoint=null)
Cancel any database changes done during a transaction or since a specific savepoint that is in progre...
$nested_transaction_counter
_modifyQuery($query, $is_manip, $limit, $offset)
Changes a query string for various DBMS specific reasons.
supports($feature)
Tell whether a DB implementation or its backend extension supports a given feature.
setCharset($charset, $connection=null)
Set the charset on the current connection.
currID($seq_name)
Returns the current id of a sequence.
__toString()
String conversation.
nextID($seq_name, $ondemand=true)
Returns the next free id of a sequence.
getDeclaration($type, $name, $field)
Obtain DBMS specific SQL code portion needed to declare of the given type.
beginNestedTransaction()
Start a nested transaction.
& loadModule($module, $property=null, $phptype_specific=null)
loads a module
getWarnings()
Get all warnings in reverse order.
setFetchMode($fetchmode, $object_class='stdClass')
Sets which fetch mode should be used by default on queries on this connection.
setOption($option, $value)
set the option for the db class
getServerVersion($native=false)
return version information about the server
queryRow($query, $types=null, $fetchmode=MDB2_FETCHMODE_DEFAULT)
Execute the specified query, fetch the values from the first row of the result set into an array and ...
setDatabase($name)
Select a different database.
setLimit($limit, $offset=null)
set the range of the next query
quoteIdentifier($str, $check_option=false)
Quote a string so it can be safely used as a table or column name.
queryCol($query, $type=null, $colnum=0)
Execute the specified query, fetch the value from the first column of each row of the result set into...
escapePattern($text)
Quotes pattern (% and _) characters in a string)
& exec($query)
Execute a manipulation query to the database and return the number of affected rows.
_skipDelimitedStrings($query, $position, $p_position)
Utility method, used by prepare() to avoid replacing placeholders within delimited strings.
quote($value, $type=null, $quote=true, $escape_wildcards=false)
Convert a text value into a DBMS specific format that is suitable to compose query statements.
commit($savepoint=null)
Commit the database changes done during a transaction that is in progress or release a savepoint.
& raiseError($code=null, $mode=null, $options=null, $userinfo=null, $method=null)
This method is used to communicate an error and invoke error callbacks etc.
MDB2_Driver_Common()
PHP 4 Constructor.
free()
Free the internal references so that the instance can be destroyed.
failNestedTransaction($error=null, $immediately=false)
Force setting nested transaction to failed.
getOption($option)
Returns the value of an option.
getDebugOutput()
output debug info
getIndexName($idx)
adds index name formatting to a index name
getAsKeyword()
Gets the string to alias column.
& prepare($query, $types=null, $result_types=null, $lobs=array())
Prepares a query for multiple execution with execute().
getDSN($type='string', $hidepw=false)
return the DSN as a string
__construct()
Constructor.
connect()
Connect to the database.
beginTransaction($savepoint=null)
Start a transaction or set a savepoint.
_fixResultArrayValues(&$row, $mode)
Do all necessary conversions on result arrays to fix DBMS quirks.
__construct($code=MDB2_ERROR, $mode=PEAR_ERROR_RETURN, $level=E_USER_NOTICE, $debuginfo=null)
MDB2_Error constructor.
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
__construct($db_index)
Constructor.
MDB2_Module_Common($db_index)
PHP 4 Constructor.
& fetchRow($fetchmode=MDB2_FETCHMODE_DEFAULT, $rownum=null)
Fetch and return a row of data.
fetchOne($colnum=0, $rownum=null)
fetch single column from the next row from a result set
__construct($db, $result, $limit=0, $offset=0)
Constructor.
getResource()
return the resource associated with the result object
rowCount()
Returns the actual row number that was last fetched (count from 0)
MDB2_Result_Common($db, $result, $limit=0, $offset=0)
PHP 4 Constructor.
bindColumn($column, &$value, $type=null)
Set bind variable to a column.
getColumnNames($flip=false)
Retrieve the names of columns returned by the DBMS in a query result or from the cache.
numRows()
Returns the number of rows in a result object.
nextResult()
Move the internal result pointer to the next available result.
setResultTypes($types)
Define the list of types to be associated with the columns of a given result set.
fetch($fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
free()
Free the internal resources associated with result.
_assignBindColumns($row)
Bind a variable to a value in the result row.
_getColumnNames()
Retrieve the names of columns returned by the DBMS in a query result.
numCols()
Count the number of columns returned by the DBMS in a query result.
seek($rownum=0)
Seek to a specific row in a result set.
fetchAll($fetchmode=MDB2_FETCHMODE_DEFAULT, $rekey=false, $force_array=false, $group=false)
Fetch and return all rows from the current row pointer position.
fetchCol($colnum=0)
Fetch and return a column from the current row pointer position.
MDB2_Row(&$row)
PHP 4 Constructor.
__construct(&$row)
constructor
bindParamArray(&$values, $types=null)
Bind the variables of multiple a parameter of a prepared query in bulk.
bindValue($parameter, $value, $type=null)
Set the value of a parameter of a prepared query.
bindValueArray($values, $types=null)
Set the values of multiple a parameter of a prepared query in bulk.
& _execute($result_class=true, $result_wrap_class=false)
Execute a prepared query statement helper method.
& execute($values=null, $result_class=true, $result_wrap_class=false)
Execute a prepared query statement.
MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip=false, $limit=null, $offset=null)
PHP 4 Constructor.
bindParam($parameter, &$value, $type=null)
Bind a variable to a parameter of a prepared query.
__construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip=false, $limit=null, $offset=null)
Constructor.
free()
Release resources allocated for the specified prepared query.
isStatement($value)
Tell whether a value is a MDB2 statement interface.
fileExists($file)
Checks if a file exists in the include path.
isError($data, $code=null)
Tell whether a value is a MDB2 error.
classExists($classname)
Checks if a class exists without triggering __autoload.
isResultCommon($value)
Tell whether a value is a MDB2 result implementing the common interface.
isResult($value)
Tell whether a value is a MDB2 result.
isConnection($value)
Tell whether a value is a MDB2 connection.
loadFile($file)
load a file (like 'Date')
errorMessage($value=null)
Return a textual error message for a MDB2 error code.
loadClass($class_name, $debug)
Loads a PEAR class.
apiVersion()
Return the MDB2 API version.
setOptions(&$db, $options)
set option array in an exiting database object
& raiseError($code=null, $mode=null, $options=null, $userinfo=null)
This method is used to communicate an error and invoke error callbacks etc.
& connect($dsn, $options=false)
Create a new MDB2 connection object and connect to the specified database.
& factory($dsn, $options=false)
Create a new MDB2 object for the specified database type.
& singleton($dsn=null, $options=false)
Returns a MDB2 connection with the requested DSN.
isError($data, $code=null)
Tell whether a value is a PEAR error.
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object's de...
Class ilDatabaseException.
The main 'MDB2' class is simply a container class with some static methods for creating DB objects as...
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
if(!is_array($argv)) $options