gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 280 forks source link

SQLite R::wipe() calls failing, claiming nonexistent table when table exists #156

Closed katanacrimson closed 12 years ago

katanacrimson commented 12 years ago

Relevant code:

<?php
                var_dump(R::wipe('post'));
                var_dump(R::wipe('post_tag'));
                var_dump(R::wipe('tag'));
                var_dump(R::wipe('tag_alias'));
                var_dump(R::wipe('tag_count'));
                var_dump(R::wipe('session'));

Results: var_dump results

As you can see, all tables specified exist, and were dynamically created by redbean earlier with sample beans and stored. For some reason, the first three calls (post, post_tag, tag) all fail. Changing the order does nothing, either. For some reason the table redbean's trying to run the DELETE FROM on is failing due to "no such table". http://www.redbeanphp.com/api/d8/dc5/_o_o_d_b_8php_source.html#l00792

DB type is sqlite.

EDIT:

Enabling debug mode only echoes this data back:

DELETE FROM `post`
Array ( ) 

DELETE FROM `post_tag`
Array ( ) 

DELETE FROM `tag`
Array ( ) 

DELETE FROM `tag_alias`
Array ( ) 

DELETE FROM `tag_count`
Array ( ) 

DELETE FROM `session`
Array ( ) 
katanacrimson commented 12 years ago

Okay, for some reason all delete queries to those tables are failing on that same pageload.

<?php
                R::debug();
                R::trash($post);
                R::trashAll(R::find('post_tag'));
                R::trash($tag);
                R::trash($alias);
                R::trash($tag_count);
                R::trash($session);

where $post, $tag, $alias, $tag_count, $session are all untainted beans that were just previously stored that pageload.

to test this I've been deleting the entire sqlite database file and checking a randomly-generated value that's stored in another table within the same db - it's changing, so the data's not being cached in sqliteman, but those tables simply will not be deleted in redbean.

Now, I have models for the post table, the tag table, and the session table, but the post_tag table is also affected and the session table isn't. I'm at a loss for where this behavior is coming from.

My controller's here if you want to take a look at the entirety of it, it's FOSS: https://github.com/damianb/homebooru/blob/master/app/src/codebite/homebooru/Controller/InstallerController.php#L312

gabordemooij commented 12 years ago

Sorry for my late reply... working on a tutorial for RB and it took a lot of time (not good at writing tutorials I guess) Can you plz send me a small script that demonstrates the problem (a script that I can run just from the cli)?

katanacrimson commented 12 years ago

Will do when I have some spare time available.

katanacrimson commented 12 years ago

Alright, I've got something for you that reproduces it. Stick rb.php beside the script.

<?php

include __DIR__ . '/rb.php';

touch(__DIR__ . '/red.db');
R::setup('sqlite:' . __DIR__ . '/red.db');

R::exec('SELECT 1');
R::debug();

$post = R::dispense('post');
$post->status = 5;

$hash = hash('sha1', 'sample');
$post->full_file = $hash . '.txt';
$post->full_height = 10000;
$post->full_width = 10000;
$post->full_md5 = hash('md5', 'sample');
$post->full_sha1 = $hash;
$post->full_size = pow(2, 31);

$small_hash = hash('sha1', $hash);
$post->small_file = $small_hash . '.txt';
$post->small_height = 650;
$post->small_width = 650;
$post->small_md5 = hash('md5', $hash);
$post->small_sha1 = $small_hash;
$post->small_size = pow(2, 31);

$thumb_hash = hash('sha1', $small_hash);
$post->thumb_file = $thumb_hash . '.txt';
$post->thumb_height = 150;
$post->thumb_width = 150;
$post->thumb_md5 = hash('md5', $small_hash);
$post->thumb_sha1 = $thumb_hash;
$post->thumb_size = pow(2, 31);

$post->rating = 5;
$post->source = str_repeat('a', 255);
$post->submit_time = time();
$post->submit_ip = implode(':', array_fill(0, 8, 'ffff')); // emulate largest possible ipv6 addr
$post->user_id = 255;

R::store($post);

