SWIGEXPORT jlong JNICALL Java_com_almworks_sqlite4java__1SQLiteSwiggedJNI_sqlite3_1soft_1heap_1limit64(JNIEnv *jenv, jclass jcls, jlong jarg1) { jlong jresult = 0 ; sqlite3_int64 arg1 ; sqlite3_int64 result; (void)jenv; (void)jcls; arg1 = (sqlite3_int64)jarg1; result = (sqlite3_int64)sqlite3_soft_heap_limit64(arg1); jresult = (jlong)result; return jresult; }
void sqlite3_soft_heap_limit(int n){ if( n<0 ) n = 0; sqlite3_soft_heap_limit64(n); }
int main ( int argc, char **argv ) { int ret = check_args(argc, argv); if (ret) { printf("invalid argument error!\n"); return -1; } if (new_db) { unlink(db_name); } soft_heap_limit = sqlite3_soft_heap_limit64(soft_heap_limit); if ( soft_heap_limit < 0 ) { ret = soft_heap_limit; printf("sqlite3_soft_heap_limit() error: %x", ret); } else { printf("sqlite3_soft_heap_limit64(): prev: %ld (byte) is set to: %lld (byte).\n", soft_heap_limit, sqlite3_soft_heap_limit64(-1)); } sqlite3 *db = NULL; ret = sqlite3_open_v2 (db_name, &db, SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE, NULL); if ( ret != SQLITE_OK ) { printf ( "Can't open database: %s\n", sqlite3_errmsg ( db ) ); return -1; } if (new_db) { // create table, transaction is useful for speed optimization printf("== execute sql_create_table ==\n"); exec_sql_list_in_transaction(db, sql_create_table); } else { printf("== use existing db: %s ==\n", db_name); } int sql_count = 0; int trans_count = 0; uint64_t total_time = 0; int64_t max_highwater = 0; uint64_t total_highwater = 0; do { uint64_t start_time = sceKernelGetProcessTime(); ret = start_transaction(db); if (ret) { printf("start_transaction() err: %x\n", ret); break; } int trans_sql_count = 0; trans_count++; do { fill_sql(sql_count); ret = exec_sql(db, sql_buf); if (ret) { break; } sql_count++; trans_sql_count++; } while (sql_count < total_sql_num && trans_sql_count < max_sql_in_trans); ret = end_transaction(db, ret); if (ret) { printf("end_transaction() err: %x\n", ret); break; } uint64_t end_time = sceKernelGetProcessTime(); total_time += end_time - start_time; printf("[%d] th transaction is end. operated sql num: %d, time: %lu (us)", trans_count, sql_count, end_time - start_time); printf("\t: sqlite3_memory_used(): %lld", sqlite3_memory_used()); int64_t highwater = sqlite3_memory_highwater(true); if (max_highwater < highwater) { max_highwater = highwater; } total_highwater += highwater; printf("\t: sqlite3_memory_highwater(true): %ld\n", highwater); } while (sql_count < total_sql_num); printf("operated sql count: %d, transaction count: %d\n", sql_count, trans_count); printf("total elapsed time: %lu (us)\n", total_time); if (trans_count != 0) { printf("maximum memory highwater: %ld, average high water / transaction: %lu\n", max_highwater, total_highwater / trans_count); } /* // select const char *sql_select[] = { "SELECT * FROM tbl1;", // select all "SELECT id, c1_int FROM tbl1 WHERE 1 < id;", // select 1 < id NULL, // terminater }; printf("\n== execute sql_select ==\n"); exec_sql(db, sql_select); */ sqlite3_close ( db ); return 0; }
SQLiteDBManager::SQLiteDBManager() : db_(nullptr) { sqlite3_soft_heap_limit64(1); setDisabledTables(Flag::getValue("disable_tables")); }