- fixed #1485032 and updated MDB2 package+drivers

release-0.6
alecpl 16 years ago
parent bbf15d8115
commit d1403fd726

@ -1,6 +1,13 @@
CHANGELOG RoundCube Webmail
---------------------------
2008/05/02 (alec)
----------
- Updated MDB2 package to version 2.5.0b1
- Updated MDB2 pgsql, mysql, mysqli, sqlite drivers to version 1.5.0b1
- Updated MDB2 mssql driver to version 1.3.0b1
- Fixed identities saving when using MDB2 pgsql driver (#1485032)
2008/05/01 (alec)
----------
- Fix BCC header reset (#1484997)

@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: MDB2.php,v 1.307 2007/11/10 13:29:05 quipo Exp $
// $Id: MDB2.php,v 1.318 2008/03/08 14:18:38 quipo Exp $
//
/**
@ -100,6 +100,8 @@ define('MDB2_ERROR_MANAGER', -32);
define('MDB2_ERROR_MANAGER_PARSE', -33);
define('MDB2_ERROR_LOADMODULE', -34);
define('MDB2_ERROR_INSUFFICIENT_DATA', -35);
define('MDB2_ERROR_NO_PERMISSION', -36);
// }}}
// {{{ Verbose constants
/**
@ -564,7 +566,7 @@ class MDB2
*/
function apiVersion()
{
return '2.5.0a2';
return '2.5.0b1';
}
// }}}
@ -764,6 +766,7 @@ class MDB2
MDB2_ERROR_LOADMODULE => 'error while including on demand module',
MDB2_ERROR_TRUNCATED => 'truncated',
MDB2_ERROR_DEADLOCK => 'deadlock detected',
MDB2_ERROR_NO_PERMISSION => 'no permission',
);
}
@ -888,7 +891,7 @@ class MDB2
//"username/password@[//]host[:port][/service_name]"
//e.g. "scott/tiger@//mymachine:1521/oracle"
$proto_opts = $dsn;
$dsn = null;
$dsn = substr($proto_opts, strrpos($proto_opts, '/') + 1);
} elseif (strpos($dsn, '/') !== false) {
list($proto_opts, $dsn) = explode('/', $dsn, 2);
} else {
@ -1095,6 +1098,7 @@ class MDB2_Driver_Common extends PEAR
'LOBs' => false,
'replace' => false,
'sub_selects' => false,
'triggers' => false,
'auto_increment' => false,
'primary_key' => false,
'result_introspection' => false,
@ -1142,6 +1146,7 @@ class MDB2_Driver_Common extends PEAR
* <li>$options['datatype_map'] -> array: map user defined datatypes to other primitive datatypes</li>
* <li>$options['datatype_map_callback'] -> array: callback function/method that should be called</li>
* <li>$options['bindname_format'] -> string: regular expression pattern for named parameters
* <li>$options['max_identifiers_length'] -> integer: max identifier length</li>
* </ul>
*
* @var array
@ -1190,6 +1195,7 @@ class MDB2_Driver_Common extends PEAR
'nativetype_map_callback' => array(),
'lob_allow_url_include' => false,
'bindname_format' => '(?:\d+)|(?:[a-zA-Z][a-zA-Z0-9_]*)',
'max_identifiers_length' => 30,
);
/**
@ -2218,6 +2224,23 @@ class MDB2_Driver_Common extends PEAR
'method not implemented', __FUNCTION__);
}
// }}}
// {{{ databaseExists()
/**
* check if given database name is exists?
*
* @param string $name name of the database that should be checked
*
* @return mixed true/false on success, a MDB2 error on failure
* @access public
*/
function databaseExists($name)
{
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
// }}}
// {{{ setCharset($charset, $connection = null)
@ -2277,7 +2300,9 @@ class MDB2_Driver_Common extends PEAR
{
$previous_database_name = (isset($this->database_name)) ? $this->database_name : '';
$this->database_name = $name;
$this->disconnect(false);
if (!empty($this->connected_database_name) && ($this->connected_database_name != $this->database_name)) {
$this->disconnect(false);
}
return $previous_database_name;
}
@ -2795,7 +2820,7 @@ class MDB2_Driver_Common extends PEAR
return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
'key value '.$name.' may not be NULL', __FUNCTION__);
}
$condition[] = $name . '=' . $value;
$condition[] = $this->quoteIdentifier($name, true) . '=' . $value;
}
}
if (empty($condition)) {
@ -2815,13 +2840,16 @@ class MDB2_Driver_Common extends PEAR
}
$condition = ' WHERE '.implode(' AND ', $condition);
$query = "DELETE FROM $table$condition";
$query = 'DELETE FROM ' . $this->quoteIdentifier($table, true) . $condition;
$result =& $this->_doQuery($query, true, $connection);
if (!PEAR::isError($result)) {
$affected_rows = $this->_affectedRows($connection, $result);
$insert = implode(', ', array_keys($values));
$insert = '';
foreach ($values as $key => $value) {
$insert .= ($insert?', ':'') . $this->quoteIdentifier($key, true);
}
$values = implode(', ', $values);
$query = "INSERT INTO $table ($insert) VALUES ($values)";
$query = 'INSERT INTO '. $this->quoteIdentifier($table, true) . "($insert) VALUES ($values)";
$result =& $this->_doQuery($query, true, $connection);
if (!PEAR::isError($result)) {
$affected_rows += $this->_affectedRows($connection, $result);;
@ -2998,7 +3026,7 @@ class MDB2_Driver_Common extends PEAR
return $err;
}
}
} while ($ignore['escape'] && $query[($end_quote - 1)] == $ignore['escape']);
} while ($ignore['escape'] && $query[($end_quote - 1)] == $ignore['escape'] && $end_quote-1 != $start_quote);
$position = $end_quote + 1;
return $position;
}
@ -3980,9 +4008,11 @@ class MDB2_Statement_Common
$types = is_array($types) ? array_values($types) : array_fill(0, count($values), null);
$parameters = array_keys($values);
foreach ($parameters as $key => $parameter) {
$this->db->pushErrorHandling(PEAR_ERROR_RETURN);
$this->db->expectError(MDB2_ERROR_NOT_FOUND);
$err = $this->bindValue($parameter, $values[$parameter], $types[$key]);
$this->db->popExpect();
$this->db->popErrorHandling();
if (PEAR::isError($err)) {
if ($err->getCode() == MDB2_ERROR_NOT_FOUND) {
//ignore (extra value for missing placeholder)

File diff suppressed because it is too large Load Diff

@ -1,498 +1,436 @@
<?php
// vim: set et ts=4 sw=4 fdm=marker:
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Authors: Lukas Smith <smith@pooteeweet.org> |
// | Daniel Convissor <danielc@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: mssql.php,v 1.59 2007/12/03 20:59:50 quipo Exp $
//
require_once 'MDB2/Driver/Datatype/Common.php';
/**
* MDB2 MS SQL driver
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Datatype_mssql extends MDB2_Driver_Datatype_Common
{
// {{{ _baseConvertResult()
/**
* general type conversion method
*
* @param mixed $value refernce to a value to be converted
* @param string $type specifies which type to convert to
* @param boolean $rtrim [optional] when TRUE [default], apply rtrim() to text
* @return object a MDB2 error on failure
* @access protected
*/
function _baseConvertResult($value, $type, $rtrim = true)
{
if (is_null($value)) {
return null;
}
switch ($type) {
case 'boolean':
return $value == '1';
case 'date':
if (strlen($value) > 10) {
$value = substr($value,0,10);
}
return $value;
case 'time':
if (strlen($value) > 8) {
$value = substr($value,11,8);
}
return $value;
}
return parent::_baseConvertResult($value, $type, $rtrim);
}
// }}}
// {{{ _getCollationFieldDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration to be used in statements like CREATE TABLE.
*
* @param string $collation name of the collation
*
* @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration.
*/
function _getCollationFieldDeclaration($collation)
{
return 'COLLATE '.$collation;
}
// }}}
// {{{ getTypeDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access public
*/
function getTypeDeclaration($field)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
switch ($field['type']) {
case 'text':
$length = !empty($field['length'])
? $field['length'] : false;
$fixed = !empty($field['fixed']) ? $field['fixed'] : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return 'VARCHAR('.$length.')';
}
}
return 'TEXT';
case 'blob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return "VARBINARY($length)";
}
}
return 'IMAGE';
case 'integer':
return 'INT';
case 'boolean':
return 'BIT';
case 'date':
return 'CHAR ('.strlen('YYYY-MM-DD').')';
case 'time':
return 'CHAR ('.strlen('HH:MM:SS').')';
case 'timestamp':
return 'CHAR ('.strlen('YYYY-MM-DD HH:MM:SS').')';
case 'float':
return 'FLOAT';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $db->options['decimal_places'];
return 'DECIMAL('.$length.','.$scale.')';
}
return '';
}
// }}}
// {{{ _getDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare a generic type
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getDeclarationOptions($field)
{
$charset = empty($field['charset']) ? '' :
' '.$this->_getCharsetFieldDeclaration($field['charset']);
$default = '';
if (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$field['default'] = empty($field['notnull'])
? null : $this->valid_default_values[$field['type']];
if ($field['default'] === ''
&& ($db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)
) {
$field['default'] = ' ';
}
}
$default = ' DEFAULT '.$this->quote($field['default'], $field['type']);
} elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL';
}
$notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL';
if ($default == ' DEFAULT NULL' && $notnull == ' NULL') {
$notnull = '';
}
$collation = empty($field['collation']) ? '' :
' '.$this->_getCollationFieldDeclaration($field['collation']);
return $charset.$default.$notnull.$collation;
}
// }}}
// {{{ _getIntegerDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an integer type
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes.
* Currently, the types of supported field
* properties are as follows:
*
* unsigned
* Boolean flag that indicates whether the field
* should be declared as unsigned integer if
* possible.
*
* default
* Integer value to be used as default for this
* field.
*
* notnull
* Boolean flag that indicates whether this field is
* constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getIntegerDeclaration($name, $field)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$default = $autoinc = '';;
if (!empty($field['autoincrement'])) {
$autoinc = ' IDENTITY PRIMARY KEY';
} elseif (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0;
}
$default = ' DEFAULT '.$this->quote($field['default'], 'integer');
} elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL';
}
$notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL';
if ($default == ' DEFAULT NULL' && $notnull == ' NULL') {
$notnull = '';
}
if (!empty($field['unsigned'])) {
$db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer";
}
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$default.$notnull.$autoinc;
}
// }}}
// {{{ _getCLOBDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an character
* large object type field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the large
* object field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access public
*/
function _getCLOBDeclaration($name, $field)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL';
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$notnull;
}
// }}}
// {{{ _getBLOBDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an binary large
* object type field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the large
* object field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getBLOBDeclaration($name, $field)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL';
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$notnull;
}
// }}}
// {{{ _quoteBLOB()
/**
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
*
* @param string $value text string value that is intended to be converted.
* @param bool $quote determines if the value should be quoted and escaped
* @param bool $escape_wildcards if to escape escape wildcards
* @return string text string that represents the given argument value in
* a DBMS specific format.
* @access protected
*/
function _quoteBLOB($value, $quote, $escape_wildcards)
{
if (!$quote) {
return $value;
}
$value = bin2hex("0x".$this->_readFile($value));
return $value;
}
// }}}
// {{{ _mapNativeDatatype()
/**
* Maps a native array description of a field to a MDB2 datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
* @access public
*/
function _mapNativeDatatype($field)
{
// todo: handle length of various int variations
$db_type = preg_replace('/\d/', '', strtolower($field['type']));
$length = $field['length'];
$type = array();
// todo: unsigned handling seems to be missing
$unsigned = $fixed = null;
switch ($db_type) {
case 'bit':
$type[0] = 'boolean';
break;
case 'tinyint':
$type[0] = 'integer';
$length = 1;
break;
case 'smallint':
$type[0] = 'integer';
$length = 2;
break;
case 'int':
$type[0] = 'integer';
$length = 4;
break;
case 'bigint':
$type[0] = 'integer';
$length = 8;
break;
case 'datetime':
$type[0] = 'timestamp';
break;
case 'float':
case 'real':
case 'numeric':
$type[0] = 'float';
break;
case 'decimal':
case 'money':
$type[0] = 'decimal';
$length = $field['numeric_precision'].','.$field['numeric_scale'];
break;
case 'text':
case 'ntext':
case 'varchar':
case 'nvarchar':
$fixed = false;
case 'char':
case 'nchar':
$type[0] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($db_type, 'text')) {
$type[] = 'clob';
$type = array_reverse($type);
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'image':
case 'varbinary':
$type[] = 'blob';
$length = null;
break;
default:
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'unknown database attribute type: '.$db_type, __FUNCTION__);
}
if ((int)$length <= 0) {
$length = null;
}
return array($type, $length, $unsigned, $fixed);
}
// }}}
}
<?php
// vim: set et ts=4 sw=4 fdm=marker:
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Authors: Lukas Smith <smith@pooteeweet.org> |
// | Daniel Convissor <danielc@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: mssql.php,v 1.65 2008/02/19 14:54:17 afz Exp $
//
require_once 'MDB2/Driver/Datatype/Common.php';
/**
* MDB2 MS SQL driver
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Datatype_mssql extends MDB2_Driver_Datatype_Common
{
// {{{ _baseConvertResult()
/**
* general type conversion method
*
* @param mixed $value refernce to a value to be converted
* @param string $type specifies which type to convert to
* @param boolean $rtrim [optional] when TRUE [default], apply rtrim() to text
* @return object a MDB2 error on failure
* @access protected
*/
function _baseConvertResult($value, $type, $rtrim = true)
{
if (is_null($value)) {
return null;
}
switch ($type) {
case 'boolean':
return $value == '1';
case 'date':
if (strlen($value) > 10) {
$value = substr($value,0,10);
}
return $value;
case 'time':
if (strlen($value) > 8) {
$value = substr($value,11,8);
}
return $value;
}
return parent::_baseConvertResult($value, $type, $rtrim);
}
// }}}
// {{{ _getCollationFieldDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration to be used in statements like CREATE TABLE.
*
* @param string $collation name of the collation
*
* @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration.
*/
function _getCollationFieldDeclaration($collation)
{
return 'COLLATE '.$collation;
}
// }}}
// {{{ getTypeDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access public
*/
function getTypeDeclaration($field)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
switch ($field['type']) {
case 'text':
$length = !empty($field['length'])
? $field['length'] : false;
$fixed = !empty($field['fixed']) ? $field['fixed'] : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return 'VARCHAR('.$length.')';
}
}
return 'TEXT';
case 'blob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return "VARBINARY($length)";
}
}
return 'IMAGE';
case 'integer':
return 'INT';
case 'boolean':
return 'BIT';
case 'date':
return 'CHAR ('.strlen('YYYY-MM-DD').')';
case 'time':
return 'CHAR ('.strlen('HH:MM:SS').')';
case 'timestamp':
return 'CHAR ('.strlen('YYYY-MM-DD HH:MM:SS').')';
case 'float':
return 'FLOAT';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $db->options['decimal_places'];
return 'DECIMAL('.$length.','.$scale.')';
}
return '';
}
// }}}
// {{{ _getIntegerDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an integer type
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes.
* Currently, the types of supported field
* properties are as follows:
*
* unsigned
* Boolean flag that indicates whether the field
* should be declared as unsigned integer if
* possible.
*
* default
* Integer value to be used as default for this
* field.
*
* notnull
* Boolean flag that indicates whether this field is
* constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getIntegerDeclaration($name, $field)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL';
$default = $autoinc = '';
if (!empty($field['autoincrement'])) {
$autoinc = ' IDENTITY PRIMARY KEY';
} elseif (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = 0;
}
if (is_null($field['default'])) {
$default = ' DEFAULT (null)';
} else {
$default = ' DEFAULT (' . $this->quote($field['default'], 'integer') . ')';
}
}
if (!empty($field['unsigned'])) {
$db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer";
}
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$notnull.$default.$autoinc;
}
// }}}
// {{{ _getCLOBDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an character
* large object type field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the large
* object field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access public
*/
function _getCLOBDeclaration($name, $field)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL';
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$notnull;
}
// }}}
// {{{ _getBLOBDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an binary large
* object type field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the large
* object field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getBLOBDeclaration($name, $field)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL';
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$notnull;
}
// }}}
// {{{ _quoteBLOB()
/**
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
*
* @param string $value text string value that is intended to be converted.
* @param bool $quote determines if the value should be quoted and escaped
* @param bool $escape_wildcards if to escape escape wildcards
* @return string text string that represents the given argument value in
* a DBMS specific format.
* @access protected
*/
function _quoteBLOB($value, $quote, $escape_wildcards)
{
if (!$quote) {
return $value;
}
$value = '0x'.bin2hex($this->_readFile($value));
return $value;
}
// }}}
// {{{ _mapNativeDatatype()
/**
* Maps a native array description of a field to a MDB2 datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
* @access public
*/
function _mapNativeDatatype($field)
{
// todo: handle length of various int variations
$db_type = preg_replace('/\d/', '', strtolower($field['type']));
$length = $field['length'];
$type = array();
// todo: unsigned handling seems to be missing
$unsigned = $fixed = null;
switch ($db_type) {
case 'bit':
$type[0] = 'boolean';
break;
case 'tinyint':
$type[0] = 'integer';
$length = 1;
break;
case 'smallint':
$type[0] = 'integer';
$length = 2;
break;
case 'int':
$type[0] = 'integer';
$length = 4;
break;
case 'bigint':
$type[0] = 'integer';
$length = 8;
break;
case 'datetime':
$type[0] = 'timestamp';
break;
case 'float':
case 'real':
case 'numeric':
$type[0] = 'float';
break;
case 'decimal':
case 'money':
$type[0] = 'decimal';
$length = $field['numeric_precision'].','.$field['numeric_scale'];
break;
case 'text':
case 'ntext':
case 'varchar':
case 'nvarchar':
$fixed = false;
case 'char':
case 'nchar':
$type[0] = 'text';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($db_type, 'text')) {
$type[] = 'clob';
$type = array_reverse($type);
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'image':
case 'varbinary':
$type[] = 'blob';
$length = null;
break;
default:
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'unknown database attribute type: '.$db_type, __FUNCTION__);
}
if ((int)$length <= 0) {
$length = null;
}
return array($type, $length, $unsigned, $fixed);
}
// }}}
}
?>

