Source for file odbc.php
Documentation is available at odbc.php
require_once 'MDB2/Driver/Datatype/Common.php';
* @author Lukas Smith <smith@pooteeweet.org>
// {{{ _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
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:
* 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.
* Text value to be used as default for this field.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
$db = & $this->getDBInstance ();
if (MDB2 ::isError ($db)) {
switch ($field['type']) {
$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');
if (!empty ($field['length'])) {
$length = $field['length'];
return 'VARCHAR('. $length. ')';
if (!empty ($field['length'])) {
$length = $field['length'];
return " VARBINARY($length)";
return 'CHAR ('. strlen('YYYY-MM-DD'). ')';
return 'CHAR ('. strlen('HH:MM:SS'). ')';
return 'CHAR ('. strlen('YYYY-MM-DD HH:MM:SS'). ')';
$length = !empty ($field['length']) ? $field['length'] : 18;
$scale = !empty ($field['scale']) ? $field['scale'] : $db->options ['decimal_places'];
return 'DECIMAL('. $length. ','. $scale. ')';
// {{{ _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:
* Boolean flag that indicates whether the field
* should be declared as unsigned integer if
* Integer value to be used as default for this
* 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.
$db = & $this->getDBInstance ();
if (MDB2 ::isError ($db)) {
$notnull = empty ($field['notnull']) ? ' NULL' : ' NOT NULL';
$default = $autoinc = '';
if (!empty ($field['autoincrement'])) {
$autoinc = ' IDENTITY PRIMARY KEY';
if ($field['default'] === '') {
$default = ' DEFAULT (null)';
$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 );
// {{{ _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:
* 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.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
$db = & $this->getDBInstance ();
if (MDB2 ::isError ($db)) {
$notnull = empty ($field['notnull']) ? ' NULL' : ' NOT NULL';
$name = $db->quoteIdentifier ($name, true );
// {{{ _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:
* 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.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
$db = & $this->getDBInstance ();
if (MDB2 ::isError ($db)) {
$notnull = empty ($field['notnull']) ? ' NULL' : ' NOT NULL';
$name = $db->quoteIdentifier ($name, true );
* 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.
function _quoteBLOB($value, $quote, $escape_wildcards)
$value = '0x'. bin2hex($this->_readFile ($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
// todo: handle length of various int variations
$length = $field['length'];
// todo: unsigned handling seems to be missing
$unsigned = $fixed = null;
$length = $field['numeric_precision']. ','. $field['numeric_scale'];
case 'varchar() for bit data':
} elseif (strstr($db_type, 'text')) {
case 'vargraphic() ccsid ':
$db = & $this->getDBInstance ();
if (MDB2 ::isError ($db)) {
return $db->raiseError (MDB2_ERROR_UNSUPPORTED , null , null ,
'unknown database attribute type: '. $db_type, __FUNCTION__ );
return array ($type, $length, $unsigned, $fixed);
Documentation generated on Mon, 11 Mar 2019 15:51:21 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|