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