00001 <?php
00002
00013
00014 if (!defined('ADODB_DIR')) die();
00015
00016 class ADODB2_sybase extends ADODB_DataDict {
00017 var $databaseType = 'sybase';
00018
00019 var $dropIndex = 'DROP INDEX %2$s.%1$s';
00020
00021 function MetaType($t,$len=-1,$fieldobj=false)
00022 {
00023 if (is_object($t)) {
00024 $fieldobj = $t;
00025 $t = $fieldobj->type;
00026 $len = $fieldobj->max_length;
00027 }
00028
00029 $len = -1;
00030 switch (strtoupper($t)) {
00031
00032 case 'INT':
00033 case 'INTEGER': return 'I';
00034 case 'BIT':
00035 case 'TINYINT': return 'I1';
00036 case 'SMALLINT': return 'I2';
00037 case 'BIGINT': return 'I8';
00038
00039 case 'REAL':
00040 case 'FLOAT': return 'F';
00041 default: return parent::MetaType($t,$len,$fieldobj);
00042 }
00043 }
00044
00045 function ActualType($meta)
00046 {
00047 switch(strtoupper($meta)) {
00048 case 'C': return 'VARCHAR';
00049 case 'XL':
00050 case 'X': return 'TEXT';
00051
00052 case 'C2': return 'NVARCHAR';
00053 case 'X2': return 'NTEXT';
00054
00055 case 'B': return 'IMAGE';
00056
00057 case 'D': return 'DATETIME';
00058 case 'T': return 'DATETIME';
00059 case 'L': return 'BIT';
00060
00061 case 'I': return 'INT';
00062 case 'I1': return 'TINYINT';
00063 case 'I2': return 'SMALLINT';
00064 case 'I4': return 'INT';
00065 case 'I8': return 'BIGINT';
00066
00067 case 'F': return 'REAL';
00068 case 'N': return 'NUMERIC';
00069 default:
00070 return $meta;
00071 }
00072 }
00073
00074
00075 function AddColumnSQL($tabname, $flds)
00076 {
00077 $tabname = $this->TableName ($tabname);
00078 $f = array();
00079 list($lines,$pkey) = $this->_GenFields($flds);
00080 $s = "ALTER TABLE $tabname $this->addCol";
00081 foreach($lines as $v) {
00082 $f[] = "\n $v";
00083 }
00084 $s .= implode(', ',$f);
00085 $sql[] = $s;
00086 return $sql;
00087 }
00088
00089 function AlterColumnSQL($tabname, $flds)
00090 {
00091 $tabname = $this->TableName ($tabname);
00092 $sql = array();
00093 list($lines,$pkey) = $this->_GenFields($flds);
00094 foreach($lines as $v) {
00095 $sql[] = "ALTER TABLE $tabname $this->alterCol $v";
00096 }
00097
00098 return $sql;
00099 }
00100
00101 function DropColumnSQL($tabname, $flds)
00102 {
00103 $tabname = $this->TableName($tabname);
00104 if (!is_array($flds)) $flds = explode(',',$flds);
00105 $f = array();
00106 $s = "ALTER TABLE $tabname";
00107 foreach($flds as $v) {
00108 $f[] = "\n$this->dropCol ".$this->NameQuote($v);
00109 }
00110 $s .= implode(', ',$f);
00111 $sql[] = $s;
00112 return $sql;
00113 }
00114
00115
00116 function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)
00117 {
00118 $suffix = '';
00119 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
00120 if ($fautoinc) $suffix .= ' DEFAULT AUTOINCREMENT';
00121 if ($fnotnull) $suffix .= ' NOT NULL';
00122 else if ($suffix == '') $suffix .= ' NULL';
00123 if ($fconstraint) $suffix .= ' '.$fconstraint;
00124 return $suffix;
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
00200 {
00201 $sql = array();
00202
00203 if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
00204 $sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
00205 if ( isset($idxoptions['DROP']) )
00206 return $sql;
00207 }
00208
00209 if ( empty ($flds) ) {
00210 return $sql;
00211 }
00212
00213 $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
00214 $clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : '';
00215
00216 if ( is_array($flds) )
00217 $flds = implode(', ',$flds);
00218 $s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
00219
00220 if ( isset($idxoptions[$this->upperName]) )
00221 $s .= $idxoptions[$this->upperName];
00222
00223 $sql[] = $s;
00224
00225 return $sql;
00226 }
00227 }
00228 ?>