resolve merge conflicts
This commit is contained in:
commit
9f677c3047
58
ext/mysql.c
58
ext/mysql.c
@ -813,18 +813,43 @@ static VALUE use_result(VALUE obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE res_free(VALUE);
|
static VALUE res_free(VALUE);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MYSQL *m;
|
||||||
|
const char *data;
|
||||||
|
unsigned long len;
|
||||||
|
} QueryArgs;
|
||||||
|
|
||||||
|
static VALUE blocking_query(void *data)
|
||||||
|
{
|
||||||
|
QueryArgs *args = (QueryArgs *) data;
|
||||||
|
return (VALUE) mysql_real_query(args->m, args->data, args->len);
|
||||||
|
}
|
||||||
|
|
||||||
/* query(sql) */
|
/* query(sql) */
|
||||||
static VALUE query(VALUE obj, VALUE sql)
|
static VALUE query(VALUE obj, VALUE sql)
|
||||||
{
|
{
|
||||||
int loop = 0;
|
int loop = 0;
|
||||||
MYSQL* m = GetHandler(obj);
|
MYSQL* m = GetHandler(obj);
|
||||||
|
QueryArgs args;
|
||||||
|
int result;
|
||||||
|
|
||||||
Check_Type(sql, T_STRING);
|
Check_Type(sql, T_STRING);
|
||||||
if (GetMysqlStruct(obj)->connection == Qfalse) {
|
if (GetMysqlStruct(obj)->connection == Qfalse) {
|
||||||
rb_raise(eMysql, "query: not connected");
|
rb_raise(eMysql, "query: not connected");
|
||||||
}
|
}
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
if (mysql_real_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0)
|
#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);
|
mysql_raise(m);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
MYSQL_RES* res = mysql_store_result(m);
|
MYSQL_RES* res = mysql_store_result(m);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
@ -843,7 +868,16 @@ static VALUE query(VALUE obj, VALUE sql)
|
|||||||
#endif
|
#endif
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
if (mysql_real_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0)
|
|
||||||
|
#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);
|
mysql_raise(m);
|
||||||
if (GetMysqlStruct(obj)->query_with_result == Qfalse)
|
if (GetMysqlStruct(obj)->query_with_result == Qfalse)
|
||||||
return obj;
|
return obj;
|
||||||
@ -858,7 +892,7 @@ static VALUE socket(VALUE obj)
|
|||||||
MYSQL* m = GetHandler(obj);
|
MYSQL* m = GetHandler(obj);
|
||||||
return INT2NUM(m->net.fd);
|
return INT2NUM(m->net.fd);
|
||||||
}
|
}
|
||||||
/* socket_type */
|
/* socket_type --currently returns true or false, needs some work */
|
||||||
static VALUE socket_type(VALUE obj)
|
static VALUE socket_type(VALUE obj)
|
||||||
{
|
{
|
||||||
MYSQL* m = GetHandler(obj);
|
MYSQL* m = GetHandler(obj);
|
||||||
@ -922,7 +956,7 @@ static VALUE get_result(VALUE obj)
|
|||||||
return store_result(obj);
|
return store_result(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE schedule(VALUE obj, VALUE timeout)
|
static void schedule(VALUE obj, VALUE timeout)
|
||||||
{
|
{
|
||||||
MYSQL* m = GetHandler(obj);
|
MYSQL* m = GetHandler(obj);
|
||||||
fd_set read;
|
fd_set read;
|
||||||
@ -937,13 +971,11 @@ static VALUE schedule(VALUE obj, VALUE timeout)
|
|||||||
if (rb_thread_select(m->net.fd + 1, &read, NULL, NULL, &tv) < 0) {
|
if (rb_thread_select(m->net.fd + 1, &read, NULL, NULL, &tv) < 0) {
|
||||||
rb_raise(eMysql, "query: timeout");
|
rb_raise(eMysql, "query: timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* async_query(sql,timeout=nil) */
|
/* async_query(sql,timeout=nil) */
|
||||||
static VALUE async_query(int argc, VALUE* argv, VALUE obj)
|
static VALUE async_query(int argc, VALUE* argv, VALUE obj)
|
||||||
{
|
{
|
||||||
MYSQL* m = GetHandler(obj);
|
|
||||||
VALUE sql, timeout;
|
VALUE sql, timeout;
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "11", &sql, &timeout);
|
rb_scan_args(argc, argv, "11", &sql, &timeout);
|
||||||
@ -1295,7 +1327,7 @@ static VALUE process_all_hashes(VALUE obj, VALUE with_table, int build_array, in
|
|||||||
if(yield)
|
if(yield)
|
||||||
return obj;
|
return obj;
|
||||||
|
|
||||||
return Qnil; // we should never get here
|
return Qnil; /* we should never get here -- this takes out a compiler warning */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fetch_hash2 (internal) */
|
/* fetch_hash2 (internal) */
|
||||||
@ -1679,12 +1711,12 @@ static VALUE stmt_execute(int argc, VALUE *argv, VALUE obj)
|
|||||||
s->param.bind[i].buffer = &(s->param.buffer[i]);
|
s->param.bind[i].buffer = &(s->param.buffer[i]);
|
||||||
t.second_part = 0;
|
t.second_part = 0;
|
||||||
t.neg = 0;
|
t.neg = 0;
|
||||||
t.second = FIX2INT(RARRAY(a)->ptr[0]);
|
t.second = FIX2INT(rb_ary_entry(a, 0));
|
||||||
t.minute = FIX2INT(RARRAY(a)->ptr[1]);
|
t.minute = FIX2INT(rb_ary_entry(a, 1));
|
||||||
t.hour = FIX2INT(RARRAY(a)->ptr[2]);
|
t.hour = FIX2INT(rb_ary_entry(a, 2));
|
||||||
t.day = FIX2INT(RARRAY(a)->ptr[3]);
|
t.day = FIX2INT(rb_ary_entry(a, 3));
|
||||||
t.month = FIX2INT(RARRAY(a)->ptr[4]);
|
t.month = FIX2INT(rb_ary_entry(a, 4));
|
||||||
t.year = FIX2INT(RARRAY(a)->ptr[5]);
|
t.year = FIX2INT(rb_ary_entry(a, 5));
|
||||||
*(MYSQL_TIME*)&(s->param.buffer[i]) = t;
|
*(MYSQL_TIME*)&(s->param.buffer[i]) = t;
|
||||||
} else if (CLASS_OF(argv[i]) == cMysqlTime) {
|
} else if (CLASS_OF(argv[i]) == cMysqlTime) {
|
||||||
MYSQL_TIME t;
|
MYSQL_TIME t;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
# note that we load all the rows first, then run .all_hashes on the result [to see more easily the effect of all hashes]
|
# note that we load all the rows first, then run .all_hashes on the result [to see more easily the effect of all hashes]
|
||||||
# on my machine and a 200_000 row table, it took 3.38s versus 3.65s for the old .each_hash way [note also that .each_hash is
|
# on my machine and a 200_000 row table, it took 3.38s versus 3.65s for the old .each_hash way [note also that .each_hash is
|
||||||
# almost as fast, now, as .all_hashes--they've both been optimized]
|
# almost as fast, now, as .all_hashes--they've both been optimized]
|
||||||
|
require 'rubygems'
|
||||||
require 'mysqlplus'
|
require 'mysqlplus'
|
||||||
|
|
||||||
use_the_all_hashes_method = true
|
use_the_all_hashes_method = true
|
||||||
|
21
test/test_failure.rb
Normal file
21
test/test_failure.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# shows the effect of using .all_hashes instead of looping on each hash
|
||||||
|
# run it by substiting in a 'long' [many row] query for the query variable and toggling use_all_hashes here at the top
|
||||||
|
# note that we load all the rows first, then run .all_hashes on the result [to see more easily the effect of all hashes]
|
||||||
|
# on my machine and a 200_000 row table, it took 3.38s versus 3.65s
|
||||||
|
require 'rubygems'
|
||||||
|
require 'mysqlplus'
|
||||||
|
begin
|
||||||
|
Mysql.real_connect('fakehost','root', '', 'local_leadgen_dev')
|
||||||
|
rescue Mysql::Error
|
||||||
|
end
|
||||||
|
begin
|
||||||
|
Mysql.real_connect('localhost','root', '', 'faketable')
|
||||||
|
rescue Mysql::Error
|
||||||
|
end
|
||||||
|
begin
|
||||||
|
Mysql.real_connect('localhost', 'root', 'pass', 'db', 3307)# bad port
|
||||||
|
rescue Mysql::Error
|
||||||
|
end
|
||||||
|
print "pass"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user