sqlite3 2.10.0-x86_64-linux-gnu → 2.10.2-x86_64-linux-gnu

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.
@@ -31,7 +31,7 @@ statement_memsize(const void *data)
31
31
  }
32
32
 
33
33
  static const rb_data_type_t statement_type = {
34
- "SQLite3::Backup",
34
+ "SQLite3::Statement",
35
35
  {
36
36
  NULL,
37
37
  statement_deallocate,
@@ -54,8 +54,9 @@ prepare(VALUE self, VALUE db, VALUE sql)
54
54
  {
55
55
  sqlite3RubyPtr db_ctx = sqlite3_database_unwrap(db);
56
56
  sqlite3StmtRubyPtr ctx;
57
- const char *tail = NULL;
58
- int status;
57
+ const char *sql_cstr, *tail = NULL;
58
+ rb_sqlite3_callback_frame_t frame;
59
+ int sql_len, status, callback_state;
59
60
 
60
61
  StringValue(sql);
61
62
 
@@ -68,17 +69,22 @@ prepare(VALUE self, VALUE db, VALUE sql)
68
69
 
69
70
  timespecclear(&db_ctx->stmt_deadline);
70
71
 
72
+ sql_cstr = StringValuePtr(sql);
73
+ sql_len = RSTRING_LENINT(sql);
74
+
75
+ rb_sqlite3_push_callback_frame(&frame);
71
76
  #ifdef HAVE_SQLITE3_PREPARE_V2
72
77
  status = sqlite3_prepare_v2(
73
78
  #else
74
79
  status = sqlite3_prepare(
75
80
  #endif
76
81
  db_ctx->db,
77
- (const char *)StringValuePtr(sql),
78
- (int)RSTRING_LEN(sql),
82
+ sql_cstr,
83
+ sql_len,
79
84
  &ctx->st,
80
85
  &tail
81
86
  );
87
+ if ((callback_state = rb_sqlite3_pop_callback_frame(&frame))) { rb_jump_tag(callback_state); }
82
88
 
83
89
  CHECK_PREPARE(db_ctx->db, status, StringValuePtr(sql));
84
90
 
@@ -125,7 +131,8 @@ step(VALUE self)
125
131
  {
126
132
  sqlite3StmtRubyPtr ctx;
127
133
  sqlite3_stmt *stmt;
128
- int value, length;
134
+ rb_sqlite3_callback_frame_t frame;
135
+ int value, length, callback_state;
129
136
  VALUE list;
130
137
  rb_encoding *internal_encoding;
131
138
 
@@ -144,14 +151,13 @@ step(VALUE self)
144
151
  timespecclear(&ctx->db->stmt_deadline);
145
152
  }
146
153
 
154
+ rb_sqlite3_push_callback_frame(&frame);
147
155
  value = sqlite3_step(stmt);
148
- if (rb_errinfo() != Qnil) {
149
- /* some user defined function was invoked as a callback during step and
150
- * it raised an exception that has been suppressed until step returns.
151
- * Now re-raise it. */
152
- VALUE exception = rb_errinfo();
153
- rb_set_errinfo(Qnil);
154
- rb_exc_raise(exception);
156
+ if ((callback_state = rb_sqlite3_pop_callback_frame(&frame))) { rb_jump_tag(callback_state); }
157
+
158
+ if (value == SQLITE_DONE) {
159
+ ctx->done_p = 1;
160
+ return Qnil;
155
161
  }
156
162
 
157
163
  length = sqlite3_column_count(stmt);
@@ -200,10 +206,6 @@ step(VALUE self)
200
206
  }
201
207
  }
202
208
  break;
203
- case SQLITE_DONE:
204
- ctx->done_p = 1;
205
- return Qnil;
206
- break;
207
209
  default:
208
210
  sqlite3_reset(stmt);
209
211
  ctx->done_p = 0;
@@ -236,6 +238,10 @@ step(VALUE self)
236
238
  *
237
239
  * stmt.bind_param(1, my_binary_str.encode(Encoding::UTF_8))
238
240
  *
241
+ * The value that this method binds stays bound when you execute or reset the
242
+ * statement. To change the value, bind a new value to the same parameter. To
243
+ * clear all values, call #clear_bindings!.
244
+ *
239
245
  * See also #bind_params.
240
246
  */
241
247
  static VALUE
@@ -274,7 +280,7 @@ bind_param(VALUE self, VALUE key, VALUE value)
274
280
  ctx->st,
275
281
  index,
276
282
  (const char *)StringValuePtr(value),
277
- (int)RSTRING_LEN(value),
283
+ RSTRING_LENINT(value),
278
284
  SQLITE_TRANSIENT
279
285
  );
280
286
  } else {
@@ -285,7 +291,7 @@ bind_param(VALUE self, VALUE key, VALUE value)
285
291
  ctx->st,
286
292
  index,
287
293
  (const char *)StringValuePtr(value),
288
- (int)RSTRING_LEN(value),
294
+ RSTRING_LENINT(value),
289
295
  SQLITE_TRANSIENT
290
296
  );
291
297
  } else {
@@ -296,7 +302,7 @@ bind_param(VALUE self, VALUE key, VALUE value)
296
302
  ctx->st,
297
303
  index,
298
304
  (const char *)StringValuePtr(value),
299
- (int)RSTRING_LEN(value),
305
+ RSTRING_LENINT(value),
300
306
  SQLITE_TRANSIENT
301
307
  );
