Adodb Dokumentation  V5.14 8 Sept 2011
datadict/datadict-sapdb.inc.php
00001 <?php
00002 
00014 // security - hide paths
00015 if (!defined('ADODB_DIR')) die();
00016 
00017 class ADODB2_sapdb extends ADODB_DataDict {
00018         
00019         var $databaseType = 'sapdb';
00020         var $seqField = false;  
00021         var $renameColumn = 'RENAME COLUMN %s.%s TO %s';
00022         
00023         function ActualType($meta)
00024         {
00025                 switch($meta) {
00026                 case 'C': return 'VARCHAR';
00027                 case 'XL':
00028                 case 'X': return 'LONG';
00029                 
00030                 case 'C2': return 'VARCHAR UNICODE';
00031                 case 'X2': return 'LONG UNICODE';
00032                 
00033                 case 'B': return 'LONG';
00034                         
00035                 case 'D': return 'DATE';
00036                 case 'TS':
00037                 case 'T': return 'TIMESTAMP';
00038                 
00039                 case 'L': return 'BOOLEAN';
00040                 case 'I': return 'INTEGER';
00041                 case 'I1': return 'FIXED(3)';
00042                 case 'I2': return 'SMALLINT';
00043                 case 'I4': return 'INTEGER';
00044                 case 'I8': return 'FIXED(20)';
00045                 
00046                 case 'F': return 'FLOAT(38)';
00047                 case 'N': return 'FIXED';
00048                 default:
00049                         return $meta;
00050                 }
00051         }
00052         
00053         function MetaType($t,$len=-1,$fieldobj=false)
00054         {
00055                 if (is_object($t)) {
00056                         $fieldobj = $t;
00057                         $t = $fieldobj->type;
00058                         $len = $fieldobj->max_length;
00059                 }
00060                 static $maxdb_type2adodb = array(
00061                         'VARCHAR'       => 'C',
00062                         'CHARACTER'     => 'C',
00063                         'LONG'          => 'X',         // no way to differ between 'X' and 'B' :-(
00064                         'DATE'          => 'D',
00065                         'TIMESTAMP'     => 'T',
00066                         'BOOLEAN'       => 'L',
00067                         'INTEGER'       => 'I4',
00068                         'SMALLINT'      => 'I2',
00069                         'FLOAT'         => 'F',
00070                         'FIXED'         => 'N',
00071                 );
00072                 $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : 'C';
00073 
00074                 // convert integer-types simulated with fixed back to integer
00075                 if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) {
00076                         $type = $len == 20 ? 'I8' : 'I1';
00077                 }
00078                 if ($fieldobj->auto_increment) $type = 'R';
00079 
00080                 return $type;
00081         }
00082         
00083         // return string must begin with space
00084         function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
00085         {       
00086                 $suffix = '';
00087                 if ($funsigned) $suffix .= ' UNSIGNED';
00088                 if ($fnotnull) $suffix .= ' NOT NULL';
00089                 if ($fautoinc) $suffix .= ' DEFAULT SERIAL';
00090                 elseif (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
00091                 if ($fconstraint) $suffix .= ' '.$fconstraint;
00092                 return $suffix;
00093         }
00094 
00095         function AddColumnSQL($tabname, $flds)
00096         {
00097                 $tabname = $this->TableName ($tabname);
00098                 $sql = array();
00099                 list($lines,$pkey) = $this->_GenFields($flds);
00100                 return array( 'ALTER TABLE ' . $tabname . ' ADD (' . implode(', ',$lines) . ')' );
00101         }
00102         
00103         function AlterColumnSQL($tabname, $flds)
00104         {
00105                 $tabname = $this->TableName ($tabname);
00106                 $sql = array();
00107                 list($lines,$pkey) = $this->_GenFields($flds);
00108                 return array( 'ALTER TABLE ' . $tabname . ' MODIFY (' . implode(', ',$lines) . ')' );
00109         }
00110 
00111         function DropColumnSQL($tabname, $flds)
00112         {
00113                 $tabname = $this->TableName ($tabname);
00114                 if (!is_array($flds)) $flds = explode(',',$flds);
00115                 foreach($flds as $k => $v) {
00116                         $flds[$k] = $this->NameQuote($v);
00117                 }
00118                 return array( 'ALTER TABLE ' . $tabname . ' DROP (' . implode(', ',$flds) . ')' );
00119         }       
00120 }
00121 
00122 ?>