Skip to content

Commit

Permalink
- remove non necessary macro TRACE from module.c
Browse files Browse the repository at this point in the history
- fix unit test so that it can be launched using 'rake'
  • Loading branch information
duhlin committed Dec 9, 2013
1 parent 910e416 commit d02b633
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 31 deletions.
29 changes: 0 additions & 29 deletions ext/sqlite3/module.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
#include <stdio.h>
#include <sqlite3_ruby.h>

#undef ENABLE_TRACE

#ifdef ENABLE_TRACE
static FILE* pf;
# define TRACE(str) \
fprintf(pf, "%s:%d:%s\n", __FILE__, __LINE__, str); \
fflush(pf);
#else
# define TRACE(str) ;
#endif

VALUE cSqlite3Module;

/** structure for ruby virtual table: inherits from sqlite3_vtab */
Expand Down Expand Up @@ -46,8 +35,6 @@ static int xCreate(sqlite3* db, VALUE *module_name,
VALUE ruby_class_args[0];
const char* module_name_cstr = (const char*)StringValuePtr(*module_name);
const char* table_name_cstr = (const char*)argv[2];
TRACE("xCreate");


// lookup for ruby class named like <module_id>::<table_name>
module_id = rb_intern( module_name_cstr );
Expand All @@ -73,7 +60,6 @@ static int xCreate(sqlite3* db, VALUE *module_name,
if ( sqlite3_declare_vtab(db, StringValuePtr(sql_stmt)) )
rb_raise(rb_eArgError, "fail to declare virtual table");

TRACE("xCreate done");
return SQLITE_OK;
}

Expand All @@ -82,32 +68,27 @@ static int xConnect(sqlite3* db, void *pAux,
ruby_sqlite3_vtab **ppVTab,
char **pzErr)
{
TRACE("xConnect");
return xCreate(db, pAux, argc, argv, ppVTab, pzErr);
}

static int xBestIndex(ruby_sqlite3_vtab *pVTab, sqlite3_index_info* info)
{
TRACE("xBestIndex");
return SQLITE_OK;
}

static int xDestroy(ruby_sqlite3_vtab *pVTab)
{
TRACE("xDestroy");
free(pVTab);
return SQLITE_OK;
}

static int xDisconnect(ruby_sqlite3_vtab *pVTab)
{
TRACE("xDisconnect");
return xDestroy(pVTab);
}

static int xOpen(ruby_sqlite3_vtab *pVTab, ruby_sqlite3_vtab_cursor **ppCursor)
{
TRACE("xOpen");
rb_funcall( pVTab->vtable, rb_intern("open"), 0 );
*ppCursor = (ruby_sqlite3_vtab_cursor*)malloc(sizeof(ruby_sqlite3_vtab_cursor));
(*ppCursor)->pVTab = pVTab;
Expand All @@ -117,15 +98,13 @@ static int xOpen(ruby_sqlite3_vtab *pVTab, ruby_sqlite3_vtab_cursor **ppCursor)

static int xClose(ruby_sqlite3_vtab_cursor* cursor)
{
TRACE("xClose");
rb_funcall( cursor->pVTab->vtable, rb_intern("close"), 0 );
free(cursor);
return SQLITE_OK;
}

static int xNext(ruby_sqlite3_vtab_cursor* cursor)
{
TRACE("xNext");
cursor->row = rb_funcall(cursor->pVTab->vtable, rb_intern("next"), 0);
++(cursor->rowid);
return SQLITE_OK;
Expand All @@ -134,29 +113,25 @@ static int xNext(ruby_sqlite3_vtab_cursor* cursor)
static int xFilter(ruby_sqlite3_vtab_cursor* cursor, int idxNum, const char *idxStr,
int argc, sqlite3_value **argv)
{
TRACE("xFilter");
cursor->rowid = 0;
return xNext(cursor);
}

static int xEof(ruby_sqlite3_vtab_cursor* cursor)
{
TRACE("xEof");
return (cursor->row == Qnil);
}

static int xColumn(ruby_sqlite3_vtab_cursor* cursor, sqlite3_context* context, int i)
{
VALUE val = rb_ary_entry(cursor->row, i);
TRACE("xColumn(%d)");

set_sqlite3_func_result(context, val);
return SQLITE_OK;
}

static int xRowid(ruby_sqlite3_vtab_cursor* cursor, sqlite_int64 *pRowid)
{
TRACE("xRowid");
*pRowid = cursor->rowid;
return SQLITE_OK;
}
Expand Down Expand Up @@ -228,15 +203,11 @@ static VALUE initialize(VALUE self, VALUE db, VALUE name)
&(ctx->module_name) //the vtable required the module name
);

TRACE("module initialized");
return self;
}

void init_sqlite3_module()
{
#ifdef ENABLE_TRACE
pf = fopen("trace.log", "w");
#endif
cSqlite3Module = rb_define_class_under(mSqlite3, "Module", rb_cObject);
rb_define_alloc_func(cSqlite3Module, allocate);
rb_define_method(cSqlite3Module, "initialize", initialize, 2);
Expand Down
2 changes: 0 additions & 2 deletions test/test_vtable.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
require "helper"
require "sqlite3"
require "sqlite3_native"

#the ruby module name should be the one given to sqlite when creating the virtual table.
module RubyModule
Expand Down

0 comments on commit d02b633

Please sign in to comment.