Discussion:
Bus error crash in SQLite
Ben
15 years ago
Permalink
Hi list,

I've encountered some SQL which causes both my app and the sqlite3 command line tool to crash. Given the following table and trigger:

CREATE TABLE stuff (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
type TEXT,
price REAL CHECK(price > 0),
parent INTEGER,
annotations TEXT,
quantity INTEGER NOT NULL DEFAULT 1 CHECK(quantity > 0)
);


CREATE TRIGGER stuff_insert_trg
BEFORE INSERT ON stuff
BEGIN
SELECT CASE
WHEN NEW.parent IS NOT NULL AND (SELECT id FROM stuff WHERE id=NEW.parent) IS NULL
THEN RAISE(ABORT, 'Foreign Key Violation: stuff.parent does not exist')
END;
END;



Trying to execute 'INSERT INTO "stuff" DEFAULT VALUES' using the command-line program causes it to output 'Bus error' and quit. When doing the same thing in my Mac app, it reports EXC_BAD_ACCESS in sqlite3Insert() at the line:
sqlite3ExprCodeAndCache(pParse, pList->a[j].pExpr, regCols+i+1);

Is this something I'm doing wrong?

If more information is needed, just let me know what to get.

- Ben
Black, Michael (IS)
15 years ago
Permalink
This has been fixed
http://www.sqlite.org/src/info/f3162063fd


Michael D. Black
Senior Scientist
Northrop Grumman Mission Systems


________________________________

From: sqlite-users-bounces-CzDROfG0BjIdnm+***@public.gmane.org on behalf of Ben
Sent: Sat 5/15/2010 7:27 AM
To: General Discussion of SQLite Database
Subject: [sqlite] Bus error crash in SQLite



Hi list,

I've encountered some SQL which causes both my app and the sqlite3 command line tool to crash. Given the following table and trigger:

CREATE TABLE stuff (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
type TEXT,
price REAL CHECK(price > 0),
parent INTEGER,
annotations TEXT,
quantity INTEGER NOT NULL DEFAULT 1 CHECK(quantity > 0)
);


CREATE TRIGGER stuff_insert_trg
BEFORE INSERT ON stuff
BEGIN
SELECT CASE
WHEN NEW.parent IS NOT NULL AND (SELECT id FROM stuff WHERE id=NEW.parent) IS NULL
THEN RAISE(ABORT, 'Foreign Key Violation: stuff.parent does not exist')
END;
END;



Trying to execute 'INSERT INTO "stuff" DEFAULT VALUES' using the command-line program causes it to output 'Bus error' and quit. When doing the same thing in my Mac app, it reports EXC_BAD_ACCESS in sqlite3Insert() at the line:
sqlite3ExprCodeAndCache(pParse, pList->a[j].pExpr, regCols+i+1);

Is this something I'm doing wrong?

If more information is needed, just let me know what to get.

- Ben
Black, Michael (IS)
15 years ago
Permalink
I tested your code with the latest fossil checkout

It now gets this:
sqlite> INSERT INTO "stuff" DEFAULT VALUES;
Error: stuff.name may not be NULL

Which makes sense as you didn't specify a default value for it.

So adding this:
name TEXT NOT NULL DEFAULT 'unk';

produces this:
sqlite> INSERT INTO "stuff" DEFAULT VALUES;
sqlite> select * from stuff;
1|unk|||||1


Michael D. Black
Senior Scientist
Northrop Grumman Mission Systems


________________________________

From: sqlite-users-bounces-CzDROfG0BjIdnm+***@public.gmane.org on behalf of Ben
Sent: Sat 5/15/2010 7:27 AM
To: General Discussion of SQLite Database
Subject: [sqlite] Bus error crash in SQLite



Hi list,

I've encountered some SQL which causes both my app and the sqlite3 command line tool to crash. Given the following table and trigger:

CREATE TABLE stuff (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
type TEXT,
price REAL CHECK(price > 0),
parent INTEGER,
annotations TEXT,
quantity INTEGER NOT NULL DEFAULT 1 CHECK(quantity > 0)
);


CREATE TRIGGER stuff_insert_trg
BEFORE INSERT ON stuff
BEGIN
SELECT CASE
WHEN NEW.parent IS NOT NULL AND (SELECT id FROM stuff WHERE id=NEW.parent) IS NULL
THEN RAISE(ABORT, 'Foreign Key Violation: stuff.parent does not exist')
END;
END;



Trying to execute 'INSERT INTO "stuff" DEFAULT VALUES' using the command-line program causes it to output 'Bus error' and quit. When doing the same thing in my Mac app, it reports EXC_BAD_ACCESS in sqlite3Insert() at the line:
sqlite3ExprCodeAndCache(pParse, pList->a[j].pExpr, regCols+i+1);

Is this something I'm doing wrong?

If more information is needed, just let me know what to get.

- Ben
Ben
15 years ago
Permalink
Thanks very much for pointing me to the ticket. I'm still not very familiar at locating stuff in the fossil repo.

The error message you show is what I was expecting as my app will notice that and handle the error.

Thanks again,

Ben
...
Loading...