/** * Shutdown database connection and associate data * structures. * @param plugin the plugin context (state for this module) */ static void database_shutdown (struct Plugin *plugin) { int result; #if SQLITE_VERSION_NUMBER >= 3007000 sqlite3_stmt *stmt; #endif if (plugin->delRow != NULL) sqlite3_finalize (plugin->delRow); if (plugin->updPrio != NULL) sqlite3_finalize (plugin->updPrio); if (plugin->updRepl != NULL) sqlite3_finalize (plugin->updRepl); if (plugin->selRepl != NULL) sqlite3_finalize (plugin->selRepl); if (plugin->maxRepl != NULL) sqlite3_finalize (plugin->maxRepl); if (plugin->selExpi != NULL) sqlite3_finalize (plugin->selExpi); if (plugin->selZeroAnon != NULL) sqlite3_finalize (plugin->selZeroAnon); if (plugin->insertContent != NULL) sqlite3_finalize (plugin->insertContent); result = sqlite3_close (plugin->dbh); #if SQLITE_VERSION_NUMBER >= 3007000 if (result == SQLITE_BUSY) { GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite", _ ("Tried to close sqlite without finalizing all prepared statements.\n")); stmt = sqlite3_next_stmt (plugin->dbh, NULL); while (stmt != NULL) { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Closing statement %p\n", stmt); result = sqlite3_finalize (stmt); if (result != SQLITE_OK) GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite", "Failed to close statement %p: %d\n", stmt, result); stmt = sqlite3_next_stmt (plugin->dbh, NULL); } result = sqlite3_close (plugin->dbh); } #endif if (SQLITE_OK != result) LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); GNUNET_free_non_null (plugin->fn); }
const bool DB::Close() { if(IsOpen()) { sqlite3_stmt *st=0; while((st=sqlite3_next_stmt(m_db,0))!=0) { sqlite3_finalize(st); } m_lastresult=sqlite3_close(m_db); if(m_lastresult==SQLITE_OK) { m_db=NULL; return true; } else { std::string errmsg(""); int err=GetLastExtendedError(errmsg); HandleError(err,errmsg,"DB::Close"); return false; } } else { return false; } }
static void private_free_database ( sqlite3* self) { /* Make sure we aren't leaking statements. */ lisys_assert (sqlite3_next_stmt (self, NULL) == NULL); sqlite3_close (self); }
void SqlDatabase::close() { if (mpDB) { // ensure that we have destroyed all compiled statements: if (sqlite3_next_stmt(mpDB, 0) != 0) throw new SqlDatabaseException("Tried to close a database before deleting or calling destroy() on all statement objects."); if (sqlite3_close(mpDB) != SQLITE_OK) throw new SqlDatabaseException(sqlite3_errmsg(mpDB)); mpDB = 0; } }
int CSqldalImpl::Close() { int srv ; if ( ! m_pDBConn ) return true; while (sqlite3_next_stmt(m_pDBConn, NULL) != NULL) { sqlite3_finalize(sqlite3_next_stmt(m_pDBConn, NULL)); } srv = sqlite3_close(m_pDBConn); if ( srv != SQLITE_OK ) { WARN("FAIL:sqlite3_close:[%d]:[%s]", sqlite3_errcode(m_pDBConn), sqlite3_errmsg(m_pDBConn)); return false ; } m_pDBConn = NULL; sync() ; return true ; }
static mrb_value mrb_sqlite3_database_close(mrb_state *mrb, mrb_value self) { mrb_value value_context = mrb_iv_get(mrb, self, mrb_intern(mrb, "context")); mrb_sqlite3_database* db = NULL; Data_Get_Struct(mrb, value_context, &mrb_sqlite3_database_type, db); if (!db) { mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument"); } if (db->db) { sqlite3_stmt* stmt = sqlite3_next_stmt(db->db, NULL); while (stmt != NULL) { sqlite3_finalize(stmt); stmt = sqlite3_next_stmt(db->db, NULL); } if (sqlite3_close(db->db) != SQLITE_OK) { mrb_raise(mrb, E_RUNTIME_ERROR, sqlite3_errmsg(db->db)); } db->db = NULL; } return mrb_nil_value(); }
static void deallocate(void * ctx) { sqlite3RubyPtr c = (sqlite3RubyPtr)ctx; sqlite3 * db = c->db; sqlite3_stmt * stmt; if(db) { while((stmt = sqlite3_next_stmt(db, NULL)) != NULL) { sqlite3_finalize(stmt); } sqlite3_close(db); } xfree(c); }
/** * Shutdown database connection and associate data * structures. * @param plugin the plugin context (state for this module) */ static void database_shutdown (struct Plugin *plugin) { int result; sqlite3_stmt *stmt; if (NULL != plugin->cache_block) sqlite3_finalize (plugin->cache_block); if (NULL != plugin->lookup_block) sqlite3_finalize (plugin->lookup_block); if (NULL != plugin->expire_blocks) sqlite3_finalize (plugin->expire_blocks); if (NULL != plugin->delete_block) sqlite3_finalize (plugin->delete_block); result = sqlite3_close (plugin->dbh); if (result == SQLITE_BUSY) { LOG (GNUNET_ERROR_TYPE_WARNING, _("Tried to close sqlite without finalizing all prepared statements.\n")); stmt = sqlite3_next_stmt (plugin->dbh, NULL); while (stmt != NULL) { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Closing statement %p\n", stmt); result = sqlite3_finalize (stmt); if (result != SQLITE_OK) GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite", "Failed to close statement %p: %d\n", stmt, result); stmt = sqlite3_next_stmt (plugin->dbh, NULL); } result = sqlite3_close (plugin->dbh); } if (SQLITE_OK != result) LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); GNUNET_free_non_null (plugin->fn); }
static void cache_close(void) { sqlite3_stmt *stmt; if (!g_db_hdl) return; /* Tear down anything that's in flight */ while ((stmt = sqlite3_next_stmt(g_db_hdl, 0))) sqlite3_finalize(stmt); sqlite3_close(g_db_hdl); DPRINTF(E_DBG, L_CACHE, "Cache closed\n"); }
/** * Shutdown database connection and associate data * structures. * @param plugin the plugin context (state for this module) */ static void database_shutdown (struct Plugin *plugin) { int result; sqlite3_stmt *stmt; while (NULL != (stmt = sqlite3_next_stmt (plugin->dbh, NULL))) { result = sqlite3_finalize (stmt); if (SQLITE_OK != result) LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to close statement %p: %d\n", stmt, result); } if (SQLITE_OK != sqlite3_close (plugin->dbh)) LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); GNUNET_free_non_null (plugin->fn); }
int close_db_handle() { int ret = sqlite3_close(_db_handle); while (ret == SQLITE_BUSY) { sqlite3_stmt* stmt = sqlite3_next_stmt(_db_handle, NULL); if (stmt == NULL) { break; } ret = sqlite3_finalize(stmt); if (ret == SQLITE_OK) { ret = sqlite3_close(_db_handle); } } return ret; }
/** @SYMTestCaseID PDS-SQLITE3-UT-4038 @SYMTestCaseDesc Database handle SQLITE3 tests. List of called SQLITE3 functions: - sqlite3_db_status; - sqlite3_file_control; - sqlite3_limit; - sqlite3_next_stmt; - sqlite3_randomness; @SYMTestPriority High @SYMTestActions Database handle SQLITE3 tests. @SYMTestExpectedResults Test must not fail @SYMREQ REQ10424 */ static void TestSqliteApi2() { int used = 0; int high = 0; int lock = -1; int limit = 0; sqlite3_stmt* next = 0; int err; unsigned char buf[10]; TEST(TheDb != 0); err = sqlite3_db_status(TheDb, SQLITE_DBSTATUS_LOOKASIDE_USED, &used, &high, 0); TEST2(err, SQLITE_OK); PrintI("Lookaside slots: %d\r\n", used); PrintI("Max used lookaside slots: %d\r\n", high); err = sqlite3_file_control(TheDb, "main", SQLITE_FCNTL_LOCKSTATE, &lock); TEST2(err, SQLITE_OK); TEST2(lock, SQLITE_LOCK_NONE); limit = sqlite3_limit(TheDb, SQLITE_LIMIT_LENGTH, -1); TEST(limit > 0); next = sqlite3_next_stmt(TheDb, 0); TEST(!next); memset(buf, 0, sizeof(buf)); sqlite3_randomness(8, buf); memset(buf, 0, sizeof(buf)); sqlite3_randomness(7, buf); memset(buf, 0, sizeof(buf)); sqlite3_randomness(3, buf); }
void DbConn::Close() { if (m_nCounter > 1) { --m_nCounter; return; } STAFF_ASSERT(m_pDb != NULL, "Staff database is not opened"); // free all prepared ops sqlite3_stmt* pStmt = NULL; while ((pStmt = sqlite3_next_stmt(m_pDb, 0)) != NULL) { sqlite3_finalize(pStmt); } // close db int nResult = sqlite3_close(m_pDb); STAFF_ASSERT(nResult == SQLITE_OK, "Failed to close staff database"); m_pDb = NULL; --m_nCounter; }
/////////////////////////////////////////////////////////////////////////////// /// \brief Cleans up the Db object. /// /// \details Assertion failure will result if there are still statement objects /// attached to this database that have not been destroyed. It is up /// to the programmer to ensure that Stmt objects have smaller scope /// than Db objects. Db::~Db() { assert(sqlite3_next_stmt(db_, NULL) == NULL); int result = sqlite3_close(db_); assert(result == SQLITE_OK); }
int proxy_db_close(pool *p, const char *schema_name) { if (p == NULL) { errno = EINVAL; return -1; } if (proxy_dbh != NULL) { pool *tmp_pool; sqlite3_stmt *pstmt; int res; tmp_pool = make_sub_pool(p); /* If we're given a schema name, then just detach that schema from the * database handle. */ if (schema_name != NULL) { const char *stmt; stmt = pstrcat(tmp_pool, "DETACH DATABASE ", schema_name, ";", NULL); res = sqlite3_exec(proxy_dbh, stmt, NULL, NULL, NULL); if (res != SQLITE_OK) { pr_trace_msg(trace_channel, 2, "error detaching '%s' from existing SQLite handle using '%s': %s", schema_name, stmt, sqlite3_errmsg(proxy_dbh)); destroy_pool(tmp_pool); errno = EPERM; return -1; } destroy_pool(tmp_pool); return 0; } /* Make sure to close/finish any prepared statements associated with * the database. */ pstmt = sqlite3_next_stmt(proxy_dbh, NULL); while (pstmt != NULL) { sqlite3_stmt *next; const char *sql; pr_signals_handle(); next = sqlite3_next_stmt(proxy_dbh, pstmt); sql = pstrdup(tmp_pool, sqlite3_sql(pstmt)); res = sqlite3_finalize(pstmt); if (res != SQLITE_OK) { pr_trace_msg(trace_channel, 2, "error finishing prepared statement '%s': %s", sql, sqlite3_errmsg(proxy_dbh)); } else { pr_trace_msg(trace_channel, 18, "finished prepared statement '%s'", sql); } pstmt = next; } destroy_pool(tmp_pool); res = sqlite3_close(proxy_dbh); if (res != SQLITE_OK) { pr_trace_msg(trace_channel, 2, "error closing SQLite database: %s", sqlite3_errmsg(proxy_dbh)); errno = EPERM; return -1; } pr_trace_msg(trace_channel, 18, "%s", "closed SQLite database"); proxy_dbh = NULL; } pr_table_empty(prepared_stmts); pr_table_free(prepared_stmts); prepared_stmts = NULL; return 0; }
DLL_FUNCTION(sqlite3_stmt*) BU_SQLite_Next_Statement(sqlite3* db, sqlite3_stmt* pStmt) { #pragma comment(linker, "/EXPORT:BU_SQLite_Next_Statement=_BU_SQLite_Next_Statement@8") return sqlite3_next_stmt(db, pStmt); }