duckdb 0.9.0.1 → 0.9.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aac4fbdeca8ed41cef872ace9dd3c8784ce43ee224a733f469fcd0907e852cd5
4
- data.tar.gz: 56c8a5831830264fd4dfac41ba7a60bb9e6493a40536a5502c10dc0fc41b16d7
3
+ metadata.gz: 6f3ac463fffc2fc6362c34abbfa5b862a7b8c993052ede087ca4403542c98dc8
4
+ data.tar.gz: c5ea1236f240a62165b7e371ae48033447868d119261def6c5310d3911e9df91
5
5
  SHA512:
6
- metadata.gz: b94ffce97a54769bae379a3b13765b2132df1efe80fdb8f4855f77248855e95e9370651dbbe165a64c6ee45aff5bef20b3800a680f3da5287528974a243af338
7
- data.tar.gz: 96accf18b7f4df7721efaec8e215e92dcbe97d22a99d89ffb64658f4696eb462b8ceaa27a3e558cba8ef5a7ce257fc4e3b35f83178fadf8047e19280563e7ae6
6
+ metadata.gz: 210fe783740da4b6eb7991de416a7b5581403d8ad3661625110e275c030fe9dc1192d6fe2d73dcb778e53408b0e349eb28f37f2a1308d31ff30b0b783be5e498
7
+ data.tar.gz: b6fcc8d47c20ff9ce053122d9d9c03f4b19f1a72d9cd56addc1704d862ab7cfda4b3bec88bb3d8580befa006dcfeeee76138e00a2a34f065cca630bde523fb7d
@@ -3,7 +3,7 @@ name: MacOS
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - master
6
+ - main
7
7
  pull_request:
8
8
  types:
9
9
  - opened
@@ -16,7 +16,7 @@ jobs:
16
16
  strategy:
17
17
  matrix:
18
18
  ruby: ['2.7.8', '3.0.6', '3.1.4', '3.2.2', '3.3.0-preview2', 'head']
19
- duckdb: ['0.9.0', '0.8.1']
19
+ duckdb: ['0.9.1', '0.8.1']
20
20
 
21
21
  steps:
22
22
  - uses: actions/checkout@v3
@@ -3,7 +3,7 @@ name: Ubuntu
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - master
6
+ - main
7
7
  pull_request:
8
8
  types:
9
9
  - opened
@@ -16,7 +16,7 @@ jobs:
16
16
  strategy:
17
17
  matrix:
18
18
  ruby: ['2.7.8', '3.0.6', '3.1.4', '3.2.2', '3.3.0-preview2', 'head']
19
- duckdb: ['0.9.0', '0.8.1']
19
+ duckdb: ['0.9.1', '0.8.1']
20
20
 
21
21
  steps:
22
22
  - uses: actions/checkout@v3
@@ -3,7 +3,7 @@ name: Windows
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - master
6
+ - main
7
7
  pull_request:
8
8
  types:
9
9
  - opened
@@ -16,7 +16,7 @@ jobs:
16
16
  strategy:
17
17
  matrix:
18
18
  ruby: ['2.7.8', '3.0.6', '3.1.4', '3.2.2', 'ucrt', 'mingw', 'mswin', 'head']
19
- duckdb: ['0.9.0', '0.8.1']
19
+ duckdb: ['0.9.1', '0.8.1']
20
20
 
21
21
  steps:
22
22
  - uses: actions/checkout@v3
data/CHANGELOG.md CHANGED
@@ -1,14 +1,28 @@
1
1
  # ChangeLog
2
2
 
3
- # 0.9.0.1
3
+ # 0.9.1.1
4
+ - change default branch to main from master.
5
+ - add DuckDB::PendingResult class.
6
+ - add DuckDB::PendingResult#state.
7
+ - add DuckDB::PendingResult#execute_task.
8
+ - add DuckDB::PendingResult#execute_pending.
9
+ - add DuckDB::PreparedStatement#pending_prepared.
10
+
11
+ ## Breaking Changes
12
+ - drop duckdb v0.7.x.
4
13
 
14
+ # 0.9.1
15
+ - add `DuckDB::PreparedStatement#parameter_name`.
16
+ - bump duckdb to 0.9.1.
17
+
18
+ # 0.9.0.1
5
19
  - add `DuckDB::PreparedStatement#bind_parameter_index`.
