new approach to logging database access and upgraded adodb
[openemr.git] / library / adodb / datadict / datadict-firebird.inc.php
blobca8c3332e2a80a23192077f652c082d32235fc32
1 <?php
3 /**
4 V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). 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 'TS':
34 case 'T': return 'TIMESTAMP';
36 case 'L': return 'SMALLINT';
37 case 'I': return 'INTEGER';
38 case 'I1': return 'SMALLINT';
39 case 'I2': return 'SMALLINT';
40 case 'I4': return 'INTEGER';
41 case 'I8': return 'INTEGER';
43 case 'F': return 'DOUBLE PRECISION';
44 case 'N': return 'DECIMAL';
45 default:
46 return $meta;
50 function NameQuote($name = NULL)
52 if (!is_string($name)) {
53 return FALSE;
56 $name = trim($name);
58 if ( !is_object($this->connection) ) {
59 return $name;
62 $quote = $this->connection->nameQuote;
64 // if name is of the form `name`, quote it
65 if ( preg_match('/^`(.+)`$/', $name, $matches) ) {
66 return $quote . $matches[1] . $quote;
69 // if name contains special characters, quote it
70 if ( !preg_match('/^[' . $this->nameRegex . ']+$/', $name) ) {
71 return $quote . $name . $quote;
74 return $quote . $name . $quote;
77 function CreateDatabase($dbname, $options=false)
79 $options = $this->_Options($options);
80 $sql = array();
82 $sql[] = "DECLARE EXTERNAL FUNCTION LOWER CSTRING(80) RETURNS CSTRING(80) FREE_IT ENTRY_POINT 'IB_UDF_lower' MODULE_NAME 'ib_udf'";
84 return $sql;
87 function _DropAutoIncrement($t)
89 if (strpos($t,'.') !== false) {
90 $tarr = explode('.',$t);
91 return 'DROP GENERATOR '.$tarr[0].'."gen_'.$tarr[1].'"';
93 return 'DROP GENERATOR "GEN_'.$t;
97 function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
99 $suffix = '';
101 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
102 if ($fnotnull) $suffix .= ' NOT NULL';
103 if ($fautoinc) $this->seqField = $fname;
104 if ($fconstraint) $suffix .= ' '.$fconstraint;
106 return $suffix;
110 CREATE or replace TRIGGER jaddress_insert
111 before insert on jaddress
112 for each row
113 begin
114 IF ( NEW."seqField" IS NULL OR NEW."seqField" = 0 ) THEN
115 NEW."seqField" = GEN_ID("GEN_tabname", 1);
116 end;
118 function _Triggers($tabname,$tableoptions)
120 if (!$this->seqField) return array();
122 $tab1 = preg_replace( '/"/', '', $tabname );
123 if ($this->schema) {
124 $t = strpos($tab1,'.');
125 if ($t !== false) $tab = substr($tab1,$t+1);
126 else $tab = $tab1;
127 $seqField = $this->seqField;
128 $seqname = $this->schema.'.'.$this->seqPrefix.$tab;
129 $trigname = $this->schema.'.trig_'.$this->seqPrefix.$tab;
130 } else {
131 $seqField = $this->seqField;
132 $seqname = $this->seqPrefix.$tab1;
133 $trigname = 'trig_'.$seqname;
135 if (isset($tableoptions['REPLACE']))
136 { $sql[] = "DROP GENERATOR \"$seqname\"";
137 $sql[] = "CREATE GENERATOR \"$seqname\"";
138 $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";
140 else
141 { $sql[] = "CREATE GENERATOR \"$seqname\"";
142 $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";
145 $this->seqField = false;
146 return $sql;