首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否有在nim-lang中实现SQLite3扩展的示例?

是否有在nim-lang中实现SQLite3扩展的示例?
EN

Stack Overflow用户
提问于 2020-07-25 22:18:24
回答 1查看 86关注 0票数 0

以下是我的示例代码。它有点工作,但有一个问题。

用于创建函数的SQLite3 API包括一个描述返回参数的原型。但是,nim-wrapper不需要。

然而,下面的例子是编译和执行的,因为我无法确定如何返回未通过测试的值。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2020-07-25 23:04:10

使用此代码而不是上面的声明。

代码语言:javascript
复制
# declare my function
proc  hello(para1: Pcontext, para2: int32, para3: PValueArg) {.cdecl.} = 
  sqlite3.result_text(para1, "hello", 5, nil)
  echo "hello"

注内存泄漏是一个大问题,目前还不清楚最佳实践是什么。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63089435

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档