1: <?php
2:
3: if (!defined('MYSQLI_ON_UPDATE_NOW_FLAG')) {
4: define ('MYSQLI_ON_UPDATE_NOW_FLAG', 8192);
5: }
6: 7: 8: 9:
10: class QMySqliDatabase extends QDatabaseBase {
11: const Adapter = 'MySql Improved Database Adapter for MySQL 4';
12:
13: protected $objMySqli;
14:
15: protected $strEscapeIdentifierBegin = '`';
16: protected $strEscapeIdentifierEnd = '`';
17:
18: public function SqlLimitVariablePrefix($strLimitInfo) {
19:
20:
21:
22: if (array_key_exists('usefoundrows', $this->objConfigArray) && $this->objConfigArray['usefoundrows'])
23: return 'SQL_CALC_FOUND_ROWS';
24:
25: return null;
26: }
27:
28: public function SqlLimitVariableSuffix($strLimitInfo) {
29:
30: if (strlen($strLimitInfo)) {
31: if (strpos($strLimitInfo, ';') !== false)
32: throw new Exception('Invalid Semicolon in LIMIT Info');
33: if (strpos($strLimitInfo, '`') !== false)
34: throw new Exception('Invalid Backtick in LIMIT Info');
35: return "LIMIT $strLimitInfo";
36: }
37:
38: return null;
39: }
40:
41: public function SqlSortByVariable($strSortByInfo) {
42:
43: if (strlen($strSortByInfo)) {
44: if (strpos($strSortByInfo, ';') !== false)
45: throw new Exception('Invalid Semicolon in ORDER BY Info');
46: if (strpos($strSortByInfo, '`') !== false)
47: throw new Exception('Invalid Backtick in ORDER BY Info');
48:
49: return "ORDER BY $strSortByInfo";
50: }
51:
52: return null;
53: }
54:
55: public function InsertOrUpdate($strTable, $mixColumnsAndValuesArray, $strPKNames = null) {
56: $strEscapedArray = $this->EscapeIdentifiersAndValues($mixColumnsAndValuesArray);
57: $strUpdateStatement = '';
58: foreach ($strEscapedArray as $strColumn => $strValue) {
59: if ($strUpdateStatement) $strUpdateStatement .= ', ';
60: $strUpdateStatement .= $strColumn . ' = ' . $strValue;
61: }
62: $strSql = sprintf('INSERT INTO %s%s%s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE %s',
63: $this->EscapeIdentifierBegin, $strTable, $this->EscapeIdentifierEnd,
64: implode(', ', array_keys($strEscapedArray)),
65: implode(', ', array_values($strEscapedArray)),
66: $strUpdateStatement
67: );
68: $this->ExecuteNonQuery($strSql);
69: }
70:
71: public function Connect() {
72:
73: $this->objMySqli = new MySqli($this->Server, $this->Username, $this->Password, $this->Database, $this->Port);
74:
75: if (!$this->objMySqli)
76: throw new QMySqliDatabaseException("Unable to connect to Database", -1, null);
77:
78: if ($this->objMySqli->error)
79: throw new QMySqliDatabaseException($this->objMySqli->error, $this->objMySqli->errno, null);
80:
81:
82: $this->blnConnectedFlag = true;
83:
84:
85: $this->NonQuery('SET AUTOCOMMIT=1;');
86:
87:
88: if (array_key_exists('encoding', $this->objConfigArray))
89: $this->NonQuery('SET NAMES ' . $this->objConfigArray['encoding'] . ';');
90: }
91:
92: public function __get($strName) {
93: switch ($strName) {
94: case 'AffectedRows':
95: return $this->objMySqli->affected_rows;
96: default:
97: try {
98: return parent::__get($strName);
99: } catch (QCallerException $objExc) {
100: $objExc->IncrementOffset();
101: throw $objExc;
102: }
103: }
104: }
105:
106: protected function ExecuteQuery($strQuery) {
107:
108: $objResult = $this->objMySqli->query($strQuery);
109: if ($this->objMySqli->error)
110: throw new QMySqliDatabaseException($this->objMySqli->error, $this->objMySqli->errno, $strQuery);
111:
112:
113: $objMySqliDatabaseResult = new QMySqliDatabaseResult($objResult, $this);
114: return $objMySqliDatabaseResult;
115: }
116:
117: protected function ExecuteNonQuery($strNonQuery) {
118:
119: $this->objMySqli->query($strNonQuery);
120: if ($this->objMySqli->error)
121: throw new QMySqliDatabaseException($this->objMySqli->error, $this->objMySqli->errno, $strNonQuery);
122: }
123:
124: public function GetTables() {
125:
126: $objResult = $this->Query("SHOW TABLES");
127: $strToReturn = array();
128: while ($strRowArray = $objResult->FetchRow())
129: array_push($strToReturn, $strRowArray[0]);
130: return $strToReturn;
131: }
132:
133: public function GetFieldsForTable($strTableName) {
134: $objResult = $this->Query(sprintf('SELECT * FROM %s%s%s LIMIT 1', $this->strEscapeIdentifierBegin, $strTableName, $this->strEscapeIdentifierEnd));
135: return $objResult->FetchFields();
136: }
137:
138: public function InsertId($strTableName = null, $strColumnName = null) {
139: return $this->objMySqli->insert_id;
140: }
141:
142: public function Close() {
143: $this->objMySqli->close();
144:
145:
146: $this->blnConnectedFlag = false;
147: }
148:
149: protected function ExecuteTransactionBegin() {
150:
151: $this->NonQuery('SET AUTOCOMMIT=0;');
152: }
153:
154: protected function ExecuteTransactionCommit() {
155: $this->NonQuery('COMMIT;');
156:
157: $this->NonQuery('SET AUTOCOMMIT=1;');
158: }
159:
160: protected function ExecuteTransactionRollBack() {
161: $this->NonQuery('ROLLBACK;');
162:
163: $this->NonQuery('SET AUTOCOMMIT=1;');
164: }
165:
166: public function GetFoundRows() {
167: if (array_key_exists('usefoundrows', $this->objConfigArray) && $this->objConfigArray['usefoundrows']) {
168: $objResult = $this->Query('SELECT FOUND_ROWS();');
169: $strRow = $objResult->FetchArray();
170: return $strRow[0];
171: } else
172: throw new QCallerException('Cannot call GetFoundRows() on the database when "usefoundrows" configuration was not set to true.');
173: }
174:
175: public function GetIndexesForTable($strTableName) {
176:
177: $strCreateStatement = $this->GetCreateStatementForTable($strTableName);
178: $strTableType = $this->GetTableTypeForCreateStatement($strCreateStatement);
179:
180: switch (true) {
181: case substr($strTableType, 0, 6) == 'MYISAM':
182: return $this->ParseForIndexes($strCreateStatement);
183:
184: case substr($strTableType, 0, 6) == 'INNODB':
185: return $this->ParseForIndexes($strCreateStatement);
186:
187: case substr($strTableType, 0, 6) == 'MEMORY':
188: case substr($strTableType, 0, 4) == 'HEAP':
189: return $this->ParseForIndexes($strCreateStatement);
190:
191: default:
192: throw new Exception("Table Type is not supported: $strTableType");
193: }
194: }
195:
196: public function GetForeignKeysForTable($strTableName) {
197:
198: $strCreateStatement = $this->GetCreateStatementForTable($strTableName);
199: $strTableType = $this->GetTableTypeForCreateStatement($strCreateStatement);
200:
201: switch (true) {
202: case substr($strTableType, 0, 6) == 'MYISAM':
203: $objForeignKeyArray = array();
204: break;
205:
206: case substr($strTableType, 0, 6) == 'MEMORY':
207: case substr($strTableType, 0, 4) == 'HEAP':
208: $objForeignKeyArray = array();
209: break;
210:
211: case substr($strTableType, 0, 6) == 'INNODB':
212: $objForeignKeyArray = $this->ParseForInnoDbForeignKeys($strCreateStatement);
213: break;
214:
215: default:
216: throw new Exception("Table Type is not supported: $strTableType");
217: }
218:
219: return $objForeignKeyArray;
220: }
221:
222:
223:
224: private function ParseNameFromKeyDefinition($strKeyDefinition) {
225: $strKeyDefinition = trim($strKeyDefinition);
226:
227: $intPosition = strpos($strKeyDefinition, '(');
228:
229: if ($intPosition === false)
230: throw new Exception("Invalid Key Definition: $strKeyDefinition");
231: else if ($intPosition == 0)
232:
233: return null;
234:
235:
236: $strName = trim(substr($strKeyDefinition, 0, $intPosition));
237:
238:
239: if (substr($strName, 0, 1) == '`')
240: return substr($strName, 1, strlen($strName) - 2);
241: else
242: return $strName;
243: }
244:
245:
246:
247: private function ParseColumnNameArrayFromKeyDefinition($strKeyDefinition) {
248: $strKeyDefinition = trim($strKeyDefinition);
249:
250:
251: $intPosition = strpos($strKeyDefinition, '(');
252: if ($intPosition === false)
253: throw new Exception("Invalid Key Definition: $strKeyDefinition");
254: $strKeyDefinition = trim(substr($strKeyDefinition, $intPosition + 1));
255:
256: $intPosition = strpos($strKeyDefinition, ')');
257: if ($intPosition === false)
258: throw new Exception("Invalid Key Definition: $strKeyDefinition");
259: $strKeyDefinition = trim(substr($strKeyDefinition, 0, $intPosition));
260:
261:
262:
263: $strToReturn = explode(',', $strKeyDefinition);
264:
265:
266: for ($intIndex = 0; $intIndex < count($strToReturn); $intIndex++) {
267: $strColumn = $strToReturn[$intIndex];
268:
269: if (substr($strColumn, 0, 1) == '`')
270: $strColumn = substr($strColumn, 1, strpos($strColumn, '`', 1) - 1);
271:
272: $strToReturn[$intIndex] = $strColumn;
273: }
274:
275: return $strToReturn;
276: }
277:
278: private function ParseForIndexes($strCreateStatement) {
279:
280:
281:
282: $strLineArray = explode("\n", $strCreateStatement);
283:
284: $objIndexArray = array();
285:
286:
287: for ($intIndex = 1; $intIndex < (count($strLineArray) - 1); $intIndex++) {
288: $strLine = $strLineArray[$intIndex];
289:
290:
291:
292: switch (2) {
293: case (strpos($strLine, 'PRIMARY KEY')):
294: $strKeyDefinition = substr($strLine, strlen(' PRIMARY KEY '));
295:
296: $strKeyName = $this->ParseNameFromKeyDefinition($strKeyDefinition);
297: $strColumnNameArray = $this->ParseColumnNameArrayFromKeyDefinition($strKeyDefinition);
298:
299: $objIndex = new QDatabaseIndex($strKeyName, $blnPrimaryKey = true, $blnUnique = true, $strColumnNameArray);
300: array_push($objIndexArray, $objIndex);
301: break;
302:
303: case (strpos($strLine, 'UNIQUE KEY')):
304: $strKeyDefinition = substr($strLine, strlen(' UNIQUE KEY '));
305:
306: $strKeyName = $this->ParseNameFromKeyDefinition($strKeyDefinition);
307: $strColumnNameArray = $this->ParseColumnNameArrayFromKeyDefinition($strKeyDefinition);
308:
309: $objIndex = new QDatabaseIndex($strKeyName, $blnPrimaryKey = false, $blnUnique = true, $strColumnNameArray);
310: array_push($objIndexArray, $objIndex);
311: break;
312:
313: case (strpos($strLine, 'KEY')):
314: $strKeyDefinition = substr($strLine, strlen(' KEY '));
315:
316: $strKeyName = $this->ParseNameFromKeyDefinition($strKeyDefinition);
317: $strColumnNameArray = $this->ParseColumnNameArrayFromKeyDefinition($strKeyDefinition);
318:
319: $objIndex = new QDatabaseIndex($strKeyName, $blnPrimaryKey = false, $blnUnique = false, $strColumnNameArray);
320: array_push($objIndexArray, $objIndex);
321: break;
322: }
323: }
324:
325: return $objIndexArray;
326: }
327:
328: private function ParseForInnoDbForeignKeys($strCreateStatement) {
329:
330:
331:
332: $strLineArray = explode("\n", $strCreateStatement);
333:
334: $objForeignKeyArray = array();
335:
336:
337: for ($intIndex = 1; $intIndex < (count($strLineArray) - 1); $intIndex++) {
338: $strLine = $strLineArray[$intIndex];
339:
340:
341:
342:
343: if ((strpos($strLine, "CONSTRAINT") == 2) &&
344: (strpos($strLine, "FOREIGN KEY") !== false)) {
345: $strLine = substr($strLine, strlen(' CONSTRAINT '));
346:
347:
348:
349:
350:
351:
352: $strTokenArray = explode(' FOREIGN KEY ', $strLine);
353: $strTokenArray[1] = explode(' REFERENCES ', $strTokenArray[1]);
354: $strTokenArray[2] = $strTokenArray[1][1];
355: $strTokenArray[1] = $strTokenArray[1][0];
356: $strTokenArray[2] = explode(' ', $strTokenArray[2]);
357: $strTokenArray[3] = $strTokenArray[2][1];
358: $strTokenArray[2] = $strTokenArray[2][0];
359:
360:
361:
362: if (substr($strTokenArray[0], 0, 1) == '`')
363: $strTokenArray[0] = substr($strTokenArray[0], 1, strlen($strTokenArray[0]) - 2);
364: $strTokenArray[1] = $this->ParseColumnNameArrayFromKeyDefinition($strTokenArray[1]);
365: if (substr($strTokenArray[2], 0, 1) == '`')
366: $strTokenArray[2] = substr($strTokenArray[2], 1, strlen($strTokenArray[2]) - 2);
367: $strTokenArray[3] = $this->ParseColumnNameArrayFromKeyDefinition($strTokenArray[3]);
368:
369:
370: $objForeignKey = new QDatabaseForeignKey($strTokenArray[0], $strTokenArray[1], $strTokenArray[2], $strTokenArray[3]);
371: array_push($objForeignKeyArray, $objForeignKey);
372:
373:
374: if ((count($objForeignKey->ColumnNameArray) == 0) ||
375: (count($objForeignKey->ColumnNameArray) != count($objForeignKey->ReferenceColumnNameArray)))
376: throw new Exception("Invalid Foreign Key definition: $strLine");
377: }
378: }
379: return $objForeignKeyArray;
380: }
381:
382: private function GetCreateStatementForTable($strTableName) {
383:
384: $objResult = $this->Query(sprintf('SHOW CREATE TABLE `%s`', $strTableName));
385: $objRow = $objResult->FetchRow();
386: $strCreateTable = $objRow[1];
387: $strCreateTable = str_replace("\r", "", $strCreateTable);
388: return $strCreateTable;
389: }
390:
391: private function GetTableTypeForCreateStatement($strCreateStatement) {
392:
393: $strLineArray = explode("\n", $strCreateStatement);
394: $strFinalLine = strtoupper($strLineArray[count($strLineArray) - 1]);
395:
396: if (substr($strFinalLine, 0, 7) == ') TYPE=') {
397: return trim(substr($strFinalLine, 7));
398: } else if (substr($strFinalLine, 0, 9) == ') ENGINE=') {
399: return trim(substr($strFinalLine, 9));
400: } else
401: throw new Exception("Invalid Table Description");
402: }
403:
404: 405: 406: 407: 408:
409: public function ExplainStatement($sql) {
410:
411:
412:
413:
414: $objDbResult = $this->Query("select version()");
415: $strDbRow = $objDbResult->FetchRow();
416: $strVersion = QType::Cast($strDbRow[0], QType::String);
417: $strVersionArray = explode('.', $strVersion);
418: $strMajorVersion = null;
419: if (count($strVersionArray) > 0) {
420: $strMajorVersion = $strVersionArray[0];
421: }
422: if (null === $strMajorVersion) {
423: return null;
424: }
425: if (intval($strMajorVersion) > 5) {
426: return $this->Query("EXPLAIN " . $sql);
427: } else if (5 == intval($strMajorVersion)) {
428: $strMinorVersion = null;
429: if (count($strVersionArray) > 1) {
430: $strMinorVersion = $strVersionArray[1];
431: }
432: if (null === $strMinorVersion) {
433: return null;
434: }
435: if (intval($strMinorVersion) > 6) {
436: return $this->Query("EXPLAIN " . $sql);
437: } else if (6 == intval($strMinorVersion)) {
438: $strSubMinorVersion = null;
439: if (count($strVersionArray) > 2) {
440: $strSubMinorVersion = $strVersionArray[2];
441: }
442: if (null === $strSubMinorVersion) {
443: return null;
444: }
445: if (!is_integer($strSubMinorVersion)) {
446: $strSubMinorVersionArray = explode("-", $strSubMinorVersion);
447: if (count($strSubMinorVersionArray) > 1) {
448: $strSubMinorVersion = $strSubMinorVersionArray[0];
449: if (!is_integer($strSubMinorVersion)) {
450:
451: return null;
452: }
453: } else {
454:
455: return null;
456: }
457: }
458: if (intval($strSubMinorVersion) > 2) {
459: return $this->Query("EXPLAIN " . $sql);
460: } else {
461:
462:
463: if (0 == substr_count($sql, "DELETE") &&
464: 0 == substr_count($sql, "INSERT") &&
465: 0 == substr_count($sql, "REPLACE") &&
466: 0 == substr_count($sql, "UPDATE")
467: ) {
468: return $this->Query("EXPLAIN " . $sql);
469: }
470: }
471: }
472: }
473:
474: return null;
475: }
476: }
477:
478: 479: 480: 481:
482: class QMySqliDatabaseException extends QDatabaseExceptionBase {
483: public function __construct($strMessage, $intNumber, $strQuery) {
484: parent::__construct(sprintf("MySqli Error: %s", $strMessage), 2);
485: $this->intErrorNumber = $intNumber;
486: $this->strQuery = $strQuery;
487: }
488: }
489:
490: 491: 492: 493:
494: class QMySqliDatabaseResult extends QDatabaseResultBase {
495: protected $objMySqliResult;
496: protected $objDb;
497:
498: public function __construct(mysqli_result $objResult, QMySqliDatabase $objDb) {
499: $this->objMySqliResult = $objResult;
500: $this->objDb = $objDb;
501: }
502:
503: public function FetchArray() {
504: return $this->objMySqliResult->fetch_array();
505: }
506:
507: public function FetchFields() {
508: $objArrayToReturn = array();
509: while ($objField = $this->objMySqliResult->fetch_field())
510: array_push($objArrayToReturn, new QMySqliDatabaseField($objField, $this->objDb));
511: return $objArrayToReturn;
512: }
513:
514: public function FetchField() {
515: if ($objField = $this->objMySqliResult->fetch_field())
516: return new QMySqliDatabaseField($objField, $this->objDb);
517: }
518:
519: public function FetchRow() {
520: return $this->objMySqliResult->fetch_row();
521: }
522:
523: public function MySqlFetchField() {
524: return $this->objMySqliResult->fetch_field();
525: }
526:
527: public function CountRows() {
528: return $this->objMySqliResult->num_rows;
529: }
530:
531: public function CountFields() {
532: return $this->objMySqliResult->num_fields();
533: }
534:
535: public function Close() {
536: $this->objMySqliResult->free();
537: }
538:
539: public function GetNextRow() {
540: $strColumnArray = $this->FetchArray();
541:
542: if ($strColumnArray)
543: return new QMySqliDatabaseRow($strColumnArray);
544: else
545: return null;
546: }
547:
548: public function GetRows() {
549: $objDbRowArray = array();
550: while ($objDbRow = $this->GetNextRow())
551: array_push($objDbRowArray, $objDbRow);
552: return $objDbRowArray;
553: }
554: }
555:
556: 557: 558: 559:
560: class QMySqliDatabaseRow extends QDatabaseRowBase {
561: protected $strColumnArray;
562:
563: public function __construct($strColumnArray) {
564: $this->strColumnArray = $strColumnArray;
565: }
566:
567: 568: 569: 570: 571: 572: 573: 574:
575: public function GetColumn($strColumnName, $strColumnType = null) {
576: if (!isset($this->strColumnArray[$strColumnName])) {
577: return null;
578: }
579: $strColumnValue = $this->strColumnArray[$strColumnName];
580:
581: switch ($strColumnType) {
582: case QDatabaseFieldType::Bit:
583:
584: $chrBit = $strColumnValue;
585: if ((strlen($chrBit) == 1) && (ord($chrBit) == 0))
586: return false;
587:
588:
589: return ($strColumnValue) ? true : false;
590:
591: case QDatabaseFieldType::Blob:
592: case QDatabaseFieldType::Char:
593: case QDatabaseFieldType::VarChar:
594: return QType::Cast($strColumnValue, QType::String);
595:
596: case QDatabaseFieldType::Date:
597: return new QDateTime($strColumnValue, null, QDateTime::DateOnlyType);
598: case QDatabaseFieldType::DateTime:
599: return new QDateTime($strColumnValue, null, QDateTime::DateAndTimeType);
600: case QDatabaseFieldType::Time:
601: return new QDateTime($strColumnValue, null, QDateTime::TimeOnlyType);
602:
603: case QDatabaseFieldType::Float:
604: return QType::Cast($strColumnValue, QType::Float);
605:
606: case QDatabaseFieldType::Integer:
607: return QType::Cast($strColumnValue, QType::Integer);
608:
609: default:
610: return $strColumnValue;
611: }
612: }
613:
614: 615: 616: 617: 618: 619: 620:
621: public function ColumnExists($strColumnName) {
622: return array_key_exists($strColumnName, $this->strColumnArray);
623: }
624:
625: public function GetColumnNameArray() {
626: return $this->strColumnArray;
627: }
628: }
629:
630: 631: 632: 633:
634: class QMySqliDatabaseField extends QDatabaseFieldBase {
635: public function __construct($mixFieldData, $objDb = null) {
636: $this->strName = $mixFieldData->name;
637: $this->strOriginalName = $mixFieldData->orgname;
638: $this->strTable = $mixFieldData->table;
639: $this->strOriginalTable = $mixFieldData->orgtable;
640: $this->strDefault = $mixFieldData->def;
641: $this->intMaxLength = null;
642: $this->strComment = null;
643:
644:
645: if (!$this->strOriginalName)
646: $this->strOriginalName = $this->strName;
647:
648: if($this->strOriginalTable)
649: {
650: $objDescriptionResult = $objDb->Query(sprintf("SHOW FULL FIELDS FROM `%s`", $this->strOriginalTable));
651: while (($objRow = $objDescriptionResult->FetchArray())) {
652: if ($objRow["Field"] == $this->strOriginalName) {
653:
654: $this->strDefault = $objRow["Default"];
655:
656:
657: $strLengthArray = explode("(", $objRow["Type"]);
658: if ((count($strLengthArray) > 1) &&
659: (strtolower($strLengthArray[0]) != 'enum') &&
660: (strtolower($strLengthArray[0]) != 'set')) {
661: $strLengthArray = explode(")", $strLengthArray[1]);
662: $this->intMaxLength = $strLengthArray[0];
663:
664:
665: $intCommaPosition = strpos($this->intMaxLength, ',');
666: if ($intCommaPosition !== false) {
667: $this->intMaxLength = substr($this->intMaxLength, 0, $intCommaPosition);
668: $this->intMaxLength++;
669: }
670:
671: if (!is_numeric($this->intMaxLength)) {
672: throw new Exception("Not a valid Column Length: " . $objRow["Type"]);
673: }
674: }
675:
676:
677: $this->strComment = $objRow["Comment"];
678: }
679: }
680: }
681:
682: $this->blnIdentity = ($mixFieldData->flags & MYSQLI_AUTO_INCREMENT_FLAG) ? true: false;
683: $this->blnNotNull = ($mixFieldData->flags & MYSQLI_NOT_NULL_FLAG) ? true : false;
684: $this->blnPrimaryKey = ($mixFieldData->flags & MYSQLI_PRI_KEY_FLAG) ? true : false;
685: $this->blnUnique = ($mixFieldData->flags & MYSQLI_UNIQUE_KEY_FLAG) ? true : false;
686:
687: $this->SetFieldType($mixFieldData->type);
688:
689:
690: if ($mixFieldData->type == MYSQLI_TYPE_TIMESTAMP &&
691: $mixFieldData->flags & MYSQLI_ON_UPDATE_NOW_FLAG) {
692: $this->strType = QDatabaseFieldType::VarChar;
693: $this->blnTimestamp = true;
694: }
695: }
696:
697: protected function SetFieldType($intMySqlFieldType) {
698:
699: if (version_compare(PHP_VERSION, '5.6.15') >= 0) {
700: if ($intMySqlFieldType == MYSQLI_TYPE_JSON) {
701: $this->strType = QDatabaseFieldType::Json;
702: return;
703: }
704: }
705: switch ($intMySqlFieldType) {
706: case MYSQLI_TYPE_TINY:
707: if ($this->intMaxLength == 1)
708: $this->strType = QDatabaseFieldType::Bit;
709: else
710: $this->strType = QDatabaseFieldType::Integer;
711: break;
712: case MYSQLI_TYPE_SHORT:
713: case MYSQLI_TYPE_LONG:
714: case MYSQLI_TYPE_LONGLONG:
715: case MYSQLI_TYPE_INT24:
716: $this->strType = QDatabaseFieldType::Integer;
717: break;
718: case MYSQLI_TYPE_NEWDECIMAL:
719: case MYSQLI_TYPE_DECIMAL:
720:
721:
722:
723:
724: $this->strType = QDatabaseFieldType::VarChar;
725: break;
726:
727: case MYSQLI_TYPE_FLOAT:
728: $this->strType = QDatabaseFieldType::Float;
729: break;
730: case MYSQLI_TYPE_DOUBLE:
731:
732:
733:
734:
735: $this->strType = QDatabaseFieldType::VarChar;
736: break;
737: case MYSQLI_TYPE_DATE:
738: $this->strType = QDatabaseFieldType::Date;
739: break;
740: case MYSQLI_TYPE_TIME:
741: $this->strType = QDatabaseFieldType::Time;
742: break;
743: case MYSQLI_TYPE_TIMESTAMP:
744: case MYSQLI_TYPE_DATETIME:
745: $this->strType = QDatabaseFieldType::DateTime;
746: break;
747: case MYSQLI_TYPE_TINY_BLOB:
748: case MYSQLI_TYPE_MEDIUM_BLOB:
749: case MYSQLI_TYPE_LONG_BLOB:
750: case MYSQLI_TYPE_BLOB:
751: $this->strType = QDatabaseFieldType::Blob;
752: break;
753: case MYSQLI_TYPE_STRING:
754: case MYSQLI_TYPE_VAR_STRING:
755: $this->strType = QDatabaseFieldType::VarChar;
756: break;
757: case MYSQLI_TYPE_CHAR:
758: $this->strType = QDatabaseFieldType::Char;
759: break;
760: case MYSQLI_TYPE_INTERVAL:
761: throw new Exception("QCubed MySqliDatabase library: MYSQLI_TYPE_INTERVAL is not supported");
762: break;
763: case MYSQLI_TYPE_NULL:
764: throw new Exception("QCubed MySqliDatabase library: MYSQLI_TYPE_NULL is not supported");
765: break;
766: case MYSQLI_TYPE_YEAR:
767: $this->strType = QDatabaseFieldType::Integer;
768: break;
769: case MYSQLI_TYPE_NEWDATE:
770: throw new Exception("QCubed MySqliDatabase library: MYSQLI_TYPE_NEWDATE is not supported");
771: break;
772: case MYSQLI_TYPE_ENUM:
773: throw new Exception("QCubed MySqliDatabase library: MYSQLI_TYPE_ENUM is not supported. Use TypeTables instead.");
774: break;
775: case MYSQLI_TYPE_SET:
776: throw new Exception("QCubed MySqliDatabase library: MYSQLI_TYPE_SET is not supported. Use TypeTables instead.");
777: break;
778: case MYSQLI_TYPE_GEOMETRY:
779: throw new Exception("QCubed MySqliDatabase library: MYSQLI_TYPE_GEOMETRY is not supported");
780: break;
781: default:
782: throw new Exception("Unable to determine MySqli Database Field Type: " . $intMySqlFieldType);
783: break;
784: }
785: }
786: }