@ -3,7 +3,7 @@
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php,v 1.62 2007/11/09 20:54:58 quipo Exp $
// $Id: mysql.php,v 1.65 2008/02/22 19:23:49 quipo Exp $
//
require_once 'MDB2/Driver/Datatype/Common.php';
@ -232,6 +232,93 @@ class MDB2_Driver_Datatype_mysql extends MDB2_Driver_Datatype_Common
$field['default'] = empty($field['notnull']) ? null : 0;
}
$default = ' DEFAULT '.$this->quote($field['default'], 'integer');
}
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
$unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED';
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc;
}
// }}}
// {{{ _getFloatDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an float type
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes.
* Currently, the types of supported field
* properties are as follows:
*
* unsigned
* Boolean flag that indicates whether the field
* should be declared as unsigned float if
* possible.
*
* default
* float value to be used as default for this
* field.
*
* notnull
* Boolean flag that indicates whether this field is
* constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getFloatDeclaration($name, $field)
{
// Since AUTO_INCREMENT can be used for integer or floating-point types,
// reuse the INTEGER declaration
// @see http://bugs.mysql.com/bug.php?id=31032
return $this->_getIntegerDeclaration($name, $field);
}
// }}}
// {{{ _getDecimalDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an decimal type
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes.
* Currently, the types of supported field
* properties are as follows:
*
* unsigned
* Boolean flag that indicates whether the field
* should be declared as unsigned integer if
* possible.
*
* default
* Decimal value to be used as default for this
* field.
*
* notnull
* Boolean flag that indicates whether this field is
* constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getDecimalDeclaration($name, $field)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$default = '';
if (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0;
}
$default = ' DEFAULT '.$this->quote($field['default'], 'integer');
} elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL';
}
@ -239,7 +326,7 @@ class MDB2_Driver_Datatype_mysql extends MDB2_Driver_Datatype_Common
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
$unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED';
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc;
return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull;
}
// }}}

@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysqli.php,v 1.61 2007/11/09 20:54:58 quipo Exp $
// $Id: mysqli.php,v 1.63 2008/02/22 19:23:49 quipo Exp $
//
require_once 'MDB2/Driver/Datatype/Common.php';
@ -232,6 +232,93 @@ class MDB2_Driver_Datatype_mysqli extends MDB2_Driver_Datatype_Common
$field['default'] = empty($field['notnull']) ? null : 0;
}
$default = ' DEFAULT '.$this->quote($field['default'], 'integer');
}
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
$unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED';
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc;
}
// }}}
// {{{ _getFloatDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an float type
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes.
* Currently, the types of supported field
* properties are as follows:
*
* unsigned
* Boolean flag that indicates whether the field
* should be declared as unsigned float if
* possible.
*
* default
* float value to be used as default for this
* field.
*
* notnull
* Boolean flag that indicates whether this field is
* constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getFloatDeclaration($name, $field)
{
// Since AUTO_INCREMENT can be used for integer or floating-point types,
// reuse the INTEGER declaration
// @see http://bugs.mysql.com/bug.php?id=31032
return $this->_getIntegerDeclaration($name, $field);
}
// }}}
// {{{ _getDecimalDeclaration()
/**
* Obtain DBMS specific SQL code portion needed to declare an decimal type
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes.
* Currently, the types of supported field
* properties are as follows:
*
* unsigned
* Boolean flag that indicates whether the field
* should be declared as unsigned integer if
* possible.
*
* default
* Decimal value to be used as default for this
* field.
*
* notnull
* Boolean flag that indicates whether this field is
* constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @access protected
*/
function _getDecimalDeclaration($name, $field)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$default = '';
if (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0;
}
$default = ' DEFAULT '.$this->quote($field['default'], 'integer');
} elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL';
}
@ -239,7 +326,7 @@ class MDB2_Driver_Datatype_mysqli extends MDB2_Driver_Datatype_Common
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
$unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED';
$name = $db->quoteIdentifier($name, true);
return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc;
return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull;
}
// }}}
@ -356,7 +443,6 @@ class MDB2_Driver_Datatype_mysqli extends MDB2_Driver_Datatype_Common
case 'mediumtext':
case 'longtext':
case 'text':
case 'text':
case 'varchar':
$fixed = false;
case 'string':

@ -42,7 +42,7 @@
// | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php,v 1.88 2007/11/09 20:54:58 quipo Exp $
// $Id: pgsql.php,v 1.91 2008/03/09 12:28:08 quipo Exp $
require_once 'MDB2/Driver/Datatype/Common.php';
@ -217,8 +217,6 @@ class MDB2_Driver_Datatype_pgsql extends MDB2_Driver_Datatype_Common
$field['default'] = empty($field['notnull']) ? null : 0;
}
$default = ' DEFAULT '.$this->quote($field['default'], 'integer');
} elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL';
}
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
@ -453,6 +451,7 @@ class MDB2_Driver_Datatype_pgsql extends MDB2_Driver_Datatype_Common
break;
case 'datetime':
case 'timestamp':
case 'timestamptz':
$type[] = 'timestamp';
$length = null;
break;
@ -461,6 +460,7 @@ class MDB2_Driver_Datatype_pgsql extends MDB2_Driver_Datatype_Common
$length = null;
break;
case 'float':
case 'float4':
case 'float8':
case 'double':
case 'real':

@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php,v 1.65 2007/12/03 20:59:51 quipo Exp $
// $Id: sqlite.php,v 1.67 2008/02/22 19:58:06 quipo Exp $
//
require_once 'MDB2/Driver/Datatype/Common.php';
@ -212,8 +212,6 @@ class MDB2_Driver_Datatype_sqlite extends MDB2_Driver_Datatype_Common
$field['default'] = empty($field['notnull']) ? null : 0;
}
$default = ' DEFAULT '.$this->quote($field['default'], 'integer');
} elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL';
}
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
@ -394,7 +392,6 @@ class MDB2_Driver_Datatype_sqlite extends MDB2_Driver_Datatype_Common
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'unknown database attribute type: '.$db_type, __FUNCTION__);
}