6
20
  - DuckDB::Connection#query accepts SQL with named bind parameters.
7
21
 
8
22
  # 0.9.0
9
23
  - bump duckdb to 0.9.0.
10
24
 
11
- ## Breaking Change
25
+ ## Breaking Changes
12
26
  - deprecation warning when DuckDB::Result.each calling with `DuckDB::Result.use_chunk_each` is false.
13
27
  The `each` behavior will be same as `DuckDB::Result.chunk_each` in the future.
14
28
  set `DuckDB::Result.use_chunk_each = true` to suppress the warning.
@@ -51,7 +65,7 @@
51
65
  - support enum type in DuckDB::Result#chunk_each.
52
66
  - support uuid type in DuckDB::Result#chunk_each.
53
67
 
54
- ## Breaking Change
68
+ ## Breaking Changes
55
69
 
56
70
  - DuckDB::Config.set_config does not raise exception when invalid key specified.
57
71
  Instead, DuckDB::Database.open raises DuckDB::Error with invalid key configuration.
@@ -61,7 +75,7 @@
61
75
  - add DuckDB::Result#_to_decimal_internal
62
76
  - add DuckDB::Result#_to_hugeint_internal
63
77
 
64
- ## Breaking Change
78
+ ## Breaking Changes
65
79
  - DuckDB::Result returns BigDecimal object instead of String object if the column type is DECIMAL.
66
80
 
67
81
  # 0.7.1
@@ -78,7 +92,7 @@
78
92
  - add DuckDB::Result#__to_decimal_internal
79
93
  - add Ruby 3.2.1 on CI test
80
94
  - add Ruby mswin on CI test
81
- ## Breaking Change
95
+ ## Breaking Changes
82
96
  - drop Ruby 2.6
83
97
 
84
98
  # 0.6.1
@@ -92,7 +106,7 @@
92
106
  - bump Ruby to 3.2.0rc1
93
107
  - bump duckdb to 0.6.0
94
108
 
95
- ## Breaking Change
109
+ ## Breaking Changes
96
110
  - drop duckdb <= 0.4.x. ruby-duckdb supports duckdb >= 0.5.0
97
111
 
98
112
  # 0.5.1.1
@@ -111,7 +125,7 @@
111
125
  - add DuckDB::Result#row_count, DuckDB::Result#row_size(alias of row_count).
112
126
  - add DuckDB::Result#column_count, DuckDB::Result#column_size(alias of column_count).
113
127
 
114
- ## Breaking Change
128
+ ## Breaking Changes
115
129
  - bind_varchar does not raised DuckDB::Error when the binding column is date or datetime.
116
130
 
117
131
  # 0.3.4.0
data/Dockerfile CHANGED
@@ -1,7 +1,7 @@
1
1
  ARG RUBY_VERSION=3.2.2
2
2
  FROM ruby:${RUBY_VERSION}
3
3
 
4
- ARG DUCKDB_VERSION=0.9.0
4
+ ARG DUCKDB_VERSION=0.9.1
5
5
 
6
6
  RUN apt update -qq && \
