Skip to content

Commit 24b6b89

Browse files
committed
Make certain functions optionally defined based on whether or not the SQLite constant is defined
1 parent 5a9a812 commit 24b6b89

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

ext/sqlite3/statement.c

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ bind_parameter_count(VALUE self)
415415
*
416416
* Return the number of times that SQLite has stepped forward in a table as part of a full table scan
417417
*/
418-
static VALUE fullscan_steps(VALUE self)
418+
static VALUE
419+
fullscan_steps(VALUE self)
419420
{
420421
sqlite3StmtRubyPtr ctx;
421422
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
@@ -428,7 +429,8 @@ static VALUE fullscan_steps(VALUE self)
428429
*
429430
* Return the number of sort operations that have occurred
430431
*/
431-
static VALUE sorts(VALUE self)
432+
static VALUE
433+
sorts(VALUE self)
432434
{
433435
sqlite3StmtRubyPtr ctx;
434436
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
@@ -441,7 +443,8 @@ static VALUE sorts(VALUE self)
441443
*
442444
* Return the number of rows inserted into transient indices that were created automatically in order to help joins run faster
443445
*/
444-
static VALUE autoindexes(VALUE self)
446+
static VALUE
447+
autoindexes(VALUE self)
445448
{
446449
sqlite3StmtRubyPtr ctx;
447450
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
@@ -454,7 +457,8 @@ static VALUE autoindexes(VALUE self)
454457
*
455458
* Return the number of virtual machine operations executed by the prepared statement
456459
*/
457-
static VALUE vm_steps(VALUE self)
460+
static VALUE
461+
vm_steps(VALUE self)
458462
{
459463
sqlite3StmtRubyPtr ctx;
460464
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
@@ -463,70 +467,85 @@ static VALUE vm_steps(VALUE self)
463467
return INT2NUM(sqlite3_stmt_status(ctx->st, SQLITE_STMTSTATUS_VM_STEP, 0));
464468
}
465469

470+
#ifdef SQLITE_STMTSTATUS_REPREPARE
466471
/* call-seq: stmt.reprepares
467472
*
468473
* Return the number of times that the prepare statement has been automatically regenerated due to schema changes or changes to bound parameters that might affect the query plan.
469474
*/
470-
static VALUE reprepares(VALUE self)
475+
static VALUE
476+
reprepares(VALUE self)
471477
{
472478
sqlite3StmtRubyPtr ctx;
473479
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
474480
REQUIRE_OPEN_STMT(ctx);
475481

476482
return INT2NUM(sqlite3_stmt_status(ctx->st, SQLITE_STMTSTATUS_REPREPARE, 0));
477483
}
484+
#endif
478485

486+
#ifdef SQLITE_STMTSTATUS_RUN
479487
/* call-seq: stmt.runs
480488
*
481489
* Return the number of times that the prepared statement has been run
482490
*/
483-
static VALUE runs(VALUE self)
491+
static VALUE
492+
runs(VALUE self)
484493
{
485494
sqlite3StmtRubyPtr ctx;
486495
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
487496
REQUIRE_OPEN_STMT(ctx);
488497

489498
return INT2NUM(sqlite3_stmt_status(ctx->st, SQLITE_STMTSTATUS_RUN, 0));
490499
}
500+
#endif
491501

502+
#ifdef SQLITE_STMTSTATUS_FILTER_MISS
492503
/* call-seq: stmt.filter_misses
493504
*
494505
* Return the number of times that the Bloom filter returned a find, and thus the join step had to be processed as normal.
495506
*/
496-
static VALUE filter_misses(VALUE self)
507+
static VALUE
508+
filter_misses(VALUE self)
497509
{
498510
sqlite3StmtRubyPtr ctx;
499511
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
500512
REQUIRE_OPEN_STMT(ctx);
501513

502514
return INT2NUM(sqlite3_stmt_status(ctx->st, SQLITE_STMTSTATUS_FILTER_MISS, 0));
503515
}
516+
#endif
504517

518+
#ifdef SQLITE_STMTSTATUS_FILTER_HIT
505519
/* call-seq: stmt.filter_hits
506520
*
507521
* Return the number of times that a join step was bypassed because a Bloom filter returned not-found
508522
*/
509-
static VALUE filter_hits(VALUE self)
523+
static VALUE
524+
filter_hits(VALUE self)
510525
{
511526
sqlite3StmtRubyPtr ctx;
512527
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
513528
REQUIRE_OPEN_STMT(ctx);
514529

515530
return INT2NUM(sqlite3_stmt_status(ctx->st, SQLITE_STMTSTATUS_FILTER_HIT, 0));
516531
}
532+
#endif
517533

534+
#ifdef SQLITE_STMTSTATUS_MEMUSED
518535
/* call-seq: stmt.memory_used
519536
*
520537
* Return the approximate number of bytes of heap memory used to store the prepared statement
521538
*/
522-
static VALUE memused(VALUE self)
539+
static VALUE
540+
memused(VALUE self)
523541
{
524542
sqlite3StmtRubyPtr ctx;
525543
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
526544
REQUIRE_OPEN_STMT(ctx);
527545

528546
return INT2NUM(sqlite3_stmt_status(ctx->st, SQLITE_STMTSTATUS_MEMUSED, 0));
529547
}
548+
#endif
530549

531550
#ifdef HAVE_SQLITE3_COLUMN_DATABASE_NAME
532551

@@ -568,14 +587,29 @@ init_sqlite3_statement(void)
568587
rb_define_method(cSqlite3Statement, "sorts", sorts, 0);
569588
rb_define_method(cSqlite3Statement, "autoindexes", autoindexes, 0);
570589
rb_define_method(cSqlite3Statement, "vm_steps", vm_steps, 0);
590+
rb_define_private_method(cSqlite3Statement, "prepare", prepare, 2);
591+
592+
#ifdef HAVE_SQLITE3_COLUMN_DATABASE_NAME
593+
rb_define_method(cSqlite3Statement, "database_name", database_name, 1);
594+
#endif
595+
596+
#ifdef SQLITE_STMTSTATUS_REPREPARE
571597
rb_define_method(cSqlite3Statement, "reprepares", reprepares, 0);
598+
#endif
599+
600+
#ifdef SQLITE_STMTSTATUS_RUN
572601
rb_define_method(cSqlite3Statement, "runs", runs, 0);
602+
#endif
603+
604+
#ifdef SQLITE_STMTSTATUS_FILTER_MISS
573605
rb_define_method(cSqlite3Statement, "filter_misses", filter_misses, 0);
606+
#endif
607+
608+
#ifdef SQLITE_STMTSTATUS_FILTER_HIT
574609
rb_define_method(cSqlite3Statement, "filter_hits", filter_hits, 0);
575-
rb_define_method(cSqlite3Statement, "memused", memused, 0);
576-
rb_define_private_method(cSqlite3Statement, "prepare", prepare, 2);
610+
#endif
577611

578-
#ifdef HAVE_SQLITE3_COLUMN_DATABASE_NAME
579-
rb_define_method(cSqlite3Statement, "database_name", database_name, 1);
612+
#ifdef SQLITE_STMTSTATUS_MEMUSED
613+
rb_define_method(cSqlite3Statement, "memused", memused, 0);
580614
#endif
581615
}

0 commit comments

Comments
 (0)