R::tag($post, array('sample_tag'));
$tag = R::find('tag');
$tag = array_shift($tag);
$tag->type = 5;
R::store($tag);

$alias = R::dispense('tag_alias');
$alias->title = 'game';
$alias->tag = $tag;
R::store($alias);

$tag_count = R::dispense('tag_count');
$tag_count->tag = $tag;
$tag_count->amount = 1;
R::store($tag_count);

$session = R::dispense('session');
$session->time = time();
$session->sid = hash('md5', 'sample_session');
$session->fingerprint = hash('sha256', 'sample_fingerprint');
$session->useragent = str_repeat('a', 255);
$session->ip = implode(':', array_fill(0, 8, 'ffff')); // emulate largest possible ipv6 addr
$session->setMeta('data.store', array_fill(0, 20, str_repeat('a', 63)));
R::store($session);

R::$f->begin()
    ->create_trigger('tag_magic_update_count')
    ->after('insert')
    ->on('post_tag')
    ->addSQL('BEGIN')
        ->update('tag_count')
        ->set('amount = amount + 1')
        ->where('tag_id = new.tag_id')
        ->addSQL(';')
    ->addSQL('END')
    ->get();

R::$f->begin()
    ->create_trigger('tag_magic_delete_count')
    ->after('delete')
    ->on('post_tag')
    ->addSQL('BEGIN')
        ->update('tag_count')
        ->set('amount = amount - 1')
        ->where('tag_id = new.tag_id')
        ->addSQL(';')
    ->addSQL('END')
    ->get();

R::$f->begin()
    ->create_trigger('tag_magic_new_count')
    ->after('insert')
    ->on('post_tag')
    ->addSQL('BEGIN')
        ->insert_into('tag_count')
        ->addSQL('(tag_id, amount)')
        ->values('(new.tag_id, 1)')
        ->addSQL(';')
    ->addSQL('END')
    ->get();

R::$f->begin()
    ->create_trigger('tag_magic_drop_count')
    ->after('delete')
    ->on('post_tag')
    ->addSQL('BEGIN')
        ->delete_from('tag_count')
        ->where('tag_id = old.tag_id')
        ->addSQL(';')
    ->addSQL('END')
    ->get();

var_dump(R::wipe('post'));
var_dump(R::wipe('post_tag'));
var_dump(R::wipe('tag'));
var_dump(R::wipe('tag_alias'));
var_dump(R::wipe('tag_count'));
var_dump(R::wipe('session'));
echo 'done';

HTML output (from R::debug())

