ここに最初の投稿!このサイトは、膨大な数の以前の技術的な問題の重要な助けとなっています。 一生懸命お世話になりました。sqlite3 Cユーザー定義関数が呼び出されていない
そして今私の問題になります。
私はCのsqlite3 UDF(ユーザ定義関数)を書いてみたいです。 関数名が "myFunc"であるとします。
私はRaspberry PI 3B - Raspbianのデフォルト(ディストリビューション)を使用しています。
TEST_TABLEは、以下のスキーマがあります
create table test_table (
a integer,
b integer
);
(アプローチをテストする)ミニプログラムは、DBを開き、機能をインストールします。 その後、トリガーイベントが無期限に待機します。
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
#include <signal.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/stat.h>
static void myFuncBody(sqlite3_context *context, int argc, sqlite3_value **argv)
{
printf("myFunc fired!\n");
fflush(stdout);
}
int main(int argc, char** argv)
{
sqlite3 *db_handler;
char *errMsg;
int error;
error = sqlite3_open("test.db", &db_handler);
if (error)
{
printf("Error opening the DB.\n");
exit(-2);
}
error = sqlite3_create_function(
db_handler,
"myFunc",
0,
SQLITE_UTF8,
NULL,
myFuncBody,
NULL,
NULL
);
if (error != SQLITE_OK)
{
printf("Error creating the function.\n");
}
for (;;);
return 0;
}
私はその後、オープンは別途sqlite3のコンソールにtest.dbという:
$ sqlite3 test.db
$ sqlite> select myFunc();
Error: no such function: myFunc
私はmyFuncという可視されるべきだと思うが、これはケースではないように思われます。
トリガーを作成することもできますが、結果は明らかに変更されません。
$ sqlite> create trigger trigger1 after insert on test_table begin select myFunc(); end;
$ sqlite> insert into test_table values(-100, -150);
Error: no such function: myFunc
私の目的は、単にtest_tableへの挿入について通知することです。
私のアプローチには基本的に何か間違っていますか?
どんな助けになるでしょうか。
よろしく、 mopyot
すぐにお返事ありがとうございます。理解し、試して検証しました。実際に他のアクターによって実行された挿入について通知される方法はありますか? – mopyot
@mopyot sqlite3エンジンが提供するメカニズムがないため、プロセス間通信の別の手段を使用してこれを達成する必要があります。 – Ctx