Skip to content

Commit

Permalink
wip - Database#discard
Browse files Browse the repository at this point in the history
- needs docs
- needs tests
  • Loading branch information
flavorjones committed Sep 15, 2024
1 parent 6c274b4 commit 1ffe29e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ext/sqlite3/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,31 @@ closed_p(VALUE self)
return Qfalse;
}

// TODO DOCUMENT
static VALUE
discard(VALUE self)
{
sqlite3RubyPtr ctx;
sqlite3_file *sfile;
int status;

TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);

status = sqlite3_file_control(ctx->db, NULL, SQLITE_FCNTL_FILE_POINTER, &sfile);
if (status == 0 && sfile->pMethods != NULL) {
sfile->pMethods->xClose(sfile);
}

status = sqlite3_file_control(ctx->db, NULL, SQLITE_FCNTL_JOURNAL_POINTER, &sfile);
if (status == 0 && sfile->pMethods != NULL) {
sfile->pMethods->xClose(sfile);
}

ctx->db = NULL;

return Qnil;
}

/* call-seq: total_changes
*
* Returns the total number of changes made to this database instance
Expand Down Expand Up @@ -890,6 +915,7 @@ init_sqlite3_database(void)
rb_define_method(cSqlite3Database, "collation", collation, 2);
rb_define_method(cSqlite3Database, "close", sqlite3_rb_close, 0);
rb_define_method(cSqlite3Database, "closed?", closed_p, 0);
rb_define_method(cSqlite3Database, "discard", discard, 0);
rb_define_method(cSqlite3Database, "total_changes", total_changes, 0);
rb_define_method(cSqlite3Database, "trace", trace, -1);
rb_define_method(cSqlite3Database, "last_insert_row_id", last_insert_row_id, 0);
Expand Down

0 comments on commit 1ffe29e

Please sign in to comment.