Class: Mysql
- Inherits:
-
Object
- Object
- Mysql
- Defined in:
- lib/mysqlplus.rb,
ext/mysql.c
Overview
The mysqlplus library is a [slightly updated] fork of the Mysql class, with asynchronous capability added See www.kitebird.com/articles/ruby-mysql.html for details, as well as the test directory within the gem
Defined Under Namespace
Classes: Error, Field, Result, RowOffset, Stmt, Time
Constant Summary collapse
- VERSION =
Mysql constant
INT2FIX(MYSQL_RUBY_VERSION)
- OPT_CONNECT_TIMEOUT =
INT2NUM(MYSQL_OPT_CONNECT_TIMEOUT)
- OPT_COMPRESS =
INT2NUM(MYSQL_OPT_COMPRESS)
- OPT_NAMED_PIPE =
INT2NUM(MYSQL_OPT_NAMED_PIPE)
- INIT_COMMAND =
INT2NUM(MYSQL_INIT_COMMAND)
- READ_DEFAULT_FILE =
INT2NUM(MYSQL_READ_DEFAULT_FILE)
- READ_DEFAULT_GROUP =
INT2NUM(MYSQL_READ_DEFAULT_GROUP)
- SET_CHARSET_DIR =
INT2NUM(MYSQL_SET_CHARSET_DIR)
- SET_CHARSET_NAME =
INT2NUM(MYSQL_SET_CHARSET_NAME)
- OPT_LOCAL_INFILE =
INT2NUM(MYSQL_OPT_LOCAL_INFILE)
- OPT_PROTOCOL =
INT2NUM(MYSQL_OPT_PROTOCOL)
- SHARED_MEMORY_BASE_NAME =
INT2NUM(MYSQL_SHARED_MEMORY_BASE_NAME)
- OPT_READ_TIMEOUT =
INT2NUM(MYSQL_OPT_READ_TIMEOUT)
- OPT_WRITE_TIMEOUT =
INT2NUM(MYSQL_OPT_WRITE_TIMEOUT)
- SECURE_AUTH =
INT2NUM(MYSQL_SECURE_AUTH)
- OPT_GUESS_CONNECTION =
INT2NUM(MYSQL_OPT_GUESS_CONNECTION)
- OPT_USE_EMBEDDED_CONNECTION =
INT2NUM(MYSQL_OPT_USE_EMBEDDED_CONNECTION)
- OPT_USE_REMOTE_CONNECTION =
INT2NUM(MYSQL_OPT_USE_REMOTE_CONNECTION)
- SET_CLIENT_IP =
INT2NUM(MYSQL_SET_CLIENT_IP)
- REFRESH_GRANT =
INT2NUM(REFRESH_GRANT)
- REFRESH_LOG =
INT2NUM(REFRESH_LOG)
- REFRESH_TABLES =
INT2NUM(REFRESH_TABLES)
- REFRESH_HOSTS =
INT2NUM(REFRESH_HOSTS)
- REFRESH_STATUS =
INT2NUM(REFRESH_STATUS)
- REFRESH_THREADS =
INT2NUM(REFRESH_THREADS)
- REFRESH_SLAVE =
INT2NUM(REFRESH_SLAVE)
- REFRESH_MASTER =
INT2NUM(REFRESH_MASTER)
- CLIENT_FOUND_ROWS =
INT2NUM(CLIENT_FOUND_ROWS)
- CLIENT_NO_SCHEMA =
INT2NUM(CLIENT_NO_SCHEMA)
- CLIENT_COMPRESS =
INT2NUM(CLIENT_COMPRESS)
- CLIENT_ODBC =
INT2NUM(CLIENT_ODBC)
- CLIENT_LOCAL_FILES =
INT2NUM(CLIENT_LOCAL_FILES)
- CLIENT_IGNORE_SPACE =
INT2NUM(CLIENT_IGNORE_SPACE)
- CLIENT_CHANGE_USER =
INT2NUM(CLIENT_CHANGE_USER)
- CLIENT_INTERACTIVE =
INT2NUM(CLIENT_INTERACTIVE)
- CLIENT_SSL =
INT2NUM(CLIENT_SSL)
- CLIENT_IGNORE_SIGPIPE =
INT2NUM(CLIENT_IGNORE_SIGPIPE)
- CLIENT_TRANSACTIONS =
INT2NUM(CLIENT_TRANSACTIONS)
- CLIENT_MULTI_STATEMENTS =
INT2NUM(CLIENT_MULTI_STATEMENTS)
- CLIENT_MULTI_RESULTS =
INT2NUM(CLIENT_MULTI_RESULTS)
- OPTION_MULTI_STATEMENTS_ON =
INT2NUM(MYSQL_OPTION_MULTI_STATEMENTS_ON)
- OPTION_MULTI_STATEMENTS_OFF =
INT2NUM(MYSQL_OPTION_MULTI_STATEMENTS_OFF)
Class Method Summary collapse
-
.client_info ⇒ Object
client_info().
-
.client_version ⇒ Object
client_version().
-
.connect(*args) ⇒ Object
real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil).
-
.debug(str) ⇒ Object
my_debug(string).
-
.escape_string(str) ⇒ Object
escape_string(string).
-
.get_client_info ⇒ Object
client_info().
-
.get_client_version ⇒ Object
client_version().
-
.init ⇒ Object
init().
-
.new(*args) ⇒ Object
real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil).
-
.quote(str) ⇒ Object
escape_string(string).
-
.real_connect(*args) ⇒ Object
real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil).
Instance Method Summary collapse
-
#affected_rows ⇒ Object
affected_rows().
- #async_in_progress=(flag) ⇒ Object
- #async_in_progress? ⇒ Boolean
-
#autocommit(mode) ⇒ Object
autocommit().
-
#blocking? ⇒ Boolean
blocking.
-
#busy=(flag) ⇒ Object
busy(true|false).
-
#busy? ⇒ Boolean
is_busy.
-
#c_async_query(*args) ⇒ Object
async_query(sql,timeout=nil) optionally take a block.
-
#change_user(*args) ⇒ Object
change_user(user=nil, passwd=nil, db=nil).
-
#character_set_name ⇒ Object
character_set_name().
-
#client_info ⇒ Object
client_info().
-
#client_version ⇒ Object
client_version().
-
#close ⇒ Object
close().
-
#commit ⇒ Object
commit().
-
#connect(*args) ⇒ Object
real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil).
-
#create_db(db) ⇒ Object
create_db(db).
-
#disable_gc=(flag) ⇒ Object
disable_gc(true|false).
-
#drop_db(db) ⇒ Object
drop_db(db).
-
#dump_debug_info ⇒ Object
dump_debug_info().
-
#errno ⇒ Object
errno().
-
#error ⇒ Object
error().
-
#escape_string(str) ⇒ Object
escape_string(string).
-
#field_count ⇒ Object
field_count().
-
#gc_disabled? ⇒ Boolean
gc_disabled.
-
#get_client_info ⇒ Object
client_info().
-
#get_client_version ⇒ Object
client_version().
-
#get_host_info ⇒ Object
host_info().
-
#get_proto_info ⇒ Object
proto_info().
-
#get_result ⇒ Object
get_result returns the mysql_result set (default) [i.e. all rows in said said] or nil if query_with_result == false.
-
#get_server_info ⇒ Object
server_info().
-
#get_server_version ⇒ Object
server_version().
-
#host_info ⇒ Object
host_info().
- #idle? ⇒ Boolean
-
#info ⇒ Object
info().
-
#initialize(*args) ⇒ Object
constructor
initialize().
-
#insert_id ⇒ Object
insert_id().
-
#interrupted? ⇒ Boolean
interrupted.
-
#kill(pid) ⇒ Object
kill(pid).
-
#list_dbs(*args) ⇒ Object
list_dbs(db=nil).
-
#list_fields(*args) ⇒ Object
list_fields(table, field=nil).
-
#list_processes ⇒ Object
list_processes().
-
#list_tables(*args) ⇒ Object
list_tables(table=nil).
-
#more_results ⇒ Object
more_results().
-
#more_results? ⇒ Boolean
more_results().
- #next_result ⇒ Object
-
#options(*args) ⇒ Object
options(opt, value=nil).
-
#ping ⇒ Object
ping().
-
#prepare(query) ⇒ Object
prepare(query).
-
#proto_info ⇒ Object
proto_info().
-
#query(sql) ⇒ Object
query(sql).
-
#query_with_result ⇒ Object
query_with_result().
-
#query_with_result=(flag) ⇒ Object
query_with_result=(flag).
-
#quote(str) ⇒ Object
escape_string(string).
-
#readable?(*args) ⇒ Boolean
readable(timeout=nil).
-
#real_connect(*args) ⇒ Object
real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil).
-
#real_query(sql) ⇒ Object
query(sql).
-
#reconnect ⇒ Object
reconnect().
-
#reconnect=(flag) ⇒ Object
reconnect=(flag).
-
#reconnected? ⇒ Boolean
reconnected.
-
#refresh(r) ⇒ Object
refresh®.
-
#reload ⇒ Object
reload().
-
#retry? ⇒ Boolean
retry.
-
#rollback ⇒ Object
rollback().
-
#ruby_async_query(sql, timeout = nil) ⇒ Object
known to deadlock TODO.
-
#select_db(db) ⇒ Object
select_db(db).
-
#send_query(sql) ⇒ Object
send_query(sql).
-
#server_info ⇒ Object
server_info().
-
#server_version ⇒ Object
server_version().
-
#set_server_option(option) ⇒ Object
set_server_option(option).
-
#shutdown(*args) ⇒ Object
shutdown().
-
#simulate_disconnect ⇒ Object
for testing.
-
#socket ⇒ Object
socket.
-
#sqlstate ⇒ Object
sqlstate().
-
#ssl_set(*args) ⇒ Object
ssl_set(key=nil, cert=nil, ca=nil, capath=nil, cipher=nil).
-
#stat ⇒ Object
stat().
-
#stmt_init ⇒ Object
stmt_init().
-
#store_result ⇒ Object
store_result().
-
#thread_id ⇒ Object
thread_id().
-
#use_result ⇒ Object
use_result().
-
#warning_count ⇒ Object
warning_count().
Constructor Details
#initialize(*args) ⇒ Object
initialize()
568 569 570 571 |
# File 'ext/mysql.c', line 568
static VALUE initialize(int argc, VALUE* argv, VALUE obj)
{
return obj;
}
|
Class Method Details
.client_info ⇒ Object
client_info()
430 431 432 433 |
# File 'ext/mysql.c', line 430
static VALUE client_info(VALUE klass)
{
return rb_tainted_str_new2(mysql_get_client_info());
}
|
.client_version ⇒ Object
client_version()
446 447 448 449 |
# File 'ext/mysql.c', line 446
static VALUE client_version(VALUE obj)
{
return INT2NUM(mysql_get_client_version());
}
|
.connect(*args) ⇒ Object
real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'ext/mysql.c', line 367
static VALUE real_connect(int argc, VALUE* argv, VALUE klass)
{
VALUE host, user, passwd, db, port, sock, flag;
char *h, *u, *p, *d, *s;
unsigned int pp, f;
struct mysql* myp;
VALUE obj;
#if MYSQL_VERSION_ID >= 32200
rb_scan_args(argc, argv, "07", &host, &user, &passwd, &db, &port, &sock, &flag);
d = NILorSTRING(db);
f = NILorINT(flag);
#elif MYSQL_VERSION_ID >= 32115
rb_scan_args(argc, argv, "06", &host, &user, &passwd, &port, &sock, &flag);
f = NILorINT(flag);
#else
rb_scan_args(argc, argv, "05", &host, &user, &passwd, &port, &sock);
#endif
h = NILorSTRING(host);
u = NILorSTRING(user);
p = NILorSTRING(passwd);
pp = NILorINT(port);
s = NILorSTRING(sock);
obj = Data_Make_Struct(klass, struct mysql, 0, free_mysql, myp);
#if MYSQL_VERSION_ID >= 32200
mysql_init(&myp->handler); /* we get here */
# ifdef HAVE_TBR
if( (MYSQL *) rb_thread_blocking_region_variable_params(10, &mysql_real_connect, RUBY_UBF_IO, &myp->handler, h, u, p, d, pp, s, f) == NULL)
# else
if(mysql_real_connect(&myp->handler, h, u, p, d, pp, s, f) == NULL)
# endif
#elif MYSQL_VERSION_ID >= 32115
if (mysql_real_connect(&myp->handler, h, u, p, pp, s, f) == NULL)
#else
if (mysql_real_connect(&myp->handler, h, u, p, pp, s) == NULL)
#endif
mysql_raise(&myp->handler);
myp->handler.reconnect = 0;
myp->connection = Qtrue;
optimize_for_async(obj);
myp->query_with_result = Qtrue;
rb_obj_call_init(obj, argc, argv);
//schedule_connect(obj);
return obj;
}
|
.debug(str) ⇒ Object
my_debug(string)
437 438 439 440 441 |
# File 'ext/mysql.c', line 437
static VALUE my_debug(VALUE obj, VALUE str)
{
mysql_debug(StringValuePtr(str));
return obj;
}
|
.escape_string(str) ⇒ Object
escape_string(string)
420 421 422 423 424 425 426 427 |
# File 'ext/mysql.c', line 420
static VALUE escape_string(VALUE klass, VALUE str)
{
VALUE ret;
Check_Type(str, T_STRING);
ret = rb_str_new(0, (RSTRING_LEN(str))*2+1);
rb_str_set_len(ret, mysql_escape_string(RSTRING_PTR(ret), RSTRING_PTR(str), RSTRING_LEN(str)));
return ret;
}
|
.get_client_info ⇒ Object
client_info()
430 431 432 433 |
# File 'ext/mysql.c', line 430
static VALUE client_info(VALUE klass)
{
return rb_tainted_str_new2(mysql_get_client_info());
}
|
.get_client_version ⇒ Object
client_version()
446 447 448 449 |
# File 'ext/mysql.c', line 446
static VALUE client_version(VALUE obj)
{
return INT2NUM(mysql_get_client_version());
}
|
.init ⇒ Object
init()
228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'ext/mysql.c', line 228
static VALUE init(VALUE klass)
{
struct mysql* myp;
VALUE obj;
obj = Data_Make_Struct(klass, struct mysql, 0, free_mysql, myp);
mysql_init(&myp->handler);
myp->connection = Qfalse;
myp->query_with_result = Qtrue;
myp->gc_disabled = Qtrue;
rb_obj_call_init(obj, 0, NULL);
return obj;
}
|
.new(*args) ⇒ Object
real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'ext/mysql.c', line 367
static VALUE real_connect(int argc, VALUE* argv, VALUE klass)
{
VALUE host, user, passwd, db, port, sock, flag;
char *h, *u, *p, *d, *s;
unsigned int pp, f;
struct mysql* myp;
VALUE obj;
#if MYSQL_VERSION_ID >= 32200
rb_scan_args(argc, argv, "07", &host, &user, &passwd, &db, &port, &sock, &flag);
d = NILorSTRING(db);
f = NILorINT(flag);
#elif MYSQL_VERSION_ID >= 32115
rb_scan_args(argc, argv, "06", &host, &user, &passwd, &port, &sock, &flag);
f = NILorINT(flag);
#else
rb_scan_args(argc, argv, "05", &host, &user, &passwd, &port, &sock);
#endif
h = NILorSTRING(host);
u = NILorSTRING(user);
p = NILorSTRING(passwd);
pp = NILorINT(port);
s = NILorSTRING(sock);
obj = Data_Make_Struct(klass, struct mysql, 0, free_mysql, myp);
#if MYSQL_VERSION_ID >= 32200
mysql_init(&myp->handler); /* we get here */
# ifdef HAVE_TBR
if( (MYSQL *) rb_thread_blocking_region_variable_params(10, &mysql_real_connect, RUBY_UBF_IO, &myp->handler, h, u, p, d, pp, s, f) == NULL)
# else
if(mysql_real_connect(&myp->handler, h, u, p, d, pp, s, f) == NULL)
# endif
#elif MYSQL_VERSION_ID >= 32115
if (mysql_real_connect(&myp->handler, h, u, p, pp, s, f) == NULL)
#else
if (mysql_real_connect(&myp->handler, h, u, p, pp, s) == NULL)
#endif
mysql_raise(&myp->handler);
myp->handler.reconnect = 0;
myp->connection = Qtrue;
optimize_for_async(obj);
myp->query_with_result = Qtrue;
rb_obj_call_init(obj, argc, argv);
//schedule_connect(obj);
return obj;
}
|
.quote(str) ⇒ Object
escape_string(string)
420 421 422 423 424 425 426 427 |
# File 'ext/mysql.c', line 420
static VALUE escape_string(VALUE klass, VALUE str)
{
VALUE ret;
Check_Type(str, T_STRING);
ret = rb_str_new(0, (RSTRING_LEN(str))*2+1);
rb_str_set_len(ret, mysql_escape_string(RSTRING_PTR(ret), RSTRING_PTR(str), RSTRING_LEN(str)));
return ret;
}
|
.real_connect(*args) ⇒ Object
real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'ext/mysql.c', line 367
static VALUE real_connect(int argc, VALUE* argv, VALUE klass)
{
VALUE host, user, passwd, db, port, sock, flag;
char *h, *u, *p, *d, *s;
unsigned int pp, f;
struct mysql* myp;
VALUE obj;
#if MYSQL_VERSION_ID >= 32200
rb_scan_args(argc, argv, "07", &host, &user, &passwd, &db, &port, &sock, &flag);
d = NILorSTRING(db);
f = NILorINT(flag);
#elif MYSQL_VERSION_ID >= 32115
rb_scan_args(argc, argv, "06", &host, &user, &passwd, &port, &sock, &flag);
f = NILorINT(flag);
#else
rb_scan_args(argc, argv, "05", &host, &user, &passwd, &port, &sock);
#endif
h = NILorSTRING(host);
u = NILorSTRING(user);
p = NILorSTRING(passwd);
pp = NILorINT(port);
s = NILorSTRING(sock);
obj = Data_Make_Struct(klass, struct mysql, 0, free_mysql, myp);
#if MYSQL_VERSION_ID >= 32200
mysql_init(&myp->handler); /* we get here */
# ifdef HAVE_TBR
if( (MYSQL *) rb_thread_blocking_region_variable_params(10, &mysql_real_connect, RUBY_UBF_IO, &myp->handler, h, u, p, d, pp, s, f) == NULL)
# else
if(mysql_real_connect(&myp->handler, h, u, p, d, pp, s, f) == NULL)
# endif
#elif MYSQL_VERSION_ID >= 32115
if (mysql_real_connect(&myp->handler, h, u, p, pp, s, f) == NULL)
#else
if (mysql_real_connect(&myp->handler, h, u, p, pp, s) == NULL)
#endif
mysql_raise(&myp->handler);
myp->handler.reconnect = 0;
myp->connection = Qtrue;
optimize_for_async(obj);
myp->query_with_result = Qtrue;
rb_obj_call_init(obj, argc, argv);
//schedule_connect(obj);
return obj;
}
|
Instance Method Details
#affected_rows ⇒ Object
affected_rows()
574 575 576 577 |
# File 'ext/mysql.c', line 574
static VALUE affected_rows(VALUE obj)
{
return INT2NUM(mysql_affected_rows(GetHandler(obj)));
}
|
#async_in_progress=(flag) ⇒ Object
324 325 326 327 328 329 |
# File 'ext/mysql.c', line 324
static VALUE async_in_progress_set( VALUE obj, VALUE flag )
{
struct mysql* m = GetMysqlStruct(obj);
m->async_in_progress = (flag == Qnil || flag == Qfalse) ? 0 : connection_identifier(obj);
return flag;
}
|
#async_in_progress? ⇒ Boolean
318 319 320 321 322 |
# File 'ext/mysql.c', line 318
static VALUE async_in_progress( VALUE obj )
{
struct mysql* m = GetMysqlStruct(obj);
return ( m->async_in_progress == connection_identifier(obj) ) ? Qtrue : Qfalse;
}
|
#autocommit(mode) ⇒ Object
autocommit()
1222 1223 1224 1225 1226 1227 1228 1229 1230 |
# File 'ext/mysql.c', line 1222
static VALUE autocommit(VALUE obj, VALUE mode)
{
MYSQL* m = GetHandler(obj);
int f;
f = (mode == Qnil || mode == Qfalse || (rb_type(mode) == T_FIXNUM && NUM2INT(mode) == 0)) ? 0 : 1;
if (mysql_autocommit(m, f) != 0)
mysql_raise(m);
return obj;
}
|
#blocking? ⇒ Boolean
blocking
975 976 977 |
# File 'ext/mysql.c', line 975
static VALUE blocking(VALUE obj){
return ( GetMysqlStruct(obj)->blocking ? Qtrue : Qfalse );
}
|
#busy=(flag) ⇒ Object
busy(true|false)
989 990 991 992 993 994 995 |
# File 'ext/mysql.c', line 989
static VALUE busy_set(VALUE obj, VALUE flag)
{
if (TYPE(flag) != T_TRUE && TYPE(flag) != T_FALSE)
rb_raise(rb_eTypeError, "invalid type, required true or false.");
GetMysqlStruct(obj)->busy = flag;
return flag;
}
|
#busy? ⇒ Boolean
is_busy
980 981 982 |
# File 'ext/mysql.c', line 980
static VALUE is_busy(VALUE obj){
return ( GetMysqlStruct(obj)->busy ? Qtrue : Qfalse );
}
|
#c_async_query(*args) ⇒ Object
async_query(sql,timeout=nil)
optionally take a block
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 |
# File 'ext/mysql.c', line 1163
static VALUE async_query(int argc, VALUE* argv, VALUE obj)
{
MYSQL* m = GetHandler(obj);
VALUE sql, timeout;
rb_scan_args(argc, argv, "11", &sql, &timeout);
async_in_progress_set( obj, Qfalse );
busy(obj);
send_query( obj, sql );
if ( should_schedule_query() ){
schedule_query(obj, timeout);
}
if (rb_block_given_p()) {
rb_yield( get_result(obj) );
idle( obj );
return obj;
}else{
idle( obj );
return get_result(obj);
}
}
|
#change_user(*args) ⇒ Object
change_user(user=nil, passwd=nil, db=nil)
581 582 583 584 585 586 587 588 589 590 591 592 593 |
# File 'ext/mysql.c', line 581
static VALUE change_user(int argc, VALUE* argv, VALUE obj)
{
VALUE user, passwd, db;
char *u, *p, *d;
MYSQL* m = GetHandler(obj);
rb_scan_args(argc, argv, "03", &user, &passwd, &db);
u = NILorSTRING(user);
p = NILorSTRING(passwd);
d = NILorSTRING(db);
if (mysql_change_user(m, u, p, d) != 0)
mysql_raise(m);
return obj;
}
|
#character_set_name ⇒ Object
character_set_name()
598 599 600 601 |
# File 'ext/mysql.c', line 598
static VALUE character_set_name(VALUE obj)
{
return rb_tainted_str_new2(mysql_character_set_name(GetHandler(obj)));
}
|
#client_info ⇒ Object
client_info()
430 431 432 433 |
# File 'ext/mysql.c', line 430
static VALUE client_info(VALUE klass)
{
return rb_tainted_str_new2(mysql_get_client_info());
}
|
#client_version ⇒ Object
client_version()
446 447 448 449 |
# File 'ext/mysql.c', line 446
static VALUE client_version(VALUE obj)
{
return INT2NUM(mysql_get_client_version());
}
|
#close ⇒ Object
close()
605 606 607 608 609 610 611 |
# File 'ext/mysql.c', line 605
static VALUE my_close(VALUE obj)
{
MYSQL* m = GetHandler(obj);
mysql_close(m);
GetMysqlStruct(obj)->connection = Qfalse;
return obj;
}
|
#commit ⇒ Object
commit()
1204 1205 1206 1207 1208 1209 1210 |
# File 'ext/mysql.c', line 1204
static VALUE commit(VALUE obj)
{
MYSQL* m = GetHandler(obj);
if (mysql_commit(m) != 0)
mysql_raise(m);
return obj;
}
|
#connect(*args) ⇒ Object
real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'ext/mysql.c', line 458
static VALUE real_connect2(int argc, VALUE* argv, VALUE obj)
{
VALUE host, user, passwd, db, port, sock, flag;
char *h, *u, *p, *d, *s;
unsigned int pp, f;
MYSQL* m = GetHandler(obj);
rb_scan_args(argc, argv, "07", &host, &user, &passwd, &db, &port, &sock, &flag);
d = NILorSTRING(db);
f = NILorINT(flag);
h = NILorSTRING(host);
u = NILorSTRING(user);
p = NILorSTRING(passwd);
pp = NILorINT(port);
s = NILorSTRING(sock);
if (mysql_real_connect(m, h, u, p, d, pp, s, f) == NULL)
mysql_raise(m);
m->reconnect = 0;
GetMysqlStruct(obj)->connection = Qtrue;
optimize_for_async(obj);
//schedule_connect(obj);
return obj;
}
|
#create_db(db) ⇒ Object
create_db(db)
615 616 617 618 619 620 621 |
# File 'ext/mysql.c', line 615
static VALUE create_db(VALUE obj, VALUE db)
{
MYSQL* m = GetHandler(obj);
if (mysql_create_db(m, StringValuePtr(db)) != 0)
mysql_raise(m);
return obj;
}
|
#disable_gc=(flag) ⇒ Object
disable_gc(true|false)
1044 1045 1046 1047 1048 1049 1050 |
# File 'ext/mysql.c', line 1044
static VALUE disable_gc_set(VALUE obj, VALUE flag)
{
if (TYPE(flag) != T_TRUE && TYPE(flag) != T_FALSE)
rb_raise(rb_eTypeError, "invalid type, required true or false.");
GetMysqlStruct(obj)->gc_disabled = flag;
return flag;
}
|
#drop_db(db) ⇒ Object
drop_db(db)
624 625 626 627 628 629 630 |
# File 'ext/mysql.c', line 624
static VALUE drop_db(VALUE obj, VALUE db)
{
MYSQL* m = GetHandler(obj);
if (mysql_drop_db(m, StringValuePtr(db)) != 0)
mysql_raise(m);
return obj;
}
|
#dump_debug_info ⇒ Object
dump_debug_info()
635 636 637 638 639 640 641 |
# File 'ext/mysql.c', line 635
static VALUE dump_debug_info(VALUE obj)
{
MYSQL* m = GetHandler(obj);
if (mysql_dump_debug_info(m) != 0)
mysql_raise(m);
return obj;
}
|
#errno ⇒ Object
errno()
645 646 647 648 |
# File 'ext/mysql.c', line 645
static VALUE my_errno(VALUE obj)
{
return INT2NUM(mysql_errno(GetHandler(obj)));
}
|
#error ⇒ Object
error()
651 652 653 654 |
# File 'ext/mysql.c', line 651
static VALUE my_error(VALUE obj)
{
return rb_str_new2(mysql_error(GetHandler(obj)));
}
|
#escape_string(str) ⇒ Object
escape_string(string)
556 557 558 559 560 561 562 563 564 |
# File 'ext/mysql.c', line 556
static VALUE real_escape_string(VALUE obj, VALUE str)
{
MYSQL* m = GetHandler(obj);
VALUE ret;
Check_Type(str, T_STRING);
ret = rb_str_new(0, (RSTRING_LEN(str))*2+1);
rb_str_set_len(ret, mysql_real_escape_string(m, RSTRING_PTR(ret), RSTRING_PTR(str), RSTRING_LEN(str)));
return ret;
}
|
#field_count ⇒ Object
field_count()
657 658 659 660 |
# File 'ext/mysql.c', line 657
static VALUE field_count(VALUE obj)
{
return INT2NUM(mysql_field_count(GetHandler(obj)));
}
|
#gc_disabled? ⇒ Boolean
gc_disabled
1053 1054 1055 |
# File 'ext/mysql.c', line 1053
static VALUE gc_disabled( VALUE obj ){
return GetMysqlStruct(obj)->gc_disabled ? Qtrue: Qfalse;
}
|
#get_client_info ⇒ Object
client_info()
430 431 432 433 |
# File 'ext/mysql.c', line 430
static VALUE client_info(VALUE klass)
{
return rb_tainted_str_new2(mysql_get_client_info());
}
|
#get_client_version ⇒ Object
client_version()
446 447 448 449 |
# File 'ext/mysql.c', line 446
static VALUE client_version(VALUE obj)
{
return INT2NUM(mysql_get_client_version());
}
|
#get_host_info ⇒ Object
host_info()
663 664 665 666 |
# File 'ext/mysql.c', line 663
static VALUE host_info(VALUE obj)
{
return rb_tainted_str_new2(mysql_get_host_info(GetHandler(obj)));
}
|
#get_proto_info ⇒ Object
proto_info()
669 670 671 672 |
# File 'ext/mysql.c', line 669
static VALUE proto_info(VALUE obj)
{
return INT2NUM(mysql_get_proto_info(GetHandler(obj)));
}
|
#get_result ⇒ Object
get_result returns the mysql_result set (default) [i.e. all rows in said said] or nil if query_with_result == false
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 |
# File 'ext/mysql.c', line 1102
static VALUE get_result(VALUE obj)
{
MYSQL* m = GetHandler(obj);
async_in_progress_set( obj, Qfalse );
if (GetMysqlStruct(obj)->connection == Qfalse) {
idle( obj );
rb_raise(eMysql, "query: not connected");
}
if (mysql_read_query_result(m) != 0){
idle( obj );
mysql_raise(m);
}
if (GetMysqlStruct(obj)->query_with_result == Qfalse)
return obj;
if (mysql_field_count(m) == 0)
return Qnil;
return store_result(obj);
}
|
#get_server_info ⇒ Object
server_info()
675 676 677 678 |
# File 'ext/mysql.c', line 675
static VALUE server_info(VALUE obj)
{
return rb_tainted_str_new2(mysql_get_server_info(GetHandler(obj)));
}
|
#get_server_version ⇒ Object
server_version()
1192 1193 1194 1195 |
# File 'ext/mysql.c', line 1192
static VALUE server_version(VALUE obj)
{
return INT2NUM(mysql_get_server_version(GetHandler(obj)));
}
|
#host_info ⇒ Object
host_info()
663 664 665 666 |
# File 'ext/mysql.c', line 663
static VALUE host_info(VALUE obj)
{
return rb_tainted_str_new2(mysql_get_host_info(GetHandler(obj)));
}
|
#idle? ⇒ Boolean
984 985 986 |
# File 'ext/mysql.c', line 984 static VALUE is_idle(VALUE obj){ return ( is_busy(obj) == Qtrue ) ? Qfalse : Qtrue; } |
#info ⇒ Object
info()
681 682 683 684 685 |
# File 'ext/mysql.c', line 681
static VALUE info(VALUE obj)
{
const char* p = mysql_info(GetHandler(obj));
return p? rb_tainted_str_new2(p): Qnil;
}
|
#insert_id ⇒ Object
insert_id()
688 689 690 691 |
# File 'ext/mysql.c', line 688
static VALUE insert_id(VALUE obj)
{
return INT2NUM(mysql_insert_id(GetHandler(obj)));
}
|
#interrupted? ⇒ Boolean
interrupted
1029 1030 1031 1032 1033 |
# File 'ext/mysql.c', line 1029
static VALUE interrupted( VALUE obj )
{
MYSQL* m = GetHandler(obj);
return ( vio_was_interrupted( m->net.vio ) == 1 ? Qtrue : Qfalse );
}
|
#kill(pid) ⇒ Object
kill(pid)
694 695 696 697 698 699 700 701 |
# File 'ext/mysql.c', line 694
static VALUE my_kill(VALUE obj, VALUE pid)
{
int p = NUM2INT(pid);
MYSQL* m = GetHandler(obj);
if (mysql_kill(m, p) != 0)
mysql_raise(m);
return obj;
}
|
#list_dbs(*args) ⇒ Object
list_dbs(db=nil)
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 |
# File 'ext/mysql.c', line 704
static VALUE list_dbs(int argc, VALUE* argv, VALUE obj)
{
unsigned int i, n;
VALUE db, ret;
MYSQL* m = GetHandler(obj);
MYSQL_RES* res;
rb_scan_args(argc, argv, "01", &db);
res = mysql_list_dbs(m, NILorSTRING(db));
if (res == NULL)
mysql_raise(m);
n = mysql_num_rows(res);
ret = rb_ary_new2(n);
for (i=0; i<n; i++)
rb_ary_store(ret, i, rb_tainted_str_new2(mysql_fetch_row(res)[0]));
mysql_free_result(res);
return ret;
}
|
#list_fields(*args) ⇒ Object
list_fields(table, field=nil)
725 726 727 728 729 730 731 732 733 734 735 |
# File 'ext/mysql.c', line 725
static VALUE list_fields(int argc, VALUE* argv, VALUE obj)
{
VALUE table, field;
MYSQL* m = GetHandler(obj);
MYSQL_RES* res;
rb_scan_args(argc, argv, "11", &table, &field);
res = mysql_list_fields(m, StringValuePtr(table), NILorSTRING(field));
if (res == NULL)
mysql_raise(m);
return mysqlres2obj(res, GetMysqlStruct(obj)->gc_disabled);
}
|
#list_processes ⇒ Object
list_processes()
738 739 740 741 742 743 744 745 |
# File 'ext/mysql.c', line 738
static VALUE list_processes(VALUE obj)
{
MYSQL* m = GetHandler(obj);
MYSQL_RES* res = mysql_list_processes(m);
if (res == NULL)
mysql_raise(m);
return mysqlres2obj(res, GetMysqlStruct(obj)->gc_disabled);
}
|
#list_tables(*args) ⇒ Object
list_tables(table=nil)
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 |
# File 'ext/mysql.c', line 748
static VALUE list_tables(int argc, VALUE* argv, VALUE obj)
{
VALUE table;
MYSQL* m = GetHandler(obj);
MYSQL_RES* res;
unsigned int i, n;
VALUE ret;
rb_scan_args(argc, argv, "01", &table);
res = mysql_list_tables(m, NILorSTRING(table));
if (res == NULL)
mysql_raise(m);
n = mysql_num_rows(res);
ret = rb_ary_new2(n);
for (i=0; i<n; i++)
rb_ary_store(ret, i, rb_tainted_str_new2(mysql_fetch_row(res)[0]));
mysql_free_result(res);
return ret;
}
|
#more_results ⇒ Object
more_results()
1253 1254 1255 1256 1257 1258 1259 |
# File 'ext/mysql.c', line 1253
static VALUE more_results(VALUE obj)
{
if (mysql_more_results(GetHandler(obj)) == 0)
return Qfalse;
else
return Qtrue;
}
|
#more_results? ⇒ Boolean
more_results()
1253 1254 1255 1256 1257 1258 1259 |
# File 'ext/mysql.c', line 1253
static VALUE more_results(VALUE obj)
{
if (mysql_more_results(GetHandler(obj)) == 0)
return Qfalse;
else
return Qtrue;
}
|
#next_result ⇒ Object
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 |
# File 'ext/mysql.c', line 1261
static VALUE next_result(VALUE obj)
{
MYSQL* m = GetHandler(obj);
int ret;
ret = mysql_next_result(m);
if (ret > 0)
mysql_raise(m);
if (ret == 0)
return Qtrue;
return Qfalse;
}
|
#options(*args) ⇒ Object
options(opt, value=nil)
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'ext/mysql.c', line 485
static VALUE options(int argc, VALUE* argv, VALUE obj)
{
VALUE opt, val;
int n;
my_bool b;
char* v;
MYSQL* m = GetHandler(obj);
rb_scan_args(argc, argv, "11", &opt, &val);
switch(NUM2INT(opt)) {
case MYSQL_OPT_CONNECT_TIMEOUT:
#if MYSQL_VERSION_ID >= 40100
case MYSQL_OPT_PROTOCOL:
#endif
#if MYSQL_VERSION_ID >= 40101
case MYSQL_OPT_READ_TIMEOUT:
case MYSQL_OPT_WRITE_TIMEOUT:
#endif
if (val == Qnil)
rb_raise(rb_eArgError, "wrong # of arguments(1 for 2)");
n = NUM2INT(val);
v = (char*)&n;
break;
case MYSQL_INIT_COMMAND:
case MYSQL_READ_DEFAULT_FILE:
case MYSQL_READ_DEFAULT_GROUP:
#if MYSQL_VERSION_ID >= 32349
case MYSQL_SET_CHARSET_DIR:
case MYSQL_SET_CHARSET_NAME:
#endif
#if MYSQL_VERSION_ID >= 40100
case MYSQL_SHARED_MEMORY_BASE_NAME:
#endif
#if MYSQL_VERSION_ID >= 40101
case MYSQL_SET_CLIENT_IP:
#endif
if (val == Qnil)
rb_raise(rb_eArgError, "wrong # of arguments(1 for 2)");
v = StringValuePtr(val);
break;
#if MYSQL_VERSION_ID >= 40101
case MYSQL_SECURE_AUTH:
if (val == Qnil || val == Qfalse)
b = 1;
else
b = 0;
v = (char*)&b;
break;
#endif
#if MYSQL_VERSION_ID >= 32349
case MYSQL_OPT_LOCAL_INFILE:
if (val == Qnil || val == Qfalse)
v = NULL;
else {
n = 1;
v = (char*)&n;
}
break;
#endif
default:
v = NULL;
}
if (mysql_options(m, NUM2INT(opt), v) != 0)
rb_raise(eMysql, "unknown option: %d", NUM2INT(opt));
return obj;
}
|
#ping ⇒ Object
ping()
770 771 772 773 774 775 776 |
# File 'ext/mysql.c', line 770
static VALUE ping(VALUE obj)
{
MYSQL* m = GetHandler(obj);
if (mysql_ping(m) != 0)
mysql_raise(m);
return obj;
}
|
#prepare(query) ⇒ Object
prepare(query)
1315 1316 1317 1318 1319 1320 |
# File 'ext/mysql.c', line 1315
static VALUE prepare(VALUE obj, VALUE query)
{
VALUE st;
st = stmt_init(obj);
return stmt_prepare(st, query);
}
|
#proto_info ⇒ Object
proto_info()
669 670 671 672 |
# File 'ext/mysql.c', line 669
static VALUE proto_info(VALUE obj)
{
return INT2NUM(mysql_get_proto_info(GetHandler(obj)));
}
|
#query(sql) ⇒ Object
query(sql)
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 |
# File 'ext/mysql.c', line 898
static VALUE query(VALUE obj, VALUE sql)
{
int loop = 0;
MYSQL* m = GetHandler(obj);
QueryArgs args;
int result;
Check_Type(sql, T_STRING);
if (GetMysqlStruct(obj)->connection == Qfalse) {
rb_raise(eMysql, "query: not connected");
}
if (rb_block_given_p()) {
#ifdef RUBY_VM
args.m = m;
args.data = RSTRING_PTR(sql);
args.len = RSTRING_LEN(sql);
result = (int) rb_thread_blocking_region(blocking_query, &args, RUBY_UBF_PROCESS, 0);
#else
result = mysql_real_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql));
#endif
if (result != 0)
mysql_raise(m);
do {
MYSQL_RES* res = mysql_store_result(m);
if (res == NULL) {
if (mysql_field_count(m) != 0)
mysql_raise(m);
} else {
VALUE robj = mysqlres2obj(res, GetMysqlStruct(obj)->gc_disabled);
rb_ensure(rb_yield, robj, res_free, robj);
}
#if MYSQL_VERSION_ID >= 40101
if ((loop = mysql_next_result(m)) > 0)
mysql_raise(m);
} while (loop == 0);
#else
} while (0);
#endif
return obj;
}
|
#query_with_result ⇒ Object
query_with_result()
1324 1325 1326 1327 |
# File 'ext/mysql.c', line 1324
static VALUE query_with_result(VALUE obj)
{
return GetMysqlStruct(obj)->query_with_result? Qtrue: Qfalse;
}
|
#query_with_result=(flag) ⇒ Object
query_with_result=(flag)
1330 1331 1332 1333 1334 1335 1336 |
# File 'ext/mysql.c', line 1330
static VALUE query_with_result_set(VALUE obj, VALUE flag)
{
if (TYPE(flag) != T_TRUE && TYPE(flag) != T_FALSE)
rb_raise(rb_eTypeError, "invalid type, required true or false.");
GetMysqlStruct(obj)->query_with_result = flag;
return flag;
}
|
#quote(str) ⇒ Object
escape_string(string)
556 557 558 559 560 561 562 563 564 |
# File 'ext/mysql.c', line 556
static VALUE real_escape_string(VALUE obj, VALUE str)
{
MYSQL* m = GetHandler(obj);
VALUE ret;
Check_Type(str, T_STRING);
ret = rb_str_new(0, (RSTRING_LEN(str))*2+1);
rb_str_set_len(ret, mysql_real_escape_string(m, RSTRING_PTR(ret), RSTRING_PTR(str), RSTRING_LEN(str)));
return ret;
}
|
#readable?(*args) ⇒ Boolean
readable(timeout=nil)
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 |
# File 'ext/mysql.c', line 1006
static VALUE readable( int argc, VALUE* argv, VALUE obj )
{
MYSQL* m = GetHandler(obj);
VALUE timeout;
rb_scan_args(argc, argv, "01", &timeout);
if ( NIL_P( timeout ) ){
timeout = m->net.read_timeout;
}
// todo could do a rb_blocking_region here
return ( vio_poll_read( m->net.vio, INT2NUM(timeout) ) == 0 ? Qtrue : Qfalse );
}
|
#real_connect(*args) ⇒ Object
real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'ext/mysql.c', line 458
static VALUE real_connect2(int argc, VALUE* argv, VALUE obj)
{
VALUE host, user, passwd, db, port, sock, flag;
char *h, *u, *p, *d, *s;
unsigned int pp, f;
MYSQL* m = GetHandler(obj);
rb_scan_args(argc, argv, "07", &host, &user, &passwd, &db, &port, &sock, &flag);
d = NILorSTRING(db);
f = NILorINT(flag);
h = NILorSTRING(host);
u = NILorSTRING(user);
p = NILorSTRING(passwd);
pp = NILorINT(port);
s = NILorSTRING(sock);
if (mysql_real_connect(m, h, u, p, d, pp, s, f) == NULL)
mysql_raise(m);
m->reconnect = 0;
GetMysqlStruct(obj)->connection = Qtrue;
optimize_for_async(obj);
//schedule_connect(obj);
return obj;
}
|
#real_query(sql) ⇒ Object
query(sql)
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 |
# File 'ext/mysql.c', line 898
static VALUE query(VALUE obj, VALUE sql)
{
int loop = 0;
MYSQL* m = GetHandler(obj);
QueryArgs args;
int result;
Check_Type(sql, T_STRING);
if (GetMysqlStruct(obj)->connection == Qfalse) {
rb_raise(eMysql, "query: not connected");
}
if (rb_block_given_p()) {
#ifdef RUBY_VM
args.m = m;
args.data = RSTRING_PTR(sql);
args.len = RSTRING_LEN(sql);
result = (int) rb_thread_blocking_region(blocking_query, &args, RUBY_UBF_PROCESS, 0);
#else
result = mysql_real_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql));
#endif
if (result != 0)
mysql_raise(m);
do {
MYSQL_RES* res = mysql_store_result(m);
if (res == NULL) {
if (mysql_field_count(m) != 0)
mysql_raise(m);
} else {
VALUE robj = mysqlres2obj(res, GetMysqlStruct(obj)->gc_disabled);
rb_ensure(rb_yield, robj, res_free, robj);
}
#if MYSQL_VERSION_ID >= 40101
if ((loop = mysql_next_result(m)) > 0)
mysql_raise(m);
} while (loop == 0);
#else
} while (0);
#endif
return obj;
}
|
#reconnect ⇒ Object
reconnect()
1339 1340 1341 1342 |
# File 'ext/mysql.c', line 1339
static VALUE reconnect(VALUE obj)
{
return GetHandler(obj)->reconnect ? Qtrue : Qfalse;
}
|
#reconnect=(flag) ⇒ Object
reconnect=(flag)
1345 1346 1347 1348 1349 |
# File 'ext/mysql.c', line 1345
static VALUE reconnect_set(VALUE obj, VALUE flag)
{
GetHandler(obj)->reconnect = (flag == Qnil || flag == Qfalse) ? 0 : 1;
return flag;
}
|
#reconnected? ⇒ Boolean
reconnected
1036 1037 1038 1039 1040 1041 |
# File 'ext/mysql.c', line 1036 static VALUE reconnected( VALUE obj ){ MYSQL* m = GetHandler(obj); int current_connection_id = mysql_thread_id( m ); mysql_ping(m); return ( current_connection_id == mysql_thread_id( m ) ) ? Qfalse : Qtrue; } |
#refresh(r) ⇒ Object
refresh®
779 780 781 782 783 784 785 |
# File 'ext/mysql.c', line 779
static VALUE refresh(VALUE obj, VALUE r)
{
MYSQL* m = GetHandler(obj);
if (mysql_refresh(m, NUM2INT(r)) != 0)
mysql_raise(m);
return obj;
}
|
#reload ⇒ Object
reload()
788 789 790 791 792 793 794 |
# File 'ext/mysql.c', line 788
static VALUE reload(VALUE obj)
{
MYSQL* m = GetHandler(obj);
if (mysql_reload(m) != 0)
mysql_raise(m);
return obj;
}
|
#retry? ⇒ Boolean
retry
1022 1023 1024 1025 1026 |
# File 'ext/mysql.c', line 1022
static VALUE retry( VALUE obj )
{
MYSQL* m = GetHandler(obj);
return ( vio_should_retry( m->net.vio ) == 1 ? Qtrue : Qfalse );
}
|
#rollback ⇒ Object
rollback()
1213 1214 1215 1216 1217 1218 1219 |
# File 'ext/mysql.c', line 1213
static VALUE rollback(VALUE obj)
{
MYSQL* m = GetHandler(obj);
if (mysql_rollback(m) != 0)
mysql_raise(m);
return obj;
}
|
#ruby_async_query(sql, timeout = nil) ⇒ Object
known to deadlock TODO
11 12 13 14 15 |
# File 'lib/mysqlplus.rb', line 11 def ruby_async_query(sql, timeout = nil) # known to deadlock TODO send_query(sql) select [ (@sockets ||= {})[socket] ||= IO.new(socket) ], nil, nil, nil get_result end |
#select_db(db) ⇒ Object
select_db(db)
797 798 799 800 801 802 803 |
# File 'ext/mysql.c', line 797
static VALUE select_db(VALUE obj, VALUE db)
{
MYSQL* m = GetHandler(obj);
if (mysql_select_db(m, StringValuePtr(db)) != 0)
mysql_raise(m);
return obj;
}
|
#send_query(sql) ⇒ Object
send_query(sql)
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 |
# File 'ext/mysql.c', line 1075
static VALUE send_query(VALUE obj, VALUE sql)
{
MYSQL* m = GetHandler(obj);
Check_Type(sql, T_STRING);
if (GetMysqlStruct(obj)->connection == Qfalse && async_in_progress(obj) == Qtrue ) {
idle( obj );
rb_raise(eMysql, "query: not connected");
}
validate_async_query(obj);
if (mysql_send_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0){
idle( obj );
mysql_raise(m);
}
async_in_progress_set( obj, Qtrue );
return Qnil;
}
|
#server_info ⇒ Object
server_info()
675 676 677 678 |
# File 'ext/mysql.c', line 675
static VALUE server_info(VALUE obj)
{
return rb_tainted_str_new2(mysql_get_server_info(GetHandler(obj)));
}
|
#server_version ⇒ Object
server_version()
1192 1193 1194 1195 |
# File 'ext/mysql.c', line 1192
static VALUE server_version(VALUE obj)
{
return INT2NUM(mysql_get_server_version(GetHandler(obj)));
}
|
#set_server_option(option) ⇒ Object
set_server_option(option)
1276 1277 1278 1279 1280 1281 1282 |
# File 'ext/mysql.c', line 1276
static VALUE set_server_option(VALUE obj, VALUE option)
{
MYSQL *m = GetHandler(obj);
if (mysql_set_server_option(m, NUM2INT(option)) != 0)
mysql_raise(m);
return obj;
}
|
#shutdown(*args) ⇒ Object
shutdown()
806 807 808 809 810 811 812 813 814 815 816 817 818 819 |
# File 'ext/mysql.c', line 806
static VALUE my_shutdown(int argc, VALUE* argv, VALUE obj)
{
MYSQL* m = GetHandler(obj);
VALUE level;
rb_scan_args(argc, argv, "01", &level);
#if MYSQL_VERSION_ID >= 40103
if (mysql_shutdown(m, NIL_P(level) ? SHUTDOWN_DEFAULT : NUM2INT(level)) != 0)
#else
if (mysql_shutdown(m) != 0)
#endif
mysql_raise(m);
return obj;
}
|
#simulate_disconnect ⇒ Object
for testing
1066 1067 1068 1069 1070 1071 |
# File 'ext/mysql.c', line 1066
static VALUE simulate_disconnect( VALUE obj )
{
MYSQL* m = GetHandler(obj);
mysql_library_end();
return Qnil;
}
|
#socket ⇒ Object
socket
958 959 960 961 962 |
# File 'ext/mysql.c', line 958
static VALUE socket(VALUE obj)
{
MYSQL* m = GetHandler(obj);
return INT2NUM(m->net.fd);
}
|
#sqlstate ⇒ Object
sqlstate()
1285 1286 1287 1288 1289 |
# File 'ext/mysql.c', line 1285
static VALUE sqlstate(VALUE obj)
{
MYSQL *m = GetHandler(obj);
return rb_tainted_str_new2(mysql_sqlstate(m));
}
|
#ssl_set(*args) ⇒ Object
ssl_set(key=nil, cert=nil, ca=nil, capath=nil, cipher=nil)
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 |
# File 'ext/mysql.c', line 1235
static VALUE ssl_set(int argc, VALUE* argv, VALUE obj)
{
VALUE key, cert, ca, capath, cipher;
char *s_key, *s_cert, *s_ca, *s_capath, *s_cipher;
MYSQL* m = GetHandler(obj);
rb_scan_args(argc, argv, "05", &key, &cert, &ca, &capath, &cipher);
s_key = NILorSTRING(key);
s_cert = NILorSTRING(cert);
s_ca = NILorSTRING(ca);
s_capath = NILorSTRING(capath);
s_cipher = NILorSTRING(cipher);
mysql_ssl_set(m, s_key, s_cert, s_ca, s_capath, s_cipher);
return obj;
}
|
#stat ⇒ Object
stat()
822 823 824 825 826 827 828 829 |
# File 'ext/mysql.c', line 822
static VALUE my_stat(VALUE obj)
{
MYSQL* m = GetHandler(obj);
const char* s = mysql_stat(m);
if (s == NULL)
mysql_raise(m);
return rb_tainted_str_new2(s);
}
|
#stmt_init ⇒ Object
stmt_init()
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 |
# File 'ext/mysql.c', line 1294
static VALUE stmt_init(VALUE obj)
{
MYSQL *m = GetHandler(obj);
MYSQL_STMT *s;
struct mysql_stmt* stmt;
my_bool true = 1;
VALUE st_obj;
if ((s = mysql_stmt_init(m)) == NULL)
mysql_raise(m);
if (mysql_stmt_attr_set(s, STMT_ATTR_UPDATE_MAX_LENGTH, &true))
rb_raise(rb_eArgError, "mysql_stmt_attr_set() failed");
st_obj = Data_Make_Struct(cMysqlStmt, struct mysql_stmt, 0, free_mysqlstmt, stmt);
memset(stmt, 0, sizeof(*stmt));
stmt->stmt = s;
stmt->closed = Qfalse;
return st_obj;
}
|
#store_result ⇒ Object
store_result()
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 |
# File 'ext/mysql.c', line 848
static VALUE store_result(VALUE obj)
{
MYSQL* m = GetHandler(obj);
MYSQL_RES* res = NULL;
#ifndef HAVE_TBR
res = mysql_store_result(m);
#else
mysql_result_to_here_t linker;
linker.mysql_instance = m;
linker.store_it_here = &res;
rb_thread_blocking_region(store_result_to_location, (void *) &linker, RUBY_UBF_IO, 0);
#endif
if (res == NULL)
mysql_raise(m);
return mysqlres2obj(res, GetMysqlStruct(obj)->gc_disabled);
}
|
#thread_id ⇒ Object
thread_id()
868 869 870 871 |
# File 'ext/mysql.c', line 868
static VALUE thread_id(VALUE obj)
{
return INT2NUM(mysql_thread_id(GetHandler(obj)));
}
|
#use_result ⇒ Object
use_result()
874 875 876 877 878 879 880 881 |
# File 'ext/mysql.c', line 874
static VALUE use_result(VALUE obj)
{
MYSQL* m = GetHandler(obj);
MYSQL_RES* res = mysql_use_result(m);
if (res == NULL)
mysql_raise(m);
return mysqlres2obj(res, GetMysqlStruct(obj)->gc_disabled);
}
|
#warning_count ⇒ Object
warning_count()
1198 1199 1200 1201 |
# File 'ext/mysql.c', line 1198
static VALUE warning_count(VALUE obj)
{
return INT2NUM(mysql_warning_count(GetHandler(obj)));
}
|