CodeIgniter Forums
db_forge's drop_table() does not clear the dropped table from the db data_cache - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: db_forge's drop_table() does not clear the dropped table from the db data_cache (/showthread.php?tid=38021)



db_forge's drop_table() does not clear the dropped table from the db data_cache - El Forum - 01-27-2011

[eluser]totels[/eluser]
When using the dbforge to drop a table(dbdriver=mysql) it is not possible to correctly check the existence of a table after it is dropped.

Code:
class Simple_db_model extends Model
{
    function __construct() {
        parent::__construct();

        $this->load->database();
    }

    function setup_db($drop=FALSE) {
        $this->load->dbforge();

        if ($drop === TRUE) {
            $this->dbforge->drop_table('my_table');
        }

        // the db class has the table cached so testing
        // for it's existence here will incorrectly confirm
        // that the table does exist
        if (!$this->db->table_exists('my_table')) {
            // ... create table, etc.
        }
    }
}

As a workaround I manually clear the cache when using this technique.
Code:
if ($drop === TRUE) {
    $this->dbforge->drop_table('my_table');
    $this->db->data_cache = array();
}
I realize I could capture the return query from the drop_table() method in order to test it instead of using table_exists(), but logically it would seem that either way should work correctly.


db_forge's drop_table() does not clear the dropped table from the db data_cache - El Forum - 04-16-2012

[eluser]Unknown[/eluser]
This still seems to be unresolved...


db_forge's drop_table() does not clear the dropped table from the db data_cache - El Forum - 04-16-2012

[eluser]CroNiX[/eluser]
File an official Issue: https://github.com/EllisLab/CodeIgniter/issues
Or no one will see it.