uiua-lang / uiqlite

WIP Sqlite bindings for Uiua
5 stars 2 forks source link

Retrieving a BLOB from a SELECT query does not work #5

Open ekgame opened 4 months ago

ekgame commented 4 months ago

Yet again, I'm not sure if I'm doing something wrong or a byte array as return value from a function is not supported.

Reproduction:

  1. Find ColumnBlob in lib.ua, remove the assertion, uncomment the "Call" function line.
  2. Create a file with 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 (X'010203'); Sqlite~Exec ⊙.

$ SELECT blob FROM test; Sqlite~Prepare ⊙. ◌Sqlite~StepRow . ◌?Sqlite~ColumnBlob 1

Sqlite~Close


3. Run the code. A file named "test.db" will be created. You can inspect the database to confirm that bytes `1, 2, 3` were added.
4. The code will crash with an FFI error.
kaikalii commented 3 months ago

I've made it possible to return simple pointers from functions. In addition, I've added the &memcpy and &memfree system functions for working with pointers in ways that the ffi type:len_index syntax doesn't allow for. Hopefully this should make a proper API for returning blobs possible.