diff options
| author | Damien Regad <dregad@mantisbt.org> | 2014-09-26 12:50:45 +0200 |
|---|---|---|
| committer | Damien Regad <dregad@mantisbt.org> | 2014-09-26 12:50:45 +0200 |
| commit | dbf80da5e6c0cdd671b9263a49206227c93a5b5a (patch) | |
| tree | f2c1d79d3abe3a22ad958ae5de263c638f6926ae /drivers/adodb-pdo_mysql.inc.php | |
| parent | 57399555f4dd991d6e010f0710fa91b3ec2d77a8 (diff) | |
| download | adodb-dbf80da5e6c0cdd671b9263a49206227c93a5b5a.tar.gz adodb-dbf80da5e6c0cdd671b9263a49206227c93a5b5a.tar.bz2 adodb-dbf80da5e6c0cdd671b9263a49206227c93a5b5a.zip | |
Coding guidelines / whitespace
Diffstat (limited to 'drivers/adodb-pdo_mysql.inc.php')
| -rw-r--r-- | drivers/adodb-pdo_mysql.inc.php | 224 |
1 files changed, 122 insertions, 102 deletions
diff --git a/drivers/adodb-pdo_mysql.inc.php b/drivers/adodb-pdo_mysql.inc.php index d0b01c15..1799060c 100644 --- a/drivers/adodb-pdo_mysql.inc.php +++ b/drivers/adodb-pdo_mysql.inc.php @@ -1,6 +1,4 @@ <?php - - /* V5.20dev ??-???-2014 (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved. Released under both BSD license and Lesser GPL library license. @@ -11,6 +9,7 @@ V5.20dev ??-???-2014 (c) 2000-2014 John Lim (jlim#natsoft.com). All rights res */ class ADODB_pdo_mysql extends ADODB_pdo { + var $metaTablesSQL = "SELECT TABLE_NAME, CASE WHEN TABLE_TYPE = 'VIEW' THEN 'V' ELSE 'T' END @@ -27,42 +26,45 @@ class ADODB_pdo_mysql extends ADODB_pdo { function _init($parentDriver) { - $parentDriver->hasTransactions = false; #$parentDriver->_bindInputArray = false; $parentDriver->hasInsertID = true; - $parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true); + $parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); } - // dayFraction is a day in floating point - function OffsetDate($dayFraction,$date=false) + // dayFraction is a day in floating point + function OffsetDate($dayFraction, $date=false) { - if (!$date) $date = $this->sysDate; + if (!$date) { + $date = $this->sysDate; + } $fraction = $dayFraction * 24 * 3600; - return $date . ' + INTERVAL ' . $fraction.' SECOND'; - + return $date . ' + INTERVAL ' . $fraction . ' SECOND'; // return "from_unixtime(unix_timestamp($date)+$fraction)"; } function Concat() { - $s = ""; + $s = ''; $arr = func_get_args(); // suggestion by andrew005#mnogo.ru - $s = implode(',',$arr); - if (strlen($s) > 0) return "CONCAT($s)"; return ''; + $s = implode(',', $arr); + if (strlen($s) > 0) { + return "CONCAT($s)"; + } + return ''; } function ServerInfo() { - $arr['description'] = ADOConnection::GetOne("select version()"); + $arr['description'] = ADOConnection::GetOne('select version()'); $arr['version'] = ADOConnection::_findvers($arr['description']); return $arr; } - function MetaTables($ttype=false,$showSchema=false,$mask=false) + function MetaTables($ttype=false, $showSchema=false, $mask=false) { $save = $this->metaTablesSQL; if ($showSchema && is_string($showSchema)) { @@ -73,26 +75,28 @@ class ADODB_pdo_mysql extends ADODB_pdo { $mask = $this->qstr($mask); $this->metaTablesSQL .= " like $mask"; } - $ret = ADOConnection::MetaTables($ttype,$showSchema); + $ret = ADOConnection::MetaTables($ttype, $showSchema); $this->metaTablesSQL = $save; return $ret; } - function SetTransactionMode( $transaction_mode ) + function SetTransactionMode($transaction_mode) { $this->_transmode = $transaction_mode; if (empty($transaction_mode)) { $this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ'); return; } - if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode; - $this->Execute("SET SESSION TRANSACTION ".$transaction_mode); + if (!stristr($transaction_mode, 'isolation')) { + $transaction_mode = 'ISOLATION LEVEL ' . $transaction_mode; + } + $this->Execute('SET SESSION TRANSACTION ' . $transaction_mode); } - function MetaColumns($table,$normalize=true) + function MetaColumns($table, $normalize=true) { - $this->_findschema($table,$schema); + $this->_findschema($table, $schema); if ($schema) { $dbName = $this->database; $this->SelectDB($schema); @@ -101,14 +105,18 @@ class ADODB_pdo_mysql extends ADODB_pdo { $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); - $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table)); + if ($this->fetchMode !== false) { + $savem = $this->SetFetchMode(false); + } + $rs = $this->Execute(sprintf($this->metaColumnsSQL, $table)); if ($schema) { $this->SelectDB($dbName); } - if (isset($savem)) $this->SetFetchMode($savem); + if (isset($savem)) { + $this->SetFetchMode($savem); + } $ADODB_FETCH_MODE = $save; if (!is_object($rs)) { $false = false; @@ -123,18 +131,18 @@ class ADODB_pdo_mysql extends ADODB_pdo { // split type into type(length): $fld->scale = null; - if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) { + if (preg_match('/^(.+)\((\d+),(\d+)/', $type, $query_array)) { $fld->type = $query_array[1]; $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1; $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1; - } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) { + } elseif (preg_match('/^(.+)\((\d+)/', $type, $query_array)) { $fld->type = $query_array[1]; $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1; - } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) { + } elseif (preg_match('/^(enum)\((.*)\)$/i', $type, $query_array)) { $fld->type = $query_array[1]; - $arr = explode(",",$query_array[2]); + $arr = explode(',', $query_array[2]); $fld->enums = $arr; - $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6 + $zlen = max(array_map('strlen', $arr)) - 2; // PHP >= 4.0.6 $fld->max_length = ($zlen > 0) ? $zlen : 1; } else { $fld->type = $type; @@ -143,8 +151,8 @@ class ADODB_pdo_mysql extends ADODB_pdo { $fld->not_null = ($rs->fields[2] != 'YES'); $fld->primary_key = ($rs->fields[3] == 'PRI'); $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false); - $fld->binary = (strpos($type,'blob') !== false); - $fld->unsigned = (strpos($type,'unsigned') !== false); + $fld->binary = (strpos($type, 'blob') !== false); + $fld->unsigned = (strpos($type, 'unsigned') !== false); if (!$fld->binary) { $d = $rs->fields[4]; @@ -161,11 +169,11 @@ class ADODB_pdo_mysql extends ADODB_pdo { } else { $retarr[strtoupper($fld->name)] = $fld; } - $rs->MoveNext(); - } + $rs->MoveNext(); + } - $rs->Close(); - return $retarr; + $rs->Close(); + return $retarr; } // returns true or false @@ -173,106 +181,118 @@ class ADODB_pdo_mysql extends ADODB_pdo { { $this->database = $dbName; $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions - $try = $this->Execute('use '.$dbName); - return ($try !== false) ? true : false; + $try = $this->Execute('use ' . $dbName); + return ($try !== false); } // parameters use PostgreSQL convention, not MySQL - function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0) + function SelectLimit($sql, $nrows=-1, $offset=-1, $inputarr=false, $secs=0) { $offsetStr =($offset>=0) ? "$offset," : ''; // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220 - if ($nrows < 0) $nrows = '18446744073709551615'; + if ($nrows < 0) { + $nrows = '18446744073709551615'; + } - if ($secs) - $rs = $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr); - else - $rs = $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr); + if ($secs) { + $rs = $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows", $inputarr); + } else { + $rs = $this->Execute($sql . " LIMIT $offsetStr$nrows", $inputarr); + } return $rs; } function SQLDate($fmt, $col=false) { - if (!$col) $col = $this->sysTimeStamp; - $s = 'DATE_FORMAT('.$col.",'"; + if (!$col) { + $col = $this->sysTimeStamp; + } + $s = 'DATE_FORMAT(' . $col . ",'"; $concat = false; $len = strlen($fmt); for ($i=0; $i < $len; $i++) { $ch = $fmt[$i]; switch($ch) { - default: - if ($ch == '\\') { - $i++; - $ch = substr($fmt,$i,1); - } - /** FALL THROUGH */ - case '-': - case '/': - $s .= $ch; - break; + default: + if ($ch == '\\') { + $i++; + $ch = substr($fmt, $i, 1); + } + // FALL THROUGH + case '-': + case '/': + $s .= $ch; + break; + + case 'Y': + case 'y': + $s .= '%Y'; + break; - case 'Y': - case 'y': - $s .= '%Y'; - break; - case 'M': - $s .= '%b'; - break; + case 'M': + $s .= '%b'; + break; - case 'm': - $s .= '%m'; - break; - case 'D': - case 'd': - $s .= '%d'; - break; + case 'm': + $s .= '%m'; + break; - case 'Q': - case 'q': - $s .= "'),Quarter($col)"; + case 'D': + case 'd': + $s .= '%d'; + break; - if ($len > $i+1) $s .= ",DATE_FORMAT($col,'"; - else $s .= ",('"; - $concat = true; - break; + case 'Q': + case 'q': + $s .= "'),Quarter($col)"; - case 'H': - $s .= '%H'; - break; + if ($len > $i+1) { + $s .= ",DATE_FORMAT($col,'"; + } else { + $s .= ",('"; + } + $concat = true; + break; - case 'h': - $s .= '%I'; - break; + case 'H': + $s .= '%H'; + break; - case 'i': - $s .= '%i'; - break; + case 'h': + $s .= '%I'; + break; - case 's': - $s .= '%s'; - break; + case 'i': + $s .= '%i'; + break; - case 'a': - case 'A': - $s .= '%p'; - break; + case 's': + $s .= '%s'; + break; - case 'w': - $s .= '%w'; - break; + case 'a': + case 'A': + $s .= '%p'; + break; - case 'W': - $s .= '%U'; - break; + case 'w': + $s .= '%w'; + break; - case 'l': - $s .= '%W'; - break; + case 'W': + $s .= '%U'; + break; + + case 'l': + $s .= '%W'; + break; } } - $s.="')"; - if ($concat) $s = "CONCAT($s)"; + $s .= "')"; + if ($concat) { + $s = "CONCAT($s)"; + } return $s; } } |
