2024-08-20 11:09:35 +00:00
|
|
|
package main
|
|
|
|
|
2024-08-26 19:10:35 +00:00
|
|
|
// #include <stdlib.h>
|
|
|
|
// #include <stdio.h>
|
2024-08-20 11:09:35 +00:00
|
|
|
import "C"
|
|
|
|
import (
|
2024-08-26 19:10:35 +00:00
|
|
|
"fmt"
|
2024-08-20 11:09:35 +00:00
|
|
|
"strings"
|
2024-08-26 19:10:35 +00:00
|
|
|
"unsafe"
|
2024-08-20 11:09:35 +00:00
|
|
|
|
2024-08-20 19:10:21 +00:00
|
|
|
"github.com/nesterow/dal/pkg/facade"
|
2024-08-20 17:34:01 +00:00
|
|
|
|
2024-08-20 11:09:35 +00:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
)
|
|
|
|
|
2024-08-26 19:10:35 +00:00
|
|
|
var iterators = make(map[int]*facade.RowsIter)
|
|
|
|
var itersize = make(map[int]C.int)
|
|
|
|
|
2024-08-20 11:09:35 +00:00
|
|
|
//export InitSQLite
|
|
|
|
func InitSQLite(pragmas string) {
|
|
|
|
pragmasArray := strings.Split(pragmas, ";")
|
|
|
|
facade.InitSQLite(pragmasArray)
|
|
|
|
}
|
|
|
|
|
2024-08-26 19:10:35 +00:00
|
|
|
//export CreateRowIterator
|
|
|
|
func CreateRowIterator(input []byte) C.int {
|
|
|
|
var it = &facade.RowsIter{}
|
|
|
|
it.Exec(input)
|
|
|
|
ptr := C.int(len(iterators))
|
|
|
|
iterators[len(iterators)] = it
|
|
|
|
defer fmt.Println(ptr)
|
|
|
|
return ptr
|
|
|
|
}
|
|
|
|
|
|
|
|
//export NextRow
|
|
|
|
func NextRow(itid C.int) unsafe.Pointer {
|
|
|
|
it := iterators[int(itid)]
|
|
|
|
if it.Result != nil {
|
|
|
|
itersize[int(itid)] = C.int(len(it.Result))
|
|
|
|
return C.CBytes(it.Result)
|
|
|
|
}
|
|
|
|
data := it.Next()
|
|
|
|
if data == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
itersize[int(itid)] = C.int(len(data))
|
|
|
|
res := C.CBytes(data)
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
//export GetLen
|
|
|
|
func GetLen(idx C.int) C.int {
|
|
|
|
return itersize[int(idx)]
|
|
|
|
}
|
|
|
|
|
|
|
|
//export FreeIter
|
|
|
|
func FreeIter(itid C.int) {
|
|
|
|
it := iterators[int(itid)]
|
|
|
|
it.Close()
|
|
|
|
delete(iterators, int(itid))
|
|
|
|
delete(itersize, int(itid))
|
2024-08-20 11:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {}
|