17 static class SQLCipherRegister :
Sql.ConnectionRegister{
19 if (drivername.
equals(DRIVERNAME)){
30 if (bloaded ==
false){
44 int cdecl sqlite3_open(
110 int err = Native.sqlite3_open(uri,
hdb);
134 return Native.sqlite3_errcode(
hdb);
137 public void key(
byte [] pKey){
138 int err = Native.sqlite3_key(
hdb, pKey, pKey.length);
145 int err = Native.sqlite3_key_v2(
hdb, dbname, pKey, pKey.
length);
152 int err = Native.sqlite3_rekey(
hdb, pKey, pKey.length);
159 int err = Native.sqlite3_rekey_v2(
hdb, dbname, pKey, pKey.
length);
166 return Native.sqlite3_errmsg(
hdb);
175 return new SQLCipherPreparedStatement(
this, sql);
179 return new SQLCipherPreparedStatement(
this);
187 return Native.sqlite3_last_insert_rowid(
hdb);
192 Native.sqlite3_close(
hdb);
206 String [] cof = {
"FULL",
"NORMAL",
"OFF"};
207 return execute(
"PRAGMA synchronous = " + cof[n] +
";");
225 byte [] data =
new byte[len + 1];
227 return new String(data, 0, len);
235 int err = Native.sqlite3_exec(
hdb, stmt, (
long)0, (
long)0, msg);
246 return Native.sqlite3_changes(
hdb);
252 int err = Native.sqlite3_prepare_v2(
hdb, sql, sql.
length(), nstmt, nilptr);
253 if (err != 0 || nstmt == 0){
267 public static class SQLCipherPreparedStatement :
Sql.PreparedStatement{
292 return Native.sqlite3_reset(nstmt) == 0;
295 int r = Native.sqlite3_step(nstmt);
303 int r = Native.sqlite3_step(nstmt);
311 return new SQLCipherResultSet(sqlite,
this);
316 return new SQLCipherResultSet(sqlite,
this);
334 Native.sqlite3_finalize(nstmt);
343 if (value != nilptr){
344 res = Native.sqlite3_bind_text(nstmt, ++param_pos, value, value.
length(), nilptr);
349 res = Native.sqlite3_bind_null(nstmt, ++param_pos);
357 int res = Native.sqlite3_bind_int(nstmt, ++param_pos, value);
364 int res = Native.sqlite3_bind_int64(nstmt, ++param_pos, value);
371 int res = Native.sqlite3_bind_int(nstmt, ++param_pos, value);
378 int res = Native.sqlite3_bind_double(nstmt, ++param_pos, value);
387 if (value != nilptr){
388 res = Native.sqlite3_bind_text(nstmt,
id, value, value.
length(), nilptr);
393 res = Native.sqlite3_bind_null(nstmt,
id);
401 int res = Native.sqlite3_bind_int(nstmt,
id, value);
408 int res = Native.sqlite3_bind_int64(nstmt,
id, value);
415 int res = Native.sqlite3_bind_int(nstmt,
id, value);
421 public void setValue(
int id,
double value)
override{
422 int res = Native.sqlite3_bind_double(nstmt,
id, value);
429 for (
int i = 0; i < args.length; i++){
430 if (args[i].instanceOf(
String)){
433 if (args[i].instanceOf(
int)){
436 if (args[i].instanceOf(
long)){
439 if (args[i].instanceOf(
byte)){
442 if (args[i].instanceOf(
double)){
445 throw new Sql.
SqlException(-1,
"sql " + sql_text +
" dont accept type:" + i);
451 public static class SQLCipherResultSet :
Sql.ResultSet{
453 SQLCipherPreparedStatement
sps;
463 return Native.sqlite3_column_count(sps.getHandle());
467 return Native.sqlite3_column_name(sps.getHandle(), n);
471 int ncolumn = Native.sqlite3_column_count(sps.getHandle());
472 for (
int i = 0; i < ncolumn; i++){
473 String colutext = Native.sqlite3_column_name(sps.getHandle(), i);
474 __fields_Map.
put(colutext, i);
479 return __fields_Map.
get(label);
493 int code = Native.sqlite3_step(sps.getHandle());
513 return sps != nilptr && (sps.getHandle() != 0);
522 return Native.sqlite3_column_int(sps.getHandle(),
label2idx(columnlabel));
526 return Native.sqlite3_column_int64(sps.getHandle(),
label2idx(columnlabel));
530 return Native.sqlite3_column_double(sps.getHandle(),
label2idx(columnlabel));
534 return Native.sqlite3_column_int(sps.getHandle(),
label2idx(columnlabel));
538 return Native.sqlite3_column_int(sps.getHandle(),
label2idx(columnlabel)) != 0;
542 return Native.sqlite3_column_text(sps.getHandle(),
label2idx(columnlabel));
545 public int getInt(
int columnIndex)
override{
546 return Native.sqlite3_column_int(sps.getHandle(), columnIndex);
550 return Native.sqlite3_column_int64(sps.getHandle(), columnIndex);
554 return Native.sqlite3_column_double(sps.getHandle(), columnIndex);
558 return Native.sqlite3_column_int(sps.getHandle(), columnIndex);
562 return Native.sqlite3_column_int(sps.getHandle(), columnIndex)!= 0;
566 return Native.sqlite3_column_text(sps.getHandle(), columnIndex);
static final void output(String)
final String getMessage()
static final void loadLibrary(String)
int cdecl sqlite3_bind_text(Pointer pStmt, int, String, int , Pointer)
int cdecl sqlite3_finalize(Pointer pStmt)
int cdecl sqlite3_rekey(Pointer db, ObjectPtr pKey, int nKey)
int cdecl sqlite3_bind_int(Pointer pStmt, int, int)
int cdecl sqlite3_close( Pointer db)
long cdecl sqlite3_column_int64(Pointer pStmt, int i)
int cdecl sqlite3_rekey_v2(Pointer db, String zDbName, ObjectPtr pKey, int nKey)
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_key_v2(Pointer db, String zDbName, ObjectPtr pKey, int len)
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 )
int cdecl sqlite3_key(Pointer db, ObjectPtr pKey, int len)
String cdecl sqlite3_column_name(Pointer pStmt, int N)
int cdecl sqlite3_changes(Pointer pStmt)
void setValue(int id, byte value) override
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
SQLCipherPreparedStatement(SQLCipher db)
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
void setValues(Object [] args) override
Sql.ResultSet getResult() override
void setValue(byte value) override
void setValue(double value) override
SQLCipherPreparedStatement(SQLCipher db, String sql)
Sql.Connection allocConnection(String drivername) override
String getString(int columnIndex) override
String getString(String columnlabel) override
bool getBoolean(int columnIndex) override
SQLCipherPreparedStatement sps
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
SQLCipherResultSet(SQLCipher db, SQLCipherPreparedStatement _sps)
byte getByte(String columnlabel) override
long getLong(String columnlabel) override
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()
void rekey(String dbname, byte [] pKey)
void create(String uri, String username, String pwd) override
Object getOption(int opt) override
static const String DRIVERNAME
void key(String dbname, byte [] pKey)
long getLastInsertedRowId()
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)
static bool reigstry(String name, ConnectionRegister reg)