302
308
  }
@@ -331,8 +337,11 @@ bind_param(VALUE self, VALUE key, VALUE value)
331
337
 
332
338
  /* call-seq: stmt.reset!
333
339
  *
334
- * Resets the statement. This is typically done internally, though it might
335
- * occasionally be necessary to manually reset the statement.
340
+ * Resets the statement. The library usually calls this method for you, but
341
+ * you can also call it yourself.
342
+ *
343
+ * This method does not clear the values that you bound to the parameters. To
344
+ * clear them, call #clear_bindings!.
336
345
  */
337
346
  static VALUE
338
347
  reset_bang(VALUE self)
@@ -353,8 +362,11 @@ reset_bang(VALUE self)
353
362
 
354
363
  /* call-seq: stmt.clear_bindings!
355
364
  *
356
- * Resets the statement. This is typically done internally, though it might
357
- * occasionally be necessary to manually reset the statement.
365
+ * Sets the value of each parameter in the statement to NULL.
366
+ *
367
+ * The values that you bind with #bind_param, #bind_params, or #execute stay
368
+ * bound when you execute or reset the statement. Call this method to clear
369
+ * them.
358
370
  */
359
371
  static VALUE
360
372
  clear_bindings_bang(VALUE self)
Binary file
Binary file
Binary file
Binary file
@@ -579,6 +579,25 @@ module SQLite3
579
579
  self
580
580
  end
581
581
 
582
+ # The "handler" that #define_aggregator hands to define_aggregator2, which
583
+ # only needs something that responds to +new+ (a fresh aggregator for each
584
+ # aggregate invocation) and +arity+.
585
+ class AggregatorFactory # :nodoc:
586
+ def initialize(template)
587
+ @template = template
588
+ end
589
+
590
+ def new
591
+ @template.clone
592
+ end
593
+
594
+ # this is what sqlite3_obj_method_arity did before
595
+ def arity
596
+ @template.method(:step).arity
597
+ end
598
+ end
599
+ private_constant :AggregatorFactory
600
+
582
601
  # Define an aggregate function named +name+ using a object template
583
602
  # object +aggregator+. +aggregator+ must respond to +step+ and +finalize+.
584
603
  # +step+ will be called with row information and +finalize+ must return the
@@ -592,36 +611,7 @@ module SQLite3
592
611
  def define_aggregator(name, aggregator)
593
612
  # Previously, this has been implemented in C. Now this is just yet
594
613
  # another compatibility shim
