mysql 2.7.1-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/README +27 -0
- data/Rakefile +59 -0
- data/docs/README.html +1017 -0
- data/ext/extconf.rb +18 -0
- data/ext/extconf.rb.orig +67 -0
- data/ext/mysql.c.in +2184 -0
- data/ext/mysql.so +0 -0
- data/ext/test.rb +1367 -0
- metadata +57 -0
data/ext/extconf.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
dir_config('mysql')
|
4
|
+
have_header('mysql.h')
|
5
|
+
if not have_library('libmysql', 'mysql_query', 'mysql.h') then
|
6
|
+
puts "Could not locate the 'mysql_query' function."
|
7
|
+
exit 1
|
8
|
+
end
|
9
|
+
|
10
|
+
have_func('mysql_ssl_set', 'mysql.h')
|
11
|
+
|
12
|
+
newf = File::open('mysql.c', 'w')
|
13
|
+
IO::foreach('mysql.c.in') do |l|
|
14
|
+
newf.puts l
|
15
|
+
end
|
16
|
+
|
17
|
+
create_makefile('mysql')
|
18
|
+
|
data/ext/extconf.rb.orig
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
if mc = with_config('mysql-config') then
|
4
|
+
mc = 'mysql_config' if mc == true
|
5
|
+
cflags = `#{mc} --cflags`.chomp
|
6
|
+
exit 1 if $? != 0
|
7
|
+
libs = `#{mc} --libs`.chomp
|
8
|
+
exit 1 if $? != 0
|
9
|
+
$CPPFLAGS += ' ' + cflags
|
10
|
+
$libs = libs + " " + $libs
|
11
|
+
else
|
12
|
+
inc, lib = dir_config('mysql', '/usr/local')
|
13
|
+
libs = ['m', 'z', 'socket', 'nsl']
|
14
|
+
while not find_library('mysqlclient', 'mysql_query', lib, "#{lib}/mysql") do
|
15
|
+
exit 1 if libs.empty?
|
16
|
+
have_library(libs.shift)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
have_func('mysql_ssl_set')
|
21
|
+
|
22
|
+
if have_header('mysql.h') then
|
23
|
+
src = "#include <errmsg.h>\n#include <mysqld_error.h>\n"
|
24
|
+
elsif have_header('mysql/mysql.h') then
|
25
|
+
src = "#include <mysql/errmsg.h>\n#include <mysql/mysqld_error.h>\n"
|
26
|
+
else
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
# make mysql constant
|
31
|
+
File::open("conftest.c", "w") do |f|
|
32
|
+
f.puts src
|
33
|
+
end
|
34
|
+
if defined? cpp_command then
|
35
|
+
cpp = Config::expand(cpp_command(''))
|
36
|
+
else
|
37
|
+
cpp = Config::expand sprintf(CPP, $CPPFLAGS, $CFLAGS, '')
|
38
|
+
end
|
39
|
+
unless system "#{cpp} > confout" then
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
File::unlink "conftest.c"
|
43
|
+
|
44
|
+
error_syms = []
|
45
|
+
IO::foreach('confout') do |l|
|
46
|
+
next unless l =~ /errmsg\.h|mysqld_error\.h/
|
47
|
+
fn = l.split(/\"/)[1]
|
48
|
+
IO::foreach(fn) do |m|
|
49
|
+
if m =~ /^#define\s+([CE]R_[0-9A-Z_]+)/ then
|
50
|
+
error_syms << $1
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
File::unlink 'confout'
|
55
|
+
error_syms.uniq!
|
56
|
+
|
57
|
+
newf = File::open('mysql.c', 'w')
|
58
|
+
IO::foreach('mysql.c.in') do |l|
|
59
|
+
newf.puts l
|
60
|
+
if l =~ /\/\* Mysql::Error constant \*\// then
|
61
|
+
error_syms.each do |s|
|
62
|
+
newf.puts " rb_define_const(eMysql, \"#{s}\", INT2NUM(#{s}));"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
create_makefile("mysql")
|
data/ext/mysql.c.in
ADDED
@@ -0,0 +1,2184 @@
|
|
1
|
+
/* ruby mysql module
|
2
|
+
* $Id: mysql.c.in,v 1.32 2006/06/04 14:29:28 tommy Exp $
|
3
|
+
*/
|
4
|
+
|
5
|
+
#include "ruby.h"
|
6
|
+
#include "version.h"
|
7
|
+
#ifdef HAVE_MYSQL_H
|
8
|
+
#include <mysql.h>
|
9
|
+
#include <errmsg.h>
|
10
|
+
#include <mysqld_error.h>
|
11
|
+
#else
|
12
|
+
#include <mysql/mysql.h>
|
13
|
+
#include <mysql/errmsg.h>
|
14
|
+
#include <mysql/mysqld_error.h>
|
15
|
+
#endif
|
16
|
+
|
17
|
+
#define MYSQL_RUBY_VERSION 20701
|
18
|
+
|
19
|
+
#define GC_STORE_RESULT_LIMIT 20
|
20
|
+
|
21
|
+
#ifndef Qtrue /* ruby 1.2.x ? */
|
22
|
+
#define Qtrue TRUE
|
23
|
+
#define Qfalse FALSE
|
24
|
+
#define rb_exc_raise rb_raise
|
25
|
+
#define rb_exc_new2 exc_new2
|
26
|
+
#define rb_str_new str_new
|
27
|
+
#define rb_str_new2 str_new2
|
28
|
+
#define rb_ary_new2 ary_new2
|
29
|
+
#define rb_ary_store ary_store
|
30
|
+
#define rb_obj_alloc obj_alloc
|
31
|
+
#define rb_hash_new hash_new
|
32
|
+
#define rb_hash_aset hash_aset
|
33
|
+
#define rb_eStandardError eStandardError
|
34
|
+
#define rb_cObject cObject
|
35
|
+
#endif
|
36
|
+
|
37
|
+
#if MYSQL_VERSION_ID < 32224
|
38
|
+
#define mysql_field_count mysql_num_fields
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#define NILorSTRING(obj) (NIL_P(obj)? NULL: StringValuePtr(obj))
|
42
|
+
#define NILorINT(obj) (NIL_P(obj)? 0: NUM2INT(obj))
|
43
|
+
|
44
|
+
#define GetMysqlStruct(obj) (Check_Type(obj, T_DATA), (struct mysql*)DATA_PTR(obj))
|
45
|
+
#define GetHandler(obj) (Check_Type(obj, T_DATA), &(((struct mysql*)DATA_PTR(obj))->handler))
|
46
|
+
#define GetMysqlRes(obj) (Check_Type(obj, T_DATA), ((struct mysql_res*)DATA_PTR(obj))->res)
|
47
|
+
#define GetMysqlStmt(obj) (Check_Type(obj, T_DATA), ((struct mysql_stmt*)DATA_PTR(obj))->stmt)
|
48
|
+
|
49
|
+
VALUE cMysql;
|
50
|
+
VALUE cMysqlRes;
|
51
|
+
VALUE cMysqlField;
|
52
|
+
VALUE cMysqlStmt;
|
53
|
+
VALUE cMysqlRowOffset;
|
54
|
+
VALUE cMysqlTime;
|
55
|
+
VALUE eMysql;
|
56
|
+
|
57
|
+
static int store_result_count = 0;
|
58
|
+
|
59
|
+
struct mysql {
|
60
|
+
MYSQL handler;
|
61
|
+
char connection;
|
62
|
+
char query_with_result;
|
63
|
+
};
|
64
|
+
|
65
|
+
struct mysql_res {
|
66
|
+
MYSQL_RES* res;
|
67
|
+
char freed;
|
68
|
+
};
|
69
|
+
|
70
|
+
#if MYSQL_VERSION_ID >= 40101
|
71
|
+
struct mysql_stmt {
|
72
|
+
MYSQL_STMT *stmt;
|
73
|
+
char closed;
|
74
|
+
struct {
|
75
|
+
int n;
|
76
|
+
MYSQL_BIND *bind;
|
77
|
+
unsigned long *length;
|
78
|
+
MYSQL_TIME *buffer;
|
79
|
+
} param;
|
80
|
+
struct {
|
81
|
+
int n;
|
82
|
+
MYSQL_BIND *bind;
|
83
|
+
my_bool *is_null;
|
84
|
+
unsigned long *length;
|
85
|
+
} result;
|
86
|
+
MYSQL_RES *res;
|
87
|
+
};
|
88
|
+
#endif
|
89
|
+
|
90
|
+
/* free Mysql class object */
|
91
|
+
static void free_mysql(struct mysql* my)
|
92
|
+
{
|
93
|
+
if (my->connection == Qtrue)
|
94
|
+
mysql_close(&my->handler);
|
95
|
+
xfree(my);
|
96
|
+
}
|
97
|
+
|
98
|
+
static void free_mysqlres(struct mysql_res* resp)
|
99
|
+
{
|
100
|
+
if (resp->freed == Qfalse) {
|
101
|
+
mysql_free_result(resp->res);
|
102
|
+
store_result_count--;
|
103
|
+
}
|
104
|
+
xfree(resp);
|
105
|
+
}
|
106
|
+
|
107
|
+
#if MYSQL_VERSION_ID >= 40101
|
108
|
+
static void free_mysqlstmt_memory(struct mysql_stmt *s)
|
109
|
+
{
|
110
|
+
if (s->param.bind) {
|
111
|
+
xfree(s->param.bind);
|
112
|
+
s->param.bind = NULL;
|
113
|
+
}
|
114
|
+
if (s->param.length) {
|
115
|
+
xfree(s->param.length);
|
116
|
+
s->param.length = NULL;
|
117
|
+
}
|
118
|
+
if (s->param.buffer) {
|
119
|
+
xfree(s->param.buffer);
|
120
|
+
s->param.buffer = NULL;
|
121
|
+
}
|
122
|
+
s->param.n = 0;
|
123
|
+
if (s->res) {
|
124
|
+
mysql_free_result(s->res);
|
125
|
+
s->res = NULL;
|
126
|
+
}
|
127
|
+
if (s->result.bind) {
|
128
|
+
int i;
|
129
|
+
for (i = 0; i < s->result.n; i++) {
|
130
|
+
if (s->result.bind[i].buffer)
|
131
|
+
xfree(s->result.bind[i].buffer);
|
132
|
+
}
|
133
|
+
xfree(s->result.bind);
|
134
|
+
s->result.bind = NULL;
|
135
|
+
}
|
136
|
+
if (s->result.is_null) {
|
137
|
+
xfree(s->result.is_null);
|
138
|
+
s->result.is_null = NULL;
|
139
|
+
}
|
140
|
+
if (s->result.length) {
|
141
|
+
xfree(s->result.length);
|
142
|
+
s->result.length = NULL;
|
143
|
+
}
|
144
|
+
s->result.n = 0;
|
145
|
+
}
|
146
|
+
|
147
|
+
static void free_mysqlstmt(struct mysql_stmt* s)
|
148
|
+
{
|
149
|
+
free_mysqlstmt_memory(s);
|
150
|
+
if (s->closed == Qfalse)
|
151
|
+
mysql_stmt_close(s->stmt);
|
152
|
+
if (s->res)
|
153
|
+
mysql_free_result(s->res);
|
154
|
+
xfree(s);
|
155
|
+
}
|
156
|
+
#endif
|
157
|
+
|
158
|
+
static void mysql_raise(MYSQL* m)
|
159
|
+
{
|
160
|
+
VALUE e = rb_exc_new2(eMysql, mysql_error(m));
|
161
|
+
rb_iv_set(e, "errno", INT2FIX(mysql_errno(m)));
|
162
|
+
#if MYSQL_VERSION_ID >= 40101
|
163
|
+
rb_iv_set(e, "sqlstate", rb_tainted_str_new2(mysql_sqlstate(m)));
|
164
|
+
#endif
|
165
|
+
rb_exc_raise(e);
|
166
|
+
}
|
167
|
+
|
168
|
+
static VALUE mysqlres2obj(MYSQL_RES* res)
|
169
|
+
{
|
170
|
+
VALUE obj;
|
171
|
+
struct mysql_res* resp;
|
172
|
+
obj = Data_Make_Struct(cMysqlRes, struct mysql_res, 0, free_mysqlres, resp);
|
173
|
+
resp->res = res;
|
174
|
+
resp->freed = Qfalse;
|
175
|
+
rb_obj_call_init(obj, 0, NULL);
|
176
|
+
if (++store_result_count > GC_STORE_RESULT_LIMIT)
|
177
|
+
rb_gc();
|
178
|
+
return obj;
|
179
|
+
}
|
180
|
+
|
181
|
+
/* make Mysql::Field object */
|
182
|
+
static VALUE make_field_obj(MYSQL_FIELD* f)
|
183
|
+
{
|
184
|
+
VALUE obj;
|
185
|
+
VALUE hash;
|
186
|
+
if (f == NULL)
|
187
|
+
return Qnil;
|
188
|
+
obj = rb_obj_alloc(cMysqlField);
|
189
|
+
rb_iv_set(obj, "name", f->name? rb_str_freeze(rb_tainted_str_new2(f->name)): Qnil);
|
190
|
+
rb_iv_set(obj, "table", f->table? rb_str_freeze(rb_tainted_str_new2(f->table)): Qnil);
|
191
|
+
rb_iv_set(obj, "def", f->def? rb_str_freeze(rb_tainted_str_new2(f->def)): Qnil);
|
192
|
+
rb_iv_set(obj, "type", INT2NUM(f->type));
|
193
|
+
rb_iv_set(obj, "length", INT2NUM(f->length));
|
194
|
+
rb_iv_set(obj, "max_length", INT2NUM(f->max_length));
|
195
|
+
rb_iv_set(obj, "flags", INT2NUM(f->flags));
|
196
|
+
rb_iv_set(obj, "decimals", INT2NUM(f->decimals));
|
197
|
+
return obj;
|
198
|
+
}
|
199
|
+
|
200
|
+
/*-------------------------------
|
201
|
+
* Mysql class method
|
202
|
+
*/
|
203
|
+
|
204
|
+
/* init() */
|
205
|
+
static VALUE init(VALUE klass)
|
206
|
+
{
|
207
|
+
struct mysql* myp;
|
208
|
+
VALUE obj;
|
209
|
+
|
210
|
+
obj = Data_Make_Struct(klass, struct mysql, 0, free_mysql, myp);
|
211
|
+
mysql_init(&myp->handler);
|
212
|
+
myp->connection = Qfalse;
|
213
|
+
myp->query_with_result = Qtrue;
|
214
|
+
rb_obj_call_init(obj, 0, NULL);
|
215
|
+
return obj;
|
216
|
+
}
|
217
|
+
|
218
|
+
/* real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil) */
|
219
|
+
static VALUE real_connect(int argc, VALUE* argv, VALUE klass)
|
220
|
+
{
|
221
|
+
VALUE host, user, passwd, db, port, sock, flag;
|
222
|
+
char *h, *u, *p, *d, *s;
|
223
|
+
unsigned int pp, f;
|
224
|
+
struct mysql* myp;
|
225
|
+
VALUE obj;
|
226
|
+
|
227
|
+
#if MYSQL_VERSION_ID >= 32200
|
228
|
+
rb_scan_args(argc, argv, "07", &host, &user, &passwd, &db, &port, &sock, &flag);
|
229
|
+
d = NILorSTRING(db);
|
230
|
+
f = NILorINT(flag);
|
231
|
+
#elif MYSQL_VERSION_ID >= 32115
|
232
|
+
rb_scan_args(argc, argv, "06", &host, &user, &passwd, &port, &sock, &flag);
|
233
|
+
f = NILorINT(flag);
|
234
|
+
#else
|
235
|
+
rb_scan_args(argc, argv, "05", &host, &user, &passwd, &port, &sock);
|
236
|
+
#endif
|
237
|
+
h = NILorSTRING(host);
|
238
|
+
u = NILorSTRING(user);
|
239
|
+
p = NILorSTRING(passwd);
|
240
|
+
pp = NILorINT(port);
|
241
|
+
s = NILorSTRING(sock);
|
242
|
+
|
243
|
+
obj = Data_Make_Struct(klass, struct mysql, 0, free_mysql, myp);
|
244
|
+
#if MYSQL_VERSION_ID >= 32200
|
245
|
+
mysql_init(&myp->handler);
|
246
|
+
if (mysql_real_connect(&myp->handler, h, u, p, d, pp, s, f) == NULL)
|
247
|
+
#elif MYSQL_VERSION_ID >= 32115
|
248
|
+
if (mysql_real_connect(&myp->handler, h, u, p, pp, s, f) == NULL)
|
249
|
+
#else
|
250
|
+
if (mysql_real_connect(&myp->handler, h, u, p, pp, s) == NULL)
|
251
|
+
#endif
|
252
|
+
mysql_raise(&myp->handler);
|
253
|
+
|
254
|
+
myp->handler.reconnect = 0;
|
255
|
+
myp->connection = Qtrue;
|
256
|
+
myp->query_with_result = Qtrue;
|
257
|
+
rb_obj_call_init(obj, argc, argv);
|
258
|
+
|
259
|
+
return obj;
|
260
|
+
}
|
261
|
+
|
262
|
+
/* escape_string(string) */
|
263
|
+
static VALUE escape_string(VALUE klass, VALUE str)
|
264
|
+
{
|
265
|
+
VALUE ret;
|
266
|
+
Check_Type(str, T_STRING);
|
267
|
+
ret = rb_str_new(0, (RSTRING(str)->len)*2+1);
|
268
|
+
RSTRING(ret)->len = mysql_escape_string(RSTRING(ret)->ptr, RSTRING(str)->ptr, RSTRING(str)->len);
|
269
|
+
return ret;
|
270
|
+
}
|
271
|
+
|
272
|
+
/* client_info() */
|
273
|
+
static VALUE client_info(VALUE klass)
|
274
|
+
{
|
275
|
+
return rb_tainted_str_new2(mysql_get_client_info());
|
276
|
+
}
|
277
|
+
|
278
|
+
#if MYSQL_VERSION_ID >= 32332
|
279
|
+
/* my_debug(string) */
|
280
|
+
static VALUE my_debug(VALUE obj, VALUE str)
|
281
|
+
{
|
282
|
+
mysql_debug(StringValuePtr(str));
|
283
|
+
return obj;
|
284
|
+
}
|
285
|
+
#endif
|
286
|
+
|
287
|
+
#if MYSQL_VERSION_ID >= 40000
|
288
|
+
/* client_version() */
|
289
|
+
static VALUE client_version(VALUE obj)
|
290
|
+
{
|
291
|
+
return INT2NUM(mysql_get_client_version());
|
292
|
+
}
|
293
|
+
#endif
|
294
|
+
|
295
|
+
/*-------------------------------
|
296
|
+
* Mysql object method
|
297
|
+
*/
|
298
|
+
|
299
|
+
#if MYSQL_VERSION_ID >= 32200
|
300
|
+
/* real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil) */
|
301
|
+
static VALUE real_connect2(int argc, VALUE* argv, VALUE obj)
|
302
|
+
{
|
303
|
+
VALUE host, user, passwd, db, port, sock, flag;
|
304
|
+
char *h, *u, *p, *d, *s;
|
305
|
+
unsigned int pp, f;
|
306
|
+
MYSQL* m = GetHandler(obj);
|
307
|
+
rb_scan_args(argc, argv, "07", &host, &user, &passwd, &db, &port, &sock, &flag);
|
308
|
+
d = NILorSTRING(db);
|
309
|
+
f = NILorINT(flag);
|
310
|
+
h = NILorSTRING(host);
|
311
|
+
u = NILorSTRING(user);
|
312
|
+
p = NILorSTRING(passwd);
|
313
|
+
pp = NILorINT(port);
|
314
|
+
s = NILorSTRING(sock);
|
315
|
+
|
316
|
+
if (mysql_real_connect(m, h, u, p, d, pp, s, f) == NULL)
|
317
|
+
mysql_raise(m);
|
318
|
+
m->reconnect = 0;
|
319
|
+
GetMysqlStruct(obj)->connection = Qtrue;
|
320
|
+
|
321
|
+
return obj;
|
322
|
+
}
|
323
|
+
|
324
|
+
/* options(opt, value=nil) */
|
325
|
+
static VALUE options(int argc, VALUE* argv, VALUE obj)
|
326
|
+
{
|
327
|
+
VALUE opt, val;
|
328
|
+
int n;
|
329
|
+
my_bool b;
|
330
|
+
char* v;
|
331
|
+
MYSQL* m = GetHandler(obj);
|
332
|
+
|
333
|
+
rb_scan_args(argc, argv, "11", &opt, &val);
|
334
|
+
switch(NUM2INT(opt)) {
|
335
|
+
case MYSQL_OPT_CONNECT_TIMEOUT:
|
336
|
+
#if MYSQL_VERSION_ID >= 40100
|
337
|
+
case MYSQL_OPT_PROTOCOL:
|
338
|
+
#endif
|
339
|
+
#if MYSQL_VERSION_ID >= 40101
|
340
|
+
case MYSQL_OPT_READ_TIMEOUT:
|
341
|
+
case MYSQL_OPT_WRITE_TIMEOUT:
|
342
|
+
#endif
|
343
|
+
if (val == Qnil)
|
344
|
+
rb_raise(rb_eArgError, "wrong # of arguments(1 for 2)");
|
345
|
+
n = NUM2INT(val);
|
346
|
+
v = (char*)&n;
|
347
|
+
break;
|
348
|
+
case MYSQL_INIT_COMMAND:
|
349
|
+
case MYSQL_READ_DEFAULT_FILE:
|
350
|
+
case MYSQL_READ_DEFAULT_GROUP:
|
351
|
+
#if MYSQL_VERSION_ID >= 32349
|
352
|
+
case MYSQL_SET_CHARSET_DIR:
|
353
|
+
case MYSQL_SET_CHARSET_NAME:
|
354
|
+
#endif
|
355
|
+
#if MYSQL_VERSION_ID >= 40100
|
356
|
+
case MYSQL_SHARED_MEMORY_BASE_NAME:
|
357
|
+
#endif
|
358
|
+
#if MYSQL_VERSION_ID >= 40101
|
359
|
+
case MYSQL_SET_CLIENT_IP:
|
360
|
+
#endif
|
361
|
+
if (val == Qnil)
|
362
|
+
rb_raise(rb_eArgError, "wrong # of arguments(1 for 2)");
|
363
|
+
v = StringValuePtr(val);
|
364
|
+
break;
|
365
|
+
#if MYSQL_VERSION_ID >= 40101
|
366
|
+
case MYSQL_SECURE_AUTH:
|
367
|
+
if (val == Qnil || val == Qfalse)
|
368
|
+
b = 1;
|
369
|
+
else
|
370
|
+
b = 0;
|
371
|
+
v = (char*)&b;
|
372
|
+
break;
|
373
|
+
#endif
|
374
|
+
#if MYSQL_VERSION_ID >= 32349
|
375
|
+
case MYSQL_OPT_LOCAL_INFILE:
|
376
|
+
if (val == Qnil || val == Qfalse)
|
377
|
+
v = NULL;
|
378
|
+
else {
|
379
|
+
n = 1;
|
380
|
+
v = (char*)&n;
|
381
|
+
}
|
382
|
+
break;
|
383
|
+
#endif
|
384
|
+
default:
|
385
|
+
v = NULL;
|
386
|
+
}
|
387
|
+
|
388
|
+
if (mysql_options(m, NUM2INT(opt), v) != 0)
|
389
|
+
rb_raise(eMysql, "unknown option: %d", NUM2INT(opt));
|
390
|
+
return obj;
|
391
|
+
}
|
392
|
+
#endif
|
393
|
+
|
394
|
+
#if MYSQL_VERSION_ID >= 32332
|
395
|
+
/* real_escape_string(string) */
|
396
|
+
static VALUE real_escape_string(VALUE obj, VALUE str)
|
397
|
+
{
|
398
|
+
MYSQL* m = GetHandler(obj);
|
399
|
+
VALUE ret;
|
400
|
+
Check_Type(str, T_STRING);
|
401
|
+
ret = rb_str_new(0, (RSTRING(str)->len)*2+1);
|
402
|
+
RSTRING(ret)->len = mysql_real_escape_string(m, RSTRING(ret)->ptr, RSTRING(str)->ptr, RSTRING(str)->len);
|
403
|
+
return ret;
|
404
|
+
}
|
405
|
+
#endif
|
406
|
+
|
407
|
+
/* initialize() */
|
408
|
+
static VALUE initialize(int argc, VALUE* argv, VALUE obj)
|
409
|
+
{
|
410
|
+
return obj;
|
411
|
+
}
|
412
|
+
|
413
|
+
/* affected_rows() */
|
414
|
+
static VALUE affected_rows(VALUE obj)
|
415
|
+
{
|
416
|
+
return INT2NUM(mysql_affected_rows(GetHandler(obj)));
|
417
|
+
}
|
418
|
+
|
419
|
+
#if MYSQL_VERSION_ID >= 32303
|
420
|
+
/* change_user(user=nil, passwd=nil, db=nil) */
|
421
|
+
static VALUE change_user(int argc, VALUE* argv, VALUE obj)
|
422
|
+
{
|
423
|
+
VALUE user, passwd, db;
|
424
|
+
char *u, *p, *d;
|
425
|
+
MYSQL* m = GetHandler(obj);
|
426
|
+
rb_scan_args(argc, argv, "03", &user, &passwd, &db);
|
427
|
+
u = NILorSTRING(user);
|
428
|
+
p = NILorSTRING(passwd);
|
429
|
+
d = NILorSTRING(db);
|
430
|
+
if (mysql_change_user(m, u, p, d) != 0)
|
431
|
+
mysql_raise(m);
|
432
|
+
return obj;
|
433
|
+
}
|
434
|
+
#endif
|
435
|
+
|
436
|
+
#if MYSQL_VERSION_ID >= 32321
|
437
|
+
/* character_set_name() */
|
438
|
+
static VALUE character_set_name(VALUE obj)
|
439
|
+
{
|
440
|
+
return rb_tainted_str_new2(mysql_character_set_name(GetHandler(obj)));
|
441
|
+
}
|
442
|
+
#endif
|
443
|
+
|
444
|
+
/* close() */
|
445
|
+
static VALUE my_close(VALUE obj)
|
446
|
+
{
|
447
|
+
MYSQL* m = GetHandler(obj);
|
448
|
+
mysql_close(m);
|
449
|
+
if (mysql_errno(m))
|
450
|
+
mysql_raise(m);
|
451
|
+
GetMysqlStruct(obj)->connection = Qfalse;
|
452
|
+
return obj;
|
453
|
+
}
|
454
|
+
|
455
|
+
#if MYSQL_VERSION_ID < 40000
|
456
|
+
/* create_db(db) */
|
457
|
+
static VALUE create_db(VALUE obj, VALUE db)
|
458
|
+
{
|
459
|
+
MYSQL* m = GetHandler(obj);
|
460
|
+
if (mysql_create_db(m, StringValuePtr(db)) != 0)
|
461
|
+
mysql_raise(m);
|
462
|
+
return obj;
|
463
|
+
}
|
464
|
+
|
465
|
+
/* drop_db(db) */
|
466
|
+
static VALUE drop_db(VALUE obj, VALUE db)
|
467
|
+
{
|
468
|
+
MYSQL* m = GetHandler(obj);
|
469
|
+
if (mysql_drop_db(m, StringValuePtr(db)) != 0)
|
470
|
+
mysql_raise(m);
|
471
|
+
return obj;
|
472
|
+
}
|
473
|
+
#endif
|
474
|
+
|
475
|
+
#if MYSQL_VERSION_ID >= 32332
|
476
|
+
/* dump_debug_info() */
|
477
|
+
static VALUE dump_debug_info(VALUE obj)
|
478
|
+
{
|
479
|
+
MYSQL* m = GetHandler(obj);
|
480
|
+
if (mysql_dump_debug_info(m) != 0)
|
481
|
+
mysql_raise(m);
|
482
|
+
return obj;
|
483
|
+
}
|
484
|
+
#endif
|
485
|
+
|
486
|
+
/* errno() */
|
487
|
+
static VALUE my_errno(VALUE obj)
|
488
|
+
{
|
489
|
+
return INT2NUM(mysql_errno(GetHandler(obj)));
|
490
|
+
}
|
491
|
+
|
492
|
+
/* error() */
|
493
|
+
static VALUE my_error(VALUE obj)
|
494
|
+
{
|
495
|
+
return rb_str_new2(mysql_error(GetHandler(obj)));
|
496
|
+
}
|
497
|
+
|
498
|
+
/* field_count() */
|
499
|
+
static VALUE field_count(VALUE obj)
|
500
|
+
{
|
501
|
+
return INT2NUM(mysql_field_count(GetHandler(obj)));
|
502
|
+
}
|
503
|
+
|
504
|
+
/* host_info() */
|
505
|
+
static VALUE host_info(VALUE obj)
|
506
|
+
{
|
507
|
+
return rb_tainted_str_new2(mysql_get_host_info(GetHandler(obj)));
|
508
|
+
}
|
509
|
+
|
510
|
+
/* proto_info() */
|
511
|
+
static VALUE proto_info(VALUE obj)
|
512
|
+
{
|
513
|
+
return INT2NUM(mysql_get_proto_info(GetHandler(obj)));
|
514
|
+
}
|
515
|
+
|
516
|
+
/* server_info() */
|
517
|
+
static VALUE server_info(VALUE obj)
|
518
|
+
{
|
519
|
+
return rb_tainted_str_new2(mysql_get_server_info(GetHandler(obj)));
|
520
|
+
}
|
521
|
+
|
522
|
+
/* info() */
|
523
|
+
static VALUE info(VALUE obj)
|
524
|
+
{
|
525
|
+
const char* p = mysql_info(GetHandler(obj));
|
526
|
+
return p? rb_tainted_str_new2(p): Qnil;
|
527
|
+
}
|
528
|
+
|
529
|
+
/* insert_id() */
|
530
|
+
static VALUE insert_id(VALUE obj)
|
531
|
+
{
|
532
|
+
return INT2NUM(mysql_insert_id(GetHandler(obj)));
|
533
|
+
}
|
534
|
+
|
535
|
+
/* kill(pid) */
|
536
|
+
static VALUE my_kill(VALUE obj, VALUE pid)
|
537
|
+
{
|
538
|
+
int p = NUM2INT(pid);
|
539
|
+
MYSQL* m = GetHandler(obj);
|
540
|
+
if (mysql_kill(m, p) != 0)
|
541
|
+
mysql_raise(m);
|
542
|
+
return obj;
|
543
|
+
}
|
544
|
+
|
545
|
+
/* list_dbs(db=nil) */
|
546
|
+
static VALUE list_dbs(int argc, VALUE* argv, VALUE obj)
|
547
|
+
{
|
548
|
+
unsigned int i, n;
|
549
|
+
VALUE db, ret;
|
550
|
+
MYSQL* m = GetHandler(obj);
|
551
|
+
MYSQL_RES* res;
|
552
|
+
|
553
|
+
rb_scan_args(argc, argv, "01", &db);
|
554
|
+
res = mysql_list_dbs(m, NILorSTRING(db));
|
555
|
+
if (res == NULL)
|
556
|
+
mysql_raise(m);
|
557
|
+
|
558
|
+
n = mysql_num_rows(res);
|
559
|
+
ret = rb_ary_new2(n);
|
560
|
+
for (i=0; i<n; i++)
|
561
|
+
rb_ary_store(ret, i, rb_tainted_str_new2(mysql_fetch_row(res)[0]));
|
562
|
+
mysql_free_result(res);
|
563
|
+
return ret;
|
564
|
+
}
|
565
|
+
|
566
|
+
/* list_fields(table, field=nil) */
|
567
|
+
static VALUE list_fields(int argc, VALUE* argv, VALUE obj)
|
568
|
+
{
|
569
|
+
VALUE table, field;
|
570
|
+
MYSQL* m = GetHandler(obj);
|
571
|
+
MYSQL_RES* res;
|
572
|
+
rb_scan_args(argc, argv, "11", &table, &field);
|
573
|
+
res = mysql_list_fields(m, StringValuePtr(table), NILorSTRING(field));
|
574
|
+
if (res == NULL)
|
575
|
+
mysql_raise(m);
|
576
|
+
return mysqlres2obj(res);
|
577
|
+
}
|
578
|
+
|
579
|
+
/* list_processes() */
|
580
|
+
static VALUE list_processes(VALUE obj)
|
581
|
+
{
|
582
|
+
MYSQL* m = GetHandler(obj);
|
583
|
+
MYSQL_RES* res = mysql_list_processes(m);
|
584
|
+
if (res == NULL)
|
585
|
+
mysql_raise(m);
|
586
|
+
return mysqlres2obj(res);
|
587
|
+
}
|
588
|
+
|
589
|
+
/* list_tables(table=nil) */
|
590
|
+
static VALUE list_tables(int argc, VALUE* argv, VALUE obj)
|
591
|
+
{
|
592
|
+
VALUE table;
|
593
|
+
MYSQL* m = GetHandler(obj);
|
594
|
+
MYSQL_RES* res;
|
595
|
+
unsigned int i, n;
|
596
|
+
VALUE ret;
|
597
|
+
|
598
|
+
rb_scan_args(argc, argv, "01", &table);
|
599
|
+
res = mysql_list_tables(m, NILorSTRING(table));
|
600
|
+
if (res == NULL)
|
601
|
+
mysql_raise(m);
|
602
|
+
|
603
|
+
n = mysql_num_rows(res);
|
604
|
+
ret = rb_ary_new2(n);
|
605
|
+
for (i=0; i<n; i++)
|
606
|
+
rb_ary_store(ret, i, rb_tainted_str_new2(mysql_fetch_row(res)[0]));
|
607
|
+
mysql_free_result(res);
|
608
|
+
return ret;
|
609
|
+
}
|
610
|
+
|
611
|
+
/* ping() */
|
612
|
+
static VALUE ping(VALUE obj)
|
613
|
+
{
|
614
|
+
MYSQL* m = GetHandler(obj);
|
615
|
+
if (mysql_ping(m) != 0)
|
616
|
+
mysql_raise(m);
|
617
|
+
return obj;
|
618
|
+
}
|
619
|
+
|
620
|
+
/* refresh(r) */
|
621
|
+
static VALUE refresh(VALUE obj, VALUE r)
|
622
|
+
{
|
623
|
+
MYSQL* m = GetHandler(obj);
|
624
|
+
if (mysql_refresh(m, NUM2INT(r)) != 0)
|
625
|
+
mysql_raise(m);
|
626
|
+
return obj;
|
627
|
+
}
|
628
|
+
|
629
|
+
/* reload() */
|
630
|
+
static VALUE reload(VALUE obj)
|
631
|
+
{
|
632
|
+
MYSQL* m = GetHandler(obj);
|
633
|
+
if (mysql_reload(m) != 0)
|
634
|
+
mysql_raise(m);
|
635
|
+
return obj;
|
636
|
+
}
|
637
|
+
|
638
|
+
/* select_db(db) */
|
639
|
+
static VALUE select_db(VALUE obj, VALUE db)
|
640
|
+
{
|
641
|
+
MYSQL* m = GetHandler(obj);
|
642
|
+
if (mysql_select_db(m, StringValuePtr(db)) != 0)
|
643
|
+
mysql_raise(m);
|
644
|
+
return obj;
|
645
|
+
}
|
646
|
+
|
647
|
+
/* shutdown() */
|
648
|
+
static VALUE my_shutdown(int argc, VALUE* argv, VALUE obj)
|
649
|
+
{
|
650
|
+
MYSQL* m = GetHandler(obj);
|
651
|
+
VALUE level;
|
652
|
+
|
653
|
+
rb_scan_args(argc, argv, "01", &level);
|
654
|
+
#if MYSQL_VERSION_ID >= 40103
|
655
|
+
if (mysql_shutdown(m, NIL_P(level) ? SHUTDOWN_DEFAULT : NUM2INT(level)) != 0)
|
656
|
+
#else
|
657
|
+
if (mysql_shutdown(m) != 0)
|
658
|
+
#endif
|
659
|
+
mysql_raise(m);
|
660
|
+
return obj;
|
661
|
+
}
|
662
|
+
|
663
|
+
/* stat() */
|
664
|
+
static VALUE my_stat(VALUE obj)
|
665
|
+
{
|
666
|
+
MYSQL* m = GetHandler(obj);
|
667
|
+
const char* s = mysql_stat(m);
|
668
|
+
if (s == NULL)
|
669
|
+
mysql_raise(m);
|
670
|
+
return rb_tainted_str_new2(s);
|
671
|
+
}
|
672
|
+
|
673
|
+
/* store_result() */
|
674
|
+
static VALUE store_result(VALUE obj)
|
675
|
+
{
|
676
|
+
MYSQL* m = GetHandler(obj);
|
677
|
+
MYSQL_RES* res = mysql_store_result(m);
|
678
|
+
if (res == NULL)
|
679
|
+
mysql_raise(m);
|
680
|
+
return mysqlres2obj(res);
|
681
|
+
}
|
682
|
+
|
683
|
+
/* thread_id() */
|
684
|
+
static VALUE thread_id(VALUE obj)
|
685
|
+
{
|
686
|
+
return INT2NUM(mysql_thread_id(GetHandler(obj)));
|
687
|
+
}
|
688
|
+
|
689
|
+
/* use_result() */
|
690
|
+
static VALUE use_result(VALUE obj)
|
691
|
+
{
|
692
|
+
MYSQL* m = GetHandler(obj);
|
693
|
+
MYSQL_RES* res = mysql_use_result(m);
|
694
|
+
if (res == NULL)
|
695
|
+
mysql_raise(m);
|
696
|
+
return mysqlres2obj(res);
|
697
|
+
}
|
698
|
+
|
699
|
+
static VALUE res_free(VALUE);
|
700
|
+
/* query(sql) */
|
701
|
+
static VALUE query(VALUE obj, VALUE sql)
|
702
|
+
{
|
703
|
+
MYSQL* m = GetHandler(obj);
|
704
|
+
Check_Type(sql, T_STRING);
|
705
|
+
if (rb_block_given_p()) {
|
706
|
+
#if MYSQL_VERSION_ID >= 40101
|
707
|
+
if (mysql_get_server_version(m) >= 40101 && mysql_set_server_option(m, MYSQL_OPTION_MULTI_STATEMENTS_ON) != 0)
|
708
|
+
mysql_raise(m);
|
709
|
+
#endif
|
710
|
+
if (mysql_real_query(m, RSTRING(sql)->ptr, RSTRING(sql)->len) != 0)
|
711
|
+
mysql_raise(m);
|
712
|
+
do {
|
713
|
+
MYSQL_RES* res = mysql_store_result(m);
|
714
|
+
if (res == NULL) {
|
715
|
+
if (mysql_field_count(m) != 0)
|
716
|
+
mysql_raise(m);
|
717
|
+
} else {
|
718
|
+
VALUE robj = mysqlres2obj(res);
|
719
|
+
rb_ensure(rb_yield, robj, res_free, robj);
|
720
|
+
}
|
721
|
+
}
|
722
|
+
#if MYSQL_VERSION_ID >= 40101
|
723
|
+
while (mysql_next_result(m) == 0);
|
724
|
+
#else
|
725
|
+
while (0);
|
726
|
+
#endif
|
727
|
+
return obj;
|
728
|
+
}
|
729
|
+
if (mysql_real_query(m, RSTRING(sql)->ptr, RSTRING(sql)->len) != 0)
|
730
|
+
mysql_raise(m);
|
731
|
+
if (GetMysqlStruct(obj)->query_with_result == Qfalse)
|
732
|
+
return obj;
|
733
|
+
if (mysql_field_count(m) == 0)
|
734
|
+
return Qnil;
|
735
|
+
return store_result(obj);
|
736
|
+
}
|
737
|
+
|
738
|
+
#if MYSQL_VERSION_ID >= 40100
|
739
|
+
/* server_version() */
|
740
|
+
static VALUE server_version(VALUE obj)
|
741
|
+
{
|
742
|
+
return INT2NUM(mysql_get_server_version(GetHandler(obj)));
|
743
|
+
}
|
744
|
+
|
745
|
+
/* warning_count() */
|
746
|
+
static VALUE warning_count(VALUE obj)
|
747
|
+
{
|
748
|
+
return INT2NUM(mysql_warning_count(GetHandler(obj)));
|
749
|
+
}
|
750
|
+
|
751
|
+
/* commit() */
|
752
|
+
static VALUE commit(VALUE obj)
|
753
|
+
{
|
754
|
+
MYSQL* m = GetHandler(obj);
|
755
|
+
if (mysql_commit(m) != 0)
|
756
|
+
mysql_raise(m);
|
757
|
+
return obj;
|
758
|
+
}
|
759
|
+
|
760
|
+
/* rollback() */
|
761
|
+
static VALUE rollback(VALUE obj)
|
762
|
+
{
|
763
|
+
MYSQL* m = GetHandler(obj);
|
764
|
+
if (mysql_rollback(m) != 0)
|
765
|
+
mysql_raise(m);
|
766
|
+
return obj;
|
767
|
+
}
|
768
|
+
|
769
|
+
/* autocommit() */
|
770
|
+
static VALUE autocommit(VALUE obj, VALUE mode)
|
771
|
+
{
|
772
|
+
MYSQL* m = GetHandler(obj);
|
773
|
+
int f;
|
774
|
+
f = (mode == Qnil || mode == Qfalse || (rb_type(mode) == T_FIXNUM && NUM2INT(mode) == 0)) ? 0 : 1;
|
775
|
+
if (mysql_autocommit(m, f) != 0)
|
776
|
+
mysql_raise(m);
|
777
|
+
return obj;
|
778
|
+
}
|
779
|
+
#endif
|
780
|
+
|
781
|
+
#ifdef HAVE_MYSQL_SSL_SET
|
782
|
+
/* ssl_set(key=nil, cert=nil, ca=nil, capath=nil, cipher=nil) */
|
783
|
+
static VALUE ssl_set(int argc, VALUE* argv, VALUE obj)
|
784
|
+
{
|
785
|
+
VALUE key, cert, ca, capath, cipher;
|
786
|
+
char *s_key, *s_cert, *s_ca, *s_capath, *s_cipher;
|
787
|
+
MYSQL* m = GetHandler(obj);
|
788
|
+
rb_scan_args(argc, argv, "05", &key, &cert, &ca, &capath, &cipher);
|
789
|
+
s_key = NILorSTRING(key);
|
790
|
+
s_cert = NILorSTRING(cert);
|
791
|
+
s_ca = NILorSTRING(ca);
|
792
|
+
s_capath = NILorSTRING(capath);
|
793
|
+
s_cipher = NILorSTRING(cipher);
|
794
|
+
mysql_ssl_set(m, s_key, s_cert, s_ca, s_capath, s_cipher);
|
795
|
+
return obj;
|
796
|
+
}
|
797
|
+
#endif
|
798
|
+
|
799
|
+
#if MYSQL_VERSION_ID >= 40100
|
800
|
+
/* more_results() */
|
801
|
+
static VALUE more_results(VALUE obj)
|
802
|
+
{
|
803
|
+
if (mysql_more_results(GetHandler(obj)) == 0)
|
804
|
+
return Qfalse;
|
805
|
+
else
|
806
|
+
return Qtrue;
|
807
|
+
}
|
808
|
+
|
809
|
+
static VALUE next_result(VALUE obj)
|
810
|
+
{
|
811
|
+
MYSQL* m = GetHandler(obj);
|
812
|
+
int ret;
|
813
|
+
ret = mysql_next_result(m);
|
814
|
+
if (ret > 0)
|
815
|
+
mysql_raise(m);
|
816
|
+
if (ret == 0)
|
817
|
+
return Qtrue;
|
818
|
+
return Qfalse;
|
819
|
+
}
|
820
|
+
#endif
|
821
|
+
|
822
|
+
#if MYSQL_VERSION_ID >= 40101
|
823
|
+
/* set_server_option(option) */
|
824
|
+
static VALUE set_server_option(VALUE obj, VALUE option)
|
825
|
+
{
|
826
|
+
MYSQL *m = GetHandler(obj);
|
827
|
+
if (mysql_set_server_option(m, NUM2INT(option)) != 0)
|
828
|
+
mysql_raise(m);
|
829
|
+
return obj;
|
830
|
+
}
|
831
|
+
|
832
|
+
/* sqlstate() */
|
833
|
+
static VALUE sqlstate(VALUE obj)
|
834
|
+
{
|
835
|
+
MYSQL *m = GetHandler(obj);
|
836
|
+
return rb_tainted_str_new2(mysql_sqlstate(m));
|
837
|
+
}
|
838
|
+
#endif
|
839
|
+
|
840
|
+
#if MYSQL_VERSION_ID >= 40102
|
841
|
+
/* stmt_init() */
|
842
|
+
static VALUE stmt_init(VALUE obj)
|
843
|
+
{
|
844
|
+
MYSQL *m = GetHandler(obj);
|
845
|
+
MYSQL_STMT *s;
|
846
|
+
struct mysql_stmt* stmt;
|
847
|
+
my_bool true = 1;
|
848
|
+
VALUE st_obj;
|
849
|
+
|
850
|
+
if ((s = mysql_stmt_init(m)) == NULL)
|
851
|
+
mysql_raise(m);
|
852
|
+
if (mysql_stmt_attr_set(s, STMT_ATTR_UPDATE_MAX_LENGTH, &true))
|
853
|
+
rb_raise(rb_eArgError, "mysql_stmt_attr_set() failed");
|
854
|
+
st_obj = Data_Make_Struct(cMysqlStmt, struct mysql_stmt, 0, free_mysqlstmt, stmt);
|
855
|
+
memset(stmt, 0, sizeof(*stmt));
|
856
|
+
stmt->stmt = s;
|
857
|
+
stmt->closed = Qfalse;
|
858
|
+
return st_obj;
|
859
|
+
}
|
860
|
+
|
861
|
+
static VALUE stmt_prepare(VALUE obj, VALUE query);
|
862
|
+
/* prepare(query) */
|
863
|
+
static VALUE prepare(VALUE obj, VALUE query)
|
864
|
+
{
|
865
|
+
VALUE st;
|
866
|
+
st = stmt_init(obj);
|
867
|
+
return stmt_prepare(st, query);
|
868
|
+
}
|
869
|
+
#endif
|
870
|
+
|
871
|
+
/* query_with_result() */
|
872
|
+
static VALUE query_with_result(VALUE obj)
|
873
|
+
{
|
874
|
+
return GetMysqlStruct(obj)->query_with_result? Qtrue: Qfalse;
|
875
|
+
}
|
876
|
+
|
877
|
+
/* query_with_result=(flag) */
|
878
|
+
static VALUE query_with_result_set(VALUE obj, VALUE flag)
|
879
|
+
{
|
880
|
+
if (TYPE(flag) != T_TRUE && TYPE(flag) != T_FALSE)
|
881
|
+
#if RUBY_VERSION_CODE < 160
|
882
|
+
TypeError("invalid type, required true or false.");
|
883
|
+
#else
|
884
|
+
rb_raise(rb_eTypeError, "invalid type, required true or false.");
|
885
|
+
#endif
|
886
|
+
GetMysqlStruct(obj)->query_with_result = flag;
|
887
|
+
return flag;
|
888
|
+
}
|
889
|
+
|
890
|
+
/* reconnect() */
|
891
|
+
static VALUE reconnect(VALUE obj)
|
892
|
+
{
|
893
|
+
return GetHandler(obj)->reconnect ? Qtrue : Qfalse;
|
894
|
+
}
|
895
|
+
|
896
|
+
/* reconnect=(flag) */
|
897
|
+
static VALUE reconnect_set(VALUE obj, VALUE flag)
|
898
|
+
{
|
899
|
+
GetHandler(obj)->reconnect = (flag == Qnil || flag == Qfalse) ? 0 : 1;
|
900
|
+
return flag;
|
901
|
+
}
|
902
|
+
|
903
|
+
/*-------------------------------
|
904
|
+
* Mysql::Result object method
|
905
|
+
*/
|
906
|
+
|
907
|
+
/* check if already freed */
|
908
|
+
static void check_free(VALUE obj)
|
909
|
+
{
|
910
|
+
struct mysql_res* resp = DATA_PTR(obj);
|
911
|
+
if (resp->freed == Qtrue)
|
912
|
+
rb_raise(eMysql, "Mysql::Result object is already freed");
|
913
|
+
}
|
914
|
+
|
915
|
+
/* data_seek(offset) */
|
916
|
+
static VALUE data_seek(VALUE obj, VALUE offset)
|
917
|
+
{
|
918
|
+
check_free(obj);
|
919
|
+
mysql_data_seek(GetMysqlRes(obj), NUM2INT(offset));
|
920
|
+
return obj;
|
921
|
+
}
|
922
|
+
|
923
|
+
/* fetch_field() */
|
924
|
+
static VALUE fetch_field(VALUE obj)
|
925
|
+
{
|
926
|
+
check_free(obj);
|
927
|
+
return make_field_obj(mysql_fetch_field(GetMysqlRes(obj)));
|
928
|
+
}
|
929
|
+
|
930
|
+
/* fetch_fields() */
|
931
|
+
static VALUE fetch_fields(VALUE obj)
|
932
|
+
{
|
933
|
+
MYSQL_RES* res;
|
934
|
+
MYSQL_FIELD* f;
|
935
|
+
unsigned int n;
|
936
|
+
VALUE ret;
|
937
|
+
unsigned int i;
|
938
|
+
check_free(obj);
|
939
|
+
res = GetMysqlRes(obj);
|
940
|
+
f = mysql_fetch_fields(res);
|
941
|
+
n = mysql_num_fields(res);
|
942
|
+
ret = rb_ary_new2(n);
|
943
|
+
for (i=0; i<n; i++)
|
944
|
+
rb_ary_store(ret, i, make_field_obj(&f[i]));
|
945
|
+
return ret;
|
946
|
+
}
|
947
|
+
|
948
|
+
/* fetch_field_direct(nr) */
|
949
|
+
static VALUE fetch_field_direct(VALUE obj, VALUE nr)
|
950
|
+
{
|
951
|
+
MYSQL_RES* res;
|
952
|
+
unsigned int max;
|
953
|
+
unsigned int n;
|
954
|
+
check_free(obj);
|
955
|
+
res = GetMysqlRes(obj);
|
956
|
+
max = mysql_num_fields(res);
|
957
|
+
n = NUM2INT(nr);
|
958
|
+
if (n >= max)
|
959
|
+
#if RUBY_VERSION_CODE < 160
|
960
|
+
Raise(eMysql, "%d: out of range (max: %d)", n, max-1);
|
961
|
+
#else
|
962
|
+
rb_raise(eMysql, "%d: out of range (max: %d)", n, max-1);
|
963
|
+
#endif
|
964
|
+
#if MYSQL_VERSION_ID >= 32226
|
965
|
+
return make_field_obj(mysql_fetch_field_direct(res, n));
|
966
|
+
#else
|
967
|
+
return make_field_obj(&mysql_fetch_field_direct(res, n));
|
968
|
+
#endif
|
969
|
+
}
|
970
|
+
|
971
|
+
/* fetch_lengths() */
|
972
|
+
static VALUE fetch_lengths(VALUE obj)
|
973
|
+
{
|
974
|
+
MYSQL_RES* res;
|
975
|
+
unsigned int n;
|
976
|
+
unsigned long* lengths;
|
977
|
+
VALUE ary;
|
978
|
+
unsigned int i;
|
979
|
+
check_free(obj);
|
980
|
+
res = GetMysqlRes(obj);
|
981
|
+
n = mysql_num_fields(res);
|
982
|
+
lengths = mysql_fetch_lengths(res);
|
983
|
+
if (lengths == NULL)
|
984
|
+
return Qnil;
|
985
|
+
ary = rb_ary_new2(n);
|
986
|
+
for (i=0; i<n; i++)
|
987
|
+
rb_ary_store(ary, i, INT2NUM(lengths[i]));
|
988
|
+
return ary;
|
989
|
+
}
|
990
|
+
|
991
|
+
/* fetch_row() */
|
992
|
+
static VALUE fetch_row(VALUE obj)
|
993
|
+
{
|
994
|
+
MYSQL_RES* res;
|
995
|
+
unsigned int n;
|
996
|
+
MYSQL_ROW row;
|
997
|
+
unsigned long* lengths;
|
998
|
+
VALUE ary;
|
999
|
+
unsigned int i;
|
1000
|
+
check_free(obj);
|
1001
|
+
res = GetMysqlRes(obj);
|
1002
|
+
n = mysql_num_fields(res);
|
1003
|
+
row = mysql_fetch_row(res);
|
1004
|
+
lengths = mysql_fetch_lengths(res);
|
1005
|
+
if (row == NULL)
|
1006
|
+
return Qnil;
|
1007
|
+
ary = rb_ary_new2(n);
|
1008
|
+
for (i=0; i<n; i++)
|
1009
|
+
rb_ary_store(ary, i, row[i]? rb_tainted_str_new(row[i], lengths[i]): Qnil);
|
1010
|
+
return ary;
|
1011
|
+
}
|
1012
|
+
|
1013
|
+
/* fetch_hash2 (internal) */
|
1014
|
+
static VALUE fetch_hash2(VALUE obj, VALUE with_table)
|
1015
|
+
{
|
1016
|
+
MYSQL_RES* res = GetMysqlRes(obj);
|
1017
|
+
unsigned int n = mysql_num_fields(res);
|
1018
|
+
MYSQL_ROW row = mysql_fetch_row(res);
|
1019
|
+
unsigned long* lengths = mysql_fetch_lengths(res);
|
1020
|
+
MYSQL_FIELD* fields = mysql_fetch_fields(res);
|
1021
|
+
unsigned int i;
|
1022
|
+
VALUE hash;
|
1023
|
+
if (row == NULL)
|
1024
|
+
return Qnil;
|
1025
|
+
hash = rb_hash_new();
|
1026
|
+
for (i=0; i<n; i++) {
|
1027
|
+
VALUE col;
|
1028
|
+
if (with_table == Qnil || with_table == Qfalse)
|
1029
|
+
col = rb_tainted_str_new2(fields[i].name);
|
1030
|
+
else {
|
1031
|
+
col = rb_tainted_str_new(fields[i].table, strlen(fields[i].table)+strlen(fields[i].name)+1);
|
1032
|
+
RSTRING(col)->ptr[strlen(fields[i].table)] = '.';
|
1033
|
+
strcpy(RSTRING(col)->ptr+strlen(fields[i].table)+1, fields[i].name);
|
1034
|
+
}
|
1035
|
+
rb_hash_aset(hash, col, row[i]? rb_tainted_str_new(row[i], lengths[i]): Qnil);
|
1036
|
+
}
|
1037
|
+
return hash;
|
1038
|
+
}
|
1039
|
+
|
1040
|
+
/* fetch_hash(with_table=false) */
|
1041
|
+
static VALUE fetch_hash(int argc, VALUE* argv, VALUE obj)
|
1042
|
+
{
|
1043
|
+
VALUE with_table;
|
1044
|
+
check_free(obj);
|
1045
|
+
rb_scan_args(argc, argv, "01", &with_table);
|
1046
|
+
if (with_table == Qnil)
|
1047
|
+
with_table = Qfalse;
|
1048
|
+
return fetch_hash2(obj, with_table);
|
1049
|
+
}
|
1050
|
+
|
1051
|
+
/* field_seek(offset) */
|
1052
|
+
static VALUE field_seek(VALUE obj, VALUE offset)
|
1053
|
+
{
|
1054
|
+
check_free(obj);
|
1055
|
+
return INT2NUM(mysql_field_seek(GetMysqlRes(obj), NUM2INT(offset)));
|
1056
|
+
}
|
1057
|
+
|
1058
|
+
/* field_tell() */
|
1059
|
+
static VALUE field_tell(VALUE obj)
|
1060
|
+
{
|
1061
|
+
check_free(obj);
|
1062
|
+
return INT2NUM(mysql_field_tell(GetMysqlRes(obj)));
|
1063
|
+
}
|
1064
|
+
|
1065
|
+
/* free() */
|
1066
|
+
static VALUE res_free(VALUE obj)
|
1067
|
+
{
|
1068
|
+
struct mysql_res* resp = DATA_PTR(obj);
|
1069
|
+
check_free(obj);
|
1070
|
+
mysql_free_result(resp->res);
|
1071
|
+
resp->freed = Qtrue;
|
1072
|
+
store_result_count--;
|
1073
|
+
return Qnil;
|
1074
|
+
}
|
1075
|
+
|
1076
|
+
/* num_fields() */
|
1077
|
+
static VALUE num_fields(VALUE obj)
|
1078
|
+
{
|
1079
|
+
check_free(obj);
|
1080
|
+
return INT2NUM(mysql_num_fields(GetMysqlRes(obj)));
|
1081
|
+
}
|
1082
|
+
|
1083
|
+
/* num_rows() */
|
1084
|
+
static VALUE num_rows(VALUE obj)
|
1085
|
+
{
|
1086
|
+
check_free(obj);
|
1087
|
+
return INT2NUM(mysql_num_rows(GetMysqlRes(obj)));
|
1088
|
+
}
|
1089
|
+
|
1090
|
+
/* row_seek(offset) */
|
1091
|
+
static VALUE row_seek(VALUE obj, VALUE offset)
|
1092
|
+
{
|
1093
|
+
MYSQL_ROW_OFFSET prev_offset;
|
1094
|
+
if (CLASS_OF(offset) != cMysqlRowOffset)
|
1095
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Mysql::RowOffset)", rb_obj_classname(offset));
|
1096
|
+
check_free(obj);
|
1097
|
+
prev_offset = mysql_row_seek(GetMysqlRes(obj), DATA_PTR(offset));
|
1098
|
+
return Data_Wrap_Struct(cMysqlRowOffset, 0, NULL, prev_offset);
|
1099
|
+
}
|
1100
|
+
|
1101
|
+
/* row_tell() */
|
1102
|
+
static VALUE row_tell(VALUE obj)
|
1103
|
+
{
|
1104
|
+
MYSQL_ROW_OFFSET offset;
|
1105
|
+
check_free(obj);
|
1106
|
+
offset = mysql_row_tell(GetMysqlRes(obj));
|
1107
|
+
return Data_Wrap_Struct(cMysqlRowOffset, 0, NULL, offset);
|
1108
|
+
}
|
1109
|
+
|
1110
|
+
/* each {...} */
|
1111
|
+
static VALUE each(VALUE obj)
|
1112
|
+
{
|
1113
|
+
VALUE row;
|
1114
|
+
check_free(obj);
|
1115
|
+
while ((row = fetch_row(obj)) != Qnil)
|
1116
|
+
rb_yield(row);
|
1117
|
+
return obj;
|
1118
|
+
}
|
1119
|
+
|
1120
|
+
/* each_hash(with_table=false) {...} */
|
1121
|
+
static VALUE each_hash(int argc, VALUE* argv, VALUE obj)
|
1122
|
+
{
|
1123
|
+
VALUE with_table;
|
1124
|
+
VALUE hash;
|
1125
|
+
check_free(obj);
|
1126
|
+
rb_scan_args(argc, argv, "01", &with_table);
|
1127
|
+
if (with_table == Qnil)
|
1128
|
+
with_table = Qfalse;
|
1129
|
+
while ((hash = fetch_hash2(obj, with_table)) != Qnil)
|
1130
|
+
rb_yield(hash);
|
1131
|
+
return obj;
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
/*-------------------------------
|
1135
|
+
* Mysql::Field object method
|
1136
|
+
*/
|
1137
|
+
|
1138
|
+
/* hash */
|
1139
|
+
static VALUE field_hash(VALUE obj)
|
1140
|
+
{
|
1141
|
+
VALUE h = rb_hash_new();
|
1142
|
+
rb_hash_aset(h, rb_str_new2("name"), rb_iv_get(obj, "name"));
|
1143
|
+
rb_hash_aset(h, rb_str_new2("table"), rb_iv_get(obj, "table"));
|
1144
|
+
rb_hash_aset(h, rb_str_new2("def"), rb_iv_get(obj, "def"));
|
1145
|
+
rb_hash_aset(h, rb_str_new2("type"), rb_iv_get(obj, "type"));
|
1146
|
+
rb_hash_aset(h, rb_str_new2("length"), rb_iv_get(obj, "length"));
|
1147
|
+
rb_hash_aset(h, rb_str_new2("max_length"), rb_iv_get(obj, "max_length"));
|
1148
|
+
rb_hash_aset(h, rb_str_new2("flags"), rb_iv_get(obj, "flags"));
|
1149
|
+
rb_hash_aset(h, rb_str_new2("decimals"), rb_iv_get(obj, "decimals"));
|
1150
|
+
return h;
|
1151
|
+
}
|
1152
|
+
|
1153
|
+
/* inspect */
|
1154
|
+
static VALUE field_inspect(VALUE obj)
|
1155
|
+
{
|
1156
|
+
VALUE n = rb_iv_get(obj, "name");
|
1157
|
+
VALUE s = rb_str_new(0, RSTRING(n)->len + 16);
|
1158
|
+
sprintf(RSTRING(s)->ptr, "#<Mysql::Field:%s>", RSTRING(n)->ptr);
|
1159
|
+
return s;
|
1160
|
+
}
|
1161
|
+
|
1162
|
+
#define DefineMysqlFieldMemberMethod(m)\
|
1163
|
+
static VALUE field_##m(VALUE obj)\
|
1164
|
+
{return rb_iv_get(obj, #m);}
|
1165
|
+
|
1166
|
+
DefineMysqlFieldMemberMethod(name)
|
1167
|
+
DefineMysqlFieldMemberMethod(table)
|
1168
|
+
DefineMysqlFieldMemberMethod(def)
|
1169
|
+
DefineMysqlFieldMemberMethod(type)
|
1170
|
+
DefineMysqlFieldMemberMethod(length)
|
1171
|
+
DefineMysqlFieldMemberMethod(max_length)
|
1172
|
+
DefineMysqlFieldMemberMethod(flags)
|
1173
|
+
DefineMysqlFieldMemberMethod(decimals)
|
1174
|
+
|
1175
|
+
#ifdef IS_NUM
|
1176
|
+
/* is_num? */
|
1177
|
+
static VALUE field_is_num(VALUE obj)
|
1178
|
+
{
|
1179
|
+
return IS_NUM(NUM2INT(rb_iv_get(obj, "type"))) ? Qtrue : Qfalse;
|
1180
|
+
}
|
1181
|
+
#endif
|
1182
|
+
|
1183
|
+
#ifdef IS_NOT_NULL
|
1184
|
+
/* is_not_null? */
|
1185
|
+
static VALUE field_is_not_null(VALUE obj)
|
1186
|
+
{
|
1187
|
+
return IS_NOT_NULL(NUM2INT(rb_iv_get(obj, "flags"))) ? Qtrue : Qfalse;
|
1188
|
+
}
|
1189
|
+
#endif
|
1190
|
+
|
1191
|
+
#ifdef IS_PRI_KEY
|
1192
|
+
/* is_pri_key? */
|
1193
|
+
static VALUE field_is_pri_key(VALUE obj)
|
1194
|
+
{
|
1195
|
+
return IS_PRI_KEY(NUM2INT(rb_iv_get(obj, "flags"))) ? Qtrue : Qfalse;
|
1196
|
+
}
|
1197
|
+
#endif
|
1198
|
+
|
1199
|
+
#if MYSQL_VERSION_ID >= 40102
|
1200
|
+
/*-------------------------------
|
1201
|
+
* Mysql::Stmt object method
|
1202
|
+
*/
|
1203
|
+
|
1204
|
+
/* check if stmt is already closed */
|
1205
|
+
static void check_stmt_closed(VALUE obj)
|
1206
|
+
{
|
1207
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1208
|
+
if (s->closed == Qtrue)
|
1209
|
+
rb_raise(eMysql, "Mysql::Stmt object is already closed");
|
1210
|
+
}
|
1211
|
+
|
1212
|
+
static void mysql_stmt_raise(MYSQL_STMT* s)
|
1213
|
+
{
|
1214
|
+
VALUE e = rb_exc_new2(eMysql, mysql_stmt_error(s));
|
1215
|
+
rb_iv_set(e, "errno", INT2FIX(mysql_stmt_errno(s)));
|
1216
|
+
rb_iv_set(e, "sqlstate", rb_tainted_str_new2(mysql_stmt_sqlstate(s)));
|
1217
|
+
rb_exc_raise(e);
|
1218
|
+
}
|
1219
|
+
|
1220
|
+
/* affected_rows() */
|
1221
|
+
static VALUE stmt_affected_rows(VALUE obj)
|
1222
|
+
{
|
1223
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1224
|
+
my_ulonglong n;
|
1225
|
+
check_stmt_closed(obj);
|
1226
|
+
n = mysql_stmt_affected_rows(s->stmt);
|
1227
|
+
return INT2NUM(n);
|
1228
|
+
}
|
1229
|
+
|
1230
|
+
#if 0
|
1231
|
+
/* attr_get(option) */
|
1232
|
+
static VALUE stmt_attr_get(VALUE obj, VALUE opt)
|
1233
|
+
{
|
1234
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1235
|
+
check_stmt_closed(obj);
|
1236
|
+
if (NUM2INT(opt) == STMT_ATTR_UPDATE_MAX_LENGTH) {
|
1237
|
+
my_bool arg;
|
1238
|
+
mysql_stmt_attr_get(s->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &arg);
|
1239
|
+
return arg == 1 ? Qtrue : Qfalse;
|
1240
|
+
}
|
1241
|
+
rb_raise(eMysql, "unknown option: %d", NUM2INT(opt));
|
1242
|
+
}
|
1243
|
+
|
1244
|
+
/* attr_set(option, arg) */
|
1245
|
+
static VALUE stmt_attr_set(VALUE obj, VALUE opt, VALUE val)
|
1246
|
+
{
|
1247
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1248
|
+
check_stmt_closed(obj);
|
1249
|
+
if (NUM2INT(opt) == STMT_ATTR_UPDATE_MAX_LENGTH) {
|
1250
|
+
my_bool arg;
|
1251
|
+
arg = (val == Qnil || val == Qfalse) ? 0 : 1;
|
1252
|
+
mysql_stmt_attr_set(s->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &arg);
|
1253
|
+
return obj;
|
1254
|
+
}
|
1255
|
+
rb_raise(eMysql, "unknown option: %d", NUM2INT(opt));
|
1256
|
+
}
|
1257
|
+
#endif
|
1258
|
+
|
1259
|
+
/* bind_result(bind,...) */
|
1260
|
+
static enum enum_field_types buffer_type(MYSQL_FIELD *field);
|
1261
|
+
static VALUE stmt_bind_result(int argc, VALUE *argv, VALUE obj)
|
1262
|
+
{
|
1263
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1264
|
+
int i;
|
1265
|
+
MYSQL_FIELD *field;
|
1266
|
+
|
1267
|
+
check_stmt_closed(obj);
|
1268
|
+
if (argc != s->result.n)
|
1269
|
+
rb_raise(eMysql, "bind_result: result value count(%d) != number of argument(%d)", s->result.n, argc);
|
1270
|
+
for (i = 0; i < argc; i++) {
|
1271
|
+
if (argv[i] == Qnil || argv[i] == rb_cNilClass) {
|
1272
|
+
field = mysql_fetch_fields(s->res);
|
1273
|
+
s->result.bind[i].buffer_type = buffer_type(&field[i]);
|
1274
|
+
}
|
1275
|
+
else if (argv[i] == rb_cString)
|
1276
|
+
s->result.bind[i].buffer_type = MYSQL_TYPE_STRING;
|
1277
|
+
else if (argv[i] == rb_cNumeric || argv[i] == rb_cInteger || argv[i] == rb_cFixnum)
|
1278
|
+
s->result.bind[i].buffer_type = MYSQL_TYPE_LONGLONG;
|
1279
|
+
else if (argv[i] == rb_cFloat)
|
1280
|
+
s->result.bind[i].buffer_type = MYSQL_TYPE_DOUBLE;
|
1281
|
+
else if (argv[i] == cMysqlTime)
|
1282
|
+
s->result.bind[i].buffer_type = MYSQL_TYPE_DATETIME;
|
1283
|
+
else
|
1284
|
+
rb_raise(rb_eTypeError, "unrecognized class: %s", RSTRING(rb_inspect(argv[i]))->ptr);
|
1285
|
+
if (mysql_stmt_bind_result(s->stmt, s->result.bind))
|
1286
|
+
mysql_stmt_raise(s->stmt);
|
1287
|
+
}
|
1288
|
+
return obj;
|
1289
|
+
}
|
1290
|
+
|
1291
|
+
/* close() */
|
1292
|
+
static VALUE stmt_close(VALUE obj)
|
1293
|
+
{
|
1294
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1295
|
+
check_stmt_closed(obj);
|
1296
|
+
mysql_stmt_close(s->stmt);
|
1297
|
+
s->closed = Qtrue;
|
1298
|
+
return Qnil;
|
1299
|
+
}
|
1300
|
+
|
1301
|
+
/* data_seek(offset) */
|
1302
|
+
static VALUE stmt_data_seek(VALUE obj, VALUE offset)
|
1303
|
+
{
|
1304
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1305
|
+
check_stmt_closed(obj);
|
1306
|
+
mysql_stmt_data_seek(s->stmt, NUM2INT(offset));
|
1307
|
+
return obj;
|
1308
|
+
}
|
1309
|
+
|
1310
|
+
/* execute(arg,...) */
|
1311
|
+
static VALUE stmt_execute(int argc, VALUE *argv, VALUE obj)
|
1312
|
+
{
|
1313
|
+
struct mysql_stmt *s = DATA_PTR(obj);
|
1314
|
+
MYSQL_STMT *stmt = s->stmt;
|
1315
|
+
my_bool true = 1;
|
1316
|
+
my_bool false = 0;
|
1317
|
+
int i;
|
1318
|
+
|
1319
|
+
check_stmt_closed(obj);
|
1320
|
+
if (s->param.n != argc)
|
1321
|
+
rb_raise(eMysql, "execute: param_count(%d) != number of argument(%d)", s->param.n, argc);
|
1322
|
+
memset(s->param.bind, 0, sizeof(*(s->param.bind))*argc);
|
1323
|
+
for (i = 0; i < argc; i++) {
|
1324
|
+
switch (TYPE(argv[i])) {
|
1325
|
+
case T_NIL:
|
1326
|
+
s->param.bind[i].buffer_type = MYSQL_TYPE_NULL;
|
1327
|
+
s->param.bind[i].is_null = &true;
|
1328
|
+
break;
|
1329
|
+
case T_FIXNUM:
|
1330
|
+
s->param.bind[i].buffer_type = MYSQL_TYPE_LONG;
|
1331
|
+
s->param.bind[i].buffer = &(s->param.buffer[i]);
|
1332
|
+
*(long*)(s->param.bind[i].buffer) = FIX2INT(argv[i]);
|
1333
|
+
break;
|
1334
|
+
case T_BIGNUM:
|
1335
|
+
s->param.bind[i].buffer_type = MYSQL_TYPE_LONGLONG;
|
1336
|
+
s->param.bind[i].buffer = &(s->param.buffer[i]);
|
1337
|
+
*(long long*)(s->param.bind[i].buffer) = rb_big2ll(argv[i]);
|
1338
|
+
break;
|
1339
|
+
case T_FLOAT:
|
1340
|
+
s->param.bind[i].buffer_type = MYSQL_TYPE_DOUBLE;
|
1341
|
+
s->param.bind[i].buffer = &(s->param.buffer[i]);
|
1342
|
+
*(double*)(s->param.bind[i].buffer) = NUM2DBL(argv[i]);
|
1343
|
+
break;
|
1344
|
+
case T_STRING:
|
1345
|
+
s->param.bind[i].buffer_type = MYSQL_TYPE_STRING;
|
1346
|
+
s->param.bind[i].buffer = RSTRING(argv[i])->ptr;
|
1347
|
+
s->param.bind[i].buffer_length = RSTRING(argv[i])->len;
|
1348
|
+
s->param.length[i] = RSTRING(argv[i])->len;
|
1349
|
+
s->param.bind[i].length = &(s->param.length[i]);
|
1350
|
+
break;
|
1351
|
+
default:
|
1352
|
+
if (CLASS_OF(argv[i]) == rb_cTime) {
|
1353
|
+
MYSQL_TIME t;
|
1354
|
+
VALUE a = rb_funcall(argv[i], rb_intern("to_a"), 0);
|
1355
|
+
s->param.bind[i].buffer_type = MYSQL_TYPE_DATETIME;
|
1356
|
+
s->param.bind[i].buffer = &(s->param.buffer[i]);
|
1357
|
+
t.second_part = 0;
|
1358
|
+
t.neg = 0;
|
1359
|
+
t.second = FIX2INT(RARRAY(a)->ptr[0]);
|
1360
|
+
t.minute = FIX2INT(RARRAY(a)->ptr[1]);
|
1361
|
+
t.hour = FIX2INT(RARRAY(a)->ptr[2]);
|
1362
|
+
t.day = FIX2INT(RARRAY(a)->ptr[3]);
|
1363
|
+
t.month = FIX2INT(RARRAY(a)->ptr[4]);
|
1364
|
+
t.year = FIX2INT(RARRAY(a)->ptr[5]);
|
1365
|
+
*(MYSQL_TIME*)&(s->param.buffer[i]) = t;
|
1366
|
+
} else if (CLASS_OF(argv[i]) == cMysqlTime) {
|
1367
|
+
MYSQL_TIME t;
|
1368
|
+
s->param.bind[i].buffer_type = MYSQL_TYPE_DATETIME;
|
1369
|
+
s->param.bind[i].buffer = &(s->param.buffer[i]);
|
1370
|
+
t.second_part = 0;
|
1371
|
+
t.neg = 0;
|
1372
|
+
t.second = NUM2INT(rb_iv_get(argv[i], "second"));
|
1373
|
+
t.minute = NUM2INT(rb_iv_get(argv[i], "minute"));
|
1374
|
+
t.hour = NUM2INT(rb_iv_get(argv[i], "hour"));
|
1375
|
+
t.day = NUM2INT(rb_iv_get(argv[i], "day"));
|
1376
|
+
t.month = NUM2INT(rb_iv_get(argv[i], "month"));
|
1377
|
+
t.year = NUM2INT(rb_iv_get(argv[i], "year"));
|
1378
|
+
*(MYSQL_TIME*)&(s->param.buffer[i]) = t;
|
1379
|
+
} else
|
1380
|
+
rb_raise(rb_eTypeError, "unsupported type: %d", TYPE(argv[i]));
|
1381
|
+
}
|
1382
|
+
}
|
1383
|
+
if (mysql_stmt_bind_param(stmt, s->param.bind))
|
1384
|
+
mysql_stmt_raise(stmt);
|
1385
|
+
|
1386
|
+
if (mysql_stmt_execute(stmt))
|
1387
|
+
mysql_stmt_raise(stmt);
|
1388
|
+
if (s->res) {
|
1389
|
+
MYSQL_FIELD *field;
|
1390
|
+
if (mysql_stmt_store_result(stmt))
|
1391
|
+
mysql_stmt_raise(stmt);
|
1392
|
+
field = mysql_fetch_fields(s->res);
|
1393
|
+
for (i = 0; i < s->result.n; i++) {
|
1394
|
+
if (s->result.bind[i].buffer_type == MYSQL_TYPE_STRING ||
|
1395
|
+
s->result.bind[i].buffer_type == MYSQL_TYPE_BLOB) {
|
1396
|
+
s->result.bind[i].buffer = xmalloc(field[i].max_length);
|
1397
|
+
memset(s->result.bind[i].buffer, 0, field[i].max_length);
|
1398
|
+
s->result.bind[i].buffer_length = field[i].max_length;
|
1399
|
+
} else {
|
1400
|
+
s->result.bind[i].buffer = xmalloc(sizeof(MYSQL_TIME));
|
1401
|
+
s->result.bind[i].buffer_length = sizeof(MYSQL_TIME);
|
1402
|
+
memset(s->result.bind[i].buffer, 0, sizeof(MYSQL_TIME));
|
1403
|
+
}
|
1404
|
+
}
|
1405
|
+
if (mysql_stmt_bind_result(s->stmt, s->result.bind))
|
1406
|
+
mysql_stmt_raise(s->stmt);
|
1407
|
+
}
|
1408
|
+
return obj;
|
1409
|
+
}
|
1410
|
+
|
1411
|
+
/* fetch() */
|
1412
|
+
static VALUE stmt_fetch(VALUE obj)
|
1413
|
+
{
|
1414
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1415
|
+
VALUE ret;
|
1416
|
+
int i;
|
1417
|
+
int r;
|
1418
|
+
|
1419
|
+
check_stmt_closed(obj);
|
1420
|
+
r = mysql_stmt_fetch(s->stmt);
|
1421
|
+
if (r == MYSQL_NO_DATA)
|
1422
|
+
return Qnil;
|
1423
|
+
if (r == 1)
|
1424
|
+
mysql_stmt_raise(s->stmt);
|
1425
|
+
|
1426
|
+
ret = rb_ary_new2(s->result.n);
|
1427
|
+
for (i = 0; i < s->result.n; i++) {
|
1428
|
+
if (s->result.is_null[i])
|
1429
|
+
rb_ary_push(ret, Qnil);
|
1430
|
+
else {
|
1431
|
+
VALUE v;
|
1432
|
+
MYSQL_TIME *t;
|
1433
|
+
switch (s->result.bind[i].buffer_type) {
|
1434
|
+
case MYSQL_TYPE_LONG:
|
1435
|
+
v = INT2NUM(*(long*)s->result.bind[i].buffer);
|
1436
|
+
break;
|
1437
|
+
case MYSQL_TYPE_LONGLONG:
|
1438
|
+
v = rb_ll2inum(*(long long*)s->result.bind[i].buffer);
|
1439
|
+
break;
|
1440
|
+
case MYSQL_TYPE_DOUBLE:
|
1441
|
+
v = rb_float_new(*(double*)s->result.bind[i].buffer);
|
1442
|
+
break;
|
1443
|
+
case MYSQL_TYPE_TIMESTAMP:
|
1444
|
+
case MYSQL_TYPE_DATE:
|
1445
|
+
case MYSQL_TYPE_TIME:
|
1446
|
+
case MYSQL_TYPE_DATETIME:
|
1447
|
+
t = (MYSQL_TIME*)s->result.bind[i].buffer;
|
1448
|
+
v = rb_obj_alloc(cMysqlTime);
|
1449
|
+
rb_funcall(v, rb_intern("initialize"), 8,
|
1450
|
+
INT2FIX(t->year), INT2FIX(t->month),
|
1451
|
+
INT2FIX(t->day), INT2FIX(t->hour),
|
1452
|
+
INT2FIX(t->minute), INT2FIX(t->second),
|
1453
|
+
(t->neg ? Qtrue : Qfalse),
|
1454
|
+
INT2FIX(t->second_part));
|
1455
|
+
break;
|
1456
|
+
case MYSQL_TYPE_STRING:
|
1457
|
+
case MYSQL_TYPE_BLOB:
|
1458
|
+
v = rb_tainted_str_new(s->result.bind[i].buffer, s->result.length[i]);
|
1459
|
+
break;
|
1460
|
+
default:
|
1461
|
+
rb_raise(rb_eTypeError, "unknown buffer_type: %d", s->result.bind[i].buffer_type);
|
1462
|
+
}
|
1463
|
+
rb_ary_push(ret, v);
|
1464
|
+
}
|
1465
|
+
}
|
1466
|
+
return ret;
|
1467
|
+
}
|
1468
|
+
|
1469
|
+
/* each {...} */
|
1470
|
+
static VALUE stmt_each(VALUE obj)
|
1471
|
+
{
|
1472
|
+
VALUE row;
|
1473
|
+
check_stmt_closed(obj);
|
1474
|
+
while ((row = stmt_fetch(obj)) != Qnil)
|
1475
|
+
rb_yield(row);
|
1476
|
+
return obj;
|
1477
|
+
}
|
1478
|
+
|
1479
|
+
/* field_count() */
|
1480
|
+
static VALUE stmt_field_count(VALUE obj)
|
1481
|
+
{
|
1482
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1483
|
+
unsigned int n;
|
1484
|
+
check_stmt_closed(obj);
|
1485
|
+
n = mysql_stmt_field_count(s->stmt);
|
1486
|
+
return INT2NUM(n);
|
1487
|
+
}
|
1488
|
+
|
1489
|
+
/* free_result() */
|
1490
|
+
static VALUE stmt_free_result(VALUE obj)
|
1491
|
+
{
|
1492
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1493
|
+
check_stmt_closed(obj);
|
1494
|
+
if (s->res) {
|
1495
|
+
mysql_free_result(s->res);
|
1496
|
+
s->res = NULL;
|
1497
|
+
}
|
1498
|
+
if (mysql_stmt_free_result(s->stmt))
|
1499
|
+
mysql_stmt_raise(s->stmt);
|
1500
|
+
return obj;
|
1501
|
+
}
|
1502
|
+
|
1503
|
+
/* insert_id() */
|
1504
|
+
static VALUE stmt_insert_id(VALUE obj)
|
1505
|
+
{
|
1506
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1507
|
+
my_ulonglong n;
|
1508
|
+
check_stmt_closed(obj);
|
1509
|
+
n = mysql_stmt_insert_id(s->stmt);
|
1510
|
+
return INT2NUM(n);
|
1511
|
+
}
|
1512
|
+
|
1513
|
+
/* num_rows() */
|
1514
|
+
static VALUE stmt_num_rows(VALUE obj)
|
1515
|
+
{
|
1516
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1517
|
+
my_ulonglong n;
|
1518
|
+
check_stmt_closed(obj);
|
1519
|
+
n = mysql_stmt_num_rows(s->stmt);
|
1520
|
+
return INT2NUM(n);
|
1521
|
+
}
|
1522
|
+
|
1523
|
+
/* param_count() */
|
1524
|
+
static VALUE stmt_param_count(VALUE obj)
|
1525
|
+
{
|
1526
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1527
|
+
unsigned long n;
|
1528
|
+
check_stmt_closed(obj);
|
1529
|
+
n = mysql_stmt_param_count(s->stmt);
|
1530
|
+
return INT2NUM(n);
|
1531
|
+
}
|
1532
|
+
|
1533
|
+
/* prepare(query) */
|
1534
|
+
static enum enum_field_types buffer_type(MYSQL_FIELD *field)
|
1535
|
+
{
|
1536
|
+
switch (field->type) {
|
1537
|
+
case FIELD_TYPE_TINY:
|
1538
|
+
case FIELD_TYPE_SHORT:
|
1539
|
+
case FIELD_TYPE_INT24:
|
1540
|
+
case FIELD_TYPE_YEAR:
|
1541
|
+
return MYSQL_TYPE_LONG;
|
1542
|
+
case FIELD_TYPE_LONG:
|
1543
|
+
case FIELD_TYPE_LONGLONG:
|
1544
|
+
return MYSQL_TYPE_LONGLONG;
|
1545
|
+
case FIELD_TYPE_FLOAT:
|
1546
|
+
case FIELD_TYPE_DOUBLE:
|
1547
|
+
return MYSQL_TYPE_DOUBLE;
|
1548
|
+
case FIELD_TYPE_TIMESTAMP:
|
1549
|
+
return MYSQL_TYPE_TIMESTAMP;
|
1550
|
+
case FIELD_TYPE_DATE:
|
1551
|
+
return MYSQL_TYPE_DATE;
|
1552
|
+
case FIELD_TYPE_TIME:
|
1553
|
+
return MYSQL_TYPE_TIME;
|
1554
|
+
case FIELD_TYPE_DATETIME:
|
1555
|
+
return MYSQL_TYPE_DATETIME;
|
1556
|
+
case FIELD_TYPE_STRING:
|
1557
|
+
case FIELD_TYPE_VAR_STRING:
|
1558
|
+
case FIELD_TYPE_SET:
|
1559
|
+
case FIELD_TYPE_ENUM:
|
1560
|
+
case FIELD_TYPE_DECIMAL:
|
1561
|
+
#if MYSQL_VERSION_ID >= 50003
|
1562
|
+
case FIELD_TYPE_NEWDECIMAL:
|
1563
|
+
#endif
|
1564
|
+
return MYSQL_TYPE_STRING;
|
1565
|
+
case FIELD_TYPE_BLOB:
|
1566
|
+
return MYSQL_TYPE_BLOB;
|
1567
|
+
case FIELD_TYPE_NULL:
|
1568
|
+
return MYSQL_TYPE_NULL;
|
1569
|
+
default:
|
1570
|
+
rb_raise(rb_eTypeError, "unknown type: %d", field->type);
|
1571
|
+
}
|
1572
|
+
}
|
1573
|
+
|
1574
|
+
static VALUE stmt_prepare(VALUE obj, VALUE query)
|
1575
|
+
{
|
1576
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1577
|
+
int n;
|
1578
|
+
int i;
|
1579
|
+
MYSQL_FIELD *field;
|
1580
|
+
|
1581
|
+
free_mysqlstmt_memory(s);
|
1582
|
+
check_stmt_closed(obj);
|
1583
|
+
Check_Type(query, T_STRING);
|
1584
|
+
if (mysql_stmt_prepare(s->stmt, RSTRING(query)->ptr, RSTRING(query)->len))
|
1585
|
+
mysql_stmt_raise(s->stmt);
|
1586
|
+
|
1587
|
+
n = mysql_stmt_param_count(s->stmt);
|
1588
|
+
s->param.n = n;
|
1589
|
+
s->param.bind = xmalloc(sizeof(s->param.bind[0]) * n);
|
1590
|
+
s->param.length = xmalloc(sizeof(s->param.length[0]) * n);
|
1591
|
+
s->param.buffer = xmalloc(sizeof(s->param.buffer[0]) * n);
|
1592
|
+
|
1593
|
+
s->res = mysql_stmt_result_metadata(s->stmt);
|
1594
|
+
if (s->res) {
|
1595
|
+
n = s->result.n = mysql_num_fields(s->res);
|
1596
|
+
s->result.bind = xmalloc(sizeof(s->result.bind[0]) * n);
|
1597
|
+
s->result.is_null = xmalloc(sizeof(s->result.is_null[0]) * n);
|
1598
|
+
s->result.length = xmalloc(sizeof(s->result.length[0]) * n);
|
1599
|
+
field = mysql_fetch_fields(s->res);
|
1600
|
+
memset(s->result.bind, 0, sizeof(s->result.bind[0]) * n);
|
1601
|
+
for (i = 0; i < n; i++) {
|
1602
|
+
s->result.bind[i].buffer_type = buffer_type(&field[i]);
|
1603
|
+
s->result.bind[i].is_null = &(s->result.is_null[i]);
|
1604
|
+
s->result.bind[i].length = &(s->result.length[i]);
|
1605
|
+
}
|
1606
|
+
} else {
|
1607
|
+
if (mysql_stmt_errno(s->stmt))
|
1608
|
+
mysql_stmt_raise(s->stmt);
|
1609
|
+
}
|
1610
|
+
|
1611
|
+
return obj;
|
1612
|
+
}
|
1613
|
+
|
1614
|
+
#if 0
|
1615
|
+
/* reset() */
|
1616
|
+
static VALUE stmt_reset(VALUE obj)
|
1617
|
+
{
|
1618
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1619
|
+
check_stmt_closed(obj);
|
1620
|
+
if (mysql_stmt_reset(s->stmt))
|
1621
|
+
mysql_stmt_raise(s->stmt);
|
1622
|
+
return obj;
|
1623
|
+
}
|
1624
|
+
#endif
|
1625
|
+
|
1626
|
+
/* result_metadata() */
|
1627
|
+
static VALUE stmt_result_metadata(VALUE obj)
|
1628
|
+
{
|
1629
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1630
|
+
MYSQL_RES *res;
|
1631
|
+
check_stmt_closed(obj);
|
1632
|
+
res = mysql_stmt_result_metadata(s->stmt);
|
1633
|
+
if (res == NULL && mysql_stmt_errno(s->stmt) != 0)
|
1634
|
+
mysql_stmt_raise(s->stmt);
|
1635
|
+
return mysqlres2obj(res);
|
1636
|
+
}
|
1637
|
+
|
1638
|
+
/* row_seek(offset) */
|
1639
|
+
static VALUE stmt_row_seek(VALUE obj, VALUE offset)
|
1640
|
+
{
|
1641
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1642
|
+
MYSQL_ROW_OFFSET prev_offset;
|
1643
|
+
if (CLASS_OF(offset) != cMysqlRowOffset)
|
1644
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Mysql::RowOffset)", rb_obj_classname(offset));
|
1645
|
+
check_stmt_closed(obj);
|
1646
|
+
prev_offset = mysql_stmt_row_seek(s->stmt, DATA_PTR(offset));
|
1647
|
+
return Data_Wrap_Struct(cMysqlRowOffset, 0, NULL, prev_offset);
|
1648
|
+
}
|
1649
|
+
|
1650
|
+
/* row_tell() */
|
1651
|
+
static VALUE stmt_row_tell(VALUE obj)
|
1652
|
+
{
|
1653
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1654
|
+
MYSQL_ROW_OFFSET offset;
|
1655
|
+
check_stmt_closed(obj);
|
1656
|
+
offset = mysql_stmt_row_tell(s->stmt);
|
1657
|
+
return Data_Wrap_Struct(cMysqlRowOffset, 0, NULL, offset);
|
1658
|
+
}
|
1659
|
+
|
1660
|
+
#if 0
|
1661
|
+
/* send_long_data(col, data) */
|
1662
|
+
static VALUE stmt_send_long_data(VALUE obj, VALUE col, VALUE data)
|
1663
|
+
{
|
1664
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1665
|
+
int c;
|
1666
|
+
check_stmt_closed(obj);
|
1667
|
+
c = NUM2INT(col);
|
1668
|
+
if (0 <= c && c < s->param.n) {
|
1669
|
+
s->param.bind[c].buffer_type = MYSQL_TYPE_STRING;
|
1670
|
+
if (mysql_stmt_bind_param(s->stmt, s->param.bind))
|
1671
|
+
mysql_stmt_raise(s->stmt);
|
1672
|
+
}
|
1673
|
+
if (mysql_stmt_send_long_data(s->stmt, c, RSTRING(data)->ptr, RSTRING(data)->len))
|
1674
|
+
mysql_stmt_raise(s->stmt);
|
1675
|
+
return obj;
|
1676
|
+
}
|
1677
|
+
#endif
|
1678
|
+
|
1679
|
+
/* sqlstate() */
|
1680
|
+
static VALUE stmt_sqlstate(VALUE obj)
|
1681
|
+
{
|
1682
|
+
struct mysql_stmt* s = DATA_PTR(obj);
|
1683
|
+
return rb_tainted_str_new2(mysql_stmt_sqlstate(s->stmt));
|
1684
|
+
}
|
1685
|
+
|
1686
|
+
/*-------------------------------
|
1687
|
+
* Mysql::Time object method
|
1688
|
+
*/
|
1689
|
+
|
1690
|
+
static VALUE time_initialize(int argc, VALUE* argv, VALUE obj)
|
1691
|
+
{
|
1692
|
+
VALUE year, month, day, hour, minute, second, neg, second_part;
|
1693
|
+
rb_scan_args(argc, argv, "08", &year, &month, &day, &hour, &minute, &second, &neg, &second_part);
|
1694
|
+
#define NILorFIXvalue(o) (NIL_P(o) ? INT2FIX(0) : (Check_Type(o, T_FIXNUM), o))
|
1695
|
+
rb_iv_set(obj, "year", NILorFIXvalue(year));
|
1696
|
+
rb_iv_set(obj, "month", NILorFIXvalue(month));
|
1697
|
+
rb_iv_set(obj, "day", NILorFIXvalue(day));
|
1698
|
+
rb_iv_set(obj, "hour", NILorFIXvalue(hour));
|
1699
|
+
rb_iv_set(obj, "minute", NILorFIXvalue(minute));
|
1700
|
+
rb_iv_set(obj, "second", NILorFIXvalue(second));
|
1701
|
+
rb_iv_set(obj, "neg", (neg == Qnil || neg == Qfalse) ? Qfalse : Qtrue);
|
1702
|
+
rb_iv_set(obj, "second_part", NILorFIXvalue(second_part));
|
1703
|
+
}
|
1704
|
+
|
1705
|
+
static VALUE time_inspect(VALUE obj)
|
1706
|
+
{
|
1707
|
+
char buf[36];
|
1708
|
+
sprintf(buf, "#<Mysql::Time:%04d-%02d-%02d %02d:%02d:%02d>",
|
1709
|
+
NUM2INT(rb_iv_get(obj, "year")),
|
1710
|
+
NUM2INT(rb_iv_get(obj, "month")),
|
1711
|
+
NUM2INT(rb_iv_get(obj, "day")),
|
1712
|
+
NUM2INT(rb_iv_get(obj, "hour")),
|
1713
|
+
NUM2INT(rb_iv_get(obj, "minute")),
|
1714
|
+
NUM2INT(rb_iv_get(obj, "second")));
|
1715
|
+
return rb_str_new2(buf);
|
1716
|
+
}
|
1717
|
+
|
1718
|
+
static VALUE time_to_s(VALUE obj)
|
1719
|
+
{
|
1720
|
+
char buf[20];
|
1721
|
+
sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d",
|
1722
|
+
NUM2INT(rb_iv_get(obj, "year")),
|
1723
|
+
NUM2INT(rb_iv_get(obj, "month")),
|
1724
|
+
NUM2INT(rb_iv_get(obj, "day")),
|
1725
|
+
NUM2INT(rb_iv_get(obj, "hour")),
|
1726
|
+
NUM2INT(rb_iv_get(obj, "minute")),
|
1727
|
+
NUM2INT(rb_iv_get(obj, "second")));
|
1728
|
+
return rb_str_new2(buf);
|
1729
|
+
}
|
1730
|
+
|
1731
|
+
#define DefineMysqlTimeGetMethod(m)\
|
1732
|
+
static VALUE time_get_##m(VALUE obj)\
|
1733
|
+
{return rb_iv_get(obj, #m);}
|
1734
|
+
|
1735
|
+
DefineMysqlTimeGetMethod(year)
|
1736
|
+
DefineMysqlTimeGetMethod(month)
|
1737
|
+
DefineMysqlTimeGetMethod(day)
|
1738
|
+
DefineMysqlTimeGetMethod(hour)
|
1739
|
+
DefineMysqlTimeGetMethod(minute)
|
1740
|
+
DefineMysqlTimeGetMethod(second)
|
1741
|
+
DefineMysqlTimeGetMethod(neg)
|
1742
|
+
DefineMysqlTimeGetMethod(second_part)
|
1743
|
+
|
1744
|
+
#define DefineMysqlTimeSetMethod(m)\
|
1745
|
+
static VALUE time_set_##m(VALUE obj, VALUE v)\
|
1746
|
+
{rb_iv_set(obj, #m, NILorFIXvalue(v)); return v;}
|
1747
|
+
|
1748
|
+
DefineMysqlTimeSetMethod(year)
|
1749
|
+
DefineMysqlTimeSetMethod(month)
|
1750
|
+
DefineMysqlTimeSetMethod(day)
|
1751
|
+
DefineMysqlTimeSetMethod(hour)
|
1752
|
+
DefineMysqlTimeSetMethod(minute)
|
1753
|
+
DefineMysqlTimeSetMethod(second)
|
1754
|
+
DefineMysqlTimeSetMethod(second_part)
|
1755
|
+
|
1756
|
+
static VALUE time_set_neg(VALUE obj, VALUE v)
|
1757
|
+
{
|
1758
|
+
rb_iv_set(obj, "neg", (v == Qnil || v == Qfalse) ? Qfalse : Qtrue);
|
1759
|
+
return v;
|
1760
|
+
}
|
1761
|
+
|
1762
|
+
static VALUE time_equal(VALUE obj, VALUE v)
|
1763
|
+
{
|
1764
|
+
if (CLASS_OF(v) == cMysqlTime &&
|
1765
|
+
NUM2INT(rb_iv_get(obj, "year")) == NUM2INT(rb_iv_get(v, "year")) &&
|
1766
|
+
NUM2INT(rb_iv_get(obj, "month")) == NUM2INT(rb_iv_get(v, "month")) &&
|
1767
|
+
NUM2INT(rb_iv_get(obj, "day")) == NUM2INT(rb_iv_get(v, "day")) &&
|
1768
|
+
NUM2INT(rb_iv_get(obj, "hour")) == NUM2INT(rb_iv_get(v, "hour")) &&
|
1769
|
+
NUM2INT(rb_iv_get(obj, "minute")) == NUM2INT(rb_iv_get(v, "minute")) &&
|
1770
|
+
NUM2INT(rb_iv_get(obj, "second")) == NUM2INT(rb_iv_get(v, "second")) &&
|
1771
|
+
rb_iv_get(obj, "neg") == rb_iv_get(v, "neg") &&
|
1772
|
+
NUM2INT(rb_iv_get(obj, "second_part")) == NUM2INT(rb_iv_get(v, "second_part")))
|
1773
|
+
return Qtrue;
|
1774
|
+
return Qfalse;
|
1775
|
+
}
|
1776
|
+
|
1777
|
+
#endif
|
1778
|
+
|
1779
|
+
/*-------------------------------
|
1780
|
+
* Mysql::Error object method
|
1781
|
+
*/
|
1782
|
+
|
1783
|
+
static VALUE error_error(VALUE obj)
|
1784
|
+
{
|
1785
|
+
return rb_iv_get(obj, "mesg");
|
1786
|
+
}
|
1787
|
+
|
1788
|
+
static VALUE error_errno(VALUE obj)
|
1789
|
+
{
|
1790
|
+
return rb_iv_get(obj, "errno");
|
1791
|
+
}
|
1792
|
+
|
1793
|
+
static VALUE error_sqlstate(VALUE obj)
|
1794
|
+
{
|
1795
|
+
return rb_iv_get(obj, "sqlstate");
|
1796
|
+
}
|
1797
|
+
|
1798
|
+
/*-------------------------------
|
1799
|
+
* Initialize
|
1800
|
+
*/
|
1801
|
+
|
1802
|
+
void Init_mysql(void)
|
1803
|
+
{
|
1804
|
+
cMysql = rb_define_class("Mysql", rb_cObject);
|
1805
|
+
cMysqlRes = rb_define_class_under(cMysql, "Result", rb_cObject);
|
1806
|
+
cMysqlField = rb_define_class_under(cMysql, "Field", rb_cObject);
|
1807
|
+
#if MYSQL_VERSION_ID >= 40102
|
1808
|
+
cMysqlStmt = rb_define_class_under(cMysql, "Stmt", rb_cObject);
|
1809
|
+
cMysqlRowOffset = rb_define_class_under(cMysql, "RowOffset", rb_cObject);
|
1810
|
+
cMysqlTime = rb_define_class_under(cMysql, "Time", rb_cObject);
|
1811
|
+
#endif
|
1812
|
+
eMysql = rb_define_class_under(cMysql, "Error", rb_eStandardError);
|
1813
|
+
|
1814
|
+
rb_define_global_const("MysqlRes", cMysqlRes);
|
1815
|
+
rb_define_global_const("MysqlField", cMysqlField);
|
1816
|
+
rb_define_global_const("MysqlError", eMysql);
|
1817
|
+
|
1818
|
+
/* Mysql class method */
|
1819
|
+
rb_define_singleton_method(cMysql, "init", init, 0);
|
1820
|
+
rb_define_singleton_method(cMysql, "real_connect", real_connect, -1);
|
1821
|
+
rb_define_singleton_method(cMysql, "connect", real_connect, -1);
|
1822
|
+
rb_define_singleton_method(cMysql, "new", real_connect, -1);
|
1823
|
+
rb_define_singleton_method(cMysql, "escape_string", escape_string, 1);
|
1824
|
+
rb_define_singleton_method(cMysql, "quote", escape_string, 1);
|
1825
|
+
rb_define_singleton_method(cMysql, "client_info", client_info, 0);
|
1826
|
+
rb_define_singleton_method(cMysql, "get_client_info", client_info, 0);
|
1827
|
+
#if MYSQL_VERSION_ID >= 32332
|
1828
|
+
rb_define_singleton_method(cMysql, "debug", my_debug, 1);
|
1829
|
+
#endif
|
1830
|
+
#if MYSQL_VERSION_ID >= 40000
|
1831
|
+
rb_define_singleton_method(cMysql, "get_client_version", client_version, 0);
|
1832
|
+
rb_define_singleton_method(cMysql, "client_version", client_version, 0);
|
1833
|
+
#endif
|
1834
|
+
|
1835
|
+
/* Mysql object method */
|
1836
|
+
#if MYSQL_VERSION_ID >= 32200
|
1837
|
+
rb_define_method(cMysql, "real_connect", real_connect2, -1);
|
1838
|
+
rb_define_method(cMysql, "connect", real_connect2, -1);
|
1839
|
+
rb_define_method(cMysql, "options", options, -1);
|
1840
|
+
#endif
|
1841
|
+
rb_define_method(cMysql, "initialize", initialize, -1);
|
1842
|
+
#if MYSQL_VERSION_ID >= 32332
|
1843
|
+
rb_define_method(cMysql, "escape_string", real_escape_string, 1);
|
1844
|
+
rb_define_method(cMysql, "quote", real_escape_string, 1);
|
1845
|
+
#else
|
1846
|
+
rb_define_method(cMysql, "escape_string", escape_string, 1);
|
1847
|
+
rb_define_method(cMysql, "quote", escape_string, 1);
|
1848
|
+
#endif
|
1849
|
+
rb_define_method(cMysql, "client_info", client_info, 0);
|
1850
|
+
rb_define_method(cMysql, "get_client_info", client_info, 0);
|
1851
|
+
rb_define_method(cMysql, "affected_rows", affected_rows, 0);
|
1852
|
+
#if MYSQL_VERSION_ID >= 32303
|
1853
|
+
rb_define_method(cMysql, "change_user", change_user, -1);
|
1854
|
+
#endif
|
1855
|
+
#if MYSQL_VERSION_ID >= 32321
|
1856
|
+
rb_define_method(cMysql, "character_set_name", character_set_name, 0);
|
1857
|
+
#endif
|
1858
|
+
rb_define_method(cMysql, "close", my_close, 0);
|
1859
|
+
#if MYSQL_VERSION_ID < 40000
|
1860
|
+
rb_define_method(cMysql, "create_db", create_db, 1);
|
1861
|
+
rb_define_method(cMysql, "drop_db", drop_db, 1);
|
1862
|
+
#endif
|
1863
|
+
#if MYSQL_VERSION_ID >= 32332
|
1864
|
+
rb_define_method(cMysql, "dump_debug_info", dump_debug_info, 0);
|
1865
|
+
#endif
|
1866
|
+
rb_define_method(cMysql, "errno", my_errno, 0);
|
1867
|
+
rb_define_method(cMysql, "error", my_error, 0);
|
1868
|
+
rb_define_method(cMysql, "field_count", field_count, 0);
|
1869
|
+
#if MYSQL_VERSION_ID >= 40000
|
1870
|
+
rb_define_method(cMysql, "get_client_version", client_version, 0);
|
1871
|
+
rb_define_method(cMysql, "client_version", client_version, 0);
|
1872
|
+
#endif
|
1873
|
+
rb_define_method(cMysql, "get_host_info", host_info, 0);
|
1874
|
+
rb_define_method(cMysql, "host_info", host_info, 0);
|
1875
|
+
rb_define_method(cMysql, "get_proto_info", proto_info, 0);
|
1876
|
+
rb_define_method(cMysql, "proto_info", proto_info, 0);
|
1877
|
+
rb_define_method(cMysql, "get_server_info", server_info, 0);
|
1878
|
+
rb_define_method(cMysql, "server_info", server_info, 0);
|
1879
|
+
rb_define_method(cMysql, "info", info, 0);
|
1880
|
+
rb_define_method(cMysql, "insert_id", insert_id, 0);
|
1881
|
+
rb_define_method(cMysql, "kill", my_kill, 1);
|
1882
|
+
rb_define_method(cMysql, "list_dbs", list_dbs, -1);
|
1883
|
+
rb_define_method(cMysql, "list_fields", list_fields, -1);
|
1884
|
+
rb_define_method(cMysql, "list_processes", list_processes, 0);
|
1885
|
+
rb_define_method(cMysql, "list_tables", list_tables, -1);
|
1886
|
+
#if MYSQL_VERSION_ID >= 32200
|
1887
|
+
rb_define_method(cMysql, "ping", ping, 0);
|
1888
|
+
#endif
|
1889
|
+
rb_define_method(cMysql, "query", query, 1);
|
1890
|
+
rb_define_method(cMysql, "real_query", query, 1);
|
1891
|
+
rb_define_method(cMysql, "refresh", refresh, 1);
|
1892
|
+
rb_define_method(cMysql, "reload", reload, 0);
|
1893
|
+
rb_define_method(cMysql, "select_db", select_db, 1);
|
1894
|
+
rb_define_method(cMysql, "shutdown", my_shutdown, -1);
|
1895
|
+
rb_define_method(cMysql, "stat", my_stat, 0);
|
1896
|
+
rb_define_method(cMysql, "store_result", store_result, 0);
|
1897
|
+
rb_define_method(cMysql, "thread_id", thread_id, 0);
|
1898
|
+
rb_define_method(cMysql, "use_result", use_result, 0);
|
1899
|
+
#if MYSQL_VERSION_ID >= 40100
|
1900
|
+
rb_define_method(cMysql, "get_server_version", server_version, 0);
|
1901
|
+
rb_define_method(cMysql, "server_version", server_version, 0);
|
1902
|
+
rb_define_method(cMysql, "warning_count", warning_count, 0);
|
1903
|
+
rb_define_method(cMysql, "commit", commit, 0);
|
1904
|
+
rb_define_method(cMysql, "rollback", rollback, 0);
|
1905
|
+
rb_define_method(cMysql, "autocommit", autocommit, 1);
|
1906
|
+
#endif
|
1907
|
+
#ifdef HAVE_MYSQL_SSL_SET
|
1908
|
+
rb_define_method(cMysql, "ssl_set", ssl_set, -1);
|
1909
|
+
#endif
|
1910
|
+
#if MYSQL_VERSION_ID >= 40102
|
1911
|
+
rb_define_method(cMysql, "stmt_init", stmt_init, 0);
|
1912
|
+
rb_define_method(cMysql, "prepare", prepare, 1);
|
1913
|
+
#endif
|
1914
|
+
#if MYSQL_VERSION_ID >= 40100
|
1915
|
+
rb_define_method(cMysql, "more_results", more_results, 0);
|
1916
|
+
rb_define_method(cMysql, "more_results?", more_results, 0);
|
1917
|
+
rb_define_method(cMysql, "next_result", next_result, 0);
|
1918
|
+
#endif
|
1919
|
+
#if MYSQL_VERSION_ID >= 40101
|
1920
|
+
rb_define_method(cMysql, "set_server_option", set_server_option, 1);
|
1921
|
+
rb_define_method(cMysql, "sqlstate", sqlstate, 0);
|
1922
|
+
#endif
|
1923
|
+
rb_define_method(cMysql, "query_with_result", query_with_result, 0);
|
1924
|
+
rb_define_method(cMysql, "query_with_result=", query_with_result_set, 1);
|
1925
|
+
|
1926
|
+
rb_define_method(cMysql, "reconnect", reconnect, 0);
|
1927
|
+
rb_define_method(cMysql, "reconnect=", reconnect_set, 1);
|
1928
|
+
|
1929
|
+
/* Mysql constant */
|
1930
|
+
rb_define_const(cMysql, "VERSION", INT2FIX(MYSQL_RUBY_VERSION));
|
1931
|
+
#if MYSQL_VERSION_ID >= 32200
|
1932
|
+
rb_define_const(cMysql, "OPT_CONNECT_TIMEOUT", INT2NUM(MYSQL_OPT_CONNECT_TIMEOUT));
|
1933
|
+
rb_define_const(cMysql, "OPT_COMPRESS", INT2NUM(MYSQL_OPT_COMPRESS));
|
1934
|
+
rb_define_const(cMysql, "OPT_NAMED_PIPE", INT2NUM(MYSQL_OPT_NAMED_PIPE));
|
1935
|
+
rb_define_const(cMysql, "INIT_COMMAND", INT2NUM(MYSQL_INIT_COMMAND));
|
1936
|
+
rb_define_const(cMysql, "READ_DEFAULT_FILE", INT2NUM(MYSQL_READ_DEFAULT_FILE));
|
1937
|
+
rb_define_const(cMysql, "READ_DEFAULT_GROUP", INT2NUM(MYSQL_READ_DEFAULT_GROUP));
|
1938
|
+
#endif
|
1939
|
+
#if MYSQL_VERSION_ID >= 32349
|
1940
|
+
rb_define_const(cMysql, "SET_CHARSET_DIR", INT2NUM(MYSQL_SET_CHARSET_DIR));
|
1941
|
+
rb_define_const(cMysql, "SET_CHARSET_NAME", INT2NUM(MYSQL_SET_CHARSET_NAME));
|
1942
|
+
rb_define_const(cMysql, "OPT_LOCAL_INFILE", INT2NUM(MYSQL_OPT_LOCAL_INFILE));
|
1943
|
+
#endif
|
1944
|
+
#if MYSQL_VERSION_ID >= 40100
|
1945
|
+
rb_define_const(cMysql, "OPT_PROTOCOL", INT2NUM(MYSQL_OPT_PROTOCOL));
|
1946
|
+
rb_define_const(cMysql, "SHARED_MEMORY_BASE_NAME", INT2NUM(MYSQL_SHARED_MEMORY_BASE_NAME));
|
1947
|
+
#endif
|
1948
|
+
#if MYSQL_VERSION_ID >= 40101
|
1949
|
+
rb_define_const(cMysql, "OPT_READ_TIMEOUT", INT2NUM(MYSQL_OPT_READ_TIMEOUT));
|
1950
|
+
rb_define_const(cMysql, "OPT_WRITE_TIMEOUT", INT2NUM(MYSQL_OPT_WRITE_TIMEOUT));
|
1951
|
+
rb_define_const(cMysql, "SECURE_AUTH", INT2NUM(MYSQL_SECURE_AUTH));
|
1952
|
+
rb_define_const(cMysql, "OPT_GUESS_CONNECTION", INT2NUM(MYSQL_OPT_GUESS_CONNECTION));
|
1953
|
+
rb_define_const(cMysql, "OPT_USE_EMBEDDED_CONNECTION", INT2NUM(MYSQL_OPT_USE_EMBEDDED_CONNECTION));
|
1954
|
+
rb_define_const(cMysql, "OPT_USE_REMOTE_CONNECTION", INT2NUM(MYSQL_OPT_USE_REMOTE_CONNECTION));
|
1955
|
+
rb_define_const(cMysql, "SET_CLIENT_IP", INT2NUM(MYSQL_SET_CLIENT_IP));
|
1956
|
+
#endif
|
1957
|
+
rb_define_const(cMysql, "REFRESH_GRANT", INT2NUM(REFRESH_GRANT));
|
1958
|
+
rb_define_const(cMysql, "REFRESH_LOG", INT2NUM(REFRESH_LOG));
|
1959
|
+
rb_define_const(cMysql, "REFRESH_TABLES", INT2NUM(REFRESH_TABLES));
|
1960
|
+
#ifdef REFRESH_HOSTS
|
1961
|
+
rb_define_const(cMysql, "REFRESH_HOSTS", INT2NUM(REFRESH_HOSTS));
|
1962
|
+
#endif
|
1963
|
+
#ifdef REFRESH_STATUS
|
1964
|
+
rb_define_const(cMysql, "REFRESH_STATUS", INT2NUM(REFRESH_STATUS));
|
1965
|
+
#endif
|
1966
|
+
#ifdef REFRESH_THREADS
|
1967
|
+
rb_define_const(cMysql, "REFRESH_THREADS", INT2NUM(REFRESH_THREADS));
|
1968
|
+
#endif
|
1969
|
+
#ifdef REFRESH_SLAVE
|
1970
|
+
rb_define_const(cMysql, "REFRESH_SLAVE", INT2NUM(REFRESH_SLAVE));
|
1971
|
+
#endif
|
1972
|
+
#ifdef REFRESH_MASTER
|
1973
|
+
rb_define_const(cMysql, "REFRESH_MASTER", INT2NUM(REFRESH_MASTER));
|
1974
|
+
#endif
|
1975
|
+
#ifdef CLIENT_LONG_PASSWORD
|
1976
|
+
#endif
|
1977
|
+
#ifdef CLIENT_FOUND_ROWS
|
1978
|
+
rb_define_const(cMysql, "CLIENT_FOUND_ROWS", INT2NUM(CLIENT_FOUND_ROWS));
|
1979
|
+
#endif
|
1980
|
+
#ifdef CLIENT_LONG_FLAG
|
1981
|
+
#endif
|
1982
|
+
#ifdef CLIENT_CONNECT_WITH_DB
|
1983
|
+
#endif
|
1984
|
+
#ifdef CLIENT_NO_SCHEMA
|
1985
|
+
rb_define_const(cMysql, "CLIENT_NO_SCHEMA", INT2NUM(CLIENT_NO_SCHEMA));
|
1986
|
+
#endif
|
1987
|
+
#ifdef CLIENT_COMPRESS
|
1988
|
+
rb_define_const(cMysql, "CLIENT_COMPRESS", INT2NUM(CLIENT_COMPRESS));
|
1989
|
+
#endif
|
1990
|
+
#ifdef CLIENT_ODBC
|
1991
|
+
rb_define_const(cMysql, "CLIENT_ODBC", INT2NUM(CLIENT_ODBC));
|
1992
|
+
#endif
|
1993
|
+
#ifdef CLIENT_LOCAL_FILES
|
1994
|
+
rb_define_const(cMysql, "CLIENT_LOCAL_FILES", INT2NUM(CLIENT_LOCAL_FILES));
|
1995
|
+
#endif
|
1996
|
+
#ifdef CLIENT_IGNORE_SPACE
|
1997
|
+
rb_define_const(cMysql, "CLIENT_IGNORE_SPACE", INT2NUM(CLIENT_IGNORE_SPACE));
|
1998
|
+
#endif
|
1999
|
+
#ifdef CLIENT_CHANGE_USER
|
2000
|
+
rb_define_const(cMysql, "CLIENT_CHANGE_USER", INT2NUM(CLIENT_CHANGE_USER));
|
2001
|
+
#endif
|
2002
|
+
#ifdef CLIENT_INTERACTIVE
|
2003
|
+
rb_define_const(cMysql, "CLIENT_INTERACTIVE", INT2NUM(CLIENT_INTERACTIVE));
|
2004
|
+
#endif
|
2005
|
+
#ifdef CLIENT_SSL
|
2006
|
+
rb_define_const(cMysql, "CLIENT_SSL", INT2NUM(CLIENT_SSL));
|
2007
|
+
#endif
|
2008
|
+
#ifdef CLIENT_IGNORE_SIGPIPE
|
2009
|
+
rb_define_const(cMysql, "CLIENT_IGNORE_SIGPIPE", INT2NUM(CLIENT_IGNORE_SIGPIPE));
|
2010
|
+
#endif
|
2011
|
+
#ifdef CLIENT_TRANSACTIONS
|
2012
|
+
rb_define_const(cMysql, "CLIENT_TRANSACTIONS", INT2NUM(CLIENT_TRANSACTIONS));
|
2013
|
+
#endif
|
2014
|
+
#ifdef CLIENT_MULTI_STATEMENTS
|
2015
|
+
rb_define_const(cMysql, "CLIENT_MULTI_STATEMENTS", INT2NUM(CLIENT_MULTI_STATEMENTS));
|
2016
|
+
#endif
|
2017
|
+
#ifdef CLIENT_MULTI_RESULTS
|
2018
|
+
rb_define_const(cMysql, "CLIENT_MULTI_RESULTS", INT2NUM(CLIENT_MULTI_RESULTS));
|
2019
|
+
#endif
|
2020
|
+
#if MYSQL_VERSION_ID >= 40101
|
2021
|
+
rb_define_const(cMysql, "OPTION_MULTI_STATEMENTS_ON", INT2NUM(MYSQL_OPTION_MULTI_STATEMENTS_ON));
|
2022
|
+
rb_define_const(cMysql, "OPTION_MULTI_STATEMENTS_OFF", INT2NUM(MYSQL_OPTION_MULTI_STATEMENTS_OFF));
|
2023
|
+
#endif
|
2024
|
+
|
2025
|
+
/* Mysql::Result object method */
|
2026
|
+
rb_define_method(cMysqlRes, "data_seek", data_seek, 1);
|
2027
|
+
rb_define_method(cMysqlRes, "fetch_field", fetch_field, 0);
|
2028
|
+
rb_define_method(cMysqlRes, "fetch_fields", fetch_fields, 0);
|
2029
|
+
rb_define_method(cMysqlRes, "fetch_field_direct", fetch_field_direct, 1);
|
2030
|
+
rb_define_method(cMysqlRes, "fetch_lengths", fetch_lengths, 0);
|
2031
|
+
rb_define_method(cMysqlRes, "fetch_row", fetch_row, 0);
|
2032
|
+
rb_define_method(cMysqlRes, "fetch_hash", fetch_hash, -1);
|
2033
|
+
rb_define_method(cMysqlRes, "field_seek", field_seek, 1);
|
2034
|
+
rb_define_method(cMysqlRes, "field_tell", field_tell, 0);
|
2035
|
+
rb_define_method(cMysqlRes, "free", res_free, 0);
|
2036
|
+
rb_define_method(cMysqlRes, "num_fields", num_fields, 0);
|
2037
|
+
rb_define_method(cMysqlRes, "num_rows", num_rows, 0);
|
2038
|
+
rb_define_method(cMysqlRes, "row_seek", row_seek, 1);
|
2039
|
+
rb_define_method(cMysqlRes, "row_tell", row_tell, 0);
|
2040
|
+
rb_define_method(cMysqlRes, "each", each, 0);
|
2041
|
+
rb_define_method(cMysqlRes, "each_hash", each_hash, -1);
|
2042
|
+
|
2043
|
+
/* MysqlField object method */
|
2044
|
+
rb_define_method(cMysqlField, "name", field_name, 0);
|
2045
|
+
rb_define_method(cMysqlField, "table", field_table, 0);
|
2046
|
+
rb_define_method(cMysqlField, "def", field_def, 0);
|
2047
|
+
rb_define_method(cMysqlField, "type", field_type, 0);
|
2048
|
+
rb_define_method(cMysqlField, "length", field_length, 0);
|
2049
|
+
rb_define_method(cMysqlField, "max_length", field_max_length, 0);
|
2050
|
+
rb_define_method(cMysqlField, "flags", field_flags, 0);
|
2051
|
+
rb_define_method(cMysqlField, "decimals", field_decimals, 0);
|
2052
|
+
rb_define_method(cMysqlField, "hash", field_hash, 0);
|
2053
|
+
rb_define_method(cMysqlField, "inspect", field_inspect, 0);
|
2054
|
+
#ifdef IS_NUM
|
2055
|
+
rb_define_method(cMysqlField, "is_num?", field_is_num, 0);
|
2056
|
+
#endif
|
2057
|
+
#ifdef IS_NOT_NULL
|
2058
|
+
rb_define_method(cMysqlField, "is_not_null?", field_is_not_null, 0);
|
2059
|
+
#endif
|
2060
|
+
#ifdef IS_PRI_KEY
|
2061
|
+
rb_define_method(cMysqlField, "is_pri_key?", field_is_pri_key, 0);
|
2062
|
+
#endif
|
2063
|
+
|
2064
|
+
/* Mysql::Field constant: TYPE */
|
2065
|
+
rb_define_const(cMysqlField, "TYPE_TINY", INT2NUM(FIELD_TYPE_TINY));
|
2066
|
+
#if MYSQL_VERSION_ID >= 32115
|
2067
|
+
rb_define_const(cMysqlField, "TYPE_ENUM", INT2NUM(FIELD_TYPE_ENUM));
|
2068
|
+
#endif
|
2069
|
+
rb_define_const(cMysqlField, "TYPE_DECIMAL", INT2NUM(FIELD_TYPE_DECIMAL));
|
2070
|
+
rb_define_const(cMysqlField, "TYPE_SHORT", INT2NUM(FIELD_TYPE_SHORT));
|
2071
|
+
rb_define_const(cMysqlField, "TYPE_LONG", INT2NUM(FIELD_TYPE_LONG));
|
2072
|
+
rb_define_const(cMysqlField, "TYPE_FLOAT", INT2NUM(FIELD_TYPE_FLOAT));
|
2073
|
+
rb_define_const(cMysqlField, "TYPE_DOUBLE", INT2NUM(FIELD_TYPE_DOUBLE));
|
2074
|
+
rb_define_const(cMysqlField, "TYPE_NULL", INT2NUM(FIELD_TYPE_NULL));
|
2075
|
+
rb_define_const(cMysqlField, "TYPE_TIMESTAMP", INT2NUM(FIELD_TYPE_TIMESTAMP));
|
2076
|
+
rb_define_const(cMysqlField, "TYPE_LONGLONG", INT2NUM(FIELD_TYPE_LONGLONG));
|
2077
|
+
rb_define_const(cMysqlField, "TYPE_INT24", INT2NUM(FIELD_TYPE_INT24));
|
2078
|
+
rb_define_const(cMysqlField, "TYPE_DATE", INT2NUM(FIELD_TYPE_DATE));
|
2079
|
+
rb_define_const(cMysqlField, "TYPE_TIME", INT2NUM(FIELD_TYPE_TIME));
|
2080
|
+
rb_define_const(cMysqlField, "TYPE_DATETIME", INT2NUM(FIELD_TYPE_DATETIME));
|
2081
|
+
#if MYSQL_VERSION_ID >= 32130
|
2082
|
+
rb_define_const(cMysqlField, "TYPE_YEAR", INT2NUM(FIELD_TYPE_YEAR));
|
2083
|
+
#endif
|
2084
|
+
rb_define_const(cMysqlField, "TYPE_SET", INT2NUM(FIELD_TYPE_SET));
|
2085
|
+
rb_define_const(cMysqlField, "TYPE_BLOB", INT2NUM(FIELD_TYPE_BLOB));
|
2086
|
+
rb_define_const(cMysqlField, "TYPE_STRING", INT2NUM(FIELD_TYPE_STRING));
|
2087
|
+
#if MYSQL_VERSION_ID >= 40000
|
2088
|
+
rb_define_const(cMysqlField, "TYPE_VAR_STRING", INT2NUM(FIELD_TYPE_VAR_STRING));
|
2089
|
+
#endif
|
2090
|
+
rb_define_const(cMysqlField, "TYPE_CHAR", INT2NUM(FIELD_TYPE_CHAR));
|
2091
|
+
|
2092
|
+
/* Mysql::Field constant: FLAG */
|
2093
|
+
rb_define_const(cMysqlField, "NOT_NULL_FLAG", INT2NUM(NOT_NULL_FLAG));
|
2094
|
+
rb_define_const(cMysqlField, "PRI_KEY_FLAG", INT2NUM(PRI_KEY_FLAG));
|
2095
|
+
rb_define_const(cMysqlField, "UNIQUE_KEY_FLAG", INT2NUM(UNIQUE_KEY_FLAG));
|
2096
|
+
rb_define_const(cMysqlField, "MULTIPLE_KEY_FLAG", INT2NUM(MULTIPLE_KEY_FLAG));
|
2097
|
+
rb_define_const(cMysqlField, "BLOB_FLAG", INT2NUM(BLOB_FLAG));
|
2098
|
+
rb_define_const(cMysqlField, "UNSIGNED_FLAG", INT2NUM(UNSIGNED_FLAG));
|
2099
|
+
rb_define_const(cMysqlField, "ZEROFILL_FLAG", INT2NUM(ZEROFILL_FLAG));
|
2100
|
+
rb_define_const(cMysqlField, "BINARY_FLAG", INT2NUM(BINARY_FLAG));
|
2101
|
+
#ifdef ENUM_FLAG
|
2102
|
+
rb_define_const(cMysqlField, "ENUM_FLAG", INT2NUM(ENUM_FLAG));
|
2103
|
+
#endif
|
2104
|
+
#ifdef AUTO_INCREMENT_FLAG
|
2105
|
+
rb_define_const(cMysqlField, "AUTO_INCREMENT_FLAG", INT2NUM(AUTO_INCREMENT_FLAG));
|
2106
|
+
#endif
|
2107
|
+
#ifdef TIMESTAMP_FLAG
|
2108
|
+
rb_define_const(cMysqlField, "TIMESTAMP_FLAG", INT2NUM(TIMESTAMP_FLAG));
|
2109
|
+
#endif
|
2110
|
+
#ifdef SET_FLAG
|
2111
|
+
rb_define_const(cMysqlField, "SET_FLAG", INT2NUM(SET_FLAG));
|
2112
|
+
#endif
|
2113
|
+
#ifdef NUM_FLAG
|
2114
|
+
rb_define_const(cMysqlField, "NUM_FLAG", INT2NUM(NUM_FLAG));
|
2115
|
+
#endif
|
2116
|
+
#ifdef PART_KEY_FLAG
|
2117
|
+
rb_define_const(cMysqlField, "PART_KEY_FLAG", INT2NUM(PART_KEY_FLAG));
|
2118
|
+
#endif
|
2119
|
+
|
2120
|
+
#if MYSQL_VERSION_ID >= 40102
|
2121
|
+
/* Mysql::Stmt object method */
|
2122
|
+
rb_define_method(cMysqlStmt, "affected_rows", stmt_affected_rows, 0);
|
2123
|
+
#if 0
|
2124
|
+
rb_define_method(cMysqlStmt, "attr_get", stmt_attr_get, 1);
|
2125
|
+
rb_define_method(cMysqlStmt, "attr_set", stmt_attr_set, 2);
|
2126
|
+
#endif
|
2127
|
+
rb_define_method(cMysqlStmt, "bind_result", stmt_bind_result, -1);
|
2128
|
+
rb_define_method(cMysqlStmt, "close", stmt_close, 0);
|
2129
|
+
rb_define_method(cMysqlStmt, "data_seek", stmt_data_seek, 1);
|
2130
|
+
rb_define_method(cMysqlStmt, "each", stmt_each, 0);
|
2131
|
+
rb_define_method(cMysqlStmt, "execute", stmt_execute, -1);
|
2132
|
+
rb_define_method(cMysqlStmt, "fetch", stmt_fetch, 0);
|
2133
|
+
rb_define_method(cMysqlStmt, "field_count", stmt_field_count, 0);
|
2134
|
+
rb_define_method(cMysqlStmt, "free_result", stmt_free_result, 0);
|
2135
|
+
rb_define_method(cMysqlStmt, "insert_id", stmt_insert_id, 0);
|
2136
|
+
rb_define_method(cMysqlStmt, "num_rows", stmt_num_rows, 0);
|
2137
|
+
rb_define_method(cMysqlStmt, "param_count", stmt_param_count, 0);
|
2138
|
+
rb_define_method(cMysqlStmt, "prepare", stmt_prepare, 1);
|
2139
|
+
#if 0
|
2140
|
+
rb_define_method(cMysqlStmt, "reset", stmt_reset, 0);
|
2141
|
+
#endif
|
2142
|
+
rb_define_method(cMysqlStmt, "result_metadata", stmt_result_metadata, 0);
|
2143
|
+
rb_define_method(cMysqlStmt, "row_seek", stmt_row_seek, 1);
|
2144
|
+
rb_define_method(cMysqlStmt, "row_tell", stmt_row_tell, 0);
|
2145
|
+
#if 0
|
2146
|
+
rb_define_method(cMysqlStmt, "send_long_data", stmt_send_long_data, 2);
|
2147
|
+
#endif
|
2148
|
+
rb_define_method(cMysqlStmt, "sqlstate", stmt_sqlstate, 0);
|
2149
|
+
|
2150
|
+
#if 0
|
2151
|
+
rb_define_const(cMysqlStmt, "ATTR_UPDATE_MAX_LENGTH", INT2NUM(STMT_ATTR_UPDATE_MAX_LENGTH));
|
2152
|
+
#endif
|
2153
|
+
|
2154
|
+
/* Mysql::Time object method */
|
2155
|
+
rb_define_method(cMysqlTime, "initialize", time_initialize, -1);
|
2156
|
+
rb_define_method(cMysqlTime, "inspect", time_inspect, 0);
|
2157
|
+
rb_define_method(cMysqlTime, "to_s", time_to_s, 0);
|
2158
|
+
rb_define_method(cMysqlTime, "year", time_get_year, 0);
|
2159
|
+
rb_define_method(cMysqlTime, "month", time_get_month, 0);
|
2160
|
+
rb_define_method(cMysqlTime, "day", time_get_day, 0);
|
2161
|
+
rb_define_method(cMysqlTime, "hour", time_get_hour, 0);
|
2162
|
+
rb_define_method(cMysqlTime, "minute", time_get_minute, 0);
|
2163
|
+
rb_define_method(cMysqlTime, "second", time_get_second, 0);
|
2164
|
+
rb_define_method(cMysqlTime, "neg", time_get_neg, 0);
|
2165
|
+
rb_define_method(cMysqlTime, "second_part", time_get_second_part, 0);
|
2166
|
+
rb_define_method(cMysqlTime, "year=", time_set_year, 1);
|
2167
|
+
rb_define_method(cMysqlTime, "month=", time_set_month, 1);
|
2168
|
+
rb_define_method(cMysqlTime, "day=", time_set_day, 1);
|
2169
|
+
rb_define_method(cMysqlTime, "hour=", time_set_hour, 1);
|
2170
|
+
rb_define_method(cMysqlTime, "minute=", time_set_minute, 1);
|
2171
|
+
rb_define_method(cMysqlTime, "second=", time_set_second, 1);
|
2172
|
+
rb_define_method(cMysqlTime, "neg=", time_set_neg, 1);
|
2173
|
+
rb_define_method(cMysqlTime, "second_part=", time_set_second_part, 1);
|
2174
|
+
rb_define_method(cMysqlTime, "==", time_equal, 1);
|
2175
|
+
|
2176
|
+
#endif
|
2177
|
+
|
2178
|
+
/* Mysql::Error object method */
|
2179
|
+
rb_define_method(eMysql, "error", error_error, 0);
|
2180
|
+
rb_define_method(eMysql, "errno", error_errno, 0);
|
2181
|
+
rb_define_method(eMysql, "sqlstate", error_sqlstate, 0);
|
2182
|
+
|
2183
|
+
/* Mysql::Error constant */
|
2184
|
+
}
|