| | |
| | | // | Daniel Convissor <danielc@php.net> |
|
| | | // +----------------------------------------------------------------------+
|
| | | //
|
| | | // $Id: mssql.php,v 1.59 2007/12/03 20:59:50 quipo Exp $
|
| | | // $Id: mssql.php,v 1.65 2008/02/19 14:54:17 afz Exp $ |
| | | //
|
| | |
|
| | | require_once 'MDB2/Driver/Datatype/Common.php';
|
| | |
| | | }
|
| | |
|
| | | // }}}
|
| | | // {{{ _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()
|
| | |
|
| | | /**
|
| | |
| | | return $db;
|
| | | }
|
| | |
|
| | | $default = $autoinc = '';;
|
| | | $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'] = empty($field['notnull']) ? null : 0;
|
| | | $field['default'] = 0; |
| | | }
|
| | | $default = ' DEFAULT '.$this->quote($field['default'], 'integer');
|
| | | } elseif (empty($field['notnull'])) {
|
| | | $default = ' DEFAULT NULL';
|
| | | if (is_null($field['default'])) { |
| | | $default = ' DEFAULT (null)'; |
| | | } else { |
| | | $default = ' DEFAULT (' . $this->quote($field['default'], 'integer') . ')'; |
| | | } |
| | | }
|
| | |
|
| | | $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;
|
| | | return $name.' '.$this->getTypeDeclaration($field).$notnull.$default.$autoinc; |
| | | }
|
| | |
|
| | | // }}}
|
| | |
| | | if (!$quote) {
|
| | | return $value;
|
| | | }
|
| | | $value = bin2hex("0x".$this->_readFile($value));
|
| | | $value = '0x'.bin2hex($this->_readFile($value)); |
| | | return $value;
|
| | | }
|
| | |
|