595
- proxy = Class.new do
596
- @template = aggregator
597
- @name = name
598
-
599
- def self.template
600
- @template
601
- end
602
-
603
- def self.name
604
- @name
605
- end
606
-
607
- def self.arity
608
- # this is what sqlite3_obj_method_arity did before
609
- @template.method(:step).arity
610
- end
611
-
612
- def initialize
613
- @klass = self.class.template.clone
614
- end
615
-
616
- def step(*args)
617
- @klass.step(*args)
618
- end
619
-
620
- def finalize
621
- @klass.finalize
622
- end
623
- end
624
- define_aggregator2(proxy, name)
614
+ define_aggregator2(AggregatorFactory.new(aggregator), name)
625
615
  self
626
616
  end
627
617
 
@@ -16,8 +16,12 @@ module SQLite3
16
16
  @stmt = stmt
17
17
  end
18
18
 
19
- # Reset the cursor, so that a result set which has reached end-of-file
20
- # can be rewound and reiterated.
19
+ # Resets the cursor to the first row, so that you can iterate over the
20
+ # result set again after it reaches the end.
21
+ #
22
+ # This method binds each argument to the statement with
23
+ # Statement#bind_params. The values that you bound before stay bound
24
+ # unless you bind new values to the same parameters.
21
25
  def reset(*bind_params)
22
26
  @stmt.reset!
23
27
  @stmt.bind_params(*bind_params)
@@ -65,6 +65,10 @@ module SQLite3
65
65
  # stmt = db.prepare( "select * from table where a=? and b=?" )
66
66
  # stmt.bind_params( 15, "hello" )
67
67
  #
68
+ # The values that this method binds stay bound when you execute or reset
69
+ # the statement. To change a value, bind a new value to the same
70
+ # parameter. To clear all values, call #clear_bindings!.
71
+ #
68
72
  # See also #execute, #bind_param, Statement#bind_param, and
69
73
  # Statement#bind_params.
70
74
  def bind_params(*bind_vars)
@@ -83,7 +87,17 @@ module SQLite3
83
87
  # statement's virtual machine. If a block was given, the new ResultSet will
84
88
  # be yielded to it; otherwise, the ResultSet will be returned.
85
89
  #
86
- # Any parameters will be bound to the statement using #bind_params.
90
+ # This method binds each argument to the statement with #bind_params. The
91
+ # values stay bound after this method returns. If a later call to #execute
92
+ # does not give a value for a parameter, the statement uses the value from
93
+ # the earlier call. To set all parameters to NULL before you execute the
94
+ # statement again, call #clear_bindings!:
95
+ #
96
+ # stmt = db.prepare( "select :a, :b" )
97
+ # stmt.execute( a: 1, b: 2 ).to_a # => [[1, 2]]
98
+ # stmt.execute( a: 3 ).to_a # => [[3, 2]]
99
+ # stmt.clear_bindings!
100
+ # stmt.execute( a: 3 ).to_a # => [[3, nil]]
87
101
  #
88
102
  # Example:
89
103
  #
@@ -92,7 +106,7 @@ module SQLite3
92
106
  # ...
93
107
  # end
94
108
  #
95
- # See also #bind_params, #execute!.
109
+ # See also #bind_params, #execute!, #clear_bindings!.
96
110
  def execute(*bind_vars)
97
111
  reset! if active? || done?
98
112
 
@@ -109,7 +123,9 @@ module SQLite3
109
123
  # rows returned by executing the statement. Otherwise, each row will be
110
124
  # yielded to the block.
111
125
  #
112
- # Any parameters will be bound to the statement using #bind_params.
126
+ # This method binds each argument to the statement with #bind_params. The
127
+ # values stay bound after this method returns. For more information, see
128
+ # #execute.
113
129
  #
114
130
  # Example:
115
131
  #
@@ -1,4 +1,4 @@
1
1
  module SQLite3
2
2
  # (String) the version of the sqlite3 gem, e.g. "2.1.1"
3
- VERSION = "2.10.0"
3
+ VERSION = "2.10.2"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqlite3
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.10.2
5
5
  platform: x86_64-linux-gnu
6
6
  authors:
7
7
  - Jamis Buck