@ -1,249 +1,293 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Common.php,v 1.19 2007/09/09 13:47:36 quipo Exp $
//
/**
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
/**
* Base class for the function modules that is extended by each MDB2 driver
*
* To load this module in the MDB2 object:
* $mdb->loadModule('Function');
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_Common extends MDB2_Module_Common
{
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $error;
}
// }}}
// {{{ functionTable()
/**
* return string for internal table used when calling only a function
*
* @return string for internal table used when calling only a function
* @access public
*/
function functionTable()
{
return '';
}
// }}}
// {{{ now()
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time:
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
* - CURRENT_DATE (date, DATE type)
* - CURRENT_TIME (time, TIME type)
*
* @return string to call a variable with the current timestamp
* @access public
*/
function now($type = 'timestamp')
{
switch ($type) {
case 'time':
return 'CURRENT_TIME';
case 'date':
return 'CURRENT_DATE';
case 'timestamp':
default:
return 'CURRENT_TIMESTAMP';
}
}
// }}}
// {{{ substring()
/**
* return string to call a function to get a substring inside an SQL statement
*
* @return string to call a function to get a substring
* @access public
*/
function substring($value, $position = 1, $length = null)
{
if (!is_null($length)) {
return "SUBSTRING($value FROM $position FOR $length)";
}
return "SUBSTRING($value FROM $position)";
}
// }}}
// {{{ concat()
/**
* Returns string to concatenate two or more string parameters
*
* @param string $value1
* @param string $value2
* @param string $values...
* @return string to concatenate two strings
* @access public
*/
function concat($value1, $value2)
{
$args = func_get_args();
return "(".implode(' || ', $args).")";
}
// }}}
// {{{ random()
/**
* return string to call a function to get random value inside an SQL statement
*
* @return return string to generate float between 0 and 1
* @access public
*/
function random()
{
return 'RAND()';
}
// }}}
// {{{ lower()
/**
* return string to call a function to lower the case of an expression
*
* @param string $expression
* @return return string to lower case of an expression
* @access public
*/
function lower($expression)
{
return "LOWER($expression)";
}
// }}}
// {{{ upper()
/**
* return string to call a function to upper the case of an expression
*
* @param string $expression
* @return return string to upper case of an expression
* @access public
*/
function upper($expression)
{
return "UPPER($expression)";
}
// }}}
// {{{ length()
/**
* return string to call a function to get the length of a string expression
*
* @param string $expression
* @return return string to get the string expression length
* @access public
*/
function length($expression)
{
return "LENGTH($expression)";
}
// }}}
// {{{ guid()
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
* @access public
*/
function guid()
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $error;
}
// }}}
}
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: Common.php,v 1.21 2008/02/17 18:51:39 quipo Exp $
//
/**
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
/**
* Base class for the function modules that is extended by each MDB2 driver
*
* To load this module in the MDB2 object:
* $mdb->loadModule('Function');
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_Common extends MDB2_Module_Common
{
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
*
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $error;
}
// }}}
// {{{ functionTable()
/**
* return string for internal table used when calling only a function
*
* @return string for internal table used when calling only a function
* @access public
*/
function functionTable()
{
return '';
}
// }}}
// {{{ now()
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time:
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
* - CURRENT_DATE (date, DATE type)
* - CURRENT_TIME (time, TIME type)
*
* @param string $type 'timestamp' | 'time' | 'date'
*
* @return string to call a variable with the current timestamp
* @access public
*/
function now($type = 'timestamp')
{
switch ($type) {
case 'time':
return 'CURRENT_TIME';
case 'date':
return 'CURRENT_DATE';
case 'timestamp':
default:
return 'CURRENT_TIMESTAMP';
}
}
// }}}
// {{{ unixtimestamp()
/**
* return string to call a function to get the unix timestamp from a iso timestamp
*
* @param string $expression
*
* @return string to call a variable with the timestamp
* @access public
*/
function unixtimestamp($expression)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $error;
}
// }}}
// {{{ substring()
/**
* return string to call a function to get a substring inside an SQL statement
*
* @return string to call a function to get a substring
* @access public
*/
function substring($value, $position = 1, $length = null)
{
if (!is_null($length)) {
return "SUBSTRING($value FROM $position FOR $length)";
}
return "SUBSTRING($value FROM $position)";
}
// }}}
// {{{ replace()
/**
* return string to call a function to get replace inside an SQL statement.
*
* @return string to call a function to get a replace
* @access public
*/
function replace($str, $from_str, $to_str)
{
return "REPLACE($str, $from_str , $to_str)";
}
// }}}
// {{{ concat()
/**
* Returns string to concatenate two or more string parameters
*
* @param string $value1
* @param string $value2
* @param string $values...
*
* @return string to concatenate two strings
* @access public
*/
function concat($value1, $value2)
{
$args = func_get_args();
return "(".implode(' || ', $args).")";
}
// }}}
// {{{ random()
/**
* return string to call a function to get random value inside an SQL statement
*
* @return return string to generate float between 0 and 1
* @access public
*/
function random()
{
return 'RAND()';
}
// }}}
// {{{ lower()
/**
* return string to call a function to lower the case of an expression
*
* @param string $expression
*
* @return return string to lower case of an expression
* @access public
*/
function lower($expression)
{
return "LOWER($expression)";
}
// }}}
// {{{ upper()
/**
* return string to call a function to upper the case of an expression
*
* @param string $expression
*
* @return return string to upper case of an expression
* @access public
*/
function upper($expression)
{
return "UPPER($expression)";
}
// }}}
// {{{ length()
/**
* return string to call a function to get the length of a string expression
*
* @param string $expression
*
* @return return string to get the string expression length
* @access public
*/
function length($expression)
{
return "LENGTH($expression)";
}
// }}}
// {{{ guid()
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
* @access public
*/
function guid()
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $error;
}
// }}}
}
?>

@ -1,178 +1,193 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Frank M. Kromann <frank@kromann.info> |
// +----------------------------------------------------------------------+
//
// $Id: mssql.php,v 1.15 2007/08/11 16:02:22 quipo Exp $
//
require_once 'MDB2/Driver/Function/Common.php';
// {{{ class MDB2_Driver_Function_mssql
/**
* MDB2 MSSQL driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_mssql extends MDB2_Driver_Function_Common
{
// }}}
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'EXECUTE '.$name;
$query .= $params ? ' '.implode(', ', $params) : '';
return $db->query($query, $types, $result_class, $result_wrap_class);
}
// }}}
// {{{ now()
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time:
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
* - CURRENT_DATE (date, DATE type)
* - CURRENT_TIME (time, TIME type)
*
* @return string to call a variable with the current timestamp
* @access public
*/
function now($type = 'timestamp')
{
switch ($type) {
case 'time':
case 'date':
case 'timestamp':
default:
return 'GETDATE()';
}
}
// }}}
// {{{ substring()
/**
* return string to call a function to get a substring inside an SQL statement
*
* @return string to call a function to get a substring
* @access public
*/
function substring($value, $position = 1, $length = null)
{
if (!is_null($length)) {
return "SUBSTRING($value, $position, $length)";
}
return "SUBSTRING($value, $position, LEN($value) - $position + 1)";
}
// }}}
// {{{ concat()
/**
* Returns string to concatenate two or more string parameters
*
* @param string $value1
* @param string $value2
* @param string $values...
* @return string to concatenate two strings
* @access public
**/
function concat($value1, $value2)
{
$args = func_get_args();
return "(".implode(' + ', $args).")";
}
// }}}
// {{{ length()
/**
* return string to call a function to get the length of a string expression
*
* @param string $expression
* @return return string to get the string expression length
* @access public
*/
function length($expression)
{
return "LEN($expression)";
}
// }}}
// {{{ guid()
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
* @access public
*/
function guid()
{
return 'NEWID()';
}
// }}}
}
// }}}
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Frank M. Kromann <frank@kromann.info> |
// +----------------------------------------------------------------------+
//
// $Id: mssql.php,v 1.16 2008/02/17 18:54:08 quipo Exp $
//
require_once 'MDB2/Driver/Function/Common.php';
// {{{ class MDB2_Driver_Function_mssql
/**
* MDB2 MSSQL driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_mssql extends MDB2_Driver_Function_Common
{
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'EXECUTE '.$name;
$query .= $params ? ' '.implode(', ', $params) : '';
return $db->query($query, $types, $result_class, $result_wrap_class);
}
// }}}
// {{{ now()
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time:
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
* - CURRENT_DATE (date, DATE type)
* - CURRENT_TIME (time, TIME type)
*
* @return string to call a variable with the current timestamp
* @access public
*/
function now($type = 'timestamp')
{
switch ($type) {
case 'time':
case 'date':
case 'timestamp':
default:
return 'GETDATE()';
}
}
// }}}
// {{{ unixtimestamp()
/**
* return string to call a function to get the unix timestamp from a iso timestamp
*
* @param string $expression
*
* @return string to call a variable with the timestamp
* @access public
*/
function unixtimestamp($expression)
{
return 'DATEDIFF(second, \'19700101\', '. $expression.') + DATEDIFF(second, GETDATE(), GETUTCDATE())';
}
// }}}
// {{{ substring()
/**
* return string to call a function to get a substring inside an SQL statement
*
* @return string to call a function to get a substring
* @access public
*/
function substring($value, $position = 1, $length = null)
{
if (!is_null($length)) {
return "SUBSTRING($value, $position, $length)";
}
return "SUBSTRING($value, $position, LEN($value) - $position + 1)";
}
// }}}
// {{{ concat()
/**
* Returns string to concatenate two or more string parameters
*
* @param string $value1
* @param string $value2
* @param string $values...
* @return string to concatenate two strings
* @access public
**/
function concat($value1, $value2)
{
$args = func_get_args();
return "(".implode(' + ', $args).")";
}
// }}}
// {{{ length()
/**
* return string to call a function to get the length of a string expression
*
* @param string $expression
* @return return string to get the string expression length
* @access public
*/
function length($expression)
{
return "LEN($expression)";
}
// }}}
// {{{ guid()
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
* @access public
*/
function guid()
{
return 'NEWID()';
}
// }}}
}
// }}}
?>

@ -1,120 +1,136 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php,v 1.11 2007/01/12 11:29:12 quipo Exp $
//
require_once 'MDB2/Driver/Function/Common.php';
/**
* MDB2 MySQL driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_mysql extends MDB2_Driver_Function_Common
{
// }}}
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'CALL '.$name;
$query .= $params ? '('.implode(', ', $params).')' : '()';
return $db->query($query, $types, $result_class, $result_wrap_class);
}
// }}}
// {{{ concat()
/**
* Returns string to concatenate two or more string parameters
*
* @param string $value1
* @param string $value2
* @param string $values...
* @return string to concatenate two strings
* @access public
**/
function concat($value1, $value2)
{
$args = func_get_args();
return "CONCAT(".implode(', ', $args).")";
}
// }}}
// {{{ guid()
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
* @access public
*/
function guid()
{
return 'UUID()';
}
// }}}
}
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php,v 1.12 2008/02/17 18:54:08 quipo Exp $
//
require_once 'MDB2/Driver/Function/Common.php';
/**
* MDB2 MySQL driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_mysql extends MDB2_Driver_Function_Common
{
// }}}
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'CALL '.$name;
$query .= $params ? '('.implode(', ', $params).')' : '()';
return $db->query($query, $types, $result_class, $result_wrap_class);
}
// }}}
// {{{ unixtimestamp()
/**
* return string to call a function to get the unix timestamp from a iso timestamp
*
* @param string $expression
*
* @return string to call a variable with the timestamp
* @access public
*/
function unixtimestamp($expression)
{
return 'UNIX_TIMESTAMP('. $expression.')';
}
// }}}
// {{{ concat()
/**
* Returns string to concatenate two or more string parameters
*
* @param string $value1
* @param string $value2
* @param string $values...
* @return string to concatenate two strings
* @access public
**/
function concat($value1, $value2)
{
$args = func_get_args();
return "CONCAT(".implode(', ', $args).")";
}
// }}}
// {{{ guid()
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
* @access public
*/
function guid()
{
return 'UUID()';
}
// }}}
}
?>

@ -1,128 +1,144 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysqli.php,v 1.13 2007/01/12 11:29:12 quipo Exp $
//
require_once 'MDB2/Driver/Function/Common.php';
/**
* MDB2 MySQLi driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_mysqli extends MDB2_Driver_Function_Common
{
// }}}
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$multi_query = $db->getOption('multi_query');
if (!$multi_query) {
$db->setOption('multi_query', true);
}
$query = 'CALL '.$name;
$query .= $params ? '('.implode(', ', $params).')' : '()';
$result =& $db->query($query, $types, $result_class, $result_wrap_class);
if (!$multi_query) {
$db->setOption('multi_query', false);
}
return $result;
}
// }}}
// {{{ concat()
/**
* Returns string to concatenate two or more string parameters
*
* @param string $value1
* @param string $value2
* @param string $values...
* @return string to concatenate two strings
* @access public
**/
function concat($value1, $value2)
{
$args = func_get_args();
return "CONCAT(".implode(', ', $args).")";
}
// }}}
// {{{ guid()
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
* @access public
*/
function guid()
{
return 'UUID()';
}
// }}}
}
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysqli.php,v 1.14 2008/02/17 18:54:08 quipo Exp $
//
require_once 'MDB2/Driver/Function/Common.php';
/**
* MDB2 MySQLi driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_mysqli extends MDB2_Driver_Function_Common
{
// }}}
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$multi_query = $db->getOption('multi_query');
if (!$multi_query) {
$db->setOption('multi_query', true);
}
$query = 'CALL '.$name;
$query .= $params ? '('.implode(', ', $params).')' : '()';
$result =& $db->query($query, $types, $result_class, $result_wrap_class);
if (!$multi_query) {
$db->setOption('multi_query', false);
}
return $result;
}
// }}}
// {{{ unixtimestamp()
/**
* return string to call a function to get the unix timestamp from a iso timestamp
*
* @param string $expression
*
* @return string to call a variable with the timestamp
* @access public
*/
function unixtimestamp($expression)
{
return 'UNIX_TIMESTAMP('. $expression.')';
}
// }}}
// {{{ concat()
/**
* Returns string to concatenate two or more string parameters
*
* @param string $value1
* @param string $value2
* @param string $values...
* @return string to concatenate two strings
* @access public
**/
function concat($value1, $value2)
{
$args = func_get_args();
return "CONCAT(".implode(', ', $args).")";
}
// }}}
// {{{ guid()
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
* @access public
*/
function guid()
{
return 'UUID()';
}
// }}}
}
?>

