Skip to content

Binding text and blobs to a prepared statement does not work #4

Open
@ekgame

Description

@ekgame

Something goes wrong when trying to bind text to a prepared statement. I'm not sure if the binding is wrong or the language needs to patch something for it to work, but I couldn't get it working. I have confirmed that the arguments for the binding look right, they make sense according to documentation and examples I could find.

Reproduction:

  1. Create a file with this code:
# Experimental!
Sqlite ~ "lib"
Sqlite~Open "test.db"

$ CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, text TEXT);
Sqlite~Exec ⊙.

$ INSERT INTO test (text) VALUES (?);
Sqlite~Prepare ⊙.
Sqlite~BindText 1 "Hello world" . # yes, indexing into bindings starts at 1
Sqlite~ExecuteInsert

Sqlite~Close
  1. Run the code. A file named "test.db" should be created without any errors.
  2. Open the file in any sqlite viewer and view the "test" table. The one entry will have gibberish text. If you run the code multiple times, the table will have multiple rows with different gibberish text.

image

The same thing happens with blobs. I assume text eventually becomes a byte array and blobs are also just bytes, so the issue is probably the same. Consider this code:

# Experimental!
Sqlite ~ "lib"
Sqlite~Open "test.db"

$ CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, blob BLOB);
Sqlite~Exec ⊙.

$ INSERT INTO test (blob) VALUES (?);
Sqlite~Prepare ⊙.
Sqlite~BindBlob 1 [1 2 3] .
Sqlite~ExecuteInsert

Sqlite~Close

Running this multiple times results in different bogus values getting inserted:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions