Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ekgame opened this issue May 13, 2024 · 0 comments
Open

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

ekgame opened this issue May 13, 2024 · 0 comments

Comments

@ekgame
Copy link
Contributor

ekgame commented May 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant