PageRenderTime 45ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/concreteOLD/libraries/3rdparty/adodb/datadict/datadict-mysql.inc.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 182 lines | 118 code | 32 blank | 32 comment | 23 complexity | b443fccee206f7c4049ebabdffdbf2a1 MD5 | raw file
  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 4 for best viewing.
  8. */
  9. // security - hide paths
  10. if (!defined('ADODB_DIR')) die();
  11. class ADODB2_mysql extends ADODB_DataDict {
  12. var $databaseType = 'mysql';
  13. var $alterCol = ' MODIFY COLUMN';
  14. var $alterTableAddIndex = true;
  15. var $dropTable = 'DROP TABLE IF EXISTS %s'; // requires mysql 3.22 or later
  16. var $dropIndex = 'DROP INDEX %s ON %s';
  17. var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s'; // needs column-definition!
  18. function MetaType($t,$len=-1,$fieldobj=false)
  19. {
  20. if (is_object($t)) {
  21. $fieldobj = $t;
  22. $t = $fieldobj->type;
  23. $len = $fieldobj->max_length;
  24. }
  25. $is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->auto_increment;
  26. $len = -1; // mysql max_length is not accurate
  27. switch (strtoupper($t)) {
  28. case 'STRING':
  29. case 'CHAR':
  30. case 'VARCHAR':
  31. case 'TINYBLOB':
  32. case 'TINYTEXT':
  33. case 'ENUM':
  34. case 'SET':
  35. if ($len <= $this->blobSize) return 'C';
  36. case 'TEXT':
  37. case 'LONGTEXT':
  38. case 'MEDIUMTEXT':
  39. return 'X';
  40. // php_mysql extension always returns 'blob' even if 'text'
  41. // so we have to check whether binary...
  42. case 'IMAGE':
  43. case 'LONGBLOB':
  44. case 'BLOB':
  45. case 'MEDIUMBLOB':
  46. return !empty($fieldobj->binary) ? 'B' : 'X';
  47. case 'YEAR':
  48. case 'DATE': return 'D';
  49. case 'TIME':
  50. case 'DATETIME':
  51. case 'TIMESTAMP': return 'T';
  52. case 'FLOAT':
  53. case 'DOUBLE':
  54. return 'F';
  55. case 'INT':
  56. case 'INTEGER': return $is_serial ? 'R' : 'I';
  57. case 'TINYINT': return $is_serial ? 'R' : 'I1';
  58. case 'SMALLINT': return $is_serial ? 'R' : 'I2';
  59. case 'MEDIUMINT': return $is_serial ? 'R' : 'I4';
  60. case 'BIGINT': return $is_serial ? 'R' : 'I8';
  61. default: return 'N';
  62. }
  63. }
  64. function ActualType($meta)
  65. {
  66. switch(strtoupper($meta)) {
  67. case 'C': return 'VARCHAR';
  68. case 'XL':return 'LONGTEXT';
  69. case 'X': return 'TEXT';
  70. case 'C2': return 'VARCHAR';
  71. case 'X2': return 'LONGTEXT';
  72. case 'B': return 'LONGBLOB';
  73. case 'D': return 'DATE';
  74. case 'TS':
  75. case 'T': return 'DATETIME';
  76. case 'L': return 'TINYINT';
  77. case 'R':
  78. case 'I4':
  79. case 'I': return 'INTEGER';
  80. case 'I1': return 'TINYINT';
  81. case 'I2': return 'SMALLINT';
  82. case 'I8': return 'BIGINT';
  83. case 'F': return 'DOUBLE';
  84. case 'N': return 'NUMERIC';
  85. default:
  86. return $meta;
  87. }
  88. }
  89. // return string must begin with space
  90. function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
  91. {
  92. $suffix = '';
  93. if ($funsigned) $suffix .= ' UNSIGNED';
  94. if ($fnotnull) $suffix .= ' NOT NULL';
  95. if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
  96. if ($fautoinc) $suffix .= ' AUTO_INCREMENT';
  97. if ($fconstraint) $suffix .= ' '.$fconstraint;
  98. return $suffix;
  99. }
  100. /*
  101. CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
  102. [table_options] [select_statement]
  103. create_definition:
  104. col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
  105. [PRIMARY KEY] [reference_definition]
  106. or PRIMARY KEY (index_col_name,...)
  107. or KEY [index_name] (index_col_name,...)
  108. or INDEX [index_name] (index_col_name,...)
  109. or UNIQUE [INDEX] [index_name] (index_col_name,...)
  110. or FULLTEXT [INDEX] [index_name] (index_col_name,...)
  111. or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...)
  112. [reference_definition]
  113. or CHECK (expr)
  114. */
  115. /*
  116. CREATE [UNIQUE|FULLTEXT] INDEX index_name
  117. ON tbl_name (col_name[(length)],... )
  118. */
  119. function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
  120. {
  121. $sql = array();
  122. if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
  123. if ($this->alterTableAddIndex) $sql[] = "ALTER TABLE $tabname DROP INDEX $idxname";
  124. else $sql[] = sprintf($this->dropIndex, $idxname, $tabname);
  125. if ( isset($idxoptions['DROP']) )
  126. return $sql;
  127. }
  128. if ( empty ($flds) ) {
  129. return $sql;
  130. }
  131. if (isset($idxoptions['FULLTEXT'])) {
  132. $unique = ' FULLTEXT';
  133. } elseif (isset($idxoptions['UNIQUE'])) {
  134. $unique = ' UNIQUE';
  135. } else {
  136. $unique = '';
  137. }
  138. if ( is_array($flds) ) $flds = implode(', ',$flds);
  139. if ($this->alterTableAddIndex) $s = "ALTER TABLE $tabname ADD $unique INDEX $idxname ";
  140. else $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname;
  141. $s .= ' (' . $flds . ')';
  142. if ( isset($idxoptions[$this->upperName]) )
  143. $s .= $idxoptions[$this->upperName];
  144. $sql[] = $s;
  145. return $sql;
  146. }
  147. }
  148. ?>