Improved performance of code set searching in Administration->Services
[openemr.git] / gacl / adodb / datadict / datadict-firebird.inc.php
blob0cd07f586ab2b63eae93c9e635e68a396bb859fe
1 <?php
3 /**
4 V4.92a 29 Aug 2006 (c) 2000-2006 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.
9 Set tabs to 4 for best viewing.
13 class ADODB2_firebird extends ADODB_DataDict {
15 var $databaseType = 'firebird';
16 var $seqField = false;
17 var $seqPrefix = 'gen_';
18 var $blobSize = 40000;
20 function ActualType($meta)
22 switch($meta) {
23 case 'C': return 'VARCHAR';
24 case 'XL': return 'VARCHAR(32000)';
25 case 'X': return 'VARCHAR(4000)';
27 case 'C2': return 'VARCHAR'; // up to 32K
28 case 'X2': return 'VARCHAR(4000)';
30 case 'B': return 'BLOB';
32 case 'D': return 'DATE';
33 case 'T': return 'TIMESTAMP';
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';
42 case 'F': return 'DOUBLE PRECISION';
43 case 'N': return 'DECIMAL';
44 default:
45 return $meta;
49 function NameQuote($name = NULL)
51 if (!is_string($name)) {
52 return FALSE;
55 $name = trim($name);
57 if ( !is_object($this->connection) ) {
58 return $name;
61 $quote = $this->connection->nameQuote;
63 // if name is of the form `name`, quote it
64 if ( preg_match('/^`(.+)`$/', $name, $matches) ) {
65 return $quote . $matches[1] . $quote;
68 // if name contains special characters, quote it
69 if ( !preg_match('/^[' . $this->nameRegex . ']+$/', $name) ) {
70 return $quote . $name . $quote;
73 return $quote . $name . $quote;
76 function CreateDatabase($dbname, $options=false)
78 $options = $this->_Options($options);
79 $sql = array();
81 $sql[] = "DECLARE EXTERNAL FUNCTION LOWER CSTRING(80) RETURNS CSTRING(80) FREE_IT ENTRY_POINT 'IB_UDF_lower' MODULE_NAME 'ib_udf'";
83 return $sql;
86 function _DropAutoIncrement($t)
88 if (strpos($t,'.') !== false) {
89 $tarr = explode('.',$t);
90 return 'DROP GENERATOR '.$tarr[0].'."gen_'.$tarr[1].'"';
92 return 'DROP GENERATOR "GEN_'.$t;
96 function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
98 $suffix = '';
100 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
101 if ($fnotnull) $suffix .= ' NOT NULL';
102 if ($fautoinc) $this->seqField = $fname;
103 if ($fconstraint) $suffix .= ' '.$fconstraint;
105 return $suffix;
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;
117 function _Triggers($tabname,$tableoptions)
119 if (!$this->seqField) return array();
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;
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";
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";
144 $this->seqField = false;
145 return $sql;