Skip to content

Statement executeStep and reset with return code instead of throwing? #121

@kaptenhonek

Description

@kaptenhonek

Hi! Thanks for developing this library, it has really made it super easy to use sqlite with c++

Would it be possible add alternatives to executeStep and reset in Statement which do not throw exceptions but instead lets me handle the error code? I need this since I want to ignore foreign key violations.

Currently I need to use two try statements (one for executeStep and one for reset) and this makes the code look really ugly (not to mention the performance impact of throwing and catching two exceptions)

Currently I'm doing something like this:

SQLite::Statement insertStmt(db, "INSERT OR IGNORE INTO...");

for (const auto &obj : objects) {

    //Bind obj to stmt...

    try {
        insertStmt.executeStep();
    } catch (SQLite::Exception &ex) {
        if (ex.getExtendedErrorCode() != SQLITE_CONSTRAINT_FOREIGNKEY) {
            throw;
        }
    }

    try {
        insertStmt.reset();
    } catch (SQLite::Exception &ex) {
        if (ex.getExtendedErrorCode() != SQLITE_CONSTRAINT_FOREIGNKEY) {
            throw;
        } else {
            continue;
        }
    }

    //Do more stuff if insert was successful
}

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions