Zikula 1.0.1
[ class tree: Zikula 1.0.1 ] [ index: Zikula 1.0.1 ] [ all elements ]

Source for file datadict-firebird.inc.php

Documentation is available at datadict-firebird.inc.php

  1. <?php
  2.  
  3. /**
  4.   V4.97 22 Jan 2008  (c) 2000-2008 John Lim (jlim#natsoft.com.my). 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.
  8.     
  9.   Set tabs to 4 for best viewing.
  10.  
  11. */
  12.  
  13. class ADODB2_firebird extends ADODB_DataDict {
  14.     
  15.     var $databaseType = 'firebird';
  16.     var $seqField = false;
  17.     var $seqPrefix = 'gen_';
  18.     var $blobSize = 40000;    
  19.      
  20.      function ActualType($meta)
  21.     {
  22.         switch($meta{
  23.         case 'C'return 'VARCHAR';
  24.         case 'XL'return 'VARCHAR(32000)'
  25.         case 'X'return 'VARCHAR(4000)'
  26.         
  27.         case 'C2'return 'VARCHAR'// up to 32K
  28.         case 'X2'return 'VARCHAR(4000)';
  29.         
  30.         case 'B'return 'BLOB';
  31.             
  32.         case 'D'return 'DATE';
  33.         case 'T'return 'TIMESTAMP';
  34.         
  35.         case 'L'return 'SMALLINT';
  36.         case 'I'return 'INTEGER';
  37.         case 'I1'return 'SMALLINT';
  38.         case 'I2'return 'SMALLINT';
  39.         case 'I4'return 'INTEGER';
  40.         case 'I8'return 'INTEGER';
  41.         
  42.         case 'F'return 'DOUBLE PRECISION';
  43.         case 'N'return 'DECIMAL';
  44.         default:
  45.             return $meta;
  46.         }
  47.     }
  48.     
  49.     function NameQuote($name NULL)
  50.     {
  51.         if (!is_string($name)) {
  52.             return FALSE;
  53.         }
  54.         
  55.         $name trim($name);
  56.         
  57.         if !is_object($this->connection) ) {
  58.             return $name;
  59.         }
  60.         
  61.         $quote $this->connection->nameQuote;
  62.         
  63.         // if name is of the form `name`, quote it
  64.         if preg_match('/^`(.+)`$/'$name$matches) ) {
  65.             return $quote $matches[1$quote;
  66.         }
  67.         
  68.         // if name contains special characters, quote it
  69.         if !preg_match('/^[' $this->nameRegex . ']+$/'$name) ) {
  70.             return $quote $name $quote;
  71.         }
  72.         
  73.         return $quote $name $quote;
  74.     }
  75.  
  76.     function CreateDatabase($dbname$options=false)
  77.     {
  78.         $options $this->_Options($options);
  79.         $sql array();
  80.         
  81.         $sql["DECLARE EXTERNAL FUNCTION LOWER CSTRING(80) RETURNS CSTRING(80) FREE_IT ENTRY_POINT 'IB_UDF_lower' MODULE_NAME 'ib_udf'";
  82.         
  83.         return $sql;
  84.     }
  85.     
  86.     function _DropAutoIncrement($t)
  87.     {
  88.         if (strpos($t,'.'!== false{
  89.             $tarr explode('.',$t);
  90.             return 'DROP GENERATOR '.$tarr[0].'."gen_'.$tarr[1].'"';
  91.         }
  92.         return 'DROP GENERATOR "GEN_'.$t;
  93.     }
  94.     
  95.  
  96.     function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
  97.     {
  98.         $suffix '';
  99.         
  100.         if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
  101.         if ($fnotnull$suffix .= ' NOT NULL';
  102.         if ($fautoinc$this->seqField = $fname;
  103.         if ($fconstraint$suffix .= ' '.$fconstraint;
  104.         
  105.         return $suffix;
  106.     }
  107.     
  108. /*
  109. CREATE or replace TRIGGER jaddress_insert
  110. before insert on jaddress
  111. for each row
  112. begin
  113. IF ( NEW."seqField" IS NULL OR NEW."seqField" = 0 ) THEN
  114.   NEW."seqField" = GEN_ID("GEN_tabname", 1);
  115. end;
  116. */
  117.     function _Triggers($tabname,$tableoptions)
  118.     {    
  119.         if (!$this->seqFieldreturn array();
  120.         
  121.         $tab1 preg_replace'/"/'''$tabname );
  122.         if ($this->schema{
  123.             $t strpos($tab1,'.');
  124.             if ($t !== false$tab substr($tab1,$t+1);
  125.             else $tab $tab1;
  126.             $seqField $this->seqField;
  127.             $seqname $this->schema.'.'.$this->seqPrefix.$tab;
  128.             $trigname $this->schema.'.trig_'.$this->seqPrefix.$tab;
  129.         else {
  130.             $seqField $this->seqField;
  131.             $seqname $this->seqPrefix.$tab1;
  132.             $trigname 'trig_'.$seqname;
  133.         }
  134.         if (isset($tableoptions['REPLACE']))
  135.         $sql["DROP GENERATOR \"$seqname\"";
  136.           $sql["CREATE GENERATOR \"$seqname\"";
  137.           $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";
  138.         }
  139.         else
  140.         $sql["CREATE GENERATOR \"$seqname\"";
  141.           $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";
  142.         }
  143.         
  144.         $this->seqField = false;
  145.         return $sql;
  146.     }
  147.  
  148. }
  149.  
  150.  
  151. ?>

Documentation generated on Fri, 18 Jul 2008 21:44:21 +0200 by phpDocumentor 1.4.1