updated adodb package to work with php 7.1
[openemr.git] / vendor / adodb / adodb-php / datadict / datadict-mssql.inc.php
blob2c496dea6bf6bc03a6856b76a034ecbb6649111b
1 <?php
3 /**
4 @version v5.20.9 21-Dec-2016
5 @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
6 @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
7 Released under both BSD license and Lesser GPL library license.
8 Whenever there is any discrepancy between the two licenses,
9 the BSD license will take precedence.
11 Set tabs to 4 for best viewing.
16 In ADOdb, named quotes for MS SQL Server use ". From the MSSQL Docs:
18 Note Delimiters are for identifiers only. Delimiters cannot be used for keywords,
19 whether or not they are marked as reserved in SQL Server.
21 Quoted identifiers are delimited by double quotation marks ("):
22 SELECT * FROM "Blanks in Table Name"
24 Bracketed identifiers are delimited by brackets ([ ]):
25 SELECT * FROM [Blanks In Table Name]
27 Quoted identifiers are valid only when the QUOTED_IDENTIFIER option is set to ON. By default,
28 the Microsoft OLE DB Provider for SQL Server and SQL Server ODBC driver set QUOTED_IDENTIFIER ON
29 when they connect.
31 In Transact-SQL, the option can be set at various levels using SET QUOTED_IDENTIFIER,
32 the quoted identifier option of sp_dboption, or the user options option of sp_configure.
34 When SET ANSI_DEFAULTS is ON, SET QUOTED_IDENTIFIER is enabled.
36 Syntax
38 SET QUOTED_IDENTIFIER { ON | OFF }
43 // security - hide paths
44 if (!defined('ADODB_DIR')) die();
46 class ADODB2_mssql extends ADODB_DataDict {
47 var $databaseType = 'mssql';
48 var $dropIndex = 'DROP INDEX %2$s.%1$s';
49 var $renameTable = "EXEC sp_rename '%s','%s'";
50 var $renameColumn = "EXEC sp_rename '%s.%s','%s'";
52 var $typeX = 'TEXT'; ## Alternatively, set it to VARCHAR(4000)
53 var $typeXL = 'TEXT';
55 //var $alterCol = ' ALTER COLUMN ';
57 function MetaType($t,$len=-1,$fieldobj=false)
59 if (is_object($t)) {
60 $fieldobj = $t;
61 $t = $fieldobj->type;
62 $len = $fieldobj->max_length;
65 $len = -1; // mysql max_length is not accurate
66 switch (strtoupper($t)) {
67 case 'R':
68 case 'INT':
69 case 'INTEGER': return 'I';
70 case 'BIT':
71 case 'TINYINT': return 'I1';
72 case 'SMALLINT': return 'I2';
73 case 'BIGINT': return 'I8';
74 case 'SMALLDATETIME': return 'T';
75 case 'REAL':
76 case 'FLOAT': return 'F';
77 default: return parent::MetaType($t,$len,$fieldobj);
81 function ActualType($meta)
83 switch(strtoupper($meta)) {
85 case 'C': return 'VARCHAR';
86 case 'XL': return (isset($this)) ? $this->typeXL : 'TEXT';
87 case 'X': return (isset($this)) ? $this->typeX : 'TEXT'; ## could be varchar(8000), but we want compat with oracle
88 case 'C2': return 'NVARCHAR';
89 case 'X2': return 'NTEXT';
91 case 'B': return 'IMAGE';
93 case 'D': return 'DATETIME';
95 case 'TS':
96 case 'T': return 'DATETIME';
97 case 'L': return 'BIT';
99 case 'R':
100 case 'I': return 'INT';
101 case 'I1': return 'TINYINT';
102 case 'I2': return 'SMALLINT';
103 case 'I4': return 'INT';
104 case 'I8': return 'BIGINT';
106 case 'F': return 'REAL';
107 case 'N': return 'NUMERIC';
108 default:
109 return $meta;
114 function AddColumnSQL($tabname, $flds)
116 $tabname = $this->TableName ($tabname);
117 $f = array();
118 list($lines,$pkey) = $this->_GenFields($flds);
119 $s = "ALTER TABLE $tabname $this->addCol";
120 foreach($lines as $v) {
121 $f[] = "\n $v";
123 $s .= implode(', ',$f);
124 $sql[] = $s;
125 return $sql;
129 function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
131 $tabname = $this->TableName ($tabname);
132 $sql = array();
133 list($lines,$pkey) = $this->_GenFields($flds);
134 foreach($lines as $v) {
135 $sql[] = "ALTER TABLE $tabname $this->alterCol $v";
138 return $sql;
142 function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
144 $tabname = $this->TableName ($tabname);
145 if (!is_array($flds))
146 $flds = explode(',',$flds);
147 $f = array();
148 $s = 'ALTER TABLE ' . $tabname;
149 foreach($flds as $v) {
150 $f[] = "\n$this->dropCol ".$this->NameQuote($v);
152 $s .= implode(', ',$f);
153 $sql[] = $s;
154 return $sql;
157 // return string must begin with space
158 function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
160 $suffix = '';
161 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
162 if ($fautoinc) $suffix .= ' IDENTITY(1,1)';
163 if ($fnotnull) $suffix .= ' NOT NULL';
164 else if ($suffix == '') $suffix .= ' NULL';
165 if ($fconstraint) $suffix .= ' '.$fconstraint;
166 return $suffix;
170 CREATE TABLE
171 [ database_name.[ owner ] . | owner. ] table_name
172 ( { < column_definition >
173 | column_name AS computed_column_expression
174 | < table_constraint > ::= [ CONSTRAINT constraint_name ] }
176 | [ { PRIMARY KEY | UNIQUE } [ ,...n ]
179 [ ON { filegroup | DEFAULT } ]
180 [ TEXTIMAGE_ON { filegroup | DEFAULT } ]
182 < column_definition > ::= { column_name data_type }
183 [ COLLATE < collation_name > ]
184 [ [ DEFAULT constant_expression ]
185 | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ]
187 [ ROWGUIDCOL]
188 [ < column_constraint > ] [ ...n ]
190 < column_constraint > ::= [ CONSTRAINT constraint_name ]
191 { [ NULL | NOT NULL ]
192 | [ { PRIMARY KEY | UNIQUE }
193 [ CLUSTERED | NONCLUSTERED ]
194 [ WITH FILLFACTOR = fillfactor ]
195 [ON {filegroup | DEFAULT} ] ]
197 | [ [ FOREIGN KEY ]
198 REFERENCES ref_table [ ( ref_column ) ]
199 [ ON DELETE { CASCADE | NO ACTION } ]
200 [ ON UPDATE { CASCADE | NO ACTION } ]
201 [ NOT FOR REPLICATION ]
203 | CHECK [ NOT FOR REPLICATION ]
204 ( logical_expression )
207 < table_constraint > ::= [ CONSTRAINT constraint_name ]
208 { [ { PRIMARY KEY | UNIQUE }
209 [ CLUSTERED | NONCLUSTERED ]
210 { ( column [ ASC | DESC ] [ ,...n ] ) }
211 [ WITH FILLFACTOR = fillfactor ]
212 [ ON { filegroup | DEFAULT } ]
214 | FOREIGN KEY
215 [ ( column [ ,...n ] ) ]
216 REFERENCES ref_table [ ( ref_column [ ,...n ] ) ]
217 [ ON DELETE { CASCADE | NO ACTION } ]
218 [ ON UPDATE { CASCADE | NO ACTION } ]
219 [ NOT FOR REPLICATION ]
220 | CHECK [ NOT FOR REPLICATION ]
221 ( search_conditions )
228 CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
229 ON { table | view } ( column [ ASC | DESC ] [ ,...n ] )
230 [ WITH < index_option > [ ,...n] ]
231 [ ON filegroup ]
232 < index_option > :: =
233 { PAD_INDEX |
234 FILLFACTOR = fillfactor |
235 IGNORE_DUP_KEY |
236 DROP_EXISTING |
237 STATISTICS_NORECOMPUTE |
238 SORT_IN_TEMPDB
241 function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
243 $sql = array();
245 if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
246 $sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
247 if ( isset($idxoptions['DROP']) )
248 return $sql;
251 if ( empty ($flds) ) {
252 return $sql;
255 $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
256 $clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : '';
258 if ( is_array($flds) )
259 $flds = implode(', ',$flds);
260 $s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
262 if ( isset($idxoptions[$this->upperName]) )
263 $s .= $idxoptions[$this->upperName];
266 $sql[] = $s;
268 return $sql;
272 function _GetSize($ftype, $ty, $fsize, $fprec)
274 switch ($ftype) {
275 case 'INT':
276 case 'SMALLINT':
277 case 'TINYINT':
278 case 'BIGINT':
279 return $ftype;
281 if ($ty == 'T') return $ftype;
282 return parent::_GetSize($ftype, $ty, $fsize, $fprec);