gpt4 book ai didi

c++ - 如何在 SQLite 中传递用于触发函数的变量?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:24:30 28 4
gpt4 key购买 nike

/* // this is the trigger definitionCREATE TEMPORARY TRIGGER 'insertTrigger' INSTEAD OF INSERT ON 'foo' BEGIN     SELECT bar(NEW.id, NEW.timestamp); "END; //*/void insert(sqlite3 *db, char *id, char *timestamp, void *context){    exec_query(db, "INSERT INTO foo(id,timestamp) VALUES(?,?)", id, timestamp);}void bar(sqlite3_context *context, int argc, sqlite3_value **argv){    char *id = (char*)sqlite3_value_text(argv[0]);    char *timestamp = (char*)sqlite3_value_text(argv[1]);    //how do I get context* ???    //this must be a thread safe function (i.e. multiple threads have their own sqlite3* and all execute queries (possibly including this one)}

是否有一些解决方法可以启用此功能?就像一个想法:

void insert(sqlite3 *db, char *id, char *timestamp, void *context){    sqlite3_mutex_enter(sqlite3_db_mutex(db));    sqlite3_user_setdata(db, context); //this doesnt exist    exec_query(db, "INSERT INTO foo(id,timestamp) VALUES(?,?)", id, timestamp);    sqlite3_mutex_leave(sqlite3_db_mutex(db));}void bar(sqlite3_context *context, int argc, sqlite3_value **argv){    char *id = (char*)sqlite3_value_text(argv[0]);    char *timestamp = (char*)sqlite3_value_text(argv[1]);    void *context_ = sqlite3_user_data(context);}

似乎还有一些其他方法可以完成此操作,例如 sqlite3_get_auxdata 函数,但我不太了解该 api 的工作原理。

最佳答案

context 不是您查询的一部分,因此它在触发器函数中不可用。

毕竟,您发送的用于更新表的 SQL 语句可能(应该)根本不知道触发器!

关于c++ - 如何在 SQLite 中传递用于触发函数的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21370061/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com