4 V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). 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.
9 Set tabs to 4 for best viewing.
13 // security - hide paths
14 if (!defined('ADODB_DIR')) die();
16 class ADODB2_sybase
extends ADODB_DataDict
{
17 var $databaseType = 'sybase';
19 var $dropIndex = 'DROP INDEX %2$s.%1$s';
21 function MetaType($t,$len=-1,$fieldobj=false)
26 $len = $fieldobj->max_length
;
29 $len = -1; // mysql max_length is not accurate
30 switch (strtoupper($t)) {
33 case 'INTEGER': return 'I';
35 case 'TINYINT': return 'I1';
36 case 'SMALLINT': return 'I2';
37 case 'BIGINT': return 'I8';
40 case 'FLOAT': return 'F';
41 default: return parent
::MetaType($t,$len,$fieldobj);
45 function ActualType($meta)
47 switch(strtoupper($meta)) {
48 case 'C': return 'VARCHAR';
50 case 'X': return 'TEXT';
52 case 'C2': return 'NVARCHAR';
53 case 'X2': return 'NTEXT';
55 case 'B': return 'IMAGE';
57 case 'D': return 'DATETIME';
58 case 'T': return 'DATETIME';
59 case 'L': return 'BIT';
61 case 'I': return 'INT';
62 case 'I1': return 'TINYINT';
63 case 'I2': return 'SMALLINT';
64 case 'I4': return 'INT';
65 case 'I8': return 'BIGINT';
67 case 'F': return 'REAL';
68 case 'N': return 'NUMERIC';
75 function AddColumnSQL($tabname, $flds)
77 $tabname = $this->TableName ($tabname);
79 list($lines,$pkey) = $this->_GenFields($flds);
80 $s = "ALTER TABLE $tabname $this->addCol";
81 foreach($lines as $v) {
84 $s .= implode(', ',$f);
89 function AlterColumnSQL($tabname, $flds)
91 $tabname = $this->TableName ($tabname);
93 list($lines,$pkey) = $this->_GenFields($flds);
94 foreach($lines as $v) {
95 $sql[] = "ALTER TABLE $tabname $this->alterCol $v";
101 function DropColumnSQL($tabname, $flds)
103 $tabname = $this->TableName($tabname);
104 if (!is_array($flds)) $flds = explode(',',$flds);
106 $s = "ALTER TABLE $tabname";
107 foreach($flds as $v) {
108 $f[] = "\n$this->dropCol ".$this->NameQuote($v);
110 $s .= implode(', ',$f);
115 // return string must begin with space
116 function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)
119 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
120 if ($fautoinc) $suffix .= ' DEFAULT AUTOINCREMENT';
121 if ($fnotnull) $suffix .= ' NOT NULL';
122 else if ($suffix == '') $suffix .= ' NULL';
123 if ($fconstraint) $suffix .= ' '.$fconstraint;
129 [ database_name.[ owner ] . | owner. ] table_name
130 ( { < column_definition >
131 | column_name AS computed_column_expression
132 | < table_constraint > ::= [ CONSTRAINT constraint_name ] }
134 | [ { PRIMARY KEY | UNIQUE } [ ,...n ]
137 [ ON { filegroup | DEFAULT } ]
138 [ TEXTIMAGE_ON { filegroup | DEFAULT } ]
140 < column_definition > ::= { column_name data_type }
141 [ COLLATE < collation_name > ]
142 [ [ DEFAULT constant_expression ]
143 | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ]
146 [ < column_constraint > ] [ ...n ]
148 < column_constraint > ::= [ CONSTRAINT constraint_name ]
149 { [ NULL | NOT NULL ]
150 | [ { PRIMARY KEY | UNIQUE }
151 [ CLUSTERED | NONCLUSTERED ]
152 [ WITH FILLFACTOR = fillfactor ]
153 [ON {filegroup | DEFAULT} ] ]
156 REFERENCES ref_table [ ( ref_column ) ]
157 [ ON DELETE { CASCADE | NO ACTION } ]
158 [ ON UPDATE { CASCADE | NO ACTION } ]
159 [ NOT FOR REPLICATION ]
161 | CHECK [ NOT FOR REPLICATION ]
162 ( logical_expression )
165 < table_constraint > ::= [ CONSTRAINT constraint_name ]
166 { [ { PRIMARY KEY | UNIQUE }
167 [ CLUSTERED | NONCLUSTERED ]
168 { ( column [ ASC | DESC ] [ ,...n ] ) }
169 [ WITH FILLFACTOR = fillfactor ]
170 [ ON { filegroup | DEFAULT } ]
173 [ ( column [ ,...n ] ) ]
174 REFERENCES ref_table [ ( ref_column [ ,...n ] ) ]
175 [ ON DELETE { CASCADE | NO ACTION } ]
176 [ ON UPDATE { CASCADE | NO ACTION } ]
177 [ NOT FOR REPLICATION ]
178 | CHECK [ NOT FOR REPLICATION ]
179 ( search_conditions )
186 CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
187 ON { table | view } ( column [ ASC | DESC ] [ ,...n ] )
188 [ WITH < index_option > [ ,...n] ]
190 < index_option > :: =
192 FILLFACTOR = fillfactor |
195 STATISTICS_NORECOMPUTE |
199 function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
203 if ( isset($idxoptions['REPLACE']) ||
isset($idxoptions['DROP']) ) {
204 $sql[] = sprintf ($this->dropIndex
, $idxname, $tabname);
205 if ( isset($idxoptions['DROP']) )
209 if ( empty ($flds) ) {
213 $unique = isset($idxoptions['UNIQUE']) ?
' UNIQUE' : '';
214 $clustered = isset($idxoptions['CLUSTERED']) ?
' CLUSTERED' : '';
216 if ( is_array($flds) )
217 $flds = implode(', ',$flds);
218 $s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
220 if ( isset($idxoptions[$this->upperName
]) )
221 $s .= $idxoptions[$this->upperName
];