diff options
| author | Mark Newnham <mark@newnhams.com> | 2021-06-15 19:56:35 -0600 |
|---|---|---|
| committer | Mark Newnham <mark@newnhams.com> | 2021-06-15 19:56:35 -0600 |
| commit | c4aadf417b7f2d985e01cead3ca70db07734bb7f (patch) | |
| tree | 7988e54691da466c8d40671944aec2667a7b36ae | |
| parent | b8df4155823350dc6c207796992f0cac90de9f93 (diff) | |
| download | adodb-c4aadf417b7f2d985e01cead3ca70db07734bb7f.tar.gz adodb-c4aadf417b7f2d985e01cead3ca70db07734bb7f.tar.bz2 adodb-c4aadf417b7f2d985e01cead3ca70db07734bb7f.zip | |
Add support for metaIndexes see #733
MetaIndexes not previously supported by PDO mysql driver.
Fix recursion error introduced in affected_rows()
| -rw-r--r-- | drivers/adodb-pdo_mysql.inc.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/drivers/adodb-pdo_mysql.inc.php b/drivers/adodb-pdo_mysql.inc.php index 6cbb1a46..a678bd97 100644 --- a/drivers/adodb-pdo_mysql.inc.php +++ b/drivers/adodb-pdo_mysql.inc.php @@ -48,6 +48,59 @@ class ADODB_pdo_mysql extends ADODB_pdo { return $date . ' + INTERVAL ' . $fraction . ' SECOND'; // return "from_unixtime(unix_timestamp($date)+$fraction)"; } + + + function metaIndexes ($table, $primary = FALSE, $owner=false) + { + // save old fetch mode + global $ADODB_FETCH_MODE; + + $false = false; + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + if ($this->fetchMode !== FALSE) { + $savem = $this->SetFetchMode(FALSE); + } + + // get index details + $rs = $this->Execute(sprintf('SHOW INDEX FROM %s',$table)); + + // restore fetchmode + if (isset($savem)) { + $this->SetFetchMode($savem); + } + $ADODB_FETCH_MODE = $save; + + if (!is_object($rs)) { + return $false; + } + + $indexes = array (); + + // parse index data into array + while ($row = $rs->FetchRow()) { + if ($primary == FALSE AND $row[2] == 'PRIMARY') { + continue; + } + + if (!isset($indexes[$row[2]])) { + $indexes[$row[2]] = array( + 'unique' => ($row[1] == 0), + 'columns' => array() + ); + } + + $indexes[$row[2]]['columns'][$row[3] - 1] = $row[4]; + } + + // sort columns by order in the index + foreach ( array_keys ($indexes) as $index ) + { + ksort ($indexes[$index]['columns']); + } + + return $indexes; + } function Concat() { |