SELECT name FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence';Array ( ) 
resultset: 0 rows
CREATE TABLE `post` ( id INTEGER PRIMARY KEY AUTOINCREMENT ) Array ( )
PRAGMA table_info('post')Array ( ) 
resultset: 1 rows
ALTER TABLE `post` ADD `status` INTEGER Array ( )
ALTER TABLE `post` ADD `full_file` TEXT Array ( )
ALTER TABLE `post` ADD `full_height` INTEGER Array ( )
ALTER TABLE `post` ADD `full_width` INTEGER Array ( )
ALTER TABLE `post` ADD `full_md5` TEXT Array ( )
ALTER TABLE `post` ADD `full_sha1` TEXT Array ( )
ALTER TABLE `post` ADD `full_size` TEXT Array ( )
ALTER TABLE `post` ADD `small_file` TEXT Array ( )
ALTER TABLE `post` ADD `small_height` INTEGER Array ( )
ALTER TABLE `post` ADD `small_width` INTEGER Array ( )
ALTER TABLE `post` ADD `small_md5` TEXT Array ( )
ALTER TABLE `post` ADD `small_sha1` TEXT Array ( )
ALTER TABLE `post` ADD `small_size` TEXT Array ( )
ALTER TABLE `post` ADD `thumb_file` TEXT Array ( )
ALTER TABLE `post` ADD `thumb_height` INTEGER Array ( )
ALTER TABLE `post` ADD `thumb_width` INTEGER Array ( )
ALTER TABLE `post` ADD `thumb_md5` TEXT Array ( )
ALTER TABLE `post` ADD `thumb_sha1` TEXT Array ( )
ALTER TABLE `post` ADD `thumb_size` TEXT Array ( )
ALTER TABLE `post` ADD `rating` INTEGER Array ( )
ALTER TABLE `post` ADD `source` TEXT Array ( )
ALTER TABLE `post` ADD `submit_time` INTEGER Array ( )
ALTER TABLE `post` ADD `submit_ip` TEXT Array ( )
ALTER TABLE `post` ADD `user_id` INTEGER Array ( )
INSERT INTO `post` ( id, `status`,`full_file`,`full_height`,`full_width`,`full_md5`,`full_sha1`,`full_size`,`small_file`,`small_height`,`small_width`,`small_md5`,`small_sha1`,`small_size`,`thumb_file`,`thumb_height`,`thumb_width`,`thumb_md5`,`thumb_sha1`,`thumb_size`,`rating`,`source`,`submit_time`,`submit_ip`,`user_id` ) VALUES ( NULL, ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) Array ( [0] => 5 [1] => 8151325dcdbae9e0ff95f9f9658432dbedfdb209.txt [2] => 10000 [3] => 10000 [4] => 5e8ff9bf55ba3508199d22e984129be6 [5] => 8151325dcdbae9e0ff95f9f9658432dbedfdb209 [6] => 2147483648 [7] => 1ff360f124b6e2453597010ea589ee6871681840.txt [8] => 650 [9] => 650 [10] => 4d66c8bc21ab997ee53e8a9828f619de [11] => 1ff360f124b6e2453597010ea589ee6871681840 [12] => 2147483648 [13] => bef8f2a147b893c00c67600f37526d3b0f5905ea.txt [14] => 150 [15] => 150 [16] => bbb4899d6d5da93c0d920bbdded7549e [17] => bef8f2a147b893c00c67600f37526d3b0f5905ea [18] => 2147483648 [19] => 5 [20] => aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [21] => 1337953686 [22] => ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff [23] => 255 )
DELETE FROM `post_tag` WHERE ( `post_id` IN ( ?) ) Array ( [0] => 1 )
SELECT * FROM `tag` WHERE title = ? Array ( [0] => sample_tag )
SELECT name FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence';Array ( ) 
resultset: 1 rows
CREATE TABLE `tag` ( id INTEGER PRIMARY KEY AUTOINCREMENT ) Array ( )
PRAGMA table_info('tag')Array ( ) 
resultset: 1 rows
ALTER TABLE `tag` ADD `title` TEXT Array ( )
INSERT INTO `tag` ( id, `title` ) VALUES ( NULL, ? ) Array ( [0] => sample_tag )
SELECT name FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence';Array ( ) 
resultset: 2 rows
CREATE TABLE `post_tag` ( id INTEGER PRIMARY KEY AUTOINCREMENT ) Array ( )
PRAGMA table_info('post_tag')Array ( ) 
resultset: 1 rows
ALTER TABLE `post_tag` ADD `post_id` INTEGER Array ( )
CREATE INDEX index_for_post_tag_post_id ON `post_tag` (`post_id`) Array ( )
ALTER TABLE `post_tag` ADD `tag_id` INTEGER Array ( )
CREATE INDEX index_for_post_tag_tag_id ON `post_tag` (`tag_id`) Array ( )
CREATE UNIQUE INDEX IF NOT EXISTS UQ_7bec4a3eda48c3b96ed49ee5b28cd8f39a78ec61 ON `post_tag` (post_id,tag_id)Array ( )
INSERT INTO `post_tag` ( id, `post_id`,`tag_id` ) VALUES ( NULL, ? , ? ) Array ( [0] => 1 [1] => 1 )
PRAGMA table_info('post_tag')Array ( ) 
resultset: 3 rows
PRAGMA foreign_key_list('post_tag'); Array ( )
DROP TABLE IF EXISTS tmp_backup;Array ( )
CREATE TEMPORARY TABLE tmp_backup(`id`,`post_id`,`tag_id`);Array ( )
INSERT INTO tmp_backup SELECT * FROM `post_tag`;Array ( )
PRAGMA foreign_keys = 0 Array ( )
DROP TABLE `post_tag`;Array ( )
CREATE TABLE `post_tag` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT ,`post_id` INTEGER,`tag_id` INTEGER , FOREIGN KEY(`post_id`) REFERENCES `post`(`id`) ON DELETE CASCADE );Array ( )
INSERT INTO `post_tag` SELECT * FROM tmp_backup;Array ( )
DROP TABLE tmp_backup;Array ( )
PRAGMA foreign_keys = 1 Array ( )
PRAGMA table_info('post_tag')Array ( ) 
resultset: 3 rows
PRAGMA foreign_key_list('post_tag'); Array ( ) 
resultset: 1 rows
DROP TABLE IF EXISTS tmp_backup;Array ( )
CREATE TEMPORARY TABLE tmp_backup(`id`,`post_id`,`tag_id`);Array ( )
INSERT INTO tmp_backup SELECT * FROM `post_tag`;Array ( )
PRAGMA foreign_keys = 0 Array ( )
DROP TABLE `post_tag`;Array ( )
CREATE TABLE `post_tag` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT ,`post_id` INTEGER,`tag_id` INTEGER , FOREIGN KEY(`post_id`) REFERENCES `post`(`id`) ON DELETE CASCADE, FOREIGN KEY(`tag_id`) REFERENCES `tag`(`id`) ON DELETE CASCADE );Array ( )
INSERT INTO `post_tag` SELECT * FROM tmp_backup;Array ( )
DROP TABLE tmp_backup;Array ( )
PRAGMA foreign_keys = 1 Array ( )
SELECT * FROM `tag`Array ( ) 
resultset: 1 rows
SELECT name FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence';Array ( ) 
resultset: 3 rows
PRAGMA table_info('tag')Array ( ) 
resultset: 2 rows
ALTER TABLE `tag` ADD `type` INTEGER Array ( )
UPDATE `tag` SET `title` = ? , `type` = ? WHERE id = 1Array ( [0] => sample_tag [1] => 5 )
SELECT name FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence';Array ( ) 
resultset: 3 rows
CREATE TABLE `tag_alias` ( id INTEGER PRIMARY KEY AUTOINCREMENT ) Array ( )
PRAGMA table_info('tag_alias')Array ( ) 
resultset: 1 rows
ALTER TABLE `tag_alias` ADD `title` TEXT Array ( )
ALTER TABLE `tag_alias` ADD `tag_id` INTEGER Array ( )
INSERT INTO `tag_alias` ( id, `title`,`tag_id` ) VALUES ( NULL, ? , ? ) Array ( [0] => game [1] => 1 )
CREATE INDEX index_foreignkey_tag ON `tag_alias` (`tag_id`) Array ( )
PRAGMA table_info('tag_alias')Array ( ) 
resultset: 3 rows
PRAGMA foreign_key_list('tag_alias'); Array ( )
DROP TABLE IF EXISTS tmp_backup;Array ( )
CREATE TEMPORARY TABLE tmp_backup(`id`,`title`,`tag_id`);Array ( )
INSERT INTO tmp_backup SELECT * FROM `tag_alias`;Array ( )
PRAGMA foreign_keys = 0 Array ( )
DROP TABLE `tag_alias`;Array ( )
CREATE TABLE `tag_alias` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT ,`title` TEXT,`tag_id` INTEGER , FOREIGN KEY(`tag_id`) REFERENCES `tag`(`id`) ON DELETE SET NULL ON UPDATE SET NULL );Array ( )
INSERT INTO `tag_alias` SELECT * FROM tmp_backup;Array ( )
DROP TABLE tmp_backup;Array ( )
PRAGMA foreign_keys = 1 Array ( )
SELECT name FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence';Array ( ) 
resultset: 4 rows
CREATE TABLE `tag_count` ( id INTEGER PRIMARY KEY AUTOINCREMENT ) Array ( )
PRAGMA table_info('tag_count')Array ( ) 
resultset: 1 rows
ALTER TABLE `tag_count` ADD `amount` INTEGER Array ( )
ALTER TABLE `tag_count` ADD `tag_id` INTEGER Array ( )
INSERT INTO `tag_count` ( id, `amount`,`tag_id` ) VALUES ( NULL, ? , ? ) Array ( [0] => 1 [1] => 1 )
CREATE INDEX index_foreignkey_tag ON `tag_count` (`tag_id`) Array ( )
PRAGMA table_info('tag_count')Array ( ) 
resultset: 3 rows
PRAGMA foreign_key_list('tag_count'); Array ( )
DROP TABLE IF EXISTS tmp_backup;Array ( )
CREATE TEMPORARY TABLE tmp_backup(`id`,`amount`,`tag_id`);Array ( )
INSERT INTO tmp_backup SELECT * FROM `tag_count`;Array ( )
PRAGMA foreign_keys = 0 Array ( )
DROP TABLE `tag_count`;Array ( )
CREATE TABLE `tag_count` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT ,`amount` INTEGER,`tag_id` INTEGER , FOREIGN KEY(`tag_id`) REFERENCES `tag`(`id`) ON DELETE SET NULL ON UPDATE SET NULL );Array ( )
INSERT INTO `tag_count` SELECT * FROM tmp_backup;Array ( )
DROP TABLE tmp_backup;Array ( )
PRAGMA foreign_keys = 1 Array ( )
SELECT name FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence';Array ( ) 
resultset: 5 rows
CREATE TABLE `session` ( id INTEGER PRIMARY KEY AUTOINCREMENT ) Array ( )
PRAGMA table_info('session')Array ( ) 
resultset: 1 rows
ALTER TABLE `session` ADD `time` INTEGER Array ( )
ALTER TABLE `session` ADD `sid` TEXT Array ( )
ALTER TABLE `session` ADD `fingerprint` TEXT Array ( )
ALTER TABLE `session` ADD `useragent` TEXT Array ( )
ALTER TABLE `session` ADD `ip` TEXT Array ( )
INSERT INTO `session` ( id, `time`,`sid`,`fingerprint`,`useragent`,`ip` ) VALUES ( NULL, ? , ? , ? , ? , ? ) Array ( [0] => 1337953692 [1] => 1e547b67532bd95c1341bc6bdf08ff5c [2] => e5e1817aa8db0c75d8404666abc86b04b0074e14b5c770f78a25557a17885606 [3] => aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [4] => ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff )
create trigger tag_magic_update_count after insert on post_tag BEGIN update tag_count set amount = amount + 1 where tag_id = new.tag_id ; END Array ( )
create trigger tag_magic_delete_count after delete on post_tag BEGIN update tag_count set amount = amount - 1 where tag_id = new.tag_id ; END Array ( )
create trigger tag_magic_new_count after insert on post_tag BEGIN insert into tag_count (tag_id, amount) values (new.tag_id, 1) ; END Array ( )
create trigger tag_magic_drop_count after delete on post_tag BEGIN delete from tag_count where tag_id = old.tag_id ; END Array ( )
DELETE FROM `post`Array ( )
var_dump = boolean false
DELETE FROM `post_tag`Array ( )
var_dump = boolean false
DELETE FROM `tag`Array ( )
var_dump = boolean false
DELETE FROM `tag_alias`Array ( )
var_dump = boolean true
DELETE FROM `tag_count`Array ( )
var_dump = boolean true
DELETE FROM `session`Array ( )
var_dump = boolean true
katanacrimson commented 12 years ago

