FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/modules/dasSQLITE/src/dasSQLITE.main.cpp at master · frodiwe/daScript · GitHub
frodiwe
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
modules
/
dasSQLITE
/
src
/
dasSQLITE.main.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
141 lines (121 loc) · 5.61 KB
Breadcrumbs
daScript
/
modules
/
dasSQLITE
/
src
/
dasSQLITE.main.cpp
Copy path
File metadata and controls
141 lines (121 loc) · 5.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#
include
"
daScript/misc/platform.h
"
#
include
"
daScript/ast/ast.h
"
#
include
"
daScript/ast/ast_interop.h
"
#
include
"
daScript/ast/ast_typefactory_bind.h
"
#
include
"
daScript/ast/ast_handle.h
"
#
include
"
dasSQLITE.h
"
#
include
"
aot_sqlite.h
"
namespace
das
{
#
if
0
SQLITE_API int sqlite3_exec(
sqlite3*, /* An open database */
const char *sql, /* SQL to be evaluated */
int (*callback)(void*,int,char**,char**), /* Callback function */
void *, /* 1st argument to callback */
char **errmsg /* Error msg written here */
);
#
endif
int
sqlite3_exec
(sqlite3 * db,
const
char
* sql,
char
** errmsg) {
return
sqlite3_exec
(db, sql,
nullptr
,
nullptr
, errmsg);
}
struct
ExecCallback
{
const
Block * block =
nullptr
;
Context * context =
nullptr
;
LineInfoArg * at =
nullptr
;
};
int
exec_callback
(
void
* arg,
int
argc,
char
** argv,
char
** colName ) {
ExecCallback * cb = (ExecCallback *) arg;
Array arrFields;
array_mark_locked
(arrFields, (
char
*) argv, argc);
Array arrColumns;
array_mark_locked
(arrColumns, (
char
*) colName, argc);
vec4f args[
2
] = {
cast<Array *>::
from
(&arrFields),
cast<Array *>::
from
(&arrColumns)
};
auto
res = cb->
context
->
invoke
(*cb->
block
, args,
nullptr
, cb->
at
);
return
cast<
int
>::
to
(res);
}
int
sqlite3_exec_cb
(sqlite3 * db,
const
char
* sql,
char
** errmsg,
const
TBlock<
int
,
const
TTemporary<TArray<
char
*>>,
const
TTemporary<TArray<
char
*>>> & block,
Context * context, LineInfoArg * at ) {
ExecCallback cb;
cb.
block
= █
cb.
context
= context;
cb.
at
= at;
return
sqlite3_exec
(db, sql, exec_callback, &cb, errmsg);
}
int
sqlite3_bind_blob_
( sqlite3_stmt * stmt,
int
index,
void
* data,
int
size ) {
return
sqlite3_bind_blob
(stmt, index, data, size,
SQLITE_TRANSIENT
);
}
int
sqlite3_bind_text_
( sqlite3_stmt * stmt,
int
index,
const
char
* data ) {
return
sqlite3_bind_text
(stmt, index, data, -
1
,
SQLITE_TRANSIENT
);
}
//
pzTail-free wrapper: libsqlite3's pzTail (const char **) renders to daslang
//
as `string const?`, which the AOT codegen emits as `char * const *` instead
//
of `const char **` (the const lands on the wrong indirection level). We
//
don't use pzTail in any boost call, so dropping the parameter at the C++
//
boundary sidesteps the codegen bug entirely.
int
sqlite3_prepare_v2_no_tail
( sqlite3 * db,
const
char
* sql, sqlite3_stmt ** stmt ) {
return
sqlite3_prepare_v2
(db, sql, -
1
, stmt,
nullptr
);
}
//
vfs-free open_v2 wrapper: daslang's `string` parameter cannot represent C `NULL`,
//
so an empty daslang string passed as zVfs hits sqlite as "" and fails ("no such vfs:").
//
The schema_from macro needs READONLY-no-create open semantics, so we expose this
//
shim that always passes nullptr for the default vfs.
int
sqlite3_open_v2_no_vfs
(
const
char
* filename, sqlite3 ** ppDb,
int
flags ) {
return
sqlite3_open_v2
(filename, ppDb, flags,
nullptr
);
}
void
Module_dasSQLITE::initMain
() {
addExtern<
DAS_BIND_FUN
(sqlite3_exec)>(*
this
,lib,
"
sqlite3_exec
"
,
SideEffects::worstDefault,
"
sqlite3_exec
"
)
->
args
({
"
db
"
,
"
sql
"
,
"
errmsg
"
});
addExtern<
DAS_BIND_FUN
(sqlite3_exec_cb)>(*
this
,lib,
"
sqlite3_exec
"
,
SideEffects::worstDefault,
"
sqlite3_exec_cb
"
)
->
args
({
"
db
"
,
"
sql
"
,
"
errmsg
"
,
"
block
"
,
"
context
"
,
"
at
"
});
addExtern<
DAS_BIND_FUN
(sqlite3_bind_blob_)>(*
this
,lib,
"
sqlite3_bind_blob
"
,
SideEffects::worstDefault,
"
sqlite3_bind_blob_
"
)
->
args
({
"
stmt
"
,
"
sqlite3_bind_text_
"
,
"
data
"
,
"
size
"
});
addExtern<
DAS_BIND_FUN
(sqlite3_bind_text_)>(*
this
,lib,
"
sqlite3_bind_text
"
,
SideEffects::worstDefault,
"
sqlite3_bind_text_
"
)
->
args
({
"
stmt
"
,
"
index
"
,
"
data
"
});
addExtern<
DAS_BIND_FUN
(sqlite3_prepare_v2_no_tail)>(*
this
,lib,
"
sqlite3_prepare_v2_no_tail
"
,
SideEffects::worstDefault,
"
sqlite3_prepare_v2_no_tail
"
)
->
args
({
"
db
"
,
"
sql
"
,
"
stmt
"
});
addExtern<
DAS_BIND_FUN
(sqlite3_open_v2_no_vfs)>(*
this
,lib,
"
sqlite3_open_v2_no_vfs
"
,
SideEffects::worstDefault,
"
sqlite3_open_v2_no_vfs
"
)
->
args
({
"
filename
"
,
"
ppDb
"
,
"
flags
"
});
addExtern<
DAS_BIND_FUN
(sqlite3_register_function)>(*
this
,lib,
"
sqlite3_register_function
"
,
SideEffects::worstDefault,
"
sqlite3_register_function
"
)
->
args
({
"
db
"
,
"
name
"
,
"
fn
"
,
"
nArgs
"
,
"
tag0
"
,
"
tag1
"
,
"
tag2
"
,
"
tag3
"
,
"
retTag
"
,
"
deterministic
"
,
"
directonly
"
,
"
context
"
,
"
at
"
});
addExtern<
DAS_BIND_FUN
(sqlite3_backup_run)>(*
this
,lib,
"
sqlite3_backup_run
"
,
SideEffects::worstDefault,
"
sqlite3_backup_run
"
)
->
args
({
"
src
"
,
"
dst
"
});
for
(
auto
& pfn :
this
->
functions
.
each
() ) {
//
ok, lets fix up everything returning uint8? into returning string# and make it unsafe operation
if
( pfn->
result
->
isPointer
() && pfn->
result
->
firstType
&&
pfn->
result
->
firstType
->
baseType
==Type::tUInt8 ) {
pfn->
result
=
new
TypeDecl
(Type::tString);
pfn->
result
->
constant
=
true
;
pfn->
result
->
temporary
=
true
;
pfn->
unsafeOperation
=
true
;
}
//
fixup module functions, so that there is a string cast
bool
anyString =
false
;
for
(
auto
& arg : pfn->
arguments
) {
if
( arg->
type
->
isString
() && !arg->
type
->
ref
) {
anyString =
true
;
}
}
if
( anyString ) {
pfn->
needStringCast
=
true
;
}
}
}
ModuleAotType
Module_dasSQLITE::aotRequire
( TextWriter & tw )
const
{
tw <<
"
#include
\"
../modules/dasSQLITE/src/aot_sqlite.h
\"\n
"
;
return
ModuleAotType::cpp;
}
}
Back
|
FazBrowse Home
|
New Git URL