7
7
  apt install -y build-essential curl git wget
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- duckdb (0.9.0.1)
4
+ duckdb (0.9.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  benchmark-ips (2.12.0)
10
- mini_portile2 (2.8.4)
10
+ mini_portile2 (2.8.5)
11
11
  minitest (5.20.0)
12
12
  nokogiri (1.15.4)
13
13
  mini_portile2 (~> 2.8.2)
@@ -15,7 +15,7 @@ GEM
15
15
  nokogiri (1.15.4-x86_64-linux)
16
16
  racc (~> 1.4)
17
17
  racc (1.7.1)
18
- rake (13.0.6)
18
+ rake (13.1.0)
19
19
  rake-compiler (1.2.5)
20
20
  rake
21
21
  ruby_memcheck (2.2.0)
data/ext/duckdb/duckdb.c CHANGED
@@ -28,6 +28,7 @@ Init_duckdb_native(void) {
28
28
  init_duckdb_result();
29
29
  init_duckdb_column();
30
30
  init_duckdb_prepared_statement();
31
+ init_duckdb_pending_result();
31
32
  init_duckdb_blob();
32
33
  init_duckdb_appender();
33
34
  init_duckdb_config();
@@ -20,15 +20,12 @@ end
20
20
 
21
21
  dir_config('duckdb')
22
22
 
23
- check_duckdb_library('duckdb_extract_statements', '0.7.0')
24
-
25
- # check duckdb >= 0.7.0
26
- have_func('duckdb_extract_statements', 'duckdb.h')
27
-
28
23
  # check duckdb >= 0.8.0
29
- have_func('duckdb_string_is_inlined', 'duckdb.h')
24
+ check_duckdb_library('duckdb_string_is_inlined', '0.8.0')
30
25
 
31
26
  # check duckdb >= 0.9.0
32
27
  have_func('duckdb_bind_parameter_index', 'duckdb.h')
33
28
 
29
+ have_func('duckdb_parameter_name', 'duckdb.h')
30
+
34
31
  create_makefile('duckdb/duckdb_native')
@@ -0,0 +1,100 @@
1
+ #include "ruby-duckdb.h"
2
+
3
+ static VALUE cDuckDBPendingResult;
4
+
5
+ static void deallocate(void *ctx);
6
+ static VALUE allocate(VALUE klass);
7
+ static size_t memsize(const void *p);
8
+ static VALUE duckdb_pending_result_initialize(VALUE self, VALUE oDuckDBPreparedStatement);
9
+ static VALUE duckdb_pending_result_execute_task(VALUE self);
10
+ static VALUE duckdb_pending_result_execute_pending(VALUE self);
11
+
12
+ #ifdef HAVE_DUCKDB_H_GE_V090
13
+ static VALUE duckdb_pending_result_execution_finished_p(VALUE self);
14
+ #endif
15
+
16
+ static VALUE duckdb_pending_result__state(VALUE self);
17
+
18
+ static const rb_data_type_t pending_result_data_type = {
19
+ "DuckDB/PendingResult",
20
+ {NULL, deallocate, memsize,},
21
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
22
+ };
23
+
24
+ static void deallocate(void *ctx) {
25
+ rubyDuckDBPendingResult *p = (rubyDuckDBPendingResult *)ctx;
26
+
27
+ duckdb_destroy_pending(&(p->pending_result));
28
+ xfree(p);
29
+ }
30
+
31
+ static VALUE allocate(VALUE klass) {
32
+ rubyDuckDBPendingResult *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBPendingResult));
33
+ ctx->state = DUCKDB_PENDING_RESULT_NOT_READY;
34
+ return TypedData_Wrap_Struct(klass, &pending_result_data_type, ctx);
35
+ }
36
+
37
+ static size_t memsize(const void *p) {
38
+ return sizeof(rubyDuckDBPendingResult);
39
+ }
40
+
41
+ static VALUE duckdb_pending_result_initialize(VALUE self, VALUE oDuckDBPreparedStatement) {
42
+ rubyDuckDBPendingResult *ctx = get_struct_pending_result(self);
43
+ rubyDuckDBPreparedStatement *stmt = get_struct_prepared_statement(oDuckDBPreparedStatement);
44
+
45
+ if (duckdb_pending_prepared(stmt->prepared_statement, &(ctx->pending_result)) == DuckDBError) {
46
+ rb_raise(eDuckDBError, "%s", duckdb_pending_error(ctx->pending_result));
47
+ }
48
+ return self;
49
+ }
50
+
51
+ static VALUE duckdb_pending_result_execute_task(VALUE self) {
52
+ rubyDuckDBPendingResult *ctx = get_struct_pending_result(self);
53
+ ctx->state = duckdb_pending_execute_task(ctx->pending_result);
54
+ return Qnil;
55
+ }
56
+
57
+ #ifdef HAVE_DUCKDB_H_GE_V090
58
+ static VALUE duckdb_pending_result_execution_finished_p(VALUE self) {
59
+ rubyDuckDBPendingResult *ctx = get_struct_pending_result(self);
60
+ return duckdb_pending_execution_is_finished(ctx->state) ? Qtrue : Qfalse;
61
+ }
62
+ #endif
63
+
64
+ static VALUE duckdb_pending_result_execute_pending(VALUE self) {
65
+ rubyDuckDBPendingResult *ctx;
66
+ rubyDuckDBResult *ctxr;
67
+ VALUE result = create_result();
68
+
69
+ TypedData_Get_Struct(self, rubyDuckDBPendingResult, &pending_result_data_type, ctx);
70
+ ctxr = get_struct_result(result);
71
+ if (duckdb_execute_pending(ctx->pending_result, &(ctxr->result)) == DuckDBError) {
72
+ rb_raise(eDuckDBError, "%s", duckdb_pending_error(ctx->pending_result));
73
+ }
74
+ return result;
75
+ }
76
+
77
+ static VALUE duckdb_pending_result__state(VALUE self) {
78
+ rubyDuckDBPendingResult *ctx = get_struct_pending_result(self);
79
+ return INT2FIX(ctx->state);
80
+ }
81
+
82
+ rubyDuckDBPendingResult *get_struct_pending_result(VALUE obj) {
83
+ rubyDuckDBPendingResult *ctx;
84
+ TypedData_Get_Struct(obj, rubyDuckDBPendingResult, &pending_result_data_type, ctx);
85
+ return ctx;
86
+ }
87
+
88
+ void init_duckdb_pending_result(void) {
89
+ cDuckDBPendingResult = rb_define_class_under(mDuckDB, "PendingResult", rb_cObject);
90
+ rb_define_alloc_func(cDuckDBPendingResult, allocate);
91
+
92
+ rb_define_method(cDuckDBPendingResult, "initialize", duckdb_pending_result_initialize, 1);
93
+ rb_define_method(cDuckDBPendingResult, "execute_task", duckdb_pending_result_execute_task, 0);
94
+ rb_define_method(cDuckDBPendingResult, "execute_pending", duckdb_pending_result_execute_pending, 0);
95
+
96
+ #ifdef HAVE_DUCKDB_H_GE_V090
97
+ rb_define_method(cDuckDBPendingResult, "execution_finished?", duckdb_pending_result_execution_finished_p, 0);
98
+ #endif
99
+ rb_define_private_method(cDuckDBPendingResult, "_state", duckdb_pending_result__state, 0);
100
+ }
@@ -0,0 +1,13 @@
1
+ #ifndef RUBY_DUCKDB_PENDING_RESULT_H
2
+ #define RUBY_DUCKDB_PENDING_RESULT_H
3
+
4
+ struct _rubyDuckDBPendingResult {
5
+ duckdb_pending_result pending_result;
6
+ duckdb_pending_state state;
7
+ };
8
+
9
+ typedef struct _rubyDuckDBPendingResult rubyDuckDBPendingResult;
10
+
11
+ rubyDuckDBPendingResult *get_struct_pending_result(VALUE obj);
12
+ void init_duckdb_pending_result(void);
13
+ #endif
@@ -12,6 +12,9 @@ static idx_t check_index(VALUE vidx);
12
12
 
