Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
DALMysqlConverter.inc
1 <?php
13 require_once dirname(__FILE__).'/DALConverter.inc';
14 
26 {
27 
34  protected $tableName = '';
35 
42  protected $name = 'MySQL';
43 
50  protected $dataTypes = array(
51  'char' => 'CHAR',
52  'varchar' => 'VARCHAR',
53  'clob' => 'LONGTEXT',
54  'blob' => 'LONGBLOB',
55  'integer' => 'INT',
56  'smallint' => 'SMALLINT',
57  'numeric' => 'NUMERIC',
58  'float' => 'FLOAT',
59  'real' => 'REAL',
60  'double_precision' => 'DOUBLE PRECISION',
61  'boolean' => 'VARCHAR(10)',
62  'date' => 'DATE',
63  'time' => 'TIME',
64  'timestamp' => 'DATETIME',
65  'time with time zone' => 'TIME',
66  );
67 
68 
74  public function __construct()
75  {
76 
77  }//end __construct()
78 
79 
88  public function convertCreateTable(array $table)
89  {
90  $this->tableName = $table['table'];
91 
92  $sql = $this->convertCreateHeader($table);
93  $sql .= "\n".$this->convertCreateColumns($table);
94  $sql .= ')TYPE=InnoDB;';
95 
96  $indexes = $this->convertCreateIndexes($table);
97  if ($indexes !== '') {
98  $sql .= "\n".$indexes;
99  }
100 
101  $constraints = $this->convertAlterQueryAddConstraint($table['CONSTRAINTS'], TRUE);
102  $sql .= "\n".$constraints;
103 
104 
105 
106  if (isset($table['SEQUENCES']) === TRUE) {
107  $sql .= "\n".$this->convertCreateSequences($table['SEQUENCES']);
108  }
109 
110  return $sql;
111 
112  }//end convertCreateTable()
113 
114 
126  protected function convertAlterQueryAddConstraint(array $constraints, $incHeader=FALSE)
127  {
128  $sql = '';
129  if (empty($constraints) === FALSE) {
130  $convertedCons = $this->convertConstraints($constraints, TRUE);
131  $cons = array();
132  foreach ($convertedCons as $constraint) {
133  $sql = '';
134  if ($incHeader === TRUE) {
135  $sql .= $this->convertAlterQueryHeader($this->tableName);
136  }
137 
138  $sql .= 'ADD '.$constraint;
139 
140  $cons[] = $sql;
141  }
142 
143  $sql = implode(";\n", $cons).";\n";
144  }
145 
146  return $sql;
147 
148  }//end convertAlterQueryAddConstraint()
149 
150 
159  protected function convertSingleSequence($sequence)
160  {
161  $sql = 'CREATE TABLE '.$sequence.' (
162  id INT AUTO_INCREMENT NOT NULL PRIMARY KEY)';
163 
164  return $sql;
165 
166  }//end convertSingleSequence()
167 
168 
179  protected function handleFunctionSeqNextVal(array $seqName)
180  {
181  $sql = 'INSERT INTO '.$seqName[0].' VALUES(0)';
182  return $sql;
183 
184  }//end handleFunctionSeqNextVal()
185 
186 
198  protected function handleFunctionSeqCurrVal(array $seqName)
199  {
200  $sql = 'SELECT LAST_INSERT_ID()';
201  return $sql;
202 
203  }//end handleFunctionSeqCurrVal()
204 
205 
216  public function convertDropSequence($sequenceName)
217  {
218  $sql = $this->convertDropTable($sequenceName);
219  return $sql;
220 
221  }//end convertDropSequence()
222 
223 
235  protected function handleFunctionToDate(array $args)
236  {
237  $iso8601_date = $this->convertSingleField($args[0]);
238 
239  // There does not appear to be any requirement for dates to be
240  // handled any other way than being quoted in MySQL
241  $sql = $iso8601_date;
242  return $sql;
243 
244  }//end handleFunctionToDate()
245 
246 
255  public function convertDropTable($tableName)
256  {
257  $sql = 'DROP TABLE IF EXISTS '.$tableName;
258  return $sql;
259 
260  }//end convertDropTable()
261 
262 
271  public function handleFunctionSequenceExists($sequenceName)
272  {
273  return $this->handleFunctionTableExists($sequenceName);
274 
275  }//end handleFunctionSequenceExists()
276 
277 
286  protected function handleFunctionConcat(array $args)
287  {
288  $sql = 'CONCAT('.implode(', ', $args).')';
289  return $sql;
290 
291  }//end handleFunctionConcat()
292 
293 
302  protected function convertCallQuery(array $callQuery)
303  {
304  $sql = 'SELECT ';
305  $sql .= $this->convertSingleFunction($callQuery);
306  return $sql;
307 
308  }//end convertCallQuery()
309 
310 
311 }//end class
312 
313 ?>