fce_sqlite_connector/sqlite3_connector/import_functions.rs
1extern crate fluence;
2
3use self::fluence::fce;
4
5pub(crate) type Sqlite3DbHandle = u32;
6pub(crate) type Sqlite3StmtHandle = u32;
7
8#[fce]
9#[derive(Clone, Debug)]
10pub struct DBOpenDescriptor {
11 pub ret_code: i32,
12 pub db_handle: u32,
13}
14
15#[fce]
16#[derive(Clone, Debug)]
17pub struct DBPrepareDescriptor {
18 pub ret_code: i32,
19 pub stmt_handle: u32,
20 pub tail: u32,
21}
22
23#[fce]
24#[derive(Clone, Debug)]
25pub struct DBExecDescriptor {
26 pub ret_code: i32,
27 pub err_msg: String,
28}
29
30#[fce]
31#[link(wasm_import_module = "sqlite3")]
32extern "C" {
33 /*
34 SQLITE_API int sqlite3_open_v2(
35 const char *filename, /* Database filename (UTF-8) */
36 sqlite3 **ppDb, /* OUT: SQLite db handle */
37 int flags, /* Flags */
38 const char *zVfs /* Name of VFS module to use */
39 );
40 */
41 pub fn sqlite3_open_v2(filename: String, flags: i32, vfs: String) -> DBOpenDescriptor;
42
43 // SQLITE_API int sqlite3_close(sqlite3*);
44 pub fn sqlite3_close(db_handle: u32) -> i32;
45
46 /*
47 SQLITE_API int sqlite3_prepare_v2(
48 sqlite3 *db, /* Database handle */
49 const char *zSql, /* SQL statement, UTF-8 encoded */
50 int nByte, /* Maximum length of zSql in bytes. */
51 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
52 const char **pzTail /* OUT: Pointer to unused portion of zSql */
53 );
54 */
55 pub fn sqlite3_prepare_v2(db_handle: u32, sql: String) -> DBPrepareDescriptor;
56
57 /*
58 SQLITE_API int sqlite3_exec(
59 sqlite3*, /* An open database */
60 const char *sql, /* SQL to be evaluated */
61 int (*callback)(void*,int,char**,char**), /* Callback function */
62 void *, /* 1st argument to callback */
63 char **errmsg /* Error msg written here */
64 );
65 */
66 pub fn sqlite3_exec(
67 db_handle: u32,
68 sql: String,
69 callback_id: i32,
70 callback_arg: i32,
71 ) -> DBExecDescriptor;
72
73 // SQLITE_API int sqlite3_libversion_number(void);
74 pub fn sqlite3_libversion_number() -> i32;
75
76 // SQLITE_API int sqlite3_changes(sqlite3*);
77 pub fn sqlite3_changes(db_handle: u32) -> i32;
78
79 // SQLITE_API int sqlite3_total_changes(sqlite3*);
80 pub fn sqlite3_total_changes(db_handle: u32) -> i32;
81
82 // SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
83 pub fn sqlite3_busy_timeout(db_handle: u32, ms: u32) -> i32;
84
85 // SQLITE_API const char *sqlite3_errmsg(sqlite3*);
86 pub fn sqlite3_errmsg(db_handle: u32) -> String;
87
88 // SQLITE_API int sqlite3_errcode(sqlite3 *db);
89 pub fn sqlite3_errcode(db: u32) -> i32;
90
91 // SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
92 pub fn sqlite3_column_type(stmt_handle: u32, icol: u32) -> i32;
93
94 // SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
95 pub fn sqlite3_column_name(stmt_handle: u32, N: u32) -> String;
96
97 // SQLITE_API int sqlite3_step(sqlite3_stmt*);
98 pub fn sqlite3_step(stmt_handle: u32) -> i32;
99
100 // SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
101 pub fn sqlite3_reset(stmt_handle: u32) -> i32;
102
103 // SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
104 pub fn sqlite3_bind_blob(stmt_handle: u32, pos: i32, blob: Vec<u8>, xDel: i32) -> i32;
105
106 // SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
107 pub fn sqlite3_bind_double(stmt_handle: u32, pos: i32, value: f64) -> i32;
108
109 // SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
110 pub fn sqlite3_bind_int64(stmt_handle: u32, pos: i32, value: i64) -> i32;
111
112 // SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
113 pub fn sqlite3_bind_null(stmt_handle: u32, pos: i32) -> i32;
114
115 // SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
116 pub fn sqlite3_bind_text(stmt_handle: u32, pos: i32, text: String, xDel: i32) -> i32;
117
118 // SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt)
119 pub fn sqlite3_column_count(stmt_handle: u32) -> i32;
120
121 // SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
122 pub fn sqlite3_column_blob(stmt_handle: u32, icol: i32) -> Vec<u8>;
123
124 // SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
125 pub fn sqlite3_column_double(stmt_handle: u32, icol: i32) -> f64;
126
127 // SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
128 pub fn sqlite3_column_int64(stmt_handle: u32, icol: u32) -> i64;
129
130 // SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
131 pub fn sqlite3_column_text(stmt_handle: u32, icol: u32) -> String;
132
133 // SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
134 pub fn sqlite3_column_bytes(stmt_handle: u32, icol: u32) -> i32;
135
136 // SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
137 pub fn sqlite3_finalize(stmt_handle: u32) -> i32;
138}