13
13
  #ifdef HAVE_DUCKDB_H_GE_V090
14
14
  static VALUE duckdb_prepared_statement_bind_parameter_index(VALUE self, VALUE name);
15
+ #ifdef HAVE_DUCKDB_PARAMETER_NAME
16
+ static VALUE duckdb_prepared_statement_parameter_name(VALUE self, VALUE vidx);
17
+ #endif
15
18
  #endif
16
19
 
17
20
  static VALUE duckdb_prepared_statement_bind_bool(VALUE self, VALUE vidx, VALUE val);
@@ -110,7 +113,26 @@ static VALUE duckdb_prepared_statement_bind_parameter_index(VALUE self, VALUE na
110
113
  }
111
114
  return ULL2NUM(idx);
112
115
  }
113
- #endif
116
+
117
+ #ifdef HAVE_DUCKDB_PARAMETER_NAME
118
+ static VALUE duckdb_prepared_statement_parameter_name(VALUE self, VALUE vidx) {
119
+ rubyDuckDBPreparedStatement *ctx;
120
+ VALUE vname;
121
+ const char *name;
122
+ idx_t idx = check_index(vidx);
123
+
124
+ TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
125
+
126
+ name = duckdb_parameter_name(ctx->prepared_statement, idx);
127
+ if (name == NULL) {
128
+ rb_raise(eDuckDBError, "fail to get name of %llu parameter", (unsigned long long)idx);
129
+ }
130
+ vname = rb_str_new2(name);
131
+ duckdb_free((void *)name);
132
+ return vname;
133
+ }
134
+ #endif /* HAVE_DUCKDB_PARAMETER_NAME */
135
+ #endif /* HAVE_DUCKDB_H_GE_V090 */
114
136
 
