Skip to content

How to structure the string to create a trigger? #94

Open
@georgevbsantiago

Description

@georgevbsantiago

Hello, I have a "Silly" question, but I'm stuck on it.
I can't create a trigger in SQLite.
I believe there is a problem when writing the string.
I can create the trigger when using DB Browser, but I can't in Visual Code with C++ code.

In DB Browser successfully:

CREATE TRIGGER IF NOT EXISTS keep_5_rows 
		AFTER INSERT 
		ON tab_datalogger
		WHEN (SELECT COUNT(*) FROM tab_datalogger) > 5
	BEGIN 
		DELETE FROM tab_datalogger 
		WHERE ts = (SELECT ts FROM tab_datalogger ORDER BY ts, ts LIMIT 1);
	END;

image

In VS without success:

rc = db_exec(db, "CREATE TRIGGER IF NOT EXISTS keep_5_rows AFTER INSERT ON tab_datalogger WHEN (SELECT COUNT(*) FROM tab_datalogger) > 5 BEGIN DELETE FROM tab_datalogger WHERE ts = (SELECT ts FROM tab_datalogger ORDER BY ts, ts LIMIT 1); END;");

Serial Monitor:

17:29:49.481 > CREATE TRIGGER IF NOT EXISTS keep_5_rows AFTER INSERT ON tab_datalogger WHEN (SELECT COUNT(*) FROM tab_datalogger) > 5 BEGIN DELETE FROM tab_datalogger WHERE ts = (SELECT ts FROM tab_datalogger ORDER BY ts, ts LIMIT 1); END;
17:29:49.503 > SQL error: parser stack overflow

Any help would be greatly appreciated as I've been stuck on this for a few hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions