Bug Report #1236

Database introspection is cached when caching is disabled

Added by Chris Bandy almost 3 years ago. Updated over 2 years ago.

Status:Closed Start date:
Priority:High Due date:
Assignee:Jeremy Bush % Done:

100%

Category:Core
Target version:2.3.3
Resolution:fixed Points:

Description

Causes #1049, #1062.

When caching is disabled, a call to clear_cache() is required for introspection to return correct results. clear_cache() should have no effect with caching disabled.

Test Case:

$db = new Database(array(
  'cache' => FALSE,
  'connection' => array(
    'type' => 'mysql',
    'host' => 'localhost',
    'socket' => TRUE,
    'user' => 'root',
    'pass' => 'password',
    'database' => 'testing',
  ),
));

$db->query('CREATE TABLE testtable ( first integer )');
$result1 = $db->list_fields('testtable'); // 1

$db->query('ALTER TABLE testtable ADD second integer');
$result2 = $db->list_fields('testtable'); // 2

// Correct results are obtained after clearing the cache
$db->clear_cache();
$result3 = $db->list_fields('testtable'); // 3

$db->query('DROP TABLE testtable');

try {
  $result4 = $db->list_fields('testtable'); // 4
} catch (Kohana_Database_Exception $de) {
  $result4 = FALSE;
}

Current Results:
  • Results 1 and 2 match.
  • Results 2 and 3 differ.
  • Results 3 and 4 match.
Expected Results:
  • Results 1 and 2 should differ.
  • Results 2 and 3 should match.
  • Call 4 should throw an exception.
  • $result1 should contain one more element than $result2.
  • $db->clear_cache() should have no effect.

Possible Solution:

Utilize the regular query cache by calling $this->query() for introspection rather than mysql_query() directly.

0001-Use-query-cache-for-introspection.patch - MySQL and MySQLi, tested with and without caching. (against trunk) (4 kB) Chris Bandy, 04/21/2009 03:58 am

0002-Use-query-cache-for-introspection.patch - PgSQL, tested with and without caching. (against trunk) (2.2 kB) Chris Bandy, 04/21/2009 03:58 am

0003-Use-query-cache-for-introspection.patch - MSSQL, untested. (against trunk) (1.3 kB) Chris Bandy, 04/21/2009 03:58 am


Related issues

related to Kohana v2.x - Bug Report #1049: Database::list_fields returns incorrect results for multi... 2.3.3 Closed
related to Kohana v2.x - Bug Report #2216: Regression: Database introspection disregards cache settings 2.4 Closed 10/08/2009

Associated revisions

History

Updated by Jeremy Bush almost 3 years ago

It seems Pgsql has already been applied:

patch -p0 < 0002-Use-query-cache-for-introspection.patch
patching file system/libraries/drivers/Database/Pgsql.php
Reversed (or previously applied) patch detected! Assume -R? [n]
Apply anyway? [n]
Skipping patch.

Mysql is out of date. Can you provide a new mysql patch?

Updated by Chris Bandy almost 3 years ago

Above patches updated and tested against r4227.

Updated by Chris Bandy over 2 years ago

Tested again against r4343.

Updated by Jeremy Bush over 2 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset r4344.

Updated by Jeremy Bush over 2 years ago

  • Resolution set to fixed

Also merged to 2.3 database branch in r4345.

Also available in: Atom PDF