rdo-sqlite 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/rdo_sqlite/driver.c +28 -4
- data/lib/rdo/sqlite/version.rb +1 -1
- metadata +2 -2
data/ext/rdo_sqlite/driver.c
CHANGED
@@ -74,10 +74,34 @@ static VALUE rdo_sqlite_driver_prepare(VALUE self, VALUE cmd) {
|
|
74
74
|
/** Quote a string literal for interpolation into a statement */
|
75
75
|
static VALUE rdo_sqlite_driver_quote(VALUE self, VALUE str) {
|
76
76
|
Check_Type(str, T_STRING);
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
|
78
|
+
char * raw = RSTRING_PTR(str);
|
79
|
+
unsigned long len = RSTRING_LEN(str);
|
80
|
+
char * buf = malloc(sizeof(char) * len * 2);
|
81
|
+
char * b = buf;
|
82
|
+
char * s = raw;
|
83
|
+
|
84
|
+
// not using sqlite3_mprintf() due to \0 check & performance
|
85
|
+
for (; (unsigned long) (s - raw) < len; ++s, ++b) {
|
86
|
+
switch (*s) {
|
87
|
+
case '\0':
|
88
|
+
free(buf);
|
89
|
+
rb_raise(rb_eArgError,
|
90
|
+
"Cannot #quote binary data. Use #prepare, #execute or a hex X'AABB' literal.");
|
91
|
+
break;
|
92
|
+
|
93
|
+
case '\'':
|
94
|
+
*(b++) = *s;
|
95
|
+
|
96
|
+
default:
|
97
|
+
*b = *s;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
VALUE quoted = rb_str_new(buf, b - buf);
|
102
|
+
free(buf);
|
103
|
+
|
104
|
+
return quoted;
|
81
105
|
}
|
82
106
|
|
83
107
|
/** Initialize driver class */
|
data/lib/rdo/sqlite/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdo-sqlite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdo
|