source: trunk/phpgwapi/inc/adodb/datadict/datadict-mysql.inc.php @ 2

Revision 2, 4.5 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2
3/**
4  V4.51 29 July 2004  (c) 2000-2004 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// security - hide paths
14if (!defined('ADODB_DIR')) die();
15
16class 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
21       
22        var $dropIndex = 'DROP INDEX %s ON %s';
23       
24        function MetaType($t,$len=-1,$fieldobj=false)
25        {
26                if (is_object($t)) {
27                        $fieldobj = $t;
28                        $t = $fieldobj->type;
29                        $len = $fieldobj->max_length;
30                }
31               
32                $len = -1; // mysql max_length is not accurate
33                switch (strtoupper($t)) {
34                case 'STRING':
35                case 'CHAR':
36                case 'VARCHAR':
37                case 'TINYBLOB':
38                case 'TINYTEXT':
39                case 'ENUM':
40                case 'SET':
41                        if ($len <= $this->blobSize) return 'C';
42                       
43                case 'TEXT':
44                case 'LONGTEXT':
45                case 'MEDIUMTEXT':
46                        return 'X';
47                       
48                // php_mysql extension always returns 'blob' even if 'text'
49                // so we have to check whether binary...
50                case 'IMAGE':
51                case 'LONGBLOB':
52                case 'BLOB':
53                case 'MEDIUMBLOB':
54                        return !empty($fieldobj->binary) ? 'B' : 'X';
55                       
56                case 'YEAR':
57                case 'DATE': return 'D';
58               
59                case 'TIME':
60                case 'DATETIME':
61                case 'TIMESTAMP': return 'T';
62               
63                case 'FLOAT':
64                case 'DOUBLE':
65                        return 'F';
66                       
67                case 'INT':
68                case 'INTEGER': return (!empty($fieldobj->primary_key)) ? 'R' : 'I';
69                case 'TINYINT': return (!empty($fieldobj->primary_key)) ? 'R' : 'I1';
70                case 'SMALLINT': return (!empty($fieldobj->primary_key)) ? 'R' : 'I2';
71                case 'MEDIUMINT': return (!empty($fieldobj->primary_key)) ? 'R' : 'I4';
72                case 'BIGINT':  return (!empty($fieldobj->primary_key)) ? 'R' : 'I8';
73                default: return 'N';
74                }
75        }
76
77        function ActualType($meta)
78        {
79                switch(strtoupper($meta)) {
80                case 'C': return 'VARCHAR';
81                case 'XL':
82                case 'X': return 'LONGTEXT';
83               
84                case 'C2': return 'VARCHAR';
85                case 'X2': return 'LONGTEXT';
86               
87                case 'B': return 'LONGBLOB';
88                       
89                case 'D': return 'DATE';
90                case 'T': return 'DATETIME';
91                case 'L': return 'TINYINT';
92               
93                case 'R':
94                case 'I': return 'INTEGER';
95                case 'I1': return 'TINYINT';
96                case 'I2': return 'SMALLINT';
97                case 'I4': return 'MEDIUMINT';
98                case 'I8': return 'BIGINT';
99               
100                case 'F': return 'DOUBLE';
101                case 'N': return 'NUMERIC';
102                default:
103                        return $meta;
104                }
105        }
106       
107        // return string must begin with space
108        function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
109        {       
110                $suffix = '';
111                if ($funsigned) $suffix .= ' UNSIGNED';
112                if ($fnotnull) $suffix .= ' NOT NULL';
113                if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
114                if ($fautoinc) $suffix .= ' AUTO_INCREMENT';
115                if ($fconstraint) $suffix .= ' '.$fconstraint;
116                return $suffix;
117        }
118       
119        /*
120        CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
121                [table_options] [select_statement]
122                create_definition:
123                col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
124                [PRIMARY KEY] [reference_definition]
125                or PRIMARY KEY (index_col_name,...)
126                or KEY [index_name] (index_col_name,...)
127                or INDEX [index_name] (index_col_name,...)
128                or UNIQUE [INDEX] [index_name] (index_col_name,...)
129                or FULLTEXT [INDEX] [index_name] (index_col_name,...)
130                or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...)
131                [reference_definition]
132                or CHECK (expr)
133        */
134       
135        /*
136        CREATE [UNIQUE|FULLTEXT] INDEX index_name
137                ON tbl_name (col_name[(length)],... )
138        */
139       
140        function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
141        {
142                $sql = array();
143               
144                if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
145                        if ($this->alterTableAddIndex) $sql[] = "ALTER TABLE $tabname DROP INDEX $idxname";
146                        else $sql[] = sprintf($this->dropIndex, $idxname, $tabname);
147
148                        if ( isset($idxoptions['DROP']) )
149                                return $sql;
150                }
151               
152                if ( empty ($flds) ) {
153                        return $sql;
154                }
155               
156                if (isset($idxoptions['FULLTEXT'])) {
157                        $unique = ' FULLTEXT';
158                } elseif (isset($idxoptions['UNIQUE'])) {
159                        $unique = ' UNIQUE';
160                } else {
161                        $unique = '';
162                }
163               
164                if ( is_array($flds) ) $flds = implode(', ',$flds);
165               
166                if ($this->alterTableAddIndex) $s = "ALTER TABLE $tabname ADD $unique INDEX $idxname ";
167                else $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname;
168               
169                $s .= ' (' . $flds . ')';
170               
171                if ( isset($idxoptions[$this->upperName]) )
172                        $s .= $idxoptions[$this->upperName];
173               
174                $sql[] = $s;
175               
176                return $sql;
177        }
178}
179?>
Note: See TracBrowser for help on using the repository browser.