@ -1,99 +1,115 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php,v 1.9 2006/06/12 21:48:43 lsmith Exp $
require_once 'MDB2/Driver/Function/Common.php';
/**
* MDB2 MySQL driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_pgsql extends MDB2_Driver_Function_Common
{
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'SELECT * FROM '.$name;
$query .= $params ? '('.implode(', ', $params).')' : '()';
return $db->query($query, $types, $result_class, $result_wrap_class);
}
// }}}
// {{{ random()
/**
* return string to call a function to get random value inside an SQL statement
*
* @return return string to generate float between 0 and 1
* @access public
*/
function random()
{
return 'RANDOM()';
}
// }}}
}
?>
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php,v 1.10 2008/02/17 18:54:08 quipo Exp $
require_once 'MDB2/Driver/Function/Common.php';
/**
* MDB2 MySQL driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_pgsql extends MDB2_Driver_Function_Common
{
// {{{ executeStoredProc()
/**
* Execute a stored procedure and return any results
*
* @param string $name string that identifies the function to execute
* @param mixed $params array that contains the paramaters to pass the stored proc
* @param mixed $types array that contains the types of the columns in
* the result set
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'SELECT * FROM '.$name;
$query .= $params ? '('.implode(', ', $params).')' : '()';
return $db->query($query, $types, $result_class, $result_wrap_class);
}
// }}}
// {{{ unixtimestamp()
/**
* return string to call a function to get the unix timestamp from a iso timestamp
*
* @param string $expression
*
* @return string to call a variable with the timestamp
* @access public
*/
function unixtimestamp($expression)
{
return 'EXTRACT(EPOCH FROM DATE_TRUNC(\'seconds\', TIMESTAMP '. $expression.'))';
}
// }}}
// {{{ random()
/**
* return string to call a function to get random value inside an SQL statement
*
* @return return string to generate float between 0 and 1
* @access public
*/
function random()
{
return 'RANDOM()';
}
// }}}
}
?>

@ -1,125 +1,162 @@
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php,v 1.8 2006/06/13 22:55:55 lsmith Exp $
//
require_once 'MDB2/Driver/Function/Common.php';
/**
* MDB2 SQLite driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_sqlite extends MDB2_Driver_Function_Common
{
// {{{ constructor
/**
* Constructor
*/
function __construct($db_index)
{
parent::__construct($db_index);
// create all sorts of UDFs
}
// {{{ now()
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time.
*
* @return string to call a variable with the current timestamp
* @access public
*/
function now($type = 'timestamp')
{
switch ($type) {
case 'time':
return 'time(\'now\')';
case 'date':
return 'date(\'now\')';
case 'timestamp':
default:
return 'datetime(\'now\')';
}
}
// }}}
// {{{ substring()
/**
* return string to call a function to get a substring inside an SQL statement
*
* @return string to call a function to get a substring
* @access public
*/
function substring($value, $position = 1, $length = null)
{
if (!is_null($length)) {
return "substr($value,$position,$length)";
}
return "substr($value,$position,length($value))";
}
// }}}
// {{{ random()
/**
* return string to call a function to get random value inside an SQL statement
*
* @return return string to generate float between 0 and 1
* @access public
*/
function random()
{
return '((RANDOM()+2147483648)/4294967296)';
}
// }}}
}
?>
<?php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php,v 1.10 2008/02/17 18:54:08 quipo Exp $
//
require_once 'MDB2/Driver/Function/Common.php';
/**
* MDB2 SQLite driver for the function modules
*
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
*/
class MDB2_Driver_Function_sqlite extends MDB2_Driver_Function_Common
{
// {{{ constructor
/**
* Constructor
*/
function __construct($db_index)
{
parent::__construct($db_index);
// create all sorts of UDFs
}
// {{{ now()
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time.
*
* @return string to call a variable with the current timestamp
* @access public
*/
function now($type = 'timestamp')
{
switch ($type) {
case 'time':
return 'time(\'now\')';
case 'date':
return 'date(\'now\')';
case 'timestamp':
default:
return 'datetime(\'now\')';
}
}
// }}}
// {{{ unixtimestamp()
/**
* return string to call a function to get the unix timestamp from a iso timestamp
*
* @param string $expression
*
* @return string to call a variable with the timestamp
* @access public
*/
function unixtimestamp($expression)
{
return 'strftime("%s",'. $expression.', "utc")';
}
// }}}
// {{{ substring()
/**
* return string to call a function to get a substring inside an SQL statement
*
* @return string to call a function to get a substring
* @access public
*/
function substring($value, $position = 1, $length = null)
{
if (!is_null($length)) {
return "substr($value,$position,$length)";
}
return "substr($value,$position,length($value))";
}
// }}}
// {{{ random()
/**
* return string to call a function to get random value inside an SQL statement
*
* @return return string to generate float between 0 and 1
* @access public
*/
function random()
{
return '((RANDOM()+2147483648)/4294967296)';
}
// }}}
// {{{ replace()
/**
* return string to call a function to get a replacement inside an SQL statement.
*
* @return string to call a function to get a replace
* @access public
*/
function replace($str, $from_str, $to_str)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
return $error;
}
// }}}
}
?>

@ -2,7 +2,7 @@
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
@ -39,16 +39,18 @@
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@pooteeweet.org> |
// | Authors: Lukas Smith <smith@pooteeweet.org> |
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// $Id: Common.php,v 1.68 2007/12/03 20:59:15 quipo Exp $
// $Id: Common.php,v 1.71 2008/02/12 23:12:27 quipo Exp $
//
/**
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
* @author Lorenzo Alberton <l.alberton@quipo.it>
*/
/**
@ -198,6 +200,29 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
'method not implemented', __FUNCTION__);
}
// }}}
// {{{ alterDatabase()
/**
* alter an existing database
*
* @param string $name name of the database that should be created
* @param array $options array with charset, collation info
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function alterDatabase($database, $options = array())
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
// }}}
// {{{ dropDatabase()
@ -359,6 +384,56 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
return $db->exec("DROP TABLE $name");
}
// }}}
// {{{ truncateTable()
/**
* Truncate an existing table (if the TRUNCATE TABLE syntax is not supported,
* it falls back to a DELETE FROM TABLE query)
*
* @param string $name name of the table that should be truncated
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function truncateTable($name)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$name = $db->quoteIdentifier($name, true);
return $db->exec("DELETE FROM $name");
}
// }}}
// {{{ vacuum()
/**
* Optimize (vacuum) all the tables in the db (or only the specified table)
* and optionally run ANALYZE.
*
* @param string $table table name (all the tables if empty)
* @param array $options an array with driver-specific options:
* - timeout [int] (in seconds) [mssql-only]
* - analyze [boolean] [pgsql and mysql]
* - full [boolean] [pgsql-only]
* - freeze [boolean] [pgsql-only]
*
* @return mixed MDB2_OK success, a MDB2 error on failure
* @access public
*/
function vacuum($table = null, $options = array())
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'method not implemented', __FUNCTION__);
}
// }}}
// {{{ alterTable()

File diff suppressed because it is too large Load Diff

