2shady4u / godot-sqlite

GDExtension wrapper for SQLite (Godot 4.x+)
MIT License
850 stars 76 forks source link

open_db on corrupted file crases project #141

Open JonnyTech opened 1 year ago

JonnyTech commented 1 year ago

Environment:

Issue description: Trying to open a corrupted / non-sqlite file crashes the project. Expecting to trap the error and handle it safely

Steps to reproduce: Create 3 buttons: create db, fill db, read db

func create_db():
    db.open_db()
    db.drop_table("table")
    db.create_table("table",{...table-data...})
    db.close_db()

func fill_db():
    db.open_db()
    db.insert_rows("table", row_array):
    db.close_db()

func read_db():
    db.open_db()
    #db.query()
    db.close_db()

Pressing the buttons in order (create, fill, read) works ok. Delete the database file test.db Press to fill the db >> an empty zero byte test.db file is created. Press to read the database, crash on db.open because test.db is not a valid db file

Additional context This is obviously a non-real-world example, but I have had an issue where the database file was unavailable and the fill/read process did happen and cause the result.