cvs: pear /MDB2/MDB2/Driver/Datatype Common.php
| From: | Lorenzo Alberton | Date: | Thu, 01 Mar 2007 14:12:53 +0000 |
| Subject: | cvs: pear /MDB2/MDB2/Driver/Datatype Common.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-44923@lists.php.net to get a copy of this message | ||
quipo Thu Mar 1 14:12:53 2007 UTC
Modified files:
/pear/MDB2/MDB2/Driver/Datatype Common.php
Log:
fixed possible bug in mapNativeDatatype() and extracted _getDeclarationOptions() method from
_getDeclaration().
Patch by Andrew Hill
http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Datatype/Common.php?r1=1.119&r2=1.120&diff_format=u
Index: pear/MDB2/MDB2/Driver/Datatype/Common.php
diff -u pear/MDB2/MDB2/Driver/Datatype/Common.php:1.119
pear/MDB2/MDB2/Driver/Datatype/Common.php:1.120
--- pear/MDB2/MDB2/Driver/Datatype/Common.php:1.119 Wed Feb 28 16:05:45 2007
+++ pear/MDB2/MDB2/Driver/Datatype/Common.php Thu Mar 1 14:12:52 2007
@@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
-// $Id: Common.php,v 1.119 2007/02/28 16:05:45 quipo Exp $
+// $Id: Common.php,v 1.120 2007/03/01 14:12:52 quipo Exp $
require_once 'MDB2/LOB.php';
@@ -454,6 +454,42 @@
return $db;
}
+ $name = $db->quoteIdentifier($name, true);
+ $declaration_options = $db->datatype->_getDeclarationOptions($field);
+ return $name.' '.$this->getTypeDeclaration($field).$declaration_options;
+ }
+
+ // }}}
+ // {{{ _getDeclarationOptions()
+
+ /**
+ * Obtain DBMS specific SQL code portion needed to declare a generic type
+ * field to be used in statement like CREATE TABLE, without the field name
+ * and type values (ie. just the character set, default value, if the
+ * field is permitted to be NULL or not, and the collation options).
+ *
+ * @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:
+ *
+ * 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.
+ * charset
+ * Text value with the default CHARACTER SET for this field.
+ * collation
+ * Text value with the default COLLATION for this field.
+ * @return string DBMS specific SQL code portion that should be used to
+ * declare the specified field's options.
+ * @access protected
+ */
+ function _getDeclarationOptions($field)
+ {
+ $charset = empty($field['charset']) ? '' :
+ ' '.$this->_getCharsetFieldDeclaration($field['charset']);
+
$default = '';
if (array_key_exists('default', $field)) {
if ($field['default'] === '') {
@@ -470,15 +506,11 @@
$default = ' DEFAULT NULL';
}
- $charset = empty($field['charset']) ? '' :
- ' '.$this->_getCharsetFieldDeclaration($field['charset']);
+ $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
$collation = empty($field['collation']) ? '' :
' '.$this->_getCollationFieldDeclaration($field['collation']);
-
- $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
- $name = $db->quoteIdentifier($name, true);
- return $name.'
'.$this->getTypeDeclaration($field).$charset.$default.$notnull.$collation;
+ return $charset.$default.$notnull.$collation;
}
// }}}
@@ -1726,8 +1758,9 @@
// If the user has specified an option to map the native field
// type to a custom MDB2 datatype...
- if (!empty($db->options['nativetype_map_callback'][$field['type']]))
{
- return
call_user_func_array($db->options['nativetype_map_callback'][$field['type']],
$field);
+ $db_type = strtok($field['type'], '(), ');
+ if (!empty($db->options['nativetype_map_callback'][$db_type])) {
+ return
call_user_func_array($db->options['nativetype_map_callback'][$db_type], array($db,
$field));
}
// Otherwise perform the built-in (i.e. normal) MDB2 native type to