Fixes to the PaintWeb cron task.
[moodle/mihaisucan.git] / lib / adodb / datadict / datadict-mysql.inc.php
blobef4dc8586a6a63809b181cc510d5c7fef9d15649
1 <?php
3 /**
4 V4.98 13 Feb 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.
9 Set tabs to 4 for best viewing.
13 // security - hide paths
14 if (!defined('ADODB_DIR')) die();
16 class ADODB2_mysql extends ADODB_DataDict {
17 var $databaseType = 'mysql';
18 var $alterCol = ' MODIFY COLUMN';
19 var $alterTableAddIndex = true;
20 var $dropTable = 'DROP TABLE IF EXISTS %s'; // requires mysql 3.22 or later
22 var $dropIndex = 'DROP INDEX %s ON %s';
23 var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s'; // needs column-definition!
25 function MetaType($t,$len=-1,$fieldobj=false)
27 if (is_object($t)) {
28 $fieldobj = $t;
29 $t = $fieldobj->type;
30 $len = $fieldobj->max_length;
32 $is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->auto_increment;
34 $len = -1; // mysql max_length is not accurate
35 switch (strtoupper($t)) {
36 case 'STRING':
37 case 'CHAR':
38 case 'VARCHAR':
39 case 'TINYBLOB':
40 case 'TINYTEXT':
41 case 'ENUM':
42 case 'SET':
43 if ($len <= $this->blobSize) return 'C';
45 case 'TEXT':
46 case 'LONGTEXT':
47 case 'MEDIUMTEXT':
48 return 'X';
50 // php_mysql extension always returns 'blob' even if 'text'
51 // so we have to check whether binary...
52 case 'IMAGE':
53 case 'LONGBLOB':
54 case 'BLOB':
55 case 'MEDIUMBLOB':
56 return !empty($fieldobj->binary) ? 'B' : 'X';
58 case 'YEAR':
59 case 'DATE': return 'D';
61 case 'TIME':
62 case 'DATETIME':
63 case 'TIMESTAMP': return 'T';
65 case 'FLOAT':
66 case 'DOUBLE':
67 return 'F';
69 case 'INT':
70 case 'INTEGER': return $is_serial ? 'R' : 'I';
71 case 'TINYINT': return $is_serial ? 'R' : 'I1';
72 case 'SMALLINT': return $is_serial ? 'R' : 'I2';
73 case 'MEDIUMINT': return $is_serial ? 'R' : 'I4';
74 case 'BIGINT': return $is_serial ? 'R' : 'I8';
75 default: return 'N';
79 function ActualType($meta)
81 switch(strtoupper($meta)) {
82 case 'C': return 'VARCHAR';
83 case 'XL':return 'LONGTEXT';
84 case 'X': return 'TEXT';
86 case 'C2': return 'VARCHAR';
87 case 'X2': return 'LONGTEXT';
89 case 'B': return 'LONGBLOB';
91 case 'D': return 'DATE';
92 case 'T': return 'DATETIME';
93 case 'L': return 'TINYINT';
95 case 'R':
96 case 'I4':
97 case 'I': return 'INTEGER';
98 case 'I1': return 'TINYINT';
99 case 'I2': return 'SMALLINT';
100 case 'I8': return 'BIGINT';
102 case 'F': return 'DOUBLE';
103 case 'N': return 'NUMERIC';
104 default:
105 return $meta;
109 // return string must begin with space
110 function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
112 $suffix = '';
113 if ($funsigned) $suffix .= ' UNSIGNED';
114 if ($fnotnull) $suffix .= ' NOT NULL';
115 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
116 if ($fautoinc) $suffix .= ' AUTO_INCREMENT';
117 if ($fconstraint) $suffix .= ' '.$fconstraint;
118 return $suffix;
122 CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
123 [table_options] [select_statement]
124 create_definition:
125 col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
126 [PRIMARY KEY] [reference_definition]
127 or PRIMARY KEY (index_col_name,...)
128 or KEY [index_name] (index_col_name,...)
129 or INDEX [index_name] (index_col_name,...)
130 or UNIQUE [INDEX] [index_name] (index_col_name,...)
131 or FULLTEXT [INDEX] [index_name] (index_col_name,...)
132 or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...)
133 [reference_definition]
134 or CHECK (expr)
138 CREATE [UNIQUE|FULLTEXT] INDEX index_name
139 ON tbl_name (col_name[(length)],... )
142 function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
144 $sql = array();
146 if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
147 if ($this->alterTableAddIndex) $sql[] = "ALTER TABLE $tabname DROP INDEX $idxname";
148 else $sql[] = sprintf($this->dropIndex, $idxname, $tabname);
150 if ( isset($idxoptions['DROP']) )
151 return $sql;
154 if ( empty ($flds) ) {
155 return $sql;
158 if (isset($idxoptions['FULLTEXT'])) {
159 $unique = ' FULLTEXT';
160 } elseif (isset($idxoptions['UNIQUE'])) {
161 $unique = ' UNIQUE';
162 } else {
163 $unique = '';
166 if ( is_array($flds) ) $flds = implode(', ',$flds);
168 if ($this->alterTableAddIndex) $s = "ALTER TABLE $tabname ADD $unique INDEX $idxname ";
169 else $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname;
171 $s .= ' (' . $flds . ')';
173 if ( isset($idxoptions[$this->upperName]) )
174 $s .= $idxoptions[$this->upperName];
176 $sql[] = $s;
178 return $sql;