I just commented out the trigger insertion code and it is working as expected, oddly enough. It appears the addition of the SQL triggers are causing SQLite to think the table doesn't exist, perhaps? Or something about them is tricking redbean about the table's existence.

katanacrimson commented 12 years ago

Added this before the R::wipe() calls.

<?php
var_dump(R::$f->begin()->addSQL('SELECT * FROM sqlite_master WHERE type="table"')->get());

Result:

resultset: 7 rows
array
  0 => 
    array
      'type' => string 'table' (length=5)
      'name' => string 'post' (length=4)
      'tbl_name' => string 'post' (length=4)
      'rootpage' => string '2' (length=1)
      'sql' => string 'CREATE TABLE `post` ( id INTEGER PRIMARY KEY AUTOINCREMENT , `status` INTEGER, `full_file` TEXT, `full_height` INTEGER, `full_width` INTEGER, `full_md5` TEXT, `full_sha1` TEXT, `full_size` TEXT, `small_file` TEXT, `small_height` INTEGER, `small_width` INTEGER, `small_md5` TEXT, `small_sha1` TEXT, `small_size` TEXT, `thumb_file` TEXT, `thumb_height` INTEGER, `thumb_width` INTEGER, `thumb_md5` TEXT, `thumb_sha1` TEXT, `thumb_size` TEXT, `rating` INTEGER, `source` TEXT, `submit_time` INTEGER, `submit_ip` TEXT,'... (length=531)
  1 => 
    array
      'type' => string 'table' (length=5)
      'name' => string 'sqlite_sequence' (length=15)
      'tbl_name' => string 'sqlite_sequence' (length=15)
      'rootpage' => string '3' (length=1)
      'sql' => string 'CREATE TABLE sqlite_sequence(name,seq)' (length=38)
  2 => 
    array
      'type' => string 'table' (length=5)
      'name' => string 'tag' (length=3)
      'tbl_name' => string 'tag' (length=3)
      'rootpage' => string '4' (length=1)
      'sql' => string 'CREATE TABLE `tag` ( id INTEGER PRIMARY KEY AUTOINCREMENT , `title` TEXT, `type` INTEGER)' (length=89)
  3 => 
    array
      'type' => string 'table' (length=5)
      'name' => string 'post_tag' (length=8)
      'tbl_name' => string 'post_tag' (length=8)
      'rootpage' => string '5' (length=1)
      'sql' => string 'CREATE TABLE `post_tag` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT  ,`post_id` INTEGER,`tag_id` INTEGER , FOREIGN KEY(`post_id`) REFERENCES `post`(`id`) ON DELETE CASCADE, FOREIGN KEY(`tag_id`) REFERENCES `tag`(`id`) ON DELETE CASCADE  )' (length=235)
  4 => 
    array
      'type' => string 'table' (length=5)
      'name' => string 'tag_alias' (length=9)
      'tbl_name' => string 'tag_alias' (length=9)
      'rootpage' => string '8' (length=1)
      'sql' => string 'CREATE TABLE `tag_alias` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT  ,`title` TEXT,`tag_id` INTEGER , FOREIGN KEY(`tag_id`) REFERENCES `tag`(`id`) ON DELETE SET NULL ON UPDATE SET NULL )' (length=184)
  5 => 
    array
      'type' => string 'table' (length=5)
      'name' => string 'tag_count' (length=9)
      'tbl_name' => string 'tag_count' (length=9)
      'rootpage' => string '9' (length=1)
      'sql' => string 'CREATE TABLE `tag_count` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT  ,`amount` INTEGER,`tag_id` INTEGER , FOREIGN KEY(`tag_id`) REFERENCES `tag`(`id`) ON DELETE SET NULL ON UPDATE SET NULL )' (length=188)
  6 => 
    array
      'type' => string 'table' (length=5)
      'name' => string 'session' (length=7)
      'tbl_name' => string 'session' (length=7)
      'rootpage' => string '10' (length=2)
      'sql' => string 'CREATE TABLE `session` ( id INTEGER PRIMARY KEY AUTOINCREMENT , `time` INTEGER, `sid` TEXT, `fingerprint` TEXT, `useragent` TEXT, `ip` TEXT)' (length=140)

The tables do, indeed, exist - I'm thinking it may be a redbean regression somewhere.

gabordemooij commented 12 years ago

Thanks I will look into this

gabordemooij commented 12 years ago

doesnt

->where('tag_id = new.tag_id')

need to be:

->where('tag_id = old.tag_id') ?

in the 2nd trigger?

katanacrimson commented 12 years ago

Good catch - copy and paste fail of mine in my own code. I'll see if that affects anything.

katanacrimson commented 12 years ago

Tested it on a couple systems, that...appears to be the problem? Interesting way for it to manifest. Thanks for the help @gabordemooij, apologies for burning so much of your time.