PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/MantisBT/library/adodb/drivers/adodb-pdo_mysql.inc.php

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