115
137
  static VALUE duckdb_prepared_statement_bind_bool(VALUE self, VALUE vidx, VALUE val) {
116
138
  rubyDuckDBPreparedStatement *ctx;
@@ -319,6 +341,12 @@ static VALUE duckdb_prepared_statement__bind_hugeint(VALUE self, VALUE vidx, VAL
319
341
  return self;
320
342
  }
321
343
 
344
+ rubyDuckDBPreparedStatement *get_struct_prepared_statement(VALUE self) {
345
+ rubyDuckDBPreparedStatement *ctx;
346
+ TypedData_Get_Struct(self, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx);
347
+ return ctx;
348
+ }
349
+
322
350
  void init_duckdb_prepared_statement(void) {
323
351
  cDuckDBPreparedStatement = rb_define_class_under(mDuckDB, "PreparedStatement", rb_cObject);
324
352
 
@@ -330,8 +358,10 @@ void init_duckdb_prepared_statement(void) {
330
358
 
331
359
  #ifdef HAVE_DUCKDB_H_GE_V090
332
360
  rb_define_method(cDuckDBPreparedStatement, "bind_parameter_index", duckdb_prepared_statement_bind_parameter_index, 1);
361
+ #ifdef HAVE_DUCKDB_PARAMETER_NAME
362
+ rb_define_method(cDuckDBPreparedStatement, "parameter_name", duckdb_prepared_statement_parameter_name, 1);
363
+ #endif
333
364
  #endif
334
-
335
365
  rb_define_method(cDuckDBPreparedStatement, "bind_bool", duckdb_prepared_statement_bind_bool, 2);
336
366
  rb_define_method(cDuckDBPreparedStatement, "bind_int8", duckdb_prepared_statement_bind_int8, 2);
337
367
  rb_define_method(cDuckDBPreparedStatement, "bind_int16", duckdb_prepared_statement_bind_int16, 2);
@@ -8,6 +8,7 @@ struct _rubyDuckDBPreparedStatement {
8
8
 
9
9
  typedef struct _rubyDuckDBPreparedStatement rubyDuckDBPreparedStatement;
10
10
 
11
+ rubyDuckDBPreparedStatement *get_struct_prepared_statement(VALUE self);
11
12
  void init_duckdb_prepared_statement(void);
12
13
 
13
14
  #endif
data/ext/duckdb/result.c CHANGED
@@ -37,7 +37,6 @@ static VALUE duckdb_result__enum_internal_type(VALUE oDuckDBResult, VALUE col_id
37
37
  static VALUE duckdb_result__enum_dictionary_size(VALUE oDuckDBResult, VALUE col_idx);
38
38
  static VALUE duckdb_result__enum_dictionary_value(VALUE oDuckDBResult, VALUE col_idx, VALUE idx);
39
39
 
40
- #ifdef HAVE_DUCKDB_H_GE_V080
41
40
  static VALUE vector_date(void *vector_data, idx_t row_idx);
42
41
  static VALUE vector_timestamp(void* vector_data, idx_t row_idx);
43
42
  static VALUE vector_interval(void* vector_data, idx_t row_idx);
@@ -52,7 +51,6 @@ static VALUE vector_struct(duckdb_logical_type ty, duckdb_vector vector, idx_t r
52
51
  static VALUE vector_uuid(void* vector_data, idx_t row_idx);
53
52
  static VALUE vector_value(duckdb_vector vector, idx_t row_idx);
54
53
  static VALUE duckdb_result_chunk_each(VALUE oDuckDBResult);
55
- #endif
56
54
 
57
55
  static const rb_data_type_t result_data_type = {
58
56
  "DuckDB/Result",
@@ -403,7 +401,6 @@ VALUE create_result(void) {
403
401
  return allocate(cDuckDBResult);
404
402
  }
405
403
 
406
- #ifdef HAVE_DUCKDB_H_GE_V080
407
404
  static VALUE vector_date(void *vector_data, idx_t row_idx) {
408
405
  duckdb_date_struct date = duckdb_from_date(((duckdb_date *) vector_data)[row_idx]);
409
406
 
@@ -719,7 +716,6 @@ static VALUE duckdb_result_chunk_each(VALUE oDuckDBResult) {
719
716
  }
720
717
  return Qnil;
721
718
  }
722
- #endif
723
719
 
724
720
  void init_duckdb_result(void) {
725
721
  cDuckDBResult = rb_define_class_under(mDuckDB, "Result", rb_cObject);
@@ -746,7 +742,5 @@ void init_duckdb_result(void) {
746
742
  rb_define_private_method(cDuckDBResult, "_enum_internal_type", duckdb_result__enum_internal_type, 1);
747
743
  rb_define_private_method(cDuckDBResult, "_enum_dictionary_size", duckdb_result__enum_dictionary_size, 1);
748
744
  rb_define_private_method(cDuckDBResult, "_enum_dictionary_value", duckdb_result__enum_dictionary_value, 2);
749
- #ifdef HAVE_DUCKDB_H_GE_V080
750
745
  rb_define_method(cDuckDBResult, "chunk_each", duckdb_result_chunk_each, 0);
751
- #endif
752
746
  }
@@ -4,14 +4,6 @@
4
4
  #include "ruby.h"
5
5
  #include <duckdb.h>
6
6
 
7
- #ifdef HAVE_DUCKDB_EXTRACT_STATEMENTS
8
- #define HAVE_DUCKDB_H_GE_V070 1
9
- #endif
10
-
11
- #ifdef HAVE_DUCKDB_STRING_IS_INLINED
12
- #define HAVE_DUCKDB_H_GE_V080 1
13
- #endif
14
-
15
7
  #ifdef HAVE_DUCKDB_BIND_PARAMETER_INDEX
16
8
  #define HAVE_DUCKDB_H_GE_V090 1
17
9
  #endif
@@ -22,6 +14,7 @@
22
14
  #include "./result.h"
23
15
  #include "./column.h"
24
16
  #include "./prepared_statement.h"
17
+ #include "./pending_result.h"
25
18
  #include "./util.h"
26
19
  #include "./converter.h"
27
20
 
@@ -1,3 +1,3 @@
1
1
  module DuckDB
2
- LIBRARY_VERSION = library_version[1..] if defined? library_version
2
+ LIBRARY_VERSION = library_version[1..]
3
3
  end
@@ -0,0 +1,39 @@
1
+ module DuckDB
2
+ # The DuckDB::PendingResult encapsulates connection with DuckDB pending
3
+ # result.
4
+ # PendingResult provides methods to execute SQL asynchronousely and check
5
+ # if the result is ready and to get the result.
6
+ #
7
+ # require 'duckdb'
8
+ #
9
+ # DuckDB::Result.use_chunk_each = true
10
+ #
11
+ # db = DuckDB::Database.open
12
+ # con = db.connect
13
+ # stmt = con.prepared_statement(VERY_SLOW_QUERY)
14
+ # pending_result = stmt.pending_prepared
15
+ # while pending_result.state == :not_ready
16
+ # print '.'
17
+ # sleep(0.01)
18
+ # pending_result.execute_task
19
+ # end
20
+ # result = pending_result.execute_pending
21
+ class PendingResult
22
+ STATES = %i[ready not_ready error no_tasks].freeze
23
+
24
+ # returns the state of the pending result.
25
+ # The result can be :ready, :not_ready, :error, :no_tasks.
26
+ # (:no_tasks is available only with duckdb 0.9.0 or later.)
27
+ #
28
+ # :ready means the result is ready to be fetched, and
29
+ # you can call `execute_pending` to get the result.
30
+ #
31
+ # :not_ready means the result is not ready yet, so
32
+ # you need to call `execute_task`.
33
+ #
34
+ # @return [Symbol] :ready, :not_ready, :error, :no_tasks
35
+ def state
36
+ STATES[_state]
37
+ end
38
+ end
39
+ end
@@ -20,6 +20,10 @@ module DuckDB
20
20
  RANGE_INT32 = -2_147_483_648..2_147_483_647
21
21
  RANGE_INT64 = -9_223_372_036_854_775_808..9_223_372_036_854_775_807
22
22
 
23
+ def pending_prepared
24
+ PendingResult.new(self)
25
+ end
26
+
23
27
  # binds i-th parameter with SQL prepared statement.
24
28
  # The first argument is index of parameter.
25
29
  # The index of first parameter is 1 not 0.
data/lib/duckdb/result.rb CHANGED
@@ -25,7 +25,7 @@ module DuckDB
25
25
  class Result
26
26
  include Enumerable
27
27
 
28
- ToRuby = {
28
+ TO_METHODS = Hash.new(:_to_string).merge(
29
29
  1 => :_to_boolean,
30
30
  3 => :_to_smallint,
31
31
  4 => :_to_integer,
@@ -35,21 +35,25 @@ module DuckDB
35
35
  16 => :_to_hugeint_internal,
36
36
  18 => :_to_blob,
37
37
  19 => :_to_decimal_internal
38
- }
39
-
40
- ToRuby.default = :_to_string
38
+ ).freeze
41
39
 
42
40
  alias column_size column_count
43
41
  alias row_size row_count
44
42
 
45
- def self.use_chunk_each=(val)
46
- raise DuckDB::Error, 'chunk_each is not available. Install duckdb >= 0.8.0 and rerun `gem install duckdb`.' unless instance_methods.include?(:chunk_each)
43
+ class << self
44
+ def new
45
+ raise DuckDB::Error, 'DuckDB::Result cannot be instantiated directly.'
46
+ end
47
47
 
48
- @use_chunk_each = val
49
- end
48
+ def use_chunk_each=(val)
49
+ raise DuckDB::Error, 'chunk_each is not available. Install duckdb >= 0.8.0 and rerun `gem install duckdb`.' unless instance_methods.include?(:chunk_each)
50
50
 
51
- def self.use_chunk_each?
52
- !!@use_chunk_each
51
+ @use_chunk_each = val
52
+ end
53
+
54
+ def use_chunk_each?
55
+ !!@use_chunk_each
56
+ end
53
57
  end
54
58
 
55
59
  def each
@@ -58,7 +62,7 @@ module DuckDB
58
62
 
59
63
  chunk_each { |row| yield row }
60
64
  else
61
- warn('this `each` behavior will be deprecated in the future. set `Result.use_chunk_each = true` to use new `each` behavior.')
65
+ warn('this `each` behavior will be deprecated in the future. set `DuckDB::Result.use_chunk_each = true` to use new `each` behavior.')
62
66
  return to_enum { row_size } unless block_given?
63
67
 
64
68
  row_count.times do |row_index|
@@ -76,7 +80,7 @@ module DuckDB
76
80
  end
77
81
 
78
82
  def to_value(row_index, col_index)
79
- send(ToRuby[_column_type(col_index)], row_index, col_index)
83
+ send(TO_METHODS[_column_type(col_index)], row_index, col_index)
80
84
  end
81
85
 
82
86
  def enum_dictionary_values(col_index)
@@ -3,5 +3,5 @@
3
3
  module DuckDB
4
4
  # The version string of ruby-duckdb.
5
5
  # Currently, ruby-duckdb is NOT semantic versioning.
6
- VERSION = '0.9.0.1'
6
+ VERSION = '0.9.1.1'
7
7
  end
data/lib/duckdb.rb CHANGED
@@ -8,6 +8,7 @@ require 'duckdb/database'
8
8
  require 'duckdb/connection'
9
9
  require 'duckdb/result'
10
10
  require 'duckdb/prepared_statement'
11
+ require 'duckdb/pending_result'
11
12
  require 'duckdb/appender'
12
13
  require 'duckdb/config'
13
14
  require 'duckdb/column'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duckdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.1
4
+ version: 0.9.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Suketa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-08 00:00:00.000000000 Z
11
+ date: 2023-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -115,6 +115,8 @@ files:
115
115
  - ext/duckdb/error.c
116
116
  - ext/duckdb/error.h
117
117
  - ext/duckdb/extconf.rb
118
+ - ext/duckdb/pending_result.c
119
+ - ext/duckdb/pending_result.h
118
120
  - ext/duckdb/prepared_statement.c
119
121
  - ext/duckdb/prepared_statement.h
120
122
  - ext/duckdb/result.c
@@ -132,6 +134,7 @@ files:
132
134
  - lib/duckdb/database.rb
133
135
  - lib/duckdb/interval.rb
134
136
  - lib/duckdb/library_version.rb
137
+ - lib/duckdb/pending_result.rb
135
138
  - lib/duckdb/prepared_statement.rb
136
139
  - lib/duckdb/result.rb
137
140
  - lib/duckdb/version.rb