trilogy 2.2.0 → 2.4.0

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: ff98f0678711dd36bae4c5f8a7e0f399d3391f393816bc8df4c4281dbfd5d53f
4
- data.tar.gz: 13914f66cde555a81814e4f2b1761895bb1e33b026a2e7d8e3b74888862e9b69
3
+ metadata.gz: e9c5df97a7642030f5c79167a0ff54ab25f500e38555b0303b9755f4102b0b17
4
+ data.tar.gz: a67ea6052ca5d2346a5b7cb72f976c6c6a445361365e7bc3f343a54cd43151dd
5
5
  SHA512:
6
- metadata.gz: 8f629502bc41dc22b8ebb65a00fb207d0bd41951d085b7bdd1d9de9956caf2b2c5f9504a533194b6fc5de30883330305482128091f4d417913b576233bf199e6
7
- data.tar.gz: 2342f373109f087b89e6802a2d7e6c05f4c6c1ed938a820af404b87c961b8ef455dad3c3ec1d8b32270340583a3cbb31bf38251d9ff0a7fa892c13c3f55c8307
6
+ metadata.gz: 8d356765239b247f1902582abfb7a724eee0b2b18a3e8e0eabe71db196555bf5749192f259dba8c65f8a0945106df4413f328abeef8241cb3517495725dedabc
7
+ data.tar.gz: c77e07b1a5e423d1ed7065a613feee4cd038be3606f519f7dc2fbbe87b389cf9d1fd4cc41993023060b504c40f12f85f8e75c688e1b4c418535c8891c192f26f
data/README.md CHANGED
@@ -34,6 +34,12 @@ if client.ping
34
34
  result.each_hash do |user|
35
35
  p user
36
36
  end
37
+
38
+ # Multi-statement
39
+
40
+ results = []
41
+ results << client.query("SELECT name FROM users WHERE id = 1; SELECT name FROM users WHERE id = 2")
42
+ results << client.next_result while client.more_results_exist?
37
43
  end
38
44
  ```
39
45
 
@@ -59,7 +65,7 @@ The official Ruby bindings are inside of the canonical trilogy repository itself
59
65
  The trilogy API was heavily inspired by the mysql2 gem but has a few notable
60
66
  differences:
61
67
 
62
- * The `query_options` hash doesn't inherit from the connection options hash.
68
+ * The `query_flags` don't inherit from the connection options hash.
63
69
  This means that options like turning on/of casting will need to be set before
64
70
  a query and not passed in at connect time.
65
71
  * For performance reasons there is no `application_timezone` query option. If
@@ -7,7 +7,7 @@
7
7
 
8
8
  #define CAST_STACK_SIZE 64
9
9
 
10
- static ID id_BigDecimal, id_new, id_local, id_localtime, id_utc;
10
+ static ID id_BigDecimal, id_Integer, id_new, id_local, id_localtime, id_utc;
11
11
 
12
12
  static const char *ruby_encoding_name_map[] = {
13
13
  [TRILOGY_ENCODING_ARMSCII8] = NULL,
@@ -71,7 +71,7 @@ static void cstr_from_value(char *buf, const trilogy_value_t *value, const char
71
71
  {
72
72
 
73
73
  if (value->data_len > CAST_STACK_SIZE - 1) {
74
- rb_raise(rb_cTrilogyError, errmsg, (int)value->data_len, (char *)value->data);
74
+ rb_raise(Trilogy_CastError, errmsg, (int)value->data_len, (char *)value->data);
75
75
  }
76
76
 
77
77
  memcpy(buf, value->data, value->data_len);
@@ -145,7 +145,11 @@ rb_trilogy_cast_value(const trilogy_value_t *value, const struct column_info *co
145
145
  // TODO - optimize so we don't have to allocate a ruby string for
146
146
  // decimal columns
147
147
  VALUE str = rb_str_new(value->data, value->data_len);
148
- return rb_funcall(rb_mKernel, id_BigDecimal, 1, str);
148
+ if (column->decimals == 0 && !options->cast_decimals_to_bigdecimals) {
149
+ return rb_funcall(rb_mKernel, id_Integer, 1, str);
150
+ } else {
151
+ return rb_funcall(rb_mKernel, id_BigDecimal, 1, str);
152
+ }
149
153
  }
150
154
  case TRILOGY_TYPE_FLOAT:
151
155
  case TRILOGY_TYPE_DOUBLE: {
@@ -156,7 +160,7 @@ rb_trilogy_cast_value(const trilogy_value_t *value, const struct column_info *co
156
160
  double dbl = strtod(cstr, &err);
157
161
 
158
162
  if (*err != 0) {
159
- rb_raise(rb_cTrilogyError, "Invalid double value: %.*s", (int)value->data_len, (char *)value->data);
163
+ rb_raise(Trilogy_CastError, "Invalid double value: %.*s", (int)value->data_len, (char *)value->data);
160
164
  }
161
165
  return rb_float_new(dbl);
162
166
  }
@@ -180,7 +184,7 @@ rb_trilogy_cast_value(const trilogy_value_t *value, const struct column_info *co
180
184
  }
181
185
 
182
186
  if (month < 1 || day < 1) {
183
- rb_raise(rb_cTrilogyError, "Invalid date: %.*s", (int)value->data_len, (char *)value->data);
187
+ rb_raise(Trilogy_CastError, "Invalid date: %.*s", (int)value->data_len, (char *)value->data);
184
188
  }
185
189
 
186
190
  // pad out msec_char with zeroes at the end as it could be at any
@@ -211,7 +215,7 @@ rb_trilogy_cast_value(const trilogy_value_t *value, const struct column_info *co
211
215
  }
212
216
 
213
217
  if (month < 1 || day < 1) {
214
- rb_raise(rb_cTrilogyError, "Invalid date: %.*s", (int)value->data_len, (char *)value->data);
218
+ rb_raise(Trilogy_CastError, "Invalid date: %.*s", (int)value->data_len, (char *)value->data);
215
219
  }
216
220
 
217
221
  return rb_funcall(Date, id_new, 3, INT2NUM(year), INT2NUM(month), INT2NUM(day));
@@ -236,7 +240,7 @@ rb_trilogy_cast_value(const trilogy_value_t *value, const struct column_info *co
236
240
  // pad out msec_char with zeroes at the end as it could be at any
237
241
  // level of precision
238
242
  for (size_t i = strlen(msec_char); i < sizeof(msec_char) - 1; i++) {
239
- msec_char[i] = 0;
243
+ msec_char[i] = '0';
240
244
  }
241
245
 
242
246
  return rb_funcall(rb_cTime, options->database_local_time ? id_local : id_utc, 7, INT2NUM(2000), INT2NUM(1),
@@ -265,6 +269,7 @@ void rb_trilogy_cast_init(void)
265
269
  rb_require("date");
266
270
 
267
271
  id_BigDecimal = rb_intern("BigDecimal");
272
+ id_Integer = rb_intern("Integer");
268
273
  id_new = rb_intern("new");
269
274
  id_local = rb_intern("local");
270
275
  id_localtime = rb_intern("localtime");