Source for file datadict-mssql.inc.php
Documentation is available at datadict-mssql.inc.php
V5.04 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
Set tabs to 4 for best viewing.
In ADOdb, named quotes for MS SQL Server use ". From the MSSQL Docs:
Note Delimiters are for identifiers only. Delimiters cannot be used for keywords,
whether or not they are marked as reserved in SQL Server.
Quoted identifiers are delimited by double quotation marks ("):
SELECT * FROM "Blanks in Table Name"
Bracketed identifiers are delimited by brackets ([ ]):
SELECT * FROM [Blanks In Table Name]
Quoted identifiers are valid only when the QUOTED_IDENTIFIER option is set to ON. By default,
the Microsoft OLE DB Provider for SQL Server and SQL Server ODBC driver set QUOTED_IDENTIFIER ON
In Transact-SQL, the option can be set at various levels using SET QUOTED_IDENTIFIER,
the quoted identifier option of sp_dboption, or the user options option of sp_configure.
When SET ANSI_DEFAULTS is ON, SET QUOTED_IDENTIFIER is enabled.
SET QUOTED_IDENTIFIER { ON | OFF }
var $typeX =
'TEXT'; ## Alternatively, set it to VARCHAR(4000)
//var $alterCol = ' ALTER COLUMN ';
function MetaType($t,$len=-
1,$fieldobj=
false)
$len =
$fieldobj->max_length;
$len = -
1; // mysql max_length is not accurate
case 'INTEGER':
return 'I';
case 'TINYINT':
return 'I1';
case 'SMALLINT':
return 'I2';
case 'BIGINT':
return 'I8';
case 'FLOAT':
return 'F';
default:
return parent::MetaType($t,$len,$fieldobj);
case 'C':
return 'VARCHAR';
case 'XL':
return (isset
($this)) ?
$this->typeXL :
'TEXT';
case 'X':
return (isset
($this)) ?
$this->typeX :
'TEXT'; ## could be varchar(8000), but we want compat with oracle
case 'C2':
return 'NVARCHAR';
case 'X2':
return 'NTEXT';
case 'B':
return 'IMAGE';
case 'D':
return 'DATETIME';
case 'T':
return 'DATETIME';
case 'I1':
return 'TINYINT';
case 'I2':
return 'SMALLINT';
case 'I8':
return 'BIGINT';
case 'N':
return 'NUMERIC';
$tabname =
$this->TableName ($tabname);
list
($lines,$pkey) =
$this->_GenFields($flds);
$s =
"ALTER TABLE $tabname $this->addCol";
function AlterColumnSQL($tabname, $flds)
$tabname = $this->TableName ($tabname);
list($lines,$pkey) = $this->_GenFields($flds);
$sql[] = "ALTER TABLE $tabname $this->alterCol $v";
$tabname =
$this->TableName ($tabname);
$s =
'ALTER TABLE ' .
$tabname;
$f[] =
"\n$this->dropCol ".
$this->NameQuote($v);
// return string must begin with space
function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)
if (strlen($fdefault)) $suffix .=
" DEFAULT $fdefault";
if ($fautoinc) $suffix .=
' IDENTITY(1,1)';
if ($fnotnull) $suffix .=
' NOT NULL';
else if ($suffix ==
'') $suffix .=
' NULL';
if ($fconstraint) $suffix .=
' '.
$fconstraint;
[ database_name.[ owner ] . | owner. ] table_name
( { < column_definition >
| column_name AS computed_column_expression
| < table_constraint > ::= [ CONSTRAINT constraint_name ] }
| [ { PRIMARY KEY | UNIQUE } [ ,...n ]
[ ON { filegroup | DEFAULT } ]
[ TEXTIMAGE_ON { filegroup | DEFAULT } ]
< column_definition > ::= { column_name data_type }
[ COLLATE < collation_name > ]
[ [ DEFAULT constant_expression ]
| [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ]
[ < column_constraint > ] [ ...n ]
< column_constraint > ::= [ CONSTRAINT constraint_name ]
| [ { PRIMARY KEY | UNIQUE }
[ CLUSTERED | NONCLUSTERED ]
[ WITH FILLFACTOR = fillfactor ]
[ON {filegroup | DEFAULT} ] ]
REFERENCES ref_table [ ( ref_column ) ]
[ ON DELETE { CASCADE | NO ACTION } ]
[ ON UPDATE { CASCADE | NO ACTION } ]
| CHECK [ NOT FOR REPLICATION ]
< table_constraint > ::= [ CONSTRAINT constraint_name ]
{ [ { PRIMARY KEY | UNIQUE }
[ CLUSTERED | NONCLUSTERED ]
{ ( column [ ASC | DESC ] [ ,...n ] ) }
[ WITH FILLFACTOR = fillfactor ]
[ ON { filegroup | DEFAULT } ]
REFERENCES ref_table [ ( ref_column [ ,...n ] ) ]
[ ON DELETE { CASCADE | NO ACTION } ]
[ ON UPDATE { CASCADE | NO ACTION } ]
| CHECK [ NOT FOR REPLICATION ]
CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
ON { table | view } ( column [ ASC | DESC ] [ ,...n ] )
[ WITH < index_option > [ ,...n] ]
FILLFACTOR = fillfactor |
function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
if ( isset
($idxoptions['REPLACE']) || isset
($idxoptions['DROP']) ) {
if ( isset
($idxoptions['DROP']) )
$unique = isset
($idxoptions['UNIQUE']) ?
' UNIQUE' :
'';
$clustered = isset
($idxoptions['CLUSTERED']) ?
' CLUSTERED' :
'';
$s =
'CREATE' .
$unique .
$clustered .
' INDEX ' .
$idxname .
' ON ' .
$tabname .
' (' .
$flds .
')';
if ( isset
($idxoptions[$this->upperName]) )
$s .=
$idxoptions[$this->upperName];
function _GetSize($ftype, $ty, $fsize, $fprec)
if ($ty ==
'T') return $ftype;
return parent::_GetSize($ftype, $ty, $fsize, $fprec);
Documentation generated on Sun, 09 Mar 2008 23:51:30 -0300 by phpDocumentor 1.4.0