@ -2,7 +2,7 @@
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysql.php,v 1.100 2007/12/03 20:59:15 quipo Exp $
// $Id: mysql.php,v 1.108 2008/03/11 19:58:12 quipo Exp $
//
require_once 'MDB2/Driver/Manager/Common.php';
@ -79,16 +79,41 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
$name = $db->quoteIdentifier($name, true);
$query = 'CREATE DATABASE ' . $name;
if (!empty($options['charset'])) {
$query .= ' DEFAULT CHARACTER SET ' . $options['charset'];
$query .= ' DEFAULT CHARACTER SET ' . $db->quote($options['charset'], 'text');
}
if (!empty($options['collation'])) {
$query .= ' COLLATE ' . $options['collation'];
$query .= ' COLLATE ' . $db->quote($options['collation'], 'text');
}
$result = $db->exec($query);
if (PEAR::isError($result)) {
return $result;
return $db->standaloneQuery($query, null, true);
}
// }}}
// {{{ alterDatabase()
/**
* alter an existing database
*
* @param string $name name of the database that is intended to be changed
* @param array $options array with charset, collation info
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function alterDatabase($name, $options = array())
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return MDB2_OK;
$query = 'ALTER DATABASE '. $db->quoteIdentifier($name, true);
if (!empty($options['charset'])) {
$query .= ' DEFAULT CHARACTER SET ' . $db->quote($options['charset'], 'text');
}
if (!empty($options['collation'])) {
$query .= ' COLLATE ' . $db->quote($options['collation'], 'text');
}
return $db->standaloneQuery($query, null, true);
}
// }}}
@ -110,11 +135,7 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
$name = $db->quoteIdentifier($name, true);
$query = "DROP DATABASE $name";
$result = $db->exec($query);
if (PEAR::isError($result)) {
return $result;
}
return MDB2_OK;
return $db->standaloneQuery($query, null, true);
}
// }}}
@ -188,11 +209,37 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
return $db;
}
// if we have an AUTO_INCREMENT column and a PK on more than one field,
// we have to handle it differently...
$autoincrement = null;
if (empty($options['primary'])) {
$pk_fields = array();
foreach ($fields as $fieldname => $def) {
if (!empty($def['primary'])) {
$pk_fields[$fieldname] = true;
}
if (!empty($def['autoincrement'])) {
$autoincrement = $fieldname;
}
}
if (!is_null($autoincrement) && count($pk_fields) > 1) {
$options['primary'] = $pk_fields;
} else {
// the PK constraint is on max one field => OK
$autoincrement = null;
}
}
$query = $this->_getCreateTableQuery($name, $fields, $options);
if (PEAR::isError($query)) {
return $query;
}
if (!is_null($autoincrement)) {
// we have to remove the PK clause added by _getIntegerDeclaration()
$query = str_replace('AUTO_INCREMENT PRIMARY KEY', 'AUTO_INCREMENT', $query);
}
$options_strings = array();
if (!empty($options['comment'])) {
@ -226,6 +273,112 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
return MDB2_OK;
}
// }}}
// {{{ dropTable()
/**
* drop an existing table
*
* @param string $name name of the table that should be dropped
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function dropTable($name)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
//delete the triggers associated to existing FK constraints
$constraints = $this->listTableConstraints($name);
if (!PEAR::isError($constraints) && !empty($constraints)) {
$db->loadModule('Reverse', null, true);
foreach ($constraints as $constraint) {
$definition = $db->reverse->getTableConstraintDefinition($name, $constraint);
if (!PEAR::isError($definition) && !empty($definition['foreign'])) {
$result = $this->_dropFKTriggers($name, $constraint, $definition['references']['table']);
if (PEAR::isError($result)) {
return $result;
}
}
}
}
return parent::dropTable($name);
}
// }}}
// {{{ truncateTable()
/**
* Truncate an existing table (if the TRUNCATE TABLE syntax is not supported,
* it falls back to a DELETE FROM TABLE query)
*
* @param string $name name of the table that should be truncated
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function truncateTable($name)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$name = $db->quoteIdentifier($name, true);
return $db->exec("TRUNCATE TABLE $name");
}
// }}}
// {{{ vacuum()
/**
* Optimize (vacuum) all the tables in the db (or only the specified table)
* and optionally run ANALYZE.
*
* @param string $table table name (all the tables if empty)
* @param array $options an array with driver-specific options:
* - timeout [int] (in seconds) [mssql-only]
* - analyze [boolean] [pgsql and mysql]
* - full [boolean] [pgsql-only]
* - freeze [boolean] [pgsql-only]
*
* @return mixed MDB2_OK success, a MDB2 error on failure
* @access public
*/
function vacuum($table = null, $options = array())
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
if (empty($table)) {
$table = $this->listTables();
if (PEAR::isError($table)) {
return $table;
}
}
if (is_array($table)) {
foreach (array_keys($table) as $k) {
$table[$k] = $db->quoteIdentifier($table[$k], true);
}
$table = implode(', ', $table);
} else {
$table = $db->quoteIdentifier($table, true);
}
$result = $db->exec('OPTIMIZE TABLE '.$table);
if (PEAR::isError($result)) {
return $result;
}
if (!empty($options['analyze'])) {
return $db->exec('ANALYZE TABLE '.$table);
}
return MDB2_OK;
}
// }}}
// {{{ alterTable()
@ -629,33 +782,34 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
* Get the stucture of a field into an array
*
* @author Leoncx
* @param string $table name of the table on which the index is to be created
* @param string $name name of the index to be created
* @param array $definition associative array that defines properties of the index to be created.
* Currently, only one property named FIELDS is supported. This property
* is also an associative with the names of the index fields as array
* indexes. Each entry of this array is set to another type of associative
* array that specifies properties of the index that are specific to
* each field.
* @param string $table name of the table on which the index is to be created
* @param string $name name of the index to be created
* @param array $definition associative array that defines properties of the index to be created.
* Currently, only one property named FIELDS is supported. This property
* is also an associative with the names of the index fields as array
* indexes. Each entry of this array is set to another type of associative
* array that specifies properties of the index that are specific to
* each field.
*
* Currently, only the sorting property is supported. It should be used
* to define the sorting direction of the index. It may be set to either
* ascending or descending.
* Currently, only the sorting property is supported. It should be used
* to define the sorting direction of the index. It may be set to either
* ascending or descending.
*
* Not all DBMS support index sorting direction configuration. The DBMS
* drivers of those that do not support it ignore this property. Use the
* function supports() to determine whether the DBMS driver can manage indexes.
* Not all DBMS support index sorting direction configuration. The DBMS
* drivers of those that do not support it ignore this property. Use the
* function supports() to determine whether the DBMS driver can manage indexes.
*
* Example
* array(
* 'fields' => array(
* 'user_name' => array(
* 'sorting' => 'ascending'
* 'length' => 10
* ),
* 'last_login' => array()
* )
* Example
* array(
* 'fields' => array(
* 'user_name' => array(
* 'sorting' => 'ascending'
* 'length' => 10
* ),
* 'last_login' => array()
* )
* )
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
@ -800,10 +954,10 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
'invalid definition, could not create constraint', __FUNCTION__);
}
$table = $db->quoteIdentifier($table, true);
$query = "ALTER TABLE $table ADD $type $name";
$table_quoted = $db->quoteIdentifier($table, true);
$query = "ALTER TABLE $table_quoted ADD $type $name";
if (!empty($definition['foreign'])) {
$query .= ' FOREIGN KEY ';
$query .= ' FOREIGN KEY';
}
$fields = array();
foreach (array_keys($definition['fields']) as $field) {
@ -819,7 +973,14 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
$query .= ' ('. implode(', ', $referenced_fields) . ')';
$query .= $this->_getAdvancedFKOptions($definition);
}
return $db->exec($query);
$res = $db->exec($query);
if (PEAR::isError($res)) {
return $res;
}
if (!empty($definition['foreign'])) {
return $this->_createFKTriggers($table, array($name => $definition));
}
return MDB2_OK;
}
// }}}
@ -841,16 +1002,210 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
return $db;
}
$table = $db->quoteIdentifier($table, true);
if ($primary || strtolower($name) == 'primary') {
$query = "ALTER TABLE $table DROP PRIMARY KEY";
} else {
$query = 'ALTER TABLE '. $db->quoteIdentifier($table, true) .' DROP PRIMARY KEY';
return $db->exec($query);
}
//is it a FK constraint? If so, also delete the associated triggers
$db->loadModule('Reverse', null, true);
$definition = $db->reverse->getTableConstraintDefinition($table, $name);
if (!PEAR::isError($definition) && !empty($definition['foreign'])) {
//first drop the FK enforcing triggers
$result = $this->_dropFKTriggers($table, $name, $definition['references']['table']);
if (PEAR::isError($result)) {
return $result;
}
//then drop the constraint itself
$table = $db->quoteIdentifier($table, true);
$name = $db->quoteIdentifier($db->getIndexName($name), true);
$query = "ALTER TABLE $table DROP INDEX $name";
$query = "ALTER TABLE $table DROP FOREIGN KEY $name";
return $db->exec($query);
}
$table = $db->quoteIdentifier($table, true);
$name = $db->quoteIdentifier($db->getIndexName($name), true);
$query = "ALTER TABLE $table DROP INDEX $name";
return $db->exec($query);
}
// }}}
// {{{ _createFKTriggers()
/**
* Create triggers to enforce the FOREIGN KEY constraint on the table
*
* NB: since there's no RAISE_APPLICATION_ERROR facility in mysql,
* we call a non-existent procedure to raise the FK violation message.
* @see http://forums.mysql.com/read.php?99,55108,71877#msg-71877
*
* @param string $table table name
* @param array $foreign_keys FOREIGN KEY definitions
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access private
*/
function _createFKTriggers($table, $foreign_keys)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
// create triggers to enforce FOREIGN KEY constraints
if ($db->supports('triggers') && !empty($foreign_keys)) {
$table = $db->quoteIdentifier($table, true);
foreach ($foreign_keys as $fkname => $fkdef) {
if (empty($fkdef)) {
continue;
}
//set actions to 'RESTRICT' if not set
$fkdef['onupdate'] = empty($fkdef['onupdate']) ? 'RESTRICT' : strtoupper($fkdef['onupdate']);
$fkdef['ondelete'] = empty($fkdef['ondelete']) ? 'RESTRICT' : strtoupper($fkdef['ondelete']);
$trigger_names = array(
'insert' => $fkname.'_insert_trg',
'update' => $fkname.'_update_trg',
'pk_update' => $fkname.'_pk_update_trg',
'pk_delete' => $fkname.'_pk_delete_trg',
);
$table_fields = array_keys($fkdef['fields']);
$referenced_fields = array_keys($fkdef['references']['fields']);
//create the ON [UPDATE|DELETE] triggers on the primary table
$restrict_action = ' IF (SELECT ';
$aliased_fields = array();
foreach ($table_fields as $field) {
$aliased_fields[] = $table .'.'.$field .' AS '.$field;
}
$restrict_action .= implode(',', $aliased_fields)
.' FROM '.$table
.' WHERE ';
$conditions = array();
$new_values = array();
$null_values = array();
for ($i=0; $i<count($table_fields); $i++) {
$conditions[] = $table_fields[$i] .' = OLD.'.$referenced_fields[$i];
$new_values[] = $table_fields[$i] .' = NEW.'.$referenced_fields[$i];
$null_values[] = $table_fields[$i] .' = NULL';
}
$restrict_action .= implode(' AND ', $conditions).') IS NOT NULL'
.' THEN CALL %s_ON_TABLE_'.$table.'_VIOLATES_FOREIGN_KEY_CONSTRAINT();'
.' END IF;';
$cascade_action_update = 'UPDATE '.$table.' SET '.implode(', ', $new_values) .' WHERE '.implode(' AND ', $conditions). ';';
$cascade_action_delete = 'DELETE FROM '.$table.' WHERE '.implode(' AND ', $conditions). ';';
$setnull_action = 'UPDATE '.$table.' SET '.implode(', ', $null_values).' WHERE '.implode(' AND ', $conditions). ';';
if ('SET DEFAULT' == $fkdef['onupdate'] || 'SET DEFAULT' == $fkdef['ondelete']) {
$db->loadModule('Reverse', null, true);
$default_values = array();
foreach ($table_fields as $table_field) {
$field_definition = $db->reverse->getTableFieldDefinition($table, $field);
if (PEAR::isError($field_definition)) {
return $field_definition;
}
$default_values[] = $table_field .' = '. $field_definition[0]['default'];
}
$setdefault_action = 'UPDATE '.$table.' SET '.implode(', ', $default_values).' WHERE '.implode(' AND ', $conditions). ';';
}
$query = 'CREATE TRIGGER %s'
.' %s ON '.$fkdef['references']['table']
.' FOR EACH ROW BEGIN '
.' SET FOREIGN_KEY_CHECKS = 0; '; //only really needed for ON UPDATE CASCADE
if ('CASCADE' == $fkdef['onupdate']) {
$sql_update = sprintf($query, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update') . $cascade_action_update;
} elseif ('SET NULL' == $fkdef['onupdate']) {
$sql_update = sprintf($query, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update') . $setnull_action;
} elseif ('SET DEFAULT' == $fkdef['onupdate']) {
$sql_update = sprintf($query, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update') . $setdefault_action;
} elseif ('NO ACTION' == $fkdef['onupdate']) {
$sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'AFTER UPDATE', 'update');
} else {
//'RESTRICT'
$sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update');
}
if ('CASCADE' == $fkdef['ondelete']) {
$sql_delete = sprintf($query, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete') . $cascade_action_delete;
} elseif ('SET NULL' == $fkdef['ondelete']) {
$sql_delete = sprintf($query, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete') . $setnull_action;
} elseif ('SET DEFAULT' == $fkdef['ondelete']) {
$sql_delete = sprintf($query, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete') . $setdefault_action;
} elseif ('NO ACTION' == $fkdef['ondelete']) {
$sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'AFTER DELETE', 'delete');
} else {
//'RESTRICT'
$sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete');
}
$sql_update .= ' SET FOREIGN_KEY_CHECKS = 1; END;';
$sql_delete .= ' SET FOREIGN_KEY_CHECKS = 1; END;';
$db->pushErrorHandling(PEAR_ERROR_RETURN);
$db->expectError(MDB2_ERROR_CANNOT_CREATE);
$result = $db->exec($sql_delete);
$expected_errmsg = 'This MySQL version doesn\'t support multiple triggers with the same action time and event for one table';
$db->popExpect();
$db->popErrorHandling();
if (PEAR::isError($result)) {
if ($result->getCode() != MDB2_ERROR_CANNOT_CREATE) {
return $result;
}
$db->warnings[] = $expected_errmsg;
}
$db->pushErrorHandling(PEAR_ERROR_RETURN);
$db->expectError(MDB2_ERROR_CANNOT_CREATE);
$result = $db->exec($sql_update);
$db->popExpect();
$db->popErrorHandling();
if (PEAR::isError($result) && $result->getCode() != MDB2_ERROR_CANNOT_CREATE) {
if ($result->getCode() != MDB2_ERROR_CANNOT_CREATE) {
return $result;
}
$db->warnings[] = $expected_errmsg;
}
}
}
return MDB2_OK;
}
// }}}
// {{{ _dropFKTriggers()
/**
* Drop the triggers created to enforce the FOREIGN KEY constraint on the table
*
* @param string $table table name
* @param string $fkname FOREIGN KEY constraint name
* @param string $referenced_table referenced table name
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access private
*/
function _dropFKTriggers($table, $fkname, $referenced_table)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$triggers = $this->listTableTriggers($table);
$triggers2 = $this->listTableTriggers($referenced_table);
if (!PEAR::isError($triggers2) && !PEAR::isError($triggers)) {
$triggers = array_merge($triggers, $triggers2);
$pattern = '/^'.$fkname.'(_pk)?_(insert|update|delete)_trg$/i';
foreach ($triggers as $trigger) {
if (preg_match($pattern, $trigger)) {
$result = $db->exec('DROP TRIGGER '.$trigger);
if (PEAR::isError($result)) {
return $result;
}
}
}
}
return MDB2_OK;
}
// }}}
// {{{ listTableConstraints()
@ -904,8 +1259,8 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
$query = 'SHOW CREATE TABLE '. $db->escape($table);
$definition = $db->queryOne($query, 'text', 1);
if (!PEAR::isError($definition) && !empty($definition)) {
$pattern = '/\bCONSTRAINT\s+([^\s]+)\s+FOREIGN KEY\b/i';
if (preg_match_all($pattern, str_replace('`', '', $definition), $matches) > 1) {
$pattern = '/\bCONSTRAINT\b\s+([^\s]+)\s+\bFOREIGN KEY\b/Uims';
if (preg_match_all($pattern, str_replace('`', '', $definition), $matches) > 0) {
foreach ($matches[1] as $constraint) {
$result[$constraint] = true;
}
@ -974,7 +1329,6 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
$query .= ' '.implode(' ', $options_strings);
}
$res = $db->exec($query);
if (PEAR::isError($res)) {
return $res;
}

@ -2,7 +2,7 @@
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: mysqli.php,v 1.87 2007/12/03 20:59:15 quipo Exp $
// $Id: mysqli.php,v 1.95 2008/03/11 19:58:12 quipo Exp $
//
require_once 'MDB2/Driver/Manager/Common.php';
@ -79,16 +79,41 @@ class MDB2_Driver_Manager_mysqli extends MDB2_Driver_Manager_Common
$name = $db->quoteIdentifier($name, true);
$query = 'CREATE DATABASE ' . $name;
if (!empty($options['charset'])) {
$query .= ' DEFAULT CHARACTER SET ' . $options['charset'];
$query .= ' DEFAULT CHARACTER SET ' . $db->quote($options['charset'], 'text');
}
if (!empty($options['collation'])) {
$query .= ' COLLATE ' . $options['collation'];
$query .= ' COLLATE ' . $db->quote($options['collation'], 'text');
}
$result = $db->exec($query);
if (PEAR::isError($result)) {
return $result;
return $db->standaloneQuery($query, null, true);
}
// }}}
// {{{ alterDatabase()
/**
* alter an existing database
*
* @param string $name name of the database that is intended to be changed
* @param array $options array with charset, collation info
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function alterDatabase($name, $options = array())
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
return MDB2_OK;
$query = 'ALTER DATABASE '. $db->quoteIdentifier($name, true);
if (!empty($options['charset'])) {
$query .= ' DEFAULT CHARACTER SET ' . $db->quote($options['charset'], 'text');
}
if (!empty($options['collation'])) {
$query .= ' COLLATE ' . $db->quote($options['collation'], 'text');
}
return $db->standaloneQuery($query, null, true);
}
// }}}
@ -110,11 +135,7 @@ class MDB2_Driver_Manager_mysqli extends MDB2_Driver_Manager_Common
$name = $db->quoteIdentifier($name, true);
$query = "DROP DATABASE $name";
$result = $db->exec($query);
if (PEAR::isError($result)) {
return $result;
}
return MDB2_OK;
return $db->standaloneQuery($query, null, true);
}
// }}}
@ -188,11 +209,37 @@ class MDB2_Driver_Manager_mysqli extends MDB2_Driver_Manager_Common
return $db;
}
// if we have an AUTO_INCREMENT column and a PK on more than one field,
// we have to handle it differently...
$autoincrement = null;
if (empty($options['primary'])) {
$pk_fields = array();
foreach ($fields as $fieldname => $def) {
if (!empty($def['primary'])) {
$pk_fields[$fieldname] = true;
}
if (!empty($def['autoincrement'])) {
$autoincrement = $fieldname;
}
}
if (!is_null($autoincrement) && count($pk_fields) > 1) {
$options['primary'] = $pk_fields;
} else {
// the PK constraint is on max one field => OK
$autoincrement = null;
}
}
$query = $this->_getCreateTableQuery($name, $fields, $options);
if (PEAR::isError($query)) {
return $query;
}
if (!is_null($autoincrement)) {
// we have to remove the PK clause added by _getIntegerDeclaration()
$query = str_replace('AUTO_INCREMENT PRIMARY KEY', 'AUTO_INCREMENT', $query);
}
$options_strings = array();
if (!empty($options['comment'])) {
@ -226,6 +273,112 @@ class MDB2_Driver_Manager_mysqli extends MDB2_Driver_Manager_Common
return MDB2_OK;
}
// }}}
// {{{ dropTable()
/**
* drop an existing table
*
* @param string $name name of the table that should be dropped
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function dropTable($name)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
//delete the triggers associated to existing FK constraints
$constraints = $this->listTableConstraints($name);
if (!PEAR::isError($constraints) && !empty($constraints)) {
$db->loadModule('Reverse', null, true);
foreach ($constraints as $constraint) {
$definition = $db->reverse->getTableConstraintDefinition($name, $constraint);
if (!PEAR::isError($definition) && !empty($definition['foreign'])) {
$result = $this->_dropFKTriggers($name, $constraint, $definition['references']['table']);
if (PEAR::isError($result)) {
return $result;
}
}
}
}
return parent::dropTable($name);
}
// }}}
// {{{ truncateTable()
/**
* Truncate an existing table (if the TRUNCATE TABLE syntax is not supported,
* it falls back to a DELETE FROM TABLE query)
*
* @param string $name name of the table that should be truncated
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function truncateTable($name)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$name = $db->quoteIdentifier($name, true);
return $db->exec("TRUNCATE TABLE $name");
}
// }}}
// {{{ vacuum()
/**
* Optimize (vacuum) all the tables in the db (or only the specified table)
* and optionally run ANALYZE.
*
* @param string $table table name (all the tables if empty)
* @param array $options an array with driver-specific options:
* - timeout [int] (in seconds) [mssql-only]
* - analyze [boolean] [pgsql and mysql]
* - full [boolean] [pgsql-only]
* - freeze [boolean] [pgsql-only]
*
* @return mixed MDB2_OK success, a MDB2 error on failure
* @access public
*/
function vacuum($table = null, $options = array())
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
if (empty($table)) {
$table = $this->listTables();
if (PEAR::isError($table)) {
return $table;
}
}
if (is_array($table)) {
foreach (array_keys($table) as $k) {
$table[$k] = $db->quoteIdentifier($table[$k], true);
}
$table = implode(', ', $table);
} else {
$table = $db->quoteIdentifier($table, true);
}
$result = $db->exec('OPTIMIZE TABLE '.$table);
if (PEAR::isError($result)) {
return $result;
}
if (!empty($options['analyze'])) {
return $db->exec('ANALYZE TABLE '.$table);
}
return MDB2_OK;
}
// }}}
// {{{ alterTable()
@ -656,6 +809,7 @@ class MDB2_Driver_Manager_mysqli extends MDB2_Driver_Manager_Common
* 'last_login' => array()
* )
* )
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
@ -800,10 +954,10 @@ class MDB2_Driver_Manager_mysqli extends MDB2_Driver_Manager_Common
'invalid definition, could not create constraint', __FUNCTION__);
}
$table = $db->quoteIdentifier($table, true);
$query = "ALTER TABLE $table ADD $type $name";
$table_quoted = $db->quoteIdentifier($table, true);
$query = "ALTER TABLE $table_quoted ADD $type $name";
if (!empty($definition['foreign'])) {
$query .= ' FOREIGN KEY ';
$query .= ' FOREIGN KEY';
}
$fields = array();
foreach (array_keys($definition['fields']) as $field) {
@ -819,7 +973,14 @@ class MDB2_Driver_Manager_mysqli extends MDB2_Driver_Manager_Common
$query .= ' ('. implode(', ', $referenced_fields) . ')';
$query .= $this->_getAdvancedFKOptions($definition);
}
return $db->exec($query);
$res = $db->exec($query);
if (PEAR::isError($res)) {
return $res;
}
if (!empty($definition['foreign'])) {
return $this->_createFKTriggers($table, array($name => $definition));
}
return MDB2_OK;
}
// }}}
@ -840,17 +1001,211 @@ class MDB2_Driver_Manager_mysqli extends MDB2_Driver_Manager_Common
if (PEAR::isError($db)) {
return $db;
}
$table = $db->quoteIdentifier($table, true);
if ($primary || strtolower($name) == 'primary') {
$query = "ALTER TABLE $table DROP PRIMARY KEY";
} else {
$query = 'ALTER TABLE '. $db->quoteIdentifier($table, true) .' DROP PRIMARY KEY';
return $db->exec($query);
}
//is it a FK constraint? If so, also delete the associated triggers
$db->loadModule('Reverse', null, true);
$definition = $db->reverse->getTableConstraintDefinition($table, $name);
if (!PEAR::isError($definition) && !empty($definition['foreign'])) {
//first drop the FK enforcing triggers
$result = $this->_dropFKTriggers($table, $name, $definition['references']['table']);
if (PEAR::isError($result)) {
return $result;
}
//then drop the constraint itself
$table = $db->quoteIdentifier($table, true);
$name = $db->quoteIdentifier($db->getIndexName($name), true);
$query = "ALTER TABLE $table DROP INDEX $name";
$query = "ALTER TABLE $table DROP FOREIGN KEY $name";
return $db->exec($query);
}
$table = $db->quoteIdentifier($table, true);
$name = $db->quoteIdentifier($db->getIndexName($name), true);
$query = "ALTER TABLE $table DROP INDEX $name";
return $db->exec($query);
}
// }}}
// {{{ _createFKTriggers()
/**
* Create triggers to enforce the FOREIGN KEY constraint on the table
*
* NB: since there's no RAISE_APPLICATION_ERROR facility in mysql,
* we call a non-existent procedure to raise the FK violation message.
* @see http://forums.mysql.com/read.php?99,55108,71877#msg-71877
*
* @param string $table table name
* @param array $foreign_keys FOREIGN KEY definitions
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access private
*/
function _createFKTriggers($table, $foreign_keys)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
// create triggers to enforce FOREIGN KEY constraints
if ($db->supports('triggers') && !empty($foreign_keys)) {
$table = $db->quoteIdentifier($table, true);
foreach ($foreign_keys as $fkname => $fkdef) {
if (empty($fkdef)) {
continue;
}
//set actions to 'RESTRICT' if not set
$fkdef['onupdate'] = empty($fkdef['onupdate']) ? 'RESTRICT' : strtoupper($fkdef['onupdate']);
$fkdef['ondelete'] = empty($fkdef['ondelete']) ? 'RESTRICT' : strtoupper($fkdef['ondelete']);
$trigger_names = array(
'insert' => $fkname.'_insert_trg',
'update' => $fkname.'_update_trg',
'pk_update' => $fkname.'_pk_update_trg',
'pk_delete' => $fkname.'_pk_delete_trg',
);
$table_fields = array_keys($fkdef['fields']);
$referenced_fields = array_keys($fkdef['references']['fields']);
//create the ON [UPDATE|DELETE] triggers on the primary table
$restrict_action = ' IF (SELECT ';
$aliased_fields = array();
foreach ($table_fields as $field) {
$aliased_fields[] = $table .'.'.$field .' AS '.$field;
}
$restrict_action .= implode(',', $aliased_fields)
.' FROM '.$table
.' WHERE ';
$conditions = array();
$new_values = array();
$null_values = array();
for ($i=0; $i<count($table_fields); $i++) {
$conditions[] = $table_fields[$i] .' = OLD.'.$referenced_fields[$i];
$new_values[] = $table_fields[$i] .' = NEW.'.$referenced_fields[$i];
$null_values[] = $table_fields[$i] .' = NULL';
}
$restrict_action .= implode(' AND ', $conditions).') IS NOT NULL'
.' THEN CALL %s_ON_TABLE_'.$table.'_VIOLATES_FOREIGN_KEY_CONSTRAINT();'
.' END IF;';
$cascade_action_update = 'UPDATE '.$table.' SET '.implode(', ', $new_values) .' WHERE '.implode(' AND ', $conditions). ';';
$cascade_action_delete = 'DELETE FROM '.$table.' WHERE '.implode(' AND ', $conditions). ';';
$setnull_action = 'UPDATE '.$table.' SET '.implode(', ', $null_values).' WHERE '.implode(' AND ', $conditions). ';';
if ('SET DEFAULT' == $fkdef['onupdate'] || 'SET DEFAULT' == $fkdef['ondelete']) {
$db->loadModule('Reverse', null, true);
$default_values = array();
foreach ($table_fields as $table_field) {
$field_definition = $db->reverse->getTableFieldDefinition($table, $field);
if (PEAR::isError($field_definition)) {
return $field_definition;
}
$default_values[] = $table_field .' = '. $field_definition[0]['default'];
}
$setdefault_action = 'UPDATE '.$table.' SET '.implode(', ', $default_values).' WHERE '.implode(' AND ', $conditions). ';';
}
$query = 'CREATE TRIGGER %s'
.' %s ON '.$fkdef['references']['table']
.' FOR EACH ROW BEGIN '
.' SET FOREIGN_KEY_CHECKS = 0; '; //only really needed for ON UPDATE CASCADE
if ('CASCADE' == $fkdef['onupdate']) {
$sql_update = sprintf($query, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update') . $cascade_action_update;
} elseif ('SET NULL' == $fkdef['onupdate']) {
$sql_update = sprintf($query, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update') . $setnull_action;
} elseif ('SET DEFAULT' == $fkdef['onupdate']) {
$sql_update = sprintf($query, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update') . $setdefault_action;
} elseif ('NO ACTION' == $fkdef['onupdate']) {
$sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'AFTER UPDATE', 'update');
} else {
//'RESTRICT'
$sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update');
}
if ('CASCADE' == $fkdef['ondelete']) {
$sql_delete = sprintf($query, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete') . $cascade_action_delete;
} elseif ('SET NULL' == $fkdef['ondelete']) {
$sql_delete = sprintf($query, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete') . $setnull_action;
} elseif ('SET DEFAULT' == $fkdef['ondelete']) {
$sql_delete = sprintf($query, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete') . $setdefault_action;
} elseif ('NO ACTION' == $fkdef['ondelete']) {
$sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'AFTER DELETE', 'delete');
} else {
//'RESTRICT'
$sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete');
}
$sql_update .= ' SET FOREIGN_KEY_CHECKS = 1; END;';
$sql_delete .= ' SET FOREIGN_KEY_CHECKS = 1; END;';
$db->pushErrorHandling(PEAR_ERROR_RETURN);
$db->expectError(MDB2_ERROR_CANNOT_CREATE);
$result = $db->exec($sql_delete);
$expected_errmsg = 'This MySQL version doesn\'t support multiple triggers with the same action time and event for one table';
$db->popExpect();
$db->popErrorHandling();
if (PEAR::isError($result)) {
if ($result->getCode() != MDB2_ERROR_CANNOT_CREATE) {
return $result;
}
$db->warnings[] = $expected_errmsg;
}
$db->pushErrorHandling(PEAR_ERROR_RETURN);
$db->expectError(MDB2_ERROR_CANNOT_CREATE);
$result = $db->exec($sql_update);
$db->popExpect();
$db->popErrorHandling();
if (PEAR::isError($result) && $result->getCode() != MDB2_ERROR_CANNOT_CREATE) {
if ($result->getCode() != MDB2_ERROR_CANNOT_CREATE) {
return $result;
}
$db->warnings[] = $expected_errmsg;
}
}
}
return MDB2_OK;
}
// }}}
// {{{ _dropFKTriggers()
/**
* Drop the triggers created to enforce the FOREIGN KEY constraint on the table
*
* @param string $table table name
* @param string $fkname FOREIGN KEY constraint name
* @param string $referenced_table referenced table name
*
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access private
*/
function _dropFKTriggers($table, $fkname, $referenced_table)
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$triggers = $this->listTableTriggers($table);
$triggers2 = $this->listTableTriggers($referenced_table);
if (!PEAR::isError($triggers2) && !PEAR::isError($triggers)) {
$triggers = array_merge($triggers, $triggers2);
$pattern = '/^'.$fkname.'(_pk)?_(insert|update|delete)_trg$/i';
foreach ($triggers as $trigger) {
if (preg_match($pattern, $trigger)) {
$result = $db->exec('DROP TRIGGER '.$trigger);
if (PEAR::isError($result)) {
return $result;
}
}
}
}
return MDB2_OK;
}
// }}}
// {{{ listTableConstraints()
@ -904,8 +1259,8 @@ class MDB2_Driver_Manager_mysqli extends MDB2_Driver_Manager_Common
$query = 'SHOW CREATE TABLE '. $db->escape($table);
$definition = $db->queryOne($query, 'text', 1);
if (!PEAR::isError($definition) && !empty($definition)) {
$pattern = '/\bCONSTRAINT\s+([^\s]+)\s+FOREIGN KEY\b/i';
if (preg_match_all($pattern, str_replace('`', '', $definition), $matches) > 1) {
$pattern = '/\bCONSTRAINT\b\s+([^\s]+)\s+\bFOREIGN KEY\b/Uims';
if (preg_match_all($pattern, str_replace('`', '', $definition), $matches) > 0) {
foreach ($matches[1] as $constraint) {
$result[$constraint] = true;
}
@ -969,10 +1324,6 @@ class MDB2_Driver_Manager_mysqli extends MDB2_Driver_Manager_Common
$options_strings[] = "ENGINE = $type";
}
if (!empty($options_strings)) {
$query.= ' '.implode(' ', $options_strings);
}
$query = "CREATE TABLE $sequence_name ($seqcol_name INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ($seqcol_name))";
if (!empty($options_strings)) {
$query .= ' '.implode(' ', $options_strings);

File diff suppressed because it is too large Load Diff

@ -2,7 +2,7 @@
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith, Lorenzo Alberton |
// | All rights reserved. |
// +----------------------------------------------------------------------+
@ -43,7 +43,7 @@
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php,v 1.72 2007/12/03 20:59:15 quipo Exp $
// $Id: sqlite.php,v 1.74 2008/03/05 11:08:53 quipo Exp $
//
require_once 'MDB2/Driver/Manager/Common.php';
@ -403,6 +403,37 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
return $db->exec("DROP TABLE $name");
}
// }}}
// {{{ vacuum()
/**
* Optimize (vacuum) all the tables in the db (or only the specified table)
* and optionally run ANALYZE.
*
* @param string $table table name (all the tables if empty)
* @param array $options an array with driver-specific options:
* - timeout [int] (in seconds) [mssql-only]
* - analyze [boolean] [pgsql and mysql]
* - full [boolean] [pgsql-only]
* - freeze [boolean] [pgsql-only]
*
* @return mixed MDB2_OK success, a MDB2 error on failure
* @access public
*/
function vacuum($table = null, $options = array())
{
$db =& $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
$query = 'VACUUM';
if (!empty($table)) {
$query .= ' '.$db->quoteIdentifier($table, true);
}
return $db->exec($query);
}
// }}}
// {{{ alterTable()
@ -1207,7 +1238,7 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
if (PEAR::isError($table_def)) {
return $table_def;
}
if (preg_match("/\bPRIMARY\s+KEY\b\s*\(([^)]+)/i", $table_def, $tmp)) {
if (preg_match("/\bPRIMARY\s+KEY\b/i", $table_def, $tmp)) {
$result['primary'] = true;
}

File diff suppressed because it is too large Load Diff

@ -43,7 +43,7 @@
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// $Id: mssql.php,v 1.48 2007/11/25 13:38:29 quipo Exp $
// $Id: mssql.php,v 1.49 2008/02/17 15:30:57 quipo Exp $
//
require_once 'MDB2/Driver/Reverse/Common.php';
@ -454,7 +454,7 @@ class MDB2_Driver_Reverse_mssql extends MDB2_Driver_Reverse_Common
}
$trg_body = $db->queryCol('EXEC sp_helptext '. $db->quote($trigger, 'text'), 'text');
if (!PEAR::isError($trg_body)) {
$def['trigger_body'] = implode('', $trg_body);
$def['trigger_body'] = implode(' ', $trg_body);
}
return $def;
}

@ -2,7 +2,7 @@
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
@ -43,7 +43,7 @@
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php,v 1.68 2007/11/25 13:38:29 quipo Exp $
// $Id: pgsql.php,v 1.70 2008/03/13 20:38:09 quipo Exp $
require_once 'MDB2/Driver/Reverse/Common.php';
@ -358,7 +358,7 @@ class MDB2_Driver_Reverse_pgsql extends MDB2_Driver_Reverse_Common
$query = 'SELECT a.attname
FROM pg_constraint c
LEFT JOIN pg_class t ON c.confrelid = t.oid
LEFT JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(c.conkey)
LEFT JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(c.confkey)
WHERE c.conname = %s
AND t.relname = ' . $db->quote($definition['references']['table'], 'text');
$constraint_name_mdb2 = $db->getIndexName($constraint_name);
@ -424,7 +424,10 @@ class MDB2_Driver_Reverse_pgsql extends MDB2_Driver_Reverse_Common
WHEN 24 THEN 'UPDATE, DELETE'
WHEN 12 THEN 'INSERT, DELETE'
END AS trigger_event,
trg.tgenabled AS trigger_enabled,
CASE trg.tgenabled
WHEN 'O' THEN 't'
ELSE trg.tgenabled
END AS trigger_enabled,
obj_description(trg.oid, 'pg_trigger') AS trigger_comment
FROM pg_trigger trg,
pg_class tbl,

@ -43,7 +43,7 @@
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php,v 1.78 2007/12/01 10:46:13 quipo Exp $
// $Id: sqlite.php,v 1.79 2008/03/05 11:08:53 quipo Exp $
//
require_once 'MDB2/Driver/Reverse/Common.php';
@ -393,6 +393,18 @@ class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
}
return $definition;
}
if (preg_match("/\"([^\"]+)\"[^\,\"]+\bPRIMARY\s+KEY\b[^\,\)]*/i", $sql, $tmp)) {
$definition['primary'] = true;
$definition['fields'] = array();
$column_names = split(',', $tmp[1]);
$colpos = 1;
foreach ($column_names as $column_name) {
$definition['fields'][trim($column_name)] = array(
'position' => $colpos++
);
}
return $definition;
}
} else {
// search in table definition for FOREIGN KEYs
$pattern = "/\bCONSTRAINT\b\s+%s\s+

@ -3,7 +3,7 @@
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith, Frank M. Kromann |
// | All rights reserved. |
// +----------------------------------------------------------------------+
@ -43,7 +43,7 @@
// | Author: Frank M. Kromann <frank@kromann.info> |
// +----------------------------------------------------------------------+
//
// $Id: mssql.php,v 1.161 2007/11/18 17:52:00 quipo Exp $
// $Id: mssql.php,v 1.174 2008/03/08 14:18:39 quipo Exp $
//
// {{{ Class MDB2_Driver_mssql
/**
@ -86,6 +86,7 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
$this->supported['LOBs'] = true;
$this->supported['replace'] = 'emulated';
$this->supported['sub_selects'] = true;
$this->supported['triggers'] = true;
$this->supported['auto_increment'] = true;
$this->supported['primary_key'] = true;
$this->supported['result_introspection'] = true;
@ -93,8 +94,11 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
$this->supported['pattern_escaping'] = true;
$this->supported['new_link'] = true;
$this->options['DBA_username'] = false;
$this->options['DBA_password'] = false;
$this->options['database_device'] = false;
$this->options['database_size'] = false;
$this->options['max_identifiers_length'] = 128; // MS Access: 64
}
// }}}
@ -107,11 +111,15 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
* @return array
* @access public
*/
function errorInfo($error = null)
function errorInfo($error = null, $connection = null)
{
if (is_null($connection)) {
$connection = $this->connection;
}
$native_code = null;
if ($this->connection) {
$result = @mssql_query('select @@ERROR as ErrorCode', $this->connection);
if ($connection) {
$result = @mssql_query('select @@ERROR as ErrorCode', $connection);
if ($result) {
$native_code = @mssql_result($result, 0, 0);
@mssql_free_result($result);
@ -136,8 +144,10 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
336 => MDB2_ERROR_SYNTAX,
515 => MDB2_ERROR_CONSTRAINT_NOT_NULL,
547 => MDB2_ERROR_CONSTRAINT,
911 => MDB2_ERROR_NOT_FOUND,
1018 => MDB2_ERROR_SYNTAX,
1035 => MDB2_ERROR_SYNTAX,
1801 => MDB2_ERROR_ALREADY_EXISTS,
1913 => MDB2_ERROR_ALREADY_EXISTS,
2209 => MDB2_ERROR_SYNTAX,
2223 => MDB2_ERROR_SYNTAX,
@ -296,39 +306,30 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
}
// }}}
// {{{ connect()
// {{{ _doConnect()
/**
* Connect to the database
* do the grunt work of the connect
*
* @return true on success, MDB2 Error Object on failure
* @return connection on success or MDB2 Error Object on failure
* @access protected
*/
function connect()
function _doConnect($username, $password, $persistent = false)
{
if (is_resource($this->connection)) {
//if (count(array_diff($this->connected_dsn, $this->dsn)) == 0
if (MDB2::areEquals($this->connected_dsn, $this->dsn)
&& $this->opened_persistent == $this->options['persistent']
) {
return MDB2_OK;
}
$this->disconnect(false);
}
if (!PEAR::loadExtension($this->phptype)) {
if (!PEAR::loadExtension($this->phptype) && !PEAR::loadExtension('sybase_ct')) {
return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__);
}
$params = array(
$this->dsn['hostspec'] ? $this->dsn['hostspec'] : 'localhost',
$this->dsn['username'] ? $this->dsn['username'] : null,
$this->dsn['password'] ? $this->dsn['password'] : null,
$username ? $username : null,
$password ? $password : null,
);
if ($this->dsn['port']) {
$params[0].= ((substr(PHP_OS, 0, 3) == 'WIN') ? ',' : ':').$this->dsn['port'];
}
if (!$this->options['persistent']) {
if (!$persistent) {
if (isset($this->dsn['new_link'])
&& ($this->dsn['new_link'] == 'true' || $this->dsn['new_link'] === true)
) {
@ -338,7 +339,7 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
}
}
$connect_function = $this->options['persistent'] ? 'mssql_pconnect' : 'mssql_connect';
$connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect';
$connection = @call_user_func_array($connect_function, $params);
if ($connection <= 0) {
@ -346,6 +347,8 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
'unable to establish a connection', __FUNCTION__, __FUNCTION__);
}
@mssql_query('SET ANSI_NULL_DFLT_ON ON', $connection);
if (!empty($this->dsn['charset'])) {
$result = $this->setCharset($this->dsn['charset'], $connection);
if (PEAR::isError($result)) {
@ -361,6 +364,38 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
@mssql_query('SET DATEFORMAT ymd', $connection);
}
return $connection;
}
// }}}
// {{{ connect()
/**
* Connect to the database
*
* @return true on success, MDB2 Error Object on failure
*/
function connect()
{
if (is_resource($this->connection)) {
//if (count(array_diff($this->connected_dsn, $this->dsn)) == 0
if (MDB2::areEquals($this->connected_dsn, $this->dsn)
&& $this->opened_persistent == $this->options['persistent']
) {
return MDB2_OK;
}
$this->disconnect(false);
}
$connection = $this->_doConnect(
$this->dsn['username'],
$this->dsn['password'],
$this->options['persistent']
);
if (PEAR::isError($connection)) {
return $connection;
}
$this->connection = $connection;
$this->connected_dsn = $this->dsn;
$this->connected_database_name = '';
@ -381,6 +416,41 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
return MDB2_OK;
}
// }}}
// {{{ databaseExists()
/**
* check if given database name is exists?
*
* @param string $name name of the database that should be checked
*
* @return mixed true/false on success, a MDB2 error on failure
* @access public
*/
function databaseExists($name)
{
$connection = $this->_doConnect($this->dsn['username'],
$this->dsn['password'],
$this->options['persistent']);
if (PEAR::isError($connection)) {
return $connection;
}
$result = @mssql_select_db($name, $connection);
$errorInfo = $this->errorInfo(null, $connection);
@mssql_close($connection);
if (!$result) {
if ($errorInfo[0] != MDB2_ERROR_NOT_FOUND) {
exit;
$result = $this->raiseError($errorInfo[0], null, null, $errorInfo[2], __FUNCTION__);
return $result;
}
$result = false;
}
return $result;
}
// }}}
// {{{ disconnect()
@ -416,6 +486,42 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
return parent::disconnect($force);
}
// }}}
// {{{ standaloneQuery()
/**
* execute a query as DBA
*
* @param string $query the SQL query
* @param mixed $types array that contains the types of the columns in
* the result set
* @param boolean $is_manip if the query is a manipulation query
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
function &standaloneQuery($query, $types = null, $is_manip = false)
{
$user = $this->options['DBA_username']? $this->options['DBA_username'] : $this->dsn['username'];
$pass = $this->options['DBA_password']? $this->options['DBA_password'] : $this->dsn['password'];
$connection = $this->_doConnect($user, $pass, $this->options['persistent']);
if (PEAR::isError($connection)) {
return $connection;
}
$offset = $this->offset;
$limit = $this->limit;
$this->offset = $this->limit = 0;
$query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
$result =& $this->_doQuery($query, $is_manip, $connection, $this->database_name);
if (!PEAR::isError($result)) {
$result = $this->_affectedRows($connection, $result);
}
@mssql_close($connection);
return $result;
}
// }}}
// {{{ _doQuery()
@ -546,7 +652,7 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
// cache server_info
$this->connected_server_info = $server_info;
if (!$native && !PEAR::isError($server_info)) {
if (preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $server_info, $tmp)) {
if (preg_match('/(\d+)\.(\d+)\.(\d+)/', $server_info, $tmp)) {
$server_info = array(
'major' => $tmp[1],
'minor' => $tmp[2],
@ -609,6 +715,7 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
{
$sequence_name = $this->quoteIdentifier($this->getSequenceName($seq_name), true);
$seqcol_name = $this->quoteIdentifier($this->options['seqcol_name'], true);
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$this->expectError(MDB2_ERROR_NOSUCHTABLE);
$seq_val = $this->_checkSequence($sequence_name);
@ -621,6 +728,7 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
}
$result =& $this->_doQuery($query, true);
$this->popExpect();
$this->popErrorHandling();
if (PEAR::isError($result)) {
if ($ondemand && !$this->_checkSequence($sequence_name)) {
$this->loadModule('Manager', null, true);
@ -669,6 +777,7 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
*
* @param string $table name of the table into which a new row was inserted
* @param string $field name of the field into which a new row was inserted
*
* @return mixed MDB2 Error Object or id
* @access public
*/
@ -678,9 +787,12 @@ class MDB2_Driver_mssql extends MDB2_Driver_Common
if (is_array($server_info) && !is_null($server_info['major'])
&& $server_info['major'] >= 8
) {
$query = "SELECT SCOPE_IDENTITY()";
$query = "SELECT IDENT_CURRENT('$table')";
} else {
$query = "SELECT @@IDENTITY";
if (!is_null($table)) {
$query .= ' FROM '.$this->quoteIdentifier($table, true);
}
}
return $this->queryOne($query, 'integer');

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -3,7 +3,7 @@
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
@ -43,7 +43,7 @@
// | Author: Paul Cooper <pgc@ucecom.com> |
// +----------------------------------------------------------------------+
//
// $Id: pgsql.php,v 1.186 2007/11/10 13:27:03 quipo Exp $
// $Id: pgsql.php,v 1.197 2008/03/08 14:18:39 quipo Exp $
/**
* MDB2 PostGreSQL driver
@ -83,6 +83,7 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
$this->supported['LOBs'] = true;
$this->supported['replace'] = 'emulated';
$this->supported['sub_selects'] = true;
$this->supported['triggers'] = true;
$this->supported['auto_increment'] = 'emulated';
$this->supported['primary_key'] = true;
$this->supported['result_introspection'] = true;
@ -91,8 +92,11 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
$this->supported['pattern_escaping'] = true;
$this->supported['new_link'] = true;
$this->options['DBA_username'] = false;
$this->options['DBA_password'] = false;
$this->options['multi_query'] = false;
$this->options['disable_smart_seqname'] = false;
$this->options['max_identifiers_length'] = 63;
}
// }}}
@ -119,6 +123,8 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
$native_msg = 'Database connection has been lost.';
$error_code = MDB2_ERROR_CONNECT_FAILED;
}
} else {
$native_msg = @pg_last_error();
}
static $error_regexps;
@ -128,8 +134,12 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
=> MDB2_ERROR_NOSUCHFIELD,
'/(relation|sequence|table).*does not exist|class .* not found/i'
=> MDB2_ERROR_NOSUCHTABLE,
'/database .* does not exist/'
=> MDB2_ERROR_NOT_FOUND,
'/index .* does not exist/'
=> MDB2_ERROR_NOT_FOUND,
'/database .* already exists/i'
=> MDB2_ERROR_ALREADY_EXISTS,
'/relation .* already exists/i'
=> MDB2_ERROR_ALREADY_EXISTS,
'/(divide|division) by zero$/i'
@ -202,7 +212,7 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
if (PEAR::isError($connection)) {
return $connection;
}
if (version_compare(PHP_VERSION, '5.2.0RC5', '>=')) {
if (is_resource($connection) && version_compare(PHP_VERSION, '5.2.0RC5', '>=')) {
$text = @pg_escape_string($connection, $text);
} else {
$text = @pg_escape_string($text);
@ -353,13 +363,18 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
// {{{ _doConnect()
/**
* Does the grunt work of connecting to the database
* Do the grunt work of connecting to the database
*
* @return mixed connection resource on success, MDB2 Error Object on failure
* @access protected
**/
function _doConnect($database_name, $persistent = false)
*/
function _doConnect($username, $password, $database_name, $persistent = false)
{
if (!PEAR::loadExtension($this->phptype)) {
return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__);
}
if ($database_name == '') {
$database_name = 'template1';
}
@ -386,11 +401,11 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
if ($database_name) {
$params[0].= ' dbname=\'' . addslashes($database_name) . '\'';
}
if ($this->dsn['username']) {
$params[0].= ' user=\'' . addslashes($this->dsn['username']) . '\'';
if ($username) {
$params[0].= ' user=\'' . addslashes($username) . '\'';
}
if ($this->dsn['password']) {
$params[0].= ' password=\'' . addslashes($this->dsn['password']) . '\'';
if ($password) {
$params[0].= ' password=\'' . addslashes($password) . '\'';
}
if (!empty($this->dsn['options'])) {
$params[0].= ' options=' . $this->dsn['options'];
@ -417,7 +432,6 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
}
$connect_function = $persistent ? 'pg_pconnect' : 'pg_connect';
$connection = @call_user_func_array($connect_function, $params);
if (!$connection) {
return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null,
@ -449,7 +463,7 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
*
* @return true on success, MDB2 Error Object on failure
* @access public
**/
*/
function connect()
{
if (is_resource($this->connection)) {
@ -463,22 +477,22 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
$this->disconnect(false);
}
if (!PEAR::loadExtension($this->phptype)) {
return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__);
}
if ($this->database_name) {
$connection = $this->_doConnect($this->database_name, $this->options['persistent']);
$connection = $this->_doConnect($this->dsn['username'],
$this->dsn['password'],
$this->database_name,
$this->options['persistent']);
if (PEAR::isError($connection)) {
return $connection;
}
$this->connection = $connection;
$this->connected_dsn = $this->dsn;
$this->connected_database_name = $this->database_name;
$this->opened_persistent = $this->options['persistent'];
$this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype;
}
return MDB2_OK;
}
@ -501,7 +515,10 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
return $connection;
}
}
if (is_array($charset)) {
$charset = array_shift($charset);
$this->warnings[] = 'postgresql does not support setting client collation';
}
$result = @pg_set_client_encoding($connection, $charset);
if ($result == -1) {
return $this->raiseError(null, null, null,
@ -510,6 +527,30 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
return MDB2_OK;
}
// }}}
// {{{ databaseExists()
/**
* check if given database name is exists?
*
* @param string $name name of the database that should be checked
*
* @return mixed true/false on success, a MDB2 error on failure
* @access public
*/
function databaseExists($name)
{
$res = $this->_doConnect($this->dsn['username'],
$this->dsn['password'],
$this->escape($name),
$this->options['persistent']);
if (!PEAR::isError($res)) {
return true;
}
return false;
}
// }}}
// {{{ disconnect()
@ -560,11 +601,11 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
*/
function &standaloneQuery($query, $types = null, $is_manip = false)
{
$connection = $this->_doConnect('template1', false);
$user = $this->options['DBA_username']? $this->options['DBA_username'] : $this->dsn['username'];
$pass = $this->options['DBA_password']? $this->options['DBA_password'] : $this->dsn['password'];
$connection = $this->_doConnect($user, $pass, $this->database_name, $this->options['persistent']);
if (PEAR::isError($connection)) {
$err =& $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null,
'Cannot connect to template1', __FUNCTION__);
return $err;
return $connection;
}
$offset = $this->offset;
@ -572,17 +613,16 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
$this->offset = $this->limit = 0;
$query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
$result =& $this->_doQuery($query, $is_manip, $connection, false);
@pg_close($connection);
if (PEAR::isError($result)) {
return $result;
$result =& $this->_doQuery($query, $is_manip, $connection, $this->database_name);
if (!PEAR::isError($result)) {
if ($is_manip) {
$result = $this->_affectedRows($connection, $result);
} else {
$result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
}
}
if ($is_manip) {
$affected_rows = $this->_affectedRows($connection, $result);
return $affected_rows;
}
$result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
@pg_close($connection);
return $result;
}
@ -910,8 +950,8 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
return $connection;
}
static $prep_statement_counter = 1;
$statement_name = sprintf($this->options['statement_format'], $this->phptype, sha1(microtime() + mt_rand())) . $prep_statement_counter++;
$statement_name = strtolower($statement_name);
$statement_name = sprintf($this->options['statement_format'], $this->phptype, $prep_statement_counter++ . sha1(microtime() + mt_rand()));
$statement_name = substr(strtolower($statement_name), 0, $this->options['max_identifiers_length']);
if ($pgtypes === false) {
$result = @pg_prepare($connection, $statement_name, $query);
if (!$result) {
@ -975,7 +1015,7 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
WHERE d.adrelid = a.attrelid
AND d.adnum = a.attnum
AND a.atthasdef
) FROM 'nextval[^\']*\'([^\']*)')
) FROM 'nextval[^'']*''([^'']*)')
FROM pg_attribute a
LEFT JOIN pg_class c ON c.oid = a.attrelid
LEFT JOIN pg_attrdef d ON d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef
@ -1017,9 +1057,11 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
{
$sequence_name = $this->quoteIdentifier($this->getSequenceName($seq_name), true);
$query = "SELECT NEXTVAL('$sequence_name')";
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$this->expectError(MDB2_ERROR_NOSUCHTABLE);
$result = $this->queryOne($query, 'integer');
$this->popExpect();
$this->popErrorHandling();
if (PEAR::isError($result)) {
if ($ondemand && $result->getCode() == MDB2_ERROR_NOSUCHTABLE) {
$this->loadModule('Manager', null, true);
@ -1052,7 +1094,7 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
return $this->queryOne('SELECT lastval()', 'integer');
}
$seq = $table.(empty($field) ? '' : '_'.$field);
$sequence_name = $this->getSequenceName($seq);
$sequence_name = $this->quoteIdentifier($this->getSequenceName($seq), true);
return $this->queryOne("SELECT currval('$sequence_name')", 'integer');
}

@ -3,7 +3,7 @@
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox, |
// | Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
// $Id: sqlite.php,v 1.152 2007/11/27 07:44:41 quipo Exp $
// $Id: sqlite.php,v 1.158 2008/03/08 14:18:39 quipo Exp $
//
/**
@ -89,6 +89,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
$this->supported['transactions'] = true;
$this->supported['savepoints'] = false;
$this->supported['sub_selects'] = true;
$this->supported['triggers'] = true;
$this->supported['auto_increment'] = true;
$this->supported['primary_key'] = false; // requires alter table implementation
$this->supported['result_introspection'] = false; // not implemented
@ -97,11 +98,14 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
$this->supported['pattern_escaping'] = false;
$this->supported['new_link'] = false;
$this->options['DBA_username'] = false;
$this->options['DBA_password'] = false;
$this->options['base_transaction_name'] = '___php_MDB2_sqlite_auto_commit_off';
$this->options['fixed_float'] = 0;
$this->options['database_path'] = '';
$this->options['database_extension'] = '';
$this->options['server_version'] = '';
$this->options['max_identifiers_length'] = 128; //no real limit
}
// }}}
@ -125,7 +129,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
// PHP 5.2+ prepends the function name to $php_errormsg, so we need
// this hack to work around it, per bug #9599.
$native_msg = preg_replace('/^sqlite[a-z_]+\(\): /', '', $native_msg);
$native_msg = preg_replace('/^sqlite[a-z_]+\(\)[^:]*: /', '', $native_msg);
if (is_null($error)) {
static $error_regexps;
@ -424,6 +428,24 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
return MDB2_OK;
}
// }}}
// {{{ databaseExists()
/**
* check if given database name is exists?
*
* @param string $name name of the database that should be checked
*
* @return mixed true/false on success, a MDB2 error on failure
* @access public
*/
function databaseExists($name)
{
$database_file = $this->_getDatabaseFile($name);
$result = file_exists($database_file);
return $result;
}
// }}}
// {{{ disconnect()
@ -721,7 +743,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
$query .= ',';
$values.= ',';
}
$query.= $name;
$query.= $this->quoteIdentifier($name, true);
if (isset($fields[$name]['null']) && $fields[$name]['null']) {
$value = 'NULL';
} else {
@ -750,6 +772,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
return $connection;
}
$table = $this->quoteIdentifier($table, true);
$query = "REPLACE INTO $table ($query) VALUES ($values)";
$result =& $this->_doQuery($query, true, $connection);
if (PEAR::isError($result)) {
@ -777,9 +800,11 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
$sequence_name = $this->quoteIdentifier($this->getSequenceName($seq_name), true);
$seqcol_name = $this->options['seqcol_name'];
$query = "INSERT INTO $sequence_name ($seqcol_name) VALUES (NULL)";
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$this->expectError(MDB2_ERROR_NOSUCHTABLE);
$result =& $this->_doQuery($query, true);
$this->popExpect();
$this->popErrorHandling();
if (PEAR::isError($result)) {
if ($ondemand && $result->getCode() == MDB2_ERROR_NOSUCHTABLE) {
$this->loadModule('Manager', null, true);

Loading…
Cancel
Save