extralite-bundle 3.1.2 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9eac653308555c057d121db6b0e17905fff645a62d926bdd3ac07323f40f8f9e
4
- data.tar.gz: 2bcfeb952ce57afa647b969016891edae0fd615fc78f97a0a6b0336cc35791d6
3
+ metadata.gz: 476ad3a137ab5292ac1e7a5b6053db39b8136141154e42c06502e0d723875680
4
+ data.tar.gz: d33bae3131575f702577d7e1960a54f64d4d2ac6d3903eb41b3f8fb9f896288f
5
5
  SHA512:
6
- metadata.gz: aa4d929c51e1f2c05fc0e67aa37447281c50d697b9dff242ca6f96e3723027e03b3db5b4c437399f28045a12d251dfff3e0f3a47709302b132347cca9c7fa514
7
- data.tar.gz: 9809ca98906d5b853e646814057b976a55171249ae85b0502eea8ab39032d725889d736d3e9eff71ee46c9ca31d64e81f42102936753e69a2714188abec3bca5
6
+ metadata.gz: cbeb90a19c16e0355825de837ef6488614c1576df06ab2ba4dba1e6868568b839ee124d1713f4884156aa58ae3d7c8314e5675d90022fe3a08c6a54ec3448498
7
+ data.tar.gz: 885f3d695eec965ef271c3500eb07a56f9f06890b514f52d27d8f3a6e25c71c43b8034d730048b1a7f9db7e8f25ddebb5f69f1ddd2a9f53fe8adb926d323ad4a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 3.1.3 2026-10-03
2
+
3
+ - Fix database finalization of stmts (on free/close)
4
+ - Use stmt_cache for storing Query stmts
5
+
1
6
  # 3.1.2 2026-10-03
2
7
 
3
8
  - Fix handling of failed BEGIN in #transaction (#89)
@@ -72,24 +72,19 @@ static void Database_compact(void *ptr) {
72
72
  db->progress_handler.proc = rb_gc_location(db->progress_handler.proc);
73
73
  }
74
74
 
75
- static int stmt_cache_iter(VALUE key, VALUE value, VALUE _param) {
76
- sqlite3_stmt *stmt = (sqlite3_stmt *)NUM2ULONG(value);
77
- sqlite3_finalize(stmt);
78
- return ST_CONTINUE;
79
- }
80
-
81
- static void stmt_cache_finalize(sqlite3 *db, VALUE stmt_cache) {
82
- if (stmt_cache == Qnil) return;
83
- if (rb_hash_size_num(stmt_cache) == 0) return;
84
-
85
- rb_hash_foreach(stmt_cache, stmt_cache_iter, Qnil);
86
- RB_GC_GUARD(stmt_cache);
75
+ static inline void finalize_all_stmts(sqlite3 *db) {
76
+ sqlite3_stmt *stmt = sqlite3_next_stmt(db, NULL);
77
+ while (stmt) {
78
+ sqlite3_stmt *next = sqlite3_next_stmt(db, stmt);
79
+ sqlite3_finalize(stmt);
80
+ stmt = next;
81
+ }
87
82
  }
88
83
 
89
84
  static void Database_free(void *ptr) {
90
85
  Database_t *db = ptr;
91
86
  if (db->sqlite3_db) {
92
- stmt_cache_finalize(db->sqlite3_db, db->stmt_cache);
87
+ finalize_all_stmts(db->sqlite3_db);
93
88
  sqlite3_close_v2(db->sqlite3_db);
94
89
  }
95
90
  free(ptr);
@@ -278,7 +273,7 @@ VALUE Database_close(VALUE self) {
278
273
  int rc;
279
274
  Database_t *db = self_to_database(self);
280
275
 
281
- stmt_cache_finalize(db->sqlite3_db, db->stmt_cache);
276
+ finalize_all_stmts(db->sqlite3_db);
282
277
  rb_hash_clear(db->stmt_cache);
283
278
  rc = sqlite3_close_v2(db->sqlite3_db);
284
279
  if (rc) {
@@ -40,8 +40,7 @@ static void Query_compact(void *ptr) {
40
40
  }
41
41
 
42
42
  static void Query_free(void *ptr) {
43
- Query_t *query = ptr;
44
- if (query->stmt) sqlite3_finalize(query->stmt);
43
+ // Query_t *query = ptr;
45
44
  free(ptr);
46
45
  }
47
46
 
@@ -70,7 +69,7 @@ static inline Query_t *self_to_query(VALUE obj) {
70
69
  // verifies that the query is not closed
71
70
  static inline Query_t *self_to_query_verify(VALUE obj) {
72
71
  Query_t *query = self_to_query(obj);
73
- if (query->closed) rb_raise(cError, "Query is closed");
72
+ if (query->closed || !(query->db_struct->sqlite3_db)) rb_raise(cError, "Query is closed");
74
73
  return query;
75
74
  }
76
75
 
@@ -133,8 +132,10 @@ VALUE Query_initialize(VALUE self, VALUE db, VALUE sql, VALUE mode) {
133
132
 
134
133
  static inline void prep_query(Query_t *query) {
135
134
  stmt_ctx stmt_ctx;
136
- make_stmt_ctx(&stmt_ctx, query->db_struct, &(query->stmt), query->sql, 0, NULL);
135
+ make_stmt_ctx(&stmt_ctx, query->db_struct, &(query->stmt), query->sql, 1, NULL);
137
136
  prep_single_stmt(&stmt_ctx);
137
+ if (!(stmt_ctx.flags & STMT_CTX_F_CACHE_HIT))
138
+ rb_hash_aset(query->db_struct->stmt_cache, query->sql, ULONG2NUM((uint64_t)(query->stmt)));
138
139
  }
139
140
 
140
141
  static inline void query_reset(Query_t *query) {
@@ -531,7 +532,6 @@ VALUE Query_clone(VALUE self) {
531
532
  VALUE Query_close(VALUE self) {
532
533
  Query_t *query = self_to_query(self);
533
534
  if (query->stmt) {
534
- sqlite3_finalize(query->stmt);
535
535
  query->stmt = NULL;
536
536
  }
537
537
  query->closed = 1;
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Extralite
4
- VERSION = '3.1.2'
4
+ VERSION = '3.1.3'
5
5
  end
data/test/test_query.rb CHANGED
@@ -933,7 +933,7 @@ class QueryTest < Minitest::Test
933
933
  def test_query_after_db_close
934
934
  assert_equal [{ x: 4, y: 5, z: 6}], @query.bind(4).to_a
935
935
  @db.close
936
- assert_equal [{ x: 4, y: 5, z: 6}], @query.bind(4).to_a
936
+ assert_raises(Extralite::Error) { @query.bind(4).to_a }
937
937
  end
938
938
 
939
939
  def test_query_eof
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extralite-bundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner