17 static class SqliteRegister :
Sql.ConnectionRegister{
19 if (drivername.
equals(
"sqlite")){
50 Pointer cdecl memcpy(ObjectPtr dest, Pointer src, Pointer n);
51 Pointer cdecl strcpy(ObjectPtr dest, ObjectPtr src);
52 Pointer cdecl strlen(Pointer);
59 if (bloaded ==
false){
60 if (CSTDNative.load()){
73 int cdecl sqlite3_open(
133 int err = Native.sqlite3_open(uri,
hdb);
157 return Native.sqlite3_errcode(
hdb);
161 return Native.sqlite3_errmsg(
hdb);
170 return new SqlitePreparedStatement(
this, sql);
174 return new SqlitePreparedStatement(
this);
182 return Native.sqlite3_last_insert_rowid(
hdb);
187 Native.sqlite3_close(
hdb);
204 String [] cof = {
"FULL",
"NORMAL",
"OFF"};
205 return execute(
"PRAGMA synchronous = " + cof[n] +
";");
222 long len = CSTDNative.strlen(herr);
223 byte [] data =
new byte[len + 1];
224 CSTDNative.memcpy(data, herr, len);
225 return new String(data, 0, len);
233 int err = Native.sqlite3_exec(
hdb, stmt, (
long)0, (
long)0, msg);
244 return Native.sqlite3_changes(
hdb);
250 int err = Native.sqlite3_prepare_v2(
hdb, sql, sql.
length(), nstmt, nilptr);
251 if (err != 0 || nstmt == 0){
265 public static class SqlitePreparedStatement :
Sql.PreparedStatement{
290 return Native.sqlite3_reset(nstmt) == 0;
293 int r = Native.sqlite3_step(nstmt);
301 int r = Native.sqlite3_step(nstmt);
309 return new SqliteResultSet(sqlite,
this);
314 return new SqliteResultSet(sqlite,
this);
332 Native.sqlite3_finalize(nstmt);
341 if (value != nilptr){
342 res = Native.sqlite3_bind_text(nstmt, ++param_pos, value, value.
length(), nilptr);
347 res = Native.sqlite3_bind_null(nstmt, ++param_pos);
355 int res = Native.sqlite3_bind_int(nstmt, ++param_pos, value);
362 int res = Native.sqlite3_bind_int64(nstmt, ++param_pos, value);
369 int res = Native.sqlite3_bind_int(nstmt, ++param_pos, value);
376 int res = Native.sqlite3_bind_double(nstmt, ++param_pos, value);
385 if (value != nilptr){
386 res = Native.sqlite3_bind_text(nstmt,
id, value, value.
length(), nilptr);
391 res = Native.sqlite3_bind_null(nstmt,
id);
399 int res = Native.sqlite3_bind_int(nstmt,
id, value);
406 int res = Native.sqlite3_bind_int64(nstmt,
id, value);
413 int res = Native.sqlite3_bind_int(nstmt,
id, value);
419 public void setValue(
int id,
double value)
override{
420 int res = Native.sqlite3_bind_double(nstmt,
id, value);
427 for (
int i = 0; i < args.length; i++){
428 if (args[i].instanceOf(
String)){
431 if (args[i].instanceOf(
int)){
434 if (args[i].instanceOf(
long)){
437 if (args[i].instanceOf(
byte)){
440 if (args[i].instanceOf(
double)){
443 throw new Sql.
SqlException(-1,
"sql " + sql_text +
" dont accept type:" + i);
449 public static class SqliteResultSet :
Sql.ResultSet{
451 SqlitePreparedStatement
sps;
461 return Native.sqlite3_column_count(sps.getHandle());
465 return Native.sqlite3_column_name(sps.getHandle(), n);
469 int ncolumn = Native.sqlite3_column_count(sps.getHandle());
470 for (
int i = 0; i < ncolumn; i++){
471 String colutext = Native.sqlite3_column_name(sps.getHandle(), i);
472 __fields_Map.
put(colutext, i);
477 return __fields_Map.
get(label);
491 int code = Native.sqlite3_step(sps.getHandle());
511 return sps != nilptr && (sps.getHandle() != 0);
520 return Native.sqlite3_column_int(sps.getHandle(),
label2idx(columnlabel));
524 return Native.sqlite3_column_int64(sps.getHandle(),
label2idx(columnlabel));
528 return Native.sqlite3_column_double(sps.getHandle(),
label2idx(columnlabel));
532 return Native.sqlite3_column_int(sps.getHandle(),
label2idx(columnlabel));
536 return Native.sqlite3_column_int(sps.getHandle(),
label2idx(columnlabel)) != 0;
540 return Native.sqlite3_column_text(sps.getHandle(),
label2idx(columnlabel));
543 public int getInt(
int columnIndex)
override{
544 return Native.sqlite3_column_int(sps.getHandle(), columnIndex);
548 return Native.sqlite3_column_int64(sps.getHandle(), columnIndex);
552 return Native.sqlite3_column_double(sps.getHandle(), columnIndex);
556 return Native.sqlite3_column_int(sps.getHandle(), columnIndex);
560 return Native.sqlite3_column_int(sps.getHandle(), columnIndex)!= 0;
564 return Native.sqlite3_column_text(sps.getHandle(), columnIndex);
static final int getPlatformId()
static final void output(String)
static const int PLATFORM_WINDOWS
static const int PLATFORM_LINUX
static const int PLATFORM_MACOSX
final String getMessage()
static final void loadLibrary(String)
static bool reigstry(String name, ConnectionRegister reg)
int cdecl sqlite3_bind_text(Pointer pStmt, int, String, int , Pointer)
int cdecl sqlite3_finalize(Pointer pStmt)
int cdecl sqlite3_bind_int(Pointer pStmt, int, int)
int cdecl sqlite3_close( Pointer db)
long cdecl sqlite3_column_int64(Pointer pStmt, int i)
double cdecl sqlite3_column_double(Pointer pStmt, int i)
int cdecl sqlite3_errcode(Pointer db)
String cdecl sqlite3_column_text(Pointer pStmt, int i)
int cdecl sqlite3_bind_double(Pointer pStmt, int, double)
int cdecl sqlite3_bind_null(Pointer pStmt, int)
int cdecl sqlite3_bind_blob(Pointer pStmt, int ,ObjectPtr, int , Pointer)
int cdecl sqlite3_prepare( Pointer db, String zSql, int nBytes, ObjectPtr ppStmt, ObjectPtr pzTail )
int cdecl sqlite3_exec( Pointer db, String sql, Pointer , Pointer , ObjectPtr msg )
int cdecl sqlite3_step(long pStmt)
String cdecl sqlite3_errmsg(Pointer pStmt)
int cdecl sqlite3_column_int(Pointer pStmt, int i)
String cdecl sqlite3_column_decltype(Pointer pStmt, int N)
int cdecl sqlite3_column_count(Pointer pStmt)
long cdecl sqlite3_last_insert_rowid(Pointer pStmt)
int cdecl sqlite3_reset(Pointer pStmt)
int cdecl sqlite3_bind_int64(Pointer pStmt, int, long)
int cdecl sqlite3_prepare_v2( Pointer db, String zSql, int nBytes, ObjectPtr ppStmt, ObjectPtr pzTail )
String cdecl sqlite3_column_name(Pointer pStmt, int N)
int cdecl sqlite3_changes(Pointer pStmt)
void setValue(int id, byte value) override
SqlitePreparedStatement(Sqlite db, String sql)
int get_changes() override
void setValue(int value) override
void setValue(int id, long value) override
void setValue(int id, int value) override
int execute(String sql) override
void setValue(long value) override
Sql.ResultSet executeQuery() override
void setValue(int id, String value) override
void setValue(int id, double value) override
Sql.ResultSet executeQuery(String sql) override
int executeUpdate() override
int executeUpdate(String sql) override
void setValue(String value) override
SqlitePreparedStatement(Sqlite db)
void setValues(Object [] args) override
Sql.ResultSet getResult() override
void setValue(byte value) override
void setValue(double value) override
Sql.Connection allocConnection(String drivername) override
String getString(int columnIndex) override
String getString(String columnlabel) override
bool getBoolean(int columnIndex) override
int getColumnCount() override
String getColumnName(int n)
double getDouble(String columnlabel) override
int label2idx(String label)
long getRowCount() override
Map<String, int> __fields_Map
int getInt(String columnlabel) override
long getLong(int columnIndex) override
double getDouble(int columnIndex) override
SqlitePreparedStatement sps
byte getByte(String columnlabel) override
long getLong(String columnlabel) override
SqliteResultSet(Sqlite db, SqlitePreparedStatement _sps)
bool getBoolean(String columnlabel) override
byte getByte(int columnIndex) override
int getInt(int columnIndex) override
int findColumn(String label) override
int getErrorCode() override
void throw_sqlite_error()
static const int SYNCHRONOUS_OFF
static const int SYNCHRONOUS_NORMAL
void create(String uri, String username, String pwd) override
Object getOption(int opt) override
static const String DRIVERNAME
long getLastInsertedRowId()
static const int SYNCHRONOUS_FULL
int enableSycnhronous(int n)
Sql.Statement createStatement() override
Sql.PreparedStatement prepareStatement(String sql) override
void setOption(int opt, Object option) override
String getError() override
String generateErrorText(long herr, String fallback)