123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- if (!defined('ADODB_DIR')) die();
- class ADODB2_sybase extends ADODB_DataDict {
- var $databaseType = 'sybase';
-
- var $dropIndex = 'DROP INDEX %2$s.%1$s';
-
- function MetaType($t,$len=-1,$fieldobj=false)
- {
- if (is_object($t)) {
- $fieldobj = $t;
- $t = $fieldobj->type;
- $len = $fieldobj->max_length;
- }
-
- $len = -1;
- switch (strtoupper($t)) {
- case 'INT':
- case 'INTEGER': return 'I';
- case 'BIT':
- case 'TINYINT': return 'I1';
- case 'SMALLINT': return 'I2';
- case 'BIGINT': return 'I8';
-
- case 'REAL':
- case 'FLOAT': return 'F';
- default: return parent::MetaType($t,$len,$fieldobj);
- }
- }
-
- function ActualType($meta)
- {
- switch(strtoupper($meta)) {
- case 'C': return 'VARCHAR';
- case 'XL':
- case 'X': return 'TEXT';
-
- case 'C2': return 'NVARCHAR';
- case 'X2': return 'NTEXT';
-
- case 'B': return 'IMAGE';
-
- case 'D': return 'DATETIME';
- case 'T': return 'DATETIME';
- case 'L': return 'BIT';
-
- case 'I': return 'INT';
- case 'I1': return 'TINYINT';
- case 'I2': return 'SMALLINT';
- case 'I4': return 'INT';
- case 'I8': return 'BIGINT';
-
- case 'F': return 'REAL';
- case 'N': return 'NUMERIC';
- default:
- return $meta;
- }
- }
-
-
- function AddColumnSQL($tabname, $flds)
- {
- $tabname = $this->TableName ($tabname);
- $f = array();
- list($lines,$pkey) = $this->_GenFields($flds);
- $s = "ALTER TABLE $tabname $this->addCol";
- foreach($lines as $v) {
- $f[] = "\n $v";
- }
- $s .= implode(', ',$f);
- $sql[] = $s;
- return $sql;
- }
-
- function AlterColumnSQL($tabname, $flds)
- {
- $tabname = $this->TableName ($tabname);
- $sql = array();
- list($lines,$pkey) = $this->_GenFields($flds);
- foreach($lines as $v) {
- $sql[] = "ALTER TABLE $tabname $this->alterCol $v";
- }
- return $sql;
- }
-
- function DropColumnSQL($tabname, $flds)
- {
- $tabname = $this->TableName($tabname);
- if (!is_array($flds)) $flds = explode(',',$flds);
- $f = array();
- $s = "ALTER TABLE $tabname";
- foreach($flds as $v) {
- $f[] = "\n$this->dropCol ".$this->NameQuote($v);
- }
- $s .= implode(', ',$f);
- $sql[] = $s;
- return $sql;
- }
-
-
- function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)
- {
- $suffix = '';
- if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
- if ($fautoinc) $suffix .= ' DEFAULT AUTOINCREMENT';
- if ($fnotnull) $suffix .= ' NOT NULL';
- else if ($suffix == '') $suffix .= ' NULL';
- if ($fconstraint) $suffix .= ' '.$fconstraint;
- return $suffix;
- }
-
-
-
-
- function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
- {
- $sql = array();
-
- if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
- $sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
- if ( isset($idxoptions['DROP']) )
- return $sql;
- }
-
- if ( empty ($flds) ) {
- return $sql;
- }
-
- $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
- $clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : '';
-
- if ( is_array($flds) )
- $flds = implode(', ',$flds);
- $s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
-
- if ( isset($idxoptions[$this->upperName]) )
- $s .= $idxoptions[$this->upperName];
- $sql[] = $s;
-
- return $sql;
- }
- }
- ?>
|