Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions sqlite3/_demo/hello/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"github.com/goplus/llpkg/sqlite3"

"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/os"
)

func main() {
os.Remove(c.Str("test.db"))

var db *sqlite3.Sqlite3
err := sqlite3.DoOpen(c.Str("test.db"), &db)
check(err, db, "sqlite: Open")

err = db.Exec(c.Str("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)"), nil, nil, nil)
check(err, db, "sqlite: Exec CREATE TABLE")

var stmt *sqlite3.Stmt
sql := "INSERT INTO users (id, name) VALUES (?, ?)"
err = db.DoPrepareV3(c.GoStringData(sql), c.Int(len(sql)), 0, &stmt, nil)
check(err, db, "sqlite: PrepareV3 INSERT")

stmt.BindInt(1, 100)
stmt.BindText(2, c.Str("Hello World"), -1, nil)

err = stmt.Step()
checkDone(err, db, "sqlite: Step INSERT 1")

stmt.Reset()
stmt.BindInt(1, 200)
stmt.BindText(2, c.Str("This is llgo"), -1, nil)

err = stmt.Step()
checkDone(err, db, "sqlite: Step INSERT 2")

stmt.Close()

sql = "SELECT * FROM users"
err = db.DoPrepareV3(c.GoStringData(sql), c.Int(len(sql)), 0, &stmt, nil)
check(err, db, "sqlite: PrepareV3 SELECT")

for {
if err = stmt.Step(); err != sqlite3.ROW {
break
}
c.Printf(c.Str("==> id=%d, name=%s\n"), stmt.ColumnInt(0), stmt.ColumnText(1))
}
checkDone(err, db, "sqlite: Step done")

stmt.Close()
db.Close()
}

func check(err c.Int, db *sqlite3.Sqlite3, at string) {
if err != sqlite3.OK {
c.Printf(c.Str("==> %s Error: (%d) %s\n"), c.AllocaCStr(at), err, db.Errmsg())
c.Exit(1)
}
}

func checkDone(err c.Int, db *sqlite3.Sqlite3, at string) {
if err != sqlite3.DONE {
check(err, db, at)
}
}
5 changes: 5 additions & 0 deletions sqlite3/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/goplus/llpkg/sqlite3

go 1.20

require github.com/goplus/llgo v0.10.0
2 changes: 2 additions & 0 deletions sqlite3/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/goplus/llgo v0.10.0 h1:s3U3cnO3cploF1xCCJleAb16NQFAmHxdUmdrNhRH3hY=
github.com/goplus/llgo v0.10.0/go.mod h1:YfOHsT/g3lc9b4GclLj812YzdSsJr0kd3CCB830TqHE=
11 changes: 11 additions & 0 deletions sqlite3/llcppg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "sqlite3",
"cflags": "$(pkg-config --cflags sqlite3)",
"libs": "$(pkg-config --libs sqlite3)",
"include": [
"sqlite3ext.h",
"sqlite3.h"
],
"trimPrefixes": ["sqlite3_","SQLITE_"],
"cplusplus": false
}
43 changes: 43 additions & 0 deletions sqlite3/llcppg.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Fts5Context
Fts5ExtensionApi
Fts5PhraseIter
Fts5Tokenizer
fts5_api Fts5Api
fts5_extension_function Fts5ExtensionFunction
fts5_tokenizer Fts5Tokenizer__1
fts5_tokenizer_v2 Fts5TokenizerV2
sqlite3 Sqlite3
sqlite3_api_routines ApiRoutines
sqlite3_backup Backup
sqlite3_blob Blob
sqlite3_callback Callback
sqlite3_context Context
sqlite3_destructor_type DestructorType
sqlite3_file File
sqlite3_filename Filename
sqlite3_index_info IndexInfo
sqlite3_int64 Int64
sqlite3_io_methods IoMethods
sqlite3_loadext_entry LoadextEntry
sqlite3_mem_methods MemMethods
sqlite3_module Module
sqlite3_mutex Mutex
sqlite3_mutex_methods MutexMethods
sqlite3_pcache Pcache
sqlite3_pcache_methods PcacheMethods
sqlite3_pcache_methods2 PcacheMethods2
sqlite3_pcache_page PcachePage
sqlite3_rtree_dbl RtreeDbl
sqlite3_rtree_geometry RtreeGeometry
sqlite3_rtree_query_info RtreeQueryInfo
sqlite3_snapshot Snapshot
sqlite3_stmt Stmt
sqlite3_str Str
sqlite3_syscall_ptr SyscallPtr
sqlite3_uint64 Uint64
sqlite3_value Value
sqlite3_vfs Vfs
sqlite3_vtab Vtab
sqlite3_vtab_cursor VtabCursor
sqlite_int64 SqliteInt64
sqlite_uint64 SqliteUint64
Loading
Loading