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.
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';
59 case 'T': return 'DATETIME';
60 case 'L': return 'BIT';
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';
68 case 'F': return 'REAL';
69 case 'N': return 'NUMERIC';
76 function AddColumnSQL($tabname, $flds)
78 $tabname = $this->TableName ($tabname);
80 list($lines,$pkey) = $this->_GenFields($flds);
81 $s = "ALTER TABLE $tabname $this->addCol";
82 foreach($lines as $v) {
85 $s .= implode(', ',$f);
90 function AlterColumnSQL($tabname, $flds)
92 $tabname = $this->TableName ($tabname);
94 list($lines,$pkey) = $this->_GenFields($flds);
95 foreach($lines as $v) {
96 $sql[] = "ALTER TABLE $tabname $this->alterCol $v";
102 function DropColumnSQL($tabname, $flds)
104 $tabname = $this->TableName($tabname);
105 if (!is_array($flds)) $flds = explode(',',$flds);
107 $s = "ALTER TABLE $tabname";
108 foreach($flds as $v) {
109 $f[] = "\n$this->dropCol ".$this->NameQuote($v);
111 $s .= implode(', ',$f);
116 // return string must begin with space
117 function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
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;
130 [ database_name.[ owner ] . | owner. ] table_name
131 ( { < column_definition >
132 | column_name AS computed_column_expression
133 | < table_constraint > ::= [ CONSTRAINT constraint_name ] }
135 | [ { PRIMARY KEY | UNIQUE } [ ,...n ]
138 [ ON { filegroup | DEFAULT } ]
139 [ TEXTIMAGE_ON { filegroup | DEFAULT } ]
141 < column_definition > ::= { column_name data_type }
142 [ COLLATE < collation_name > ]
143 [ [ DEFAULT constant_expression ]
144 | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ]
147 [ < column_constraint > ] [ ...n ]
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} ] ]
157 REFERENCES ref_table [ ( ref_column ) ]
158 [ ON DELETE { CASCADE | NO ACTION } ]
159 [ ON UPDATE { CASCADE | NO ACTION } ]
160 [ NOT FOR REPLICATION ]
162 | CHECK [ NOT FOR REPLICATION ]
163 ( logical_expression )
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 } ]
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 )
187 CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
188 ON { table | view } ( column [ ASC | DESC ] [ ,...n ] )
189 [ WITH < index_option > [ ,...n] ]
191 < index_option > :: =
193 FILLFACTOR = fillfactor |
196 STATISTICS_NORECOMPUTE |
200 function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
204 if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
205 $sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
206 if ( isset($idxoptions['DROP']) )
210 if ( empty ($flds) ) {
214 $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
215 $clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : '';
217 if ( is_array($flds) )
218 $flds = implode(', ',$flds);
219 $s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
221 if ( isset($idxoptions[$this->upperName]) )
222 $s .= $idxoptions[$this->upperName];