0

Here is my sample code. It kinda works but there is a problem.

The SQLite3 API for creating a function includes a prototype that described the return params. However, the nim-wrapper does not.

The example below compiles and executes, however, since I cannot determine how to return a value it does not pass the test.

import db_sqlite, sqlite3

# open the DB
let theDb = open("mytest.db", "", "", "")

# declare my function
proc  hello(para1: Pcontext, para2: int32, para3: PValueArg){.cdecl.} = echo "hello"

# register the function
let ret = theDb.create_function("Hello", 0, 0, nil, hello, nil, nil)
echo "create function {ret}"
echo $ret

# test the extension
for x in theDb.fastRows(sql"SELECT hello()"):
  echo x

# close the DB
# because I'm importing both db_sqlite and sqlite3 I need to be explicit or generate an error
db_sqlite.close(theDb)
Richard
  • 10,122
  • 10
  • 42
  • 61

1 Answers1

0

Use this code instead of the declaration above.

# declare my function
proc  hello(para1: Pcontext, para2: int32, para3: PValueArg) {.cdecl.} = 
  sqlite3.result_text(para1, "hello", 5, nil)
  echo "hello"

NOTE memory leaks are a big deal and it's not clear what the best practices are.

Richard
  • 10,122
  • 10
  • 42
  • 61