以下是我的示例代码。它有点工作,但有一个问题。
用于创建函数的SQLite3 API包括一个描述返回参数的原型。但是,nim-wrapper不需要。
然而,下面的例子是编译和执行的,因为我无法确定如何返回未通过测试的值。
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)发布于 2020-07-25 23:04:10
使用此代码而不是上面的声明。
# declare my function
proc hello(para1: Pcontext, para2: int32, para3: PValueArg) {.cdecl.} =
sqlite3.result_text(para1, "hello", 5, nil)
echo "hello"注内存泄漏是一个大问题,目前还不清楚最佳实践是什么。
https://stackoverflow.com/questions/63089435
复制相似问题