| 6 | jclass class = (*env)->FindClass(env, "org/telegram/SQLite/SQLitePreparedStatement"); |
| 7 | queryArgsCountField = (*env)->GetFieldID(env, class, "queryArgsCount", "I"); |
| 8 | return JNI_VERSION_1_6; |
| 9 | } |
| 10 |
| 11 | int Java_org_telegram_SQLite_SQLitePreparedStatement_step(JNIEnv *env, jobject object, int statementHandle) { |
| 12 | sqlite3_stmt *handle = (sqlite3_stmt *) statementHandle; |
| 13 |
| 14 | int errcode = sqlite3_step(handle); |
| 15 | if (errcode == SQLITE_ROW) { |
| 16 | return 0; |
| 17 | } else if(errcode == SQLITE_DONE) { |
| 18 | return 1; |
| 19 | } else if(errcode == SQLITE_BUSY) { |
| 20 | return -1; |
| 21 | } |
| 22 | throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode); |
| 23 | } |
| 24 |
| 25 | int Java_org_telegram_SQLite_SQLitePreparedStatement_prepare(JNIEnv *env, jobject object, int sqliteHandle, jstring sql) { |
| 26 | sqlite3 *handle = (sqlite3 *) sqliteHandle; |
| 27 |
| 28 | char const *sqlStr = (*env)->GetStringUTFChars(env, sql, 0); |
| 29 |
| 30 | sqlite3_stmt *stmt_handle; |
| 31 |
| 32 | int errcode = sqlite3_prepare_v2(handle, sqlStr, -1, &stmt_handle, 0); |
| 33 | if (SQLITE_OK != errcode) { |
| 34 | throw_sqlite3_exception(env, handle, errcode); |
| 35 | } else { |
| 36 | int argsCount = sqlite3_bind_parameter_count(stmt_handle); |
| 37 | (*env)->SetIntField(env, object, queryArgsCountField, argsCount); |
| 38 | } |
| 39 |
| 40 | if (sqlStr != 0) { |
| 41 | (*env)->ReleaseStringUTFChars(env, sql, sqlStr); |
| 42 | } |
| 43 |
| 44 | return (int) stmt_handle; |
| 45 | } |
| 46 |
| 47 | void Java_org_telegram_SQLite_SQLitePreparedStatement_reset(JNIEnv *env, jobject object, int statementHandle) { |
| 48 | sqlite3_stmt *handle = (sqlite3_stmt *) statementHandle; |
| 49 |
| 50 | int errcode = sqlite3_reset(handle); |
| 51 | if (SQLITE_OK != errcode) { |
| 52 | throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode); |
| 53 | } |
| 54 | } |
| 55 |
| 56 | void Java_org_telegram_SQLite_SQLitePreparedStatement_finalize(JNIEnv *env, jobject object, int statementHandle) { |
| 57 | sqlite3_finalize((sqlite3_stmt *) statementHandle); |
| 58 | } |
| 59 |
| 60 | void Java_org_telegram_SQLite_SQLitePreparedStatement_bindByteBuffer(JNIEnv *env, jobject object, int statementHandle, int index, jobject value, int length) { |
| 61 | sqlite3_stmt *handle = (sqlite3_stmt *) statementHandle; |
| 62 | jbyte *buf = (*env)->GetDirectBufferAddress(env, value); |
| 63 |
| 64 | int errcode = sqlite3_bind_blob(handle, index, buf, length, SQLITE_STATIC); |
| 65 | if (SQLITE_OK != errcode) { |
| 66 | throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode); |
| 67 | } |
| 68 | } |
| 69 |
| 70 | void Java_org_telegram_SQLite_SQLitePreparedStatement_bindString(JNIEnv *env, jobject object, int statementHandle, int index, jstring value) { |
| 71 | sqlite3_stmt *handle = (sqlite3_stmt *) statementHandle; |
| 72 |
| 73 | char const *valueStr = (*env)->GetStringUTFChars(env, value, 0); |
| 74 |
| 75 | int errcode = sqlite3_bind_text(handle, index, valueStr, -1, SQLITE_TRANSIENT); |
| 76 | if (SQLITE_OK != errcode) { |
| 77 | throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode); |
| 78 | } |
| 79 |
| 80 | if (valueStr != 0) { |
| 81 | (*env)->ReleaseStringUTFChars(env, value, valueStr); |
| 82 | } |
| 83 | } |
| 84 |
| 85 | void Java_org_telegram_SQLite_SQLitePreparedStatement_bindInt(JNIEnv *env, jobject object, int statementHandle, int index, int value) { |
| 86 | sqlite3_stmt *handle = (sqlite3_stmt *) statementHandle; |
| 87 |
| 88 | int errcode = sqlite3_bind_int(handle, index, value); |
| 89 | if (SQLITE_OK != errcode) { |
| 90 | throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode); |
| 91 | } |
| 92 | } |
| 93 |
| 94 | void Java_org_telegram_SQLite_SQLitePreparedStatement_bindLong(JNIEnv *env, jobject object, int statementHandle, int index, long long value) { |
| 95 | sqlite3_stmt *handle = (sqlite3_stmt *) statementHandle; |
| 96 |
| 97 | int errcode = sqlite3_bind_int64(handle, index, value); |
| 98 | if (SQLITE_OK != errcode) { |
| 99 | throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode); |
| 100 | } |
| 101 | } |
| 102 |
| 103 | void Java_org_telegram_SQLite_SQLitePreparedStatement_bindDouble(JNIEnv *env, jobject object, int statementHandle, int index, double value) { |
| 104 | sqlite3_stmt *handle = (sqlite3_stmt *) statementHandle; |
| 105 |
| 106 | int errcode = sqlite3_bind_double(handle, index, value); |
| 107 | if (SQLITE_OK != errcode) { |
| 108 | throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode); |
| 109 | } |
| 110 | } |
| 111 |
| 112 | void Java_org_telegram_SQLite_SQLitePreparedStatement_bindNull(JNIEnv *env, jobject object, int statementHandle, int index) { |
| 113 | sqlite3_stmt *handle = (sqlite3_stmt *) statementHandle; |
| 114 |
| 115 | int errcode = sqlite3_bind_null(handle, index); |
| 116 | if (SQLITE_OK != errcode) { |
| 117 | throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode); |
| 118 | } |
| 119 | } |
| 120 |
| 121 |