summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Newnham <mark@newnhams.com>2020-12-12 17:34:01 -0700
committerGitHub <noreply@github.com>2020-12-12 17:34:01 -0700
commitfae7f92925c99b44d01f82edb8553d143f446ac7 (patch)
treeaf36a03c11e23fb35fe5c09b7e23b1c9204394ca
parent3b3adc88fc2e924ceaa9f59eecb951f4fa272838 (diff)
downloadadodb-fae7f92925c99b44d01f82edb8553d143f446ac7.tar.gz
adodb-fae7f92925c99b44d01f82edb8553d143f446ac7.tar.bz2
adodb-fae7f92925c99b44d01f82edb8553d143f446ac7.zip
Mysqli metacolumns (#653)
* Add support for MySQL Version 8. See #642 The metacolumns function returns the incorrect type for unsigned integers because it doesn't include the length in MySQL 8 * Metacolumns returns wrong type for integer fields in Mysql 8 #642
-rw-r--r--drivers/adodb-mysqli.inc.php20
1 files changed, 20 insertions, 0 deletions
diff --git a/drivers/adodb-mysqli.inc.php b/drivers/adodb-mysqli.inc.php
index 56b48da7..9f4dd2c6 100644
--- a/drivers/adodb-mysqli.inc.php
+++ b/drivers/adodb-mysqli.inc.php
@@ -629,6 +629,19 @@ class ADODB_mysqli extends ADOConnection {
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false)
$savem = $this->SetFetchMode(false);
+ /*
+ * Return assoc array where key is column name, value is column type
+ * [1] => int unsigned
+ */
+
+ $SQL = "SELECT column_name, column_type
+ FROM information_schema.columns
+ WHERE table_schema='{$this->databaseName}'
+ AND table_name='$table'";
+
+ $schemaArray = $this->getAssoc($SQL);
+ $schemaArray = array_change_key_case($schemaArray,CASE_LOWER);
+
$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
@@ -640,6 +653,12 @@ class ADODB_mysqli extends ADOConnection {
$fld = new ADOFieldObject();
$fld->name = $rs->fields[0];
$type = $rs->fields[1];
+
+ /*
+ * Type from information_schema returns
+ * the same format in V8 mysql as V5
+ */
+ $type = $schemaArray[strtolower($fld->name)];
// split type into type(length):
$fld->scale = null;
@@ -660,6 +679,7 @@ class ADODB_mysqli extends ADOConnection {
$fld->type = $type;
$fld->max_length = -1;
}
+
$fld->not_null = ($rs->fields[2] != 'YES');
$fld->primary_key = ($rs->fields[3] == 'PRI');
$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);