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

Is it not possible to do something like that ? #162

Closed Pismice closed 3 months ago

Pismice commented 3 months ago

zig-sqlite commit

latest

Zig version

0.13.0

Steps to reproduce

const query2 =
    \\ INSERT INTO villages(name,player_id,x_position,y_position) VALUES(?,(SELECT id FROM players WHERE session_id = ?),?,?);
;
var stmt2 = try app.db.prepare(query2);
defer stmt2.deinit();
// FIXME pour eviter l erreur verifier avec une requete avant ??
stmt2.exec(.{}, .{ .name = "vilajo", .session_id = session_id, .x_position = 1.0, .y_position = 2.0 }) catch {
    try res.json(.{ .message = "Error while creating village" }, .{});
    return;
};

Expected behaviour

I would except to pass the parameter to the SELECT inside the INSERT but I simply get an "Err: error.SQLiteError". I have no idea why. Is it possible to do requests the way I did ?

Pismice commented 3 months ago

Looks like any attempt to chain multiple requests fail:

            const query =
                \\ INSERT INTO buildings(level,space_taken) VALUES(1,0);
                \\ INSERT INTO gold_mines(building_id,productivity) VALUES(last_insert_rowid(),?)
            ;

With SQLiteRangeError

Pismice commented 3 months ago

It worked using savepoints :)