@@ -85,11 +85,30 @@ threadsafe_p(VALUE UNUSED(klass))
85
85
return INT2NUM (sqlite3_threadsafe ());
86
86
}
87
87
88
+ /*
89
+ * call-seq:
90
+ * status(parameter) → Hash
91
+ * status(parameter, reset_flag = false) → Hash
92
+ *
93
+ * Queries the SQLite3 library for run-time status information. Passing a truthy +reset_flag+ will
94
+ * reset the highwater mark to the current value.
95
+ *
96
+ * [Parameters]
97
+ * - +parameter+ (Integer, SQLite3::Constants::Status): The status parameter to query.
98
+ * - +reset_flag+ (Boolean): Whether to reset the highwater mark. (default is +false+)
99
+ *
100
+ * [Returns]
101
+ * A Hash containing +:current+ and +:highwater+ keys for integer values.
102
+ */
88
103
static VALUE
89
- status_p ( VALUE UNUSED ( klass ) , VALUE opArg , VALUE resetFlagArg )
104
+ rb_sqlite3_status ( int argc , VALUE * argv , VALUE klass )
90
105
{
106
+ VALUE opArg , resetFlagArg ;
107
+
108
+ rb_scan_args (argc , argv , "11" , & opArg , & resetFlagArg );
109
+
91
110
int op = NUM2INT (opArg );
92
- bool resetFlag = TYPE (resetFlagArg ) == T_TRUE ;
111
+ bool resetFlag = RTEST (resetFlagArg );
93
112
94
113
int pCurrent = 0 ;
95
114
int pHighwater = 0 ;
@@ -98,6 +117,7 @@ status_p(VALUE UNUSED(klass), VALUE opArg, VALUE resetFlagArg)
98
117
VALUE hash = rb_hash_new ();
99
118
rb_hash_aset (hash , ID2SYM (rb_intern ("current" )), INT2FIX (pCurrent ));
100
119
rb_hash_aset (hash , ID2SYM (rb_intern ("highwater" )), INT2FIX (pHighwater ));
120
+
101
121
return hash ;
102
122
}
103
123
@@ -180,7 +200,7 @@ Init_sqlite3_native(void)
180
200
rb_define_singleton_method (mSqlite3 , "sqlcipher?" , using_sqlcipher , 0 );
181
201
rb_define_singleton_method (mSqlite3 , "libversion" , libversion , 0 );
182
202
rb_define_singleton_method (mSqlite3 , "threadsafe" , threadsafe_p , 0 );
183
- rb_define_singleton_method (mSqlite3 , "status" , status_p , 2 );
203
+ rb_define_singleton_method (mSqlite3 , "status" , rb_sqlite3_status , -1 );
184
204
rb_define_const (mSqlite3 , "SQLITE_VERSION" , rb_str_new2 (SQLITE_VERSION ));
185
205
rb_define_const (mSqlite3 , "SQLITE_VERSION_NUMBER" , INT2FIX (SQLITE_VERSION_NUMBER ));
186
206
rb_define_const (mSqlite3 , "SQLITE_LOADED_VERSION" , rb_str_new2 (sqlite3_libversion ()));
0 commit comments