[TASK] Update ADOdb to 5.18
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / adodb / datadict / datadict-sybase.inc.php
1 <?php
2
3 /**
4 V5.18 3 Sep 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
5 Released under both BSD license and Lesser GPL library license.
6 Whenever there is any discrepancy between the two licenses,
7 the BSD license will take precedence.
8
9 Set tabs to 4 for best viewing.
10
11 */
12
13 // security - hide paths
14 if (!defined('ADODB_DIR')) die();
15
16 class ADODB2_sybase extends ADODB_DataDict {
17 var $databaseType = 'sybase';
18
19 var $dropIndex = 'DROP INDEX %2$s.%1$s';
20
21 function MetaType($t, $len=-1, $fieldobj=false)
22 {
23 if (is_object($t)) {
24 $fieldobj = $t;
25 $t = $fieldobj->type;
26 $len = $fieldobj->max_length;
27 }
28
29 $len = -1; // mysql max_length is not accurate
30 switch (strtoupper($t)) {
31
32 case 'INT':
33 case 'INTEGER': return 'I';
34 case 'BIT':
35 case 'TINYINT': return 'I1';
36 case 'SMALLINT': return 'I2';
37 case 'BIGINT': return 'I8';
38
39 case 'REAL':
40 case 'FLOAT': return 'F';
41 default: return parent::MetaType($t,$len,$fieldobj);
42 }
43 }
44
45 function ActualType($meta)
46 {
47 switch(strtoupper($meta)) {
48 case 'C': return 'VARCHAR';
49 case 'XL':
50 case 'X': return 'TEXT';
51
52 case 'C2': return 'NVARCHAR';
53 case 'X2': return 'NTEXT';
54
55 case 'B': return 'IMAGE';
56
57 case 'D': return 'DATETIME';
58 case 'TS':
59 case 'T': return 'DATETIME';
60 case 'L': return 'BIT';
61
62 case 'I': return 'INT';
63 case 'I1': return 'TINYINT';
64 case 'I2': return 'SMALLINT';
65 case 'I4': return 'INT';
66 case 'I8': return 'BIGINT';
67
68 case 'F': return 'REAL';
69 case 'N': return 'NUMERIC';
70 default:
71 return $meta;
72 }
73 }
74
75
76 function AddColumnSQL($tabname, $flds)
77 {
78 $tabname = $this->TableName ($tabname);
79 $f = array();
80 list($lines,$pkey) = $this->_GenFields($flds);
81 $s = "ALTER TABLE $tabname $this->addCol";
82 foreach($lines as $v) {
83 $f[] = "\n $v";
84 }
85 $s .= implode(', ',$f);
86 $sql[] = $s;
87 return $sql;
88 }
89
90 function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
91 {
92 $tabname = $this->TableName ($tabname);
93 $sql = array();
94 list($lines,$pkey) = $this->_GenFields($flds);
95 foreach($lines as $v) {
96 $sql[] = "ALTER TABLE $tabname $this->alterCol $v";
97 }
98
99 return $sql;
100 }
101
102 function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
103 {
104 $tabname = $this->TableName($tabname);
105 if (!is_array($flds)) $flds = explode(',',$flds);
106 $f = array();
107 $s = "ALTER TABLE $tabname";
108 foreach($flds as $v) {
109 $f[] = "\n$this->dropCol ".$this->NameQuote($v);
110 }
111 $s .= implode(', ',$f);
112 $sql[] = $s;
113 return $sql;
114 }
115
116 // return string must begin with space
117 function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
118 {
119 $suffix = '';
120 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
121 if ($fautoinc) $suffix .= ' DEFAULT AUTOINCREMENT';
122 if ($fnotnull) $suffix .= ' NOT NULL';
123 else if ($suffix == '') $suffix .= ' NULL';
124 if ($fconstraint) $suffix .= ' '.$fconstraint;
125 return $suffix;
126 }
127
128 /*
129 CREATE TABLE
130 [ database_name.[ owner ] . | owner. ] table_name
131 ( { < column_definition >
132 | column_name AS computed_column_expression
133 | < table_constraint > ::= [ CONSTRAINT constraint_name ] }
134
135 | [ { PRIMARY KEY | UNIQUE } [ ,...n ]
136 )
137
138 [ ON { filegroup | DEFAULT } ]
139 [ TEXTIMAGE_ON { filegroup | DEFAULT } ]
140
141 < column_definition > ::= { column_name data_type }
142 [ COLLATE < collation_name > ]
143 [ [ DEFAULT constant_expression ]
144 | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ]
145 ]
146 [ ROWGUIDCOL]
147 [ < column_constraint > ] [ ...n ]
148
149 < column_constraint > ::= [ CONSTRAINT constraint_name ]
150 { [ NULL | NOT NULL ]
151 | [ { PRIMARY KEY | UNIQUE }
152 [ CLUSTERED | NONCLUSTERED ]
153 [ WITH FILLFACTOR = fillfactor ]
154 [ON {filegroup | DEFAULT} ] ]
155 ]
156 | [ [ FOREIGN KEY ]
157 REFERENCES ref_table [ ( ref_column ) ]
158 [ ON DELETE { CASCADE | NO ACTION } ]
159 [ ON UPDATE { CASCADE | NO ACTION } ]
160 [ NOT FOR REPLICATION ]
161 ]
162 | CHECK [ NOT FOR REPLICATION ]
163 ( logical_expression )
164 }
165
166 < table_constraint > ::= [ CONSTRAINT constraint_name ]
167 { [ { PRIMARY KEY | UNIQUE }
168 [ CLUSTERED | NONCLUSTERED ]
169 { ( column [ ASC | DESC ] [ ,...n ] ) }
170 [ WITH FILLFACTOR = fillfactor ]
171 [ ON { filegroup | DEFAULT } ]
172 ]
173 | FOREIGN KEY
174 [ ( column [ ,...n ] ) ]
175 REFERENCES ref_table [ ( ref_column [ ,...n ] ) ]
176 [ ON DELETE { CASCADE | NO ACTION } ]
177 [ ON UPDATE { CASCADE | NO ACTION } ]
178 [ NOT FOR REPLICATION ]
179 | CHECK [ NOT FOR REPLICATION ]
180 ( search_conditions )
181 }
182
183
184 */
185
186 /*
187 CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
188 ON { table | view } ( column [ ASC | DESC ] [ ,...n ] )
189 [ WITH < index_option > [ ,...n] ]
190 [ ON filegroup ]
191 < index_option > :: =
192 { PAD_INDEX |
193 FILLFACTOR = fillfactor |
194 IGNORE_DUP_KEY |
195 DROP_EXISTING |
196 STATISTICS_NORECOMPUTE |
197 SORT_IN_TEMPDB
198 }
199 */
200 function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
201 {
202 $sql = array();
203
204 if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
205 $sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
206 if ( isset($idxoptions['DROP']) )
207 return $sql;
208 }
209
210 if ( empty ($flds) ) {
211 return $sql;
212 }
213
214 $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
215 $clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : '';
216
217 if ( is_array($flds) )
218 $flds = implode(', ',$flds);
219 $s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
220
221 if ( isset($idxoptions[$this->upperName]) )
222 $s .= $idxoptions[$this->upperName];
223
224 $sql[] = $s;
225
226 return $sql;
227 }
228 }
229 ?>