1
1
#include <stdio.h>
2
2
#include <sqlite3_ruby.h>
3
3
4
- #undef ENABLE_TRACE
5
-
6
- #ifdef ENABLE_TRACE
7
- static FILE * pf ;
8
- # define TRACE (str ) \
9
- fprintf(pf, "%s:%d:%s\n", __FILE__, __LINE__, str); \
10
- fflush(pf);
11
- #else
12
- # define TRACE (str ) ;
13
- #endif
14
-
15
4
VALUE cSqlite3Module ;
16
5
17
6
/** structure for ruby virtual table: inherits from sqlite3_vtab */
@@ -46,8 +35,6 @@ static int xCreate(sqlite3* db, VALUE *module_name,
46
35
VALUE ruby_class_args [0 ];
47
36
const char * module_name_cstr = (const char * )StringValuePtr (* module_name );
48
37
const char * table_name_cstr = (const char * )argv [2 ];
49
- TRACE ("xCreate" );
50
-
51
38
52
39
// lookup for ruby class named like <module_id>::<table_name>
53
40
module_id = rb_intern ( module_name_cstr );
@@ -73,7 +60,6 @@ static int xCreate(sqlite3* db, VALUE *module_name,
73
60
if ( sqlite3_declare_vtab (db , StringValuePtr (sql_stmt )) )
74
61
rb_raise (rb_eArgError , "fail to declare virtual table" );
75
62
76
- TRACE ("xCreate done" );
77
63
return SQLITE_OK ;
78
64
}
79
65
@@ -82,32 +68,27 @@ static int xConnect(sqlite3* db, void *pAux,
82
68
ruby_sqlite3_vtab * * ppVTab ,
83
69
char * * pzErr )
84
70
{
85
- TRACE ("xConnect" );
86
71
return xCreate (db , pAux , argc , argv , ppVTab , pzErr );
87
72
}
88
73
89
74
static int xBestIndex (ruby_sqlite3_vtab * pVTab , sqlite3_index_info * info )
90
75
{
91
- TRACE ("xBestIndex" );
92
76
return SQLITE_OK ;
93
77
}
94
78
95
79
static int xDestroy (ruby_sqlite3_vtab * pVTab )
96
80
{
97
- TRACE ("xDestroy" );
98
81
free (pVTab );
99
82
return SQLITE_OK ;
100
83
}
101
84
102
85
static int xDisconnect (ruby_sqlite3_vtab * pVTab )
103
86
{
104
- TRACE ("xDisconnect" );
105
87
return xDestroy (pVTab );
106
88
}
107
89
108
90
static int xOpen (ruby_sqlite3_vtab * pVTab , ruby_sqlite3_vtab_cursor * * ppCursor )
109
91
{
110
- TRACE ("xOpen" );
111
92
rb_funcall ( pVTab -> vtable , rb_intern ("open" ), 0 );
112
93
* ppCursor = (ruby_sqlite3_vtab_cursor * )malloc (sizeof (ruby_sqlite3_vtab_cursor ));
113
94
(* ppCursor )-> pVTab = pVTab ;
@@ -117,15 +98,13 @@ static int xOpen(ruby_sqlite3_vtab *pVTab, ruby_sqlite3_vtab_cursor **ppCursor)
117
98
118
99
static int xClose (ruby_sqlite3_vtab_cursor * cursor )
119
100
{
120
- TRACE ("xClose" );
121
101
rb_funcall ( cursor -> pVTab -> vtable , rb_intern ("close" ), 0 );
122
102
free (cursor );
123
103
return SQLITE_OK ;
124
104
}
125
105
126
106
static int xNext (ruby_sqlite3_vtab_cursor * cursor )
127
107
{
128
- TRACE ("xNext" );
129
108
cursor -> row = rb_funcall (cursor -> pVTab -> vtable , rb_intern ("next" ), 0 );
130
109
++ (cursor -> rowid );
131
110
return SQLITE_OK ;
@@ -134,29 +113,25 @@ static int xNext(ruby_sqlite3_vtab_cursor* cursor)
134
113
static int xFilter (ruby_sqlite3_vtab_cursor * cursor , int idxNum , const char * idxStr ,
135
114
int argc , sqlite3_value * * argv )
136
115
{
137
- TRACE ("xFilter" );
138
116
cursor -> rowid = 0 ;
139
117
return xNext (cursor );
140
118
}
141
119
142
120
static int xEof (ruby_sqlite3_vtab_cursor * cursor )
143
121
{
144
- TRACE ("xEof" );
145
122
return (cursor -> row == Qnil );
146
123
}
147
124
148
125
static int xColumn (ruby_sqlite3_vtab_cursor * cursor , sqlite3_context * context , int i )
149
126
{
150
127
VALUE val = rb_ary_entry (cursor -> row , i );
151
- TRACE ("xColumn(%d)" );
152
128
153
129
set_sqlite3_func_result (context , val );
154
130
return SQLITE_OK ;
155
131
}
156
132
157
133
static int xRowid (ruby_sqlite3_vtab_cursor * cursor , sqlite_int64 * pRowid )
158
134
{
159
- TRACE ("xRowid" );
160
135
* pRowid = cursor -> rowid ;
161
136
return SQLITE_OK ;
162
137
}
@@ -228,15 +203,11 @@ static VALUE initialize(VALUE self, VALUE db, VALUE name)
228
203
& (ctx -> module_name ) //the vtable required the module name
229
204
);
230
205
231
- TRACE ("module initialized" );
232
206
return self ;
233
207
}
234
208
235
209
void init_sqlite3_module ()
236
210
{
237
- #ifdef ENABLE_TRACE
238
- pf = fopen ("trace.log" , "w" );
239
- #endif
240
211
cSqlite3Module = rb_define_class_under (mSqlite3 , "Module" , rb_cObject );
241
212
rb_define_alloc_func (cSqlite3Module , allocate );
242
213
rb_define_method (cSqlite3Module , "initialize" , initialize , 2 );
0 commit comments