diff options
author | mattn <mattn.jp@gmail.com> | 2013-09-12 09:40:57 +0900 |
---|---|---|
committer | mattn <mattn.jp@gmail.com> | 2013-09-12 09:40:57 +0900 |
commit | 1c16dbe6094532d16d1a89c38012aa9118764476 (patch) | |
tree | a219851c466b7a0172e9f6f829f5e546eab08591 /_example/extension | |
parent | Execer/Queryer should use transaction (diff) | |
download | golite-1c16dbe6094532d16d1a89c38012aa9118764476.tar.gz golite-1c16dbe6094532d16d1a89c38012aa9118764476.tar.xz |
rename
Diffstat (limited to '_example/extension')
-rw-r--r-- | _example/extension/Makefile | 22 | ||||
-rw-r--r-- | _example/extension/extension.go | 43 | ||||
-rw-r--r-- | _example/extension/sqlite3_mod_regexp.c | 31 |
3 files changed, 0 insertions, 96 deletions
diff --git a/_example/extension/Makefile b/_example/extension/Makefile deleted file mode 100644 index 97b1e0f..0000000 --- a/_example/extension/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -ifeq ($(OS),Windows_NT) -EXE=extension.exe -EXT=sqlite3_mod_regexp.dll -RM=cmd /c del -LDFLAG= -else -EXE=extension -EXT=sqlite3_mod_regexp.so -RM=rm -LDFLAG=-fPIC -endif - -all : $(EXE) $(EXT) - -$(EXE) : extension.go - go build $< - -$(EXT) : sqlite3_mod_regexp.c - gcc $(LDFLAG) -shared -o $@ $< -lsqlite3 -lpcre - -clean : - @-$(RM) $(EXE) $(EXT) diff --git a/_example/extension/extension.go b/_example/extension/extension.go deleted file mode 100644 index 61ceb55..0000000 --- a/_example/extension/extension.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "database/sql" - "fmt" - "github.com/mattn/go-sqlite3" - "log" -) - -func main() { - sql.Register("sqlite3_with_extensions", - &sqlite3.SQLiteDriver{ - Extensions: []string{ - "sqlite3_mod_regexp", - }, - }) - - db, err := sql.Open("sqlite3_with_extensions", ":memory:") - if err != nil { - log.Fatal(err) - } - defer db.Close() - - // Force db to make a new connection in pool - // by putting the original in a transaction - tx, err := db.Begin() - if err != nil { - log.Fatal(err) - } - defer tx.Commit() - - // New connection works (hopefully!) - rows, err := db.Query("select 'hello world' where 'hello world' regexp '^hello.*d$'") - if err != nil { - log.Fatal(err) - } - defer rows.Close() - for rows.Next() { - var helloworld string - rows.Scan(&helloworld) - fmt.Println(helloworld) - } -} diff --git a/_example/extension/sqlite3_mod_regexp.c b/_example/extension/sqlite3_mod_regexp.c deleted file mode 100644 index 277764d..0000000 --- a/_example/extension/sqlite3_mod_regexp.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <pcre.h> -#include <string.h> -#include <stdio.h> -#include <sqlite3ext.h> - -SQLITE_EXTENSION_INIT1 -static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) { - if (argc >= 2) { - const char *target = (const char *)sqlite3_value_text(argv[1]); - const char *pattern = (const char *)sqlite3_value_text(argv[0]); - const char* errstr = NULL; - int erroff = 0; - int vec[500]; - int n, rc; - pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL); - rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500); - if (rc <= 0) { - sqlite3_result_error(context, errstr, 0); - return; - } - sqlite3_result_int(context, 1); - } -} - -#ifdef _WIN32 -__declspec(dllexport) -#endif -int sqlite3_extension_init(sqlite3 *db, char **errmsg, const sqlite3_api_routines *api) { - SQLITE_EXTENSION_INIT2(api); - return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, (void*)db, regexp_func, NULL, NULL); -} |