vrischmann / zig-sqlite

zig-sqlite is a small wrapper around sqlite's C API, making it easier to use with Zig.
MIT License
367 stars 49 forks source link

add error offsets to DetailedError #81

Closed lun-4 closed 2 years ago

lun-4 commented 2 years ago

sqlite3_error_offset API introduced on 3.38.0:

Added the sqlite3_error_offset() interface, which can sometimes help to localize an SQL error to a specific character in the input SQL text, so that applications can provide better error messages.

lun-4 commented 2 years ago

Hm. CI's failing because it's using the system sqlite library, which means it fails on ubuntu who hasn't updated to 3.38, yet it works fine on my Void machine... what should be the best course of action here?

vrischmann commented 2 years ago

I don't think we can require a version that recent yet (Debian Bullseye is shipping 3.34.1, Fedora 35 is shipping 3.36.0).

But I think you can simply add a comptime check using the SQLITE_VERSION_NUMBER constant.

Something like this:

fn getErrorOffset(db: *c.sqlite3) i32 {
    if (comptime c.SQLITE_VERSION_NUMBER >= 3038000) {
        return c.sqlite3_error_offset(db);
    }
    return -1;
}

and then call that instead of sqlite3_error_offset.

but actually there was another problem that I just fixed in #83. In the build.zig file we used to always add the c directory to the include directories, but this would result in the comptime check passing (because we include the 3.38.0 version) even though the system library is not always 3.38.0. If you rebase on master the CI should fail while compiling, not linking.

vrischmann commented 2 years ago

Thanks !