Adodb Dokumentation  V5.14 8 Sept 2011
datadict/datadict-firebird.inc.php
00001 <?php
00002 
00013 class ADODB2_firebird extends ADODB_DataDict {
00014         
00015         var $databaseType = 'firebird';
00016         var $seqField = false;
00017         var $seqPrefix = 'gen_';
00018         var $blobSize = 40000;  
00019         
00020         function ActualType($meta)
00021         {
00022                 switch($meta) {
00023                 case 'C': return 'VARCHAR';
00024                 case 'XL': return 'VARCHAR(32000)'; 
00025                 case 'X': return 'VARCHAR(4000)'; 
00026                 
00027                 case 'C2': return 'VARCHAR'; // up to 32K
00028                 case 'X2': return 'VARCHAR(4000)';
00029                 
00030                 case 'B': return 'BLOB';
00031                         
00032                 case 'D': return 'DATE';
00033                 case 'TS':
00034                 case 'T': return 'TIMESTAMP';
00035                 
00036                 case 'L': return 'SMALLINT';
00037                 case 'I': return 'INTEGER';
00038                 case 'I1': return 'SMALLINT';
00039                 case 'I2': return 'SMALLINT';
00040                 case 'I4': return 'INTEGER';
00041                 case 'I8': return 'INTEGER';
00042                 
00043                 case 'F': return 'DOUBLE PRECISION';
00044                 case 'N': return 'DECIMAL';
00045                 default:
00046                         return $meta;
00047                 }
00048         }
00049         
00050         function NameQuote($name = NULL)
00051         {
00052                 if (!is_string($name)) {
00053                         return FALSE;
00054                 }
00055                 
00056                 $name = trim($name);
00057                 
00058                 if ( !is_object($this->connection) ) {
00059                         return $name;
00060                 }
00061                 
00062                 $quote = $this->connection->nameQuote;
00063                 
00064                 // if name is of the form `name`, quote it
00065                 if ( preg_match('/^`(.+)`$/', $name, $matches) ) {
00066                         return $quote . $matches[1] . $quote;
00067                 }
00068                 
00069                 // if name contains special characters, quote it
00070                 if ( !preg_match('/^[' . $this->nameRegex . ']+$/', $name) ) {
00071                         return $quote . $name . $quote;
00072                 }
00073                 
00074                 return $quote . $name . $quote;
00075         }
00076 
00077         function CreateDatabase($dbname, $options=false)
00078         {
00079                 $options = $this->_Options($options);
00080                 $sql = array();
00081                 
00082                 $sql[] = "DECLARE EXTERNAL FUNCTION LOWER CSTRING(80) RETURNS CSTRING(80) FREE_IT ENTRY_POINT 'IB_UDF_lower' MODULE_NAME 'ib_udf'";
00083                 
00084                 return $sql;
00085         }
00086         
00087         function _DropAutoIncrement($t)
00088         {
00089                 if (strpos($t,'.') !== false) {
00090                         $tarr = explode('.',$t);
00091                         return 'DROP GENERATOR '.$tarr[0].'."gen_'.$tarr[1].'"';
00092                 }
00093                 return 'DROP GENERATOR "GEN_'.$t;
00094         }
00095         
00096 
00097         function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
00098         {
00099                 $suffix = '';
00100                 
00101                 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
00102                 if ($fnotnull) $suffix .= ' NOT NULL';
00103                 if ($fautoinc) $this->seqField = $fname;
00104                 if ($fconstraint) $suffix .= ' '.$fconstraint;
00105                 
00106                 return $suffix;
00107         }
00108         
00109 /*
00110 CREATE or replace TRIGGER jaddress_insert
00111 before insert on jaddress
00112 for each row
00113 begin
00114 IF ( NEW."seqField" IS NULL OR NEW."seqField" = 0 ) THEN
00115   NEW."seqField" = GEN_ID("GEN_tabname", 1);
00116 end;
00117 */
00118         function _Triggers($tabname,$tableoptions)
00119         {       
00120                 if (!$this->seqField) return array();
00121                 
00122                 $tab1 = preg_replace( '/"/', '', $tabname );
00123                 if ($this->schema) {
00124                         $t = strpos($tab1,'.');
00125                         if ($t !== false) $tab = substr($tab1,$t+1);
00126                         else $tab = $tab1;
00127                         $seqField = $this->seqField;
00128                         $seqname = $this->schema.'.'.$this->seqPrefix.$tab;
00129                         $trigname = $this->schema.'.trig_'.$this->seqPrefix.$tab;
00130                 } else {
00131                         $seqField = $this->seqField;
00132                         $seqname = $this->seqPrefix.$tab1;
00133                         $trigname = 'trig_'.$seqname;
00134                 }
00135                 if (isset($tableoptions['REPLACE']))
00136                 { $sql[] = "DROP GENERATOR \"$seqname\"";
00137                   $sql[] = "CREATE GENERATOR \"$seqname\"";
00138                   $sql[] = "ALTER TRIGGER \"$trigname\" BEFORE INSERT OR UPDATE AS BEGIN IF ( NEW.$seqField IS NULL OR NEW.$seqField = 0 ) THEN NEW.$seqField = GEN_ID(\"$seqname\", 1); END";
00139                 }
00140                 else
00141                 { $sql[] = "CREATE GENERATOR \"$seqname\"";
00142                   $sql[] = "CREATE TRIGGER \"$trigname\" FOR $tabname BEFORE INSERT OR UPDATE AS BEGIN IF ( NEW.$seqField IS NULL OR NEW.$seqField = 0 ) THEN NEW.$seqField = GEN_ID(\"$seqname\", 1); END";
00143                 }
00144                 
00145                 $this->seqField = false;
00146                 return $sql;
00147         }
00148 
00149 }
00150 
00151 
00152 ?>