98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'ext/swift/db/postgres/statement.c', line 98
VALUE db_postgres_statement_execute(int argc, VALUE *argv, VALUE self) {
PGresult *result;
PGconn *connection;
char **bind_args_data = 0;
int n, *bind_args_size = 0, *bind_args_fmt = 0;
VALUE bind, data, typecast_bind;
Statement *s = db_postgres_statement_handle_safe(self);
connection = db_postgres_adapter_handle_safe(s->adapter)->connection;
rb_scan_args(argc, argv, "00*", &bind);
typecast_bind = rb_ary_new();
rb_gc_register_address(&typecast_bind);
rb_gc_register_address(&bind);
if (RARRAY_LEN(bind) > 0) {
bind_args_size = (int *) malloc(sizeof(int) * RARRAY_LEN(bind));
bind_args_fmt = (int *) malloc(sizeof(int) * RARRAY_LEN(bind));
bind_args_data = (char **) malloc(sizeof(char *) * RARRAY_LEN(bind));
for (n = 0; n < RARRAY_LEN(bind); n++) {
data = rb_ary_entry(bind, n);
if (NIL_P(data)) {
bind_args_size[n] = 0;
bind_args_data[n] = 0;
bind_args_fmt[n] = 0;
}
else {
if (rb_obj_is_kind_of(data, rb_cIO) || rb_obj_is_kind_of(data, cStringIO))
bind_args_fmt[n] = 1;
else
bind_args_fmt[n] = 0;
data = typecast_to_string(data);
rb_ary_push(typecast_bind, data);
bind_args_size[n] = RSTRING_LEN(data);
bind_args_data[n] = RSTRING_PTR(data);
}
}
Query q = {
.connection = connection,
.command = s->id,
.n_args = RARRAY_LEN(bind),
.data = bind_args_data,
.size = bind_args_size,
.format = bind_args_fmt
};
result = (PGresult *)GVL_NOLOCK(nogvl_pq_exec_prepared, &q, RUBY_UBF_IO, 0);
free(bind_args_fmt);
free(bind_args_size);
free(bind_args_data);
}
else {
Query q = {
.connection = connection,
.command = s->id,
.n_args = 0,
.data = 0,
.size = 0,
.format = 0
};
result = (PGresult *)GVL_NOLOCK(nogvl_pq_exec_prepared, &q, RUBY_UBF_IO, 0);
}
rb_gc_unregister_address(&typecast_bind);
rb_gc_unregister_address(&bind);
db_postgres_check_result(result);
return db_postgres_result_load(db_postgres_result_allocate(cDPR), result);
}
|