source: Dev/trunk/rdfapi/util/adodb/drivers/adodb-pdo_mysql.inc.php @ 12

Last change on this file since 12 was 12, checked in by basvannuland, 14 years ago

Added RAP RDF API
Added RDF reader writer for save and load survey

File size: 4.8 KB
Line 
1<?php
2
3
4/*
5V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
6  Released under both BSD license and Lesser GPL library license.
7  Whenever there is any discrepancy between the two licenses,
8  the BSD license will take precedence.
9  Set tabs to 8.
10 
11*/
12
13class ADODB_pdo_mysql extends ADODB_pdo {
14        var $metaTablesSQL = "SHOW TABLES";     
15        var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
16        var $sysDate = 'CURDATE()';
17        var $sysTimeStamp = 'NOW()';
18        var $nameQuote = '`';
19
20        function _init($parentDriver)
21        {
22       
23                $parentDriver->hasTransactions = false;
24                $parentDriver->_bindInputArray = false;
25                $parentDriver->hasInsertID = true;
26                $parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
27        }
28       
29                // dayFraction is a day in floating point
30        function OffsetDate($dayFraction,$date=false)
31        {               
32                if (!$date) $date = $this->sysDate;
33               
34                $fraction = $dayFraction * 24 * 3600;
35                return $date . ' + INTERVAL ' .  $fraction.' SECOND';
36               
37//              return "from_unixtime(unix_timestamp($date)+$fraction)";
38        }
39       
40        function ServerInfo()
41        {
42                $arr['description'] = ADOConnection::GetOne("select version()");
43                $arr['version'] = ADOConnection::_findvers($arr['description']);
44                return $arr;
45        }
46       
47        function &MetaTables($ttype=false,$showSchema=false,$mask=false)
48        {       
49                $save = $this->metaTablesSQL;
50                if ($showSchema && is_string($showSchema)) {
51                        $this->metaTablesSQL .= " from $showSchema";
52                }
53               
54                if ($mask) {
55                        $mask = $this->qstr($mask);
56                        $this->metaTablesSQL .= " like $mask";
57                }
58                $ret =& ADOConnection::MetaTables($ttype,$showSchema);
59               
60                $this->metaTablesSQL = $save;
61                return $ret;
62        }
63       
64        function SetTransactionMode( $transaction_mode )
65        {
66                $this->_transmode  = $transaction_mode;
67                if (empty($transaction_mode)) {
68                        $this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
69                        return;
70                }
71                if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
72                $this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
73        }
74       
75        function &MetaColumns($table)
76        {
77                $this->_findschema($table,$schema);
78                if ($schema) {
79                        $dbName = $this->database;
80                        $this->SelectDB($schema);
81                }
82                global $ADODB_FETCH_MODE;
83                $save = $ADODB_FETCH_MODE;
84                $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
85               
86                if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
87                $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
88               
89                if ($schema) {
90                        $this->SelectDB($dbName);
91                }
92               
93                if (isset($savem)) $this->SetFetchMode($savem);
94                $ADODB_FETCH_MODE = $save;
95                if (!is_object($rs)) {
96                        $false = false;
97                        return $false;
98                }
99                       
100                $retarr = array();
101                while (!$rs->EOF){
102                        $fld = new ADOFieldObject();
103                        $fld->name = $rs->fields[0];
104                        $type = $rs->fields[1];
105                       
106                        // split type into type(length):
107                        $fld->scale = null;
108                        if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
109                                $fld->type = $query_array[1];
110                                $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
111                                $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
112                        } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
113                                $fld->type = $query_array[1];
114                                $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
115                        } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
116                                $fld->type = $query_array[1];
117                                $arr = explode(",",$query_array[2]);
118                                $fld->enums = $arr;
119                                $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
120                                $fld->max_length = ($zlen > 0) ? $zlen : 1;
121                        } else {
122                                $fld->type = $type;
123                                $fld->max_length = -1;
124                        }
125                        $fld->not_null = ($rs->fields[2] != 'YES');
126                        $fld->primary_key = ($rs->fields[3] == 'PRI');
127                        $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
128                        $fld->binary = (strpos($type,'blob') !== false);
129                        $fld->unsigned = (strpos($type,'unsigned') !== false);
130                               
131                        if (!$fld->binary) {
132                                $d = $rs->fields[4];
133                                if ($d != '' && $d != 'NULL') {
134                                        $fld->has_default = true;
135                                        $fld->default_value = $d;
136                                } else {
137                                        $fld->has_default = false;
138                                }
139                        }
140                       
141                        if ($save == ADODB_FETCH_NUM) {
142                                $retarr[] = $fld;
143                        } else {
144                                $retarr[strtoupper($fld->name)] = $fld;
145                        }
146                                $rs->MoveNext();
147                        }
148               
149                        $rs->Close();
150                        return $retarr;
151        }
152               
153       
154        // parameters use PostgreSQL convention, not MySQL
155        function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
156        {
157                $offsetStr =($offset>=0) ? "$offset," : '';
158                // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
159                if ($nrows < 0) $nrows = '18446744073709551615';
160               
161                if ($secs)
162                        $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
163                else
164                        $rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
165                return $rs;
166        }
167}
168?>
Note: See TracBrowser for help on using the repository browser.