Commit Graph

132 Commits

Author SHA1 Message Date
Brian Lopez
40f0cd012c change connection check symantecs 2010-10-05 23:36:05 -07:00
Brian Lopez
4383885634 was in a hurry earlier 2010-09-27 13:24:37 -07:00
Brian Lopez
307b92b966 whoops, lost this line in a previous patch 2010-09-27 11:17:47 -07:00
Brian Lopez
dc9164d016 re-fix some compiler warnings 2010-09-14 22:27:18 -07:00
Brian Lopez
e7924df06a make sure we only attempt to close/free the MYSQL pointer once 2010-09-14 22:27:07 -07:00
Brian Lopez
5cadce3417 fix bug in rb_mysql_client_free 2010-09-14 20:51:21 -07:00
Joe Damato
05c942a668 Fix macros and associated semicolons 2010-09-14 19:14:07 -07:00
Joe Damato
7b8d6359c2 Fix data corruption bug 2010-09-14 18:01:14 -07:00
Brian Lopez
b1b66cc389 enable cross-compilation 2010-09-09 07:35:31 -07:00
Brian Lopez
64be4019ad work around an rbx bug (it's going to be fixed in rbx soon anyhow) 2010-09-07 15:43:22 -07:00
Brian Lopez
530b082905 Revert "remove cached values for better rbx compatibility (this may come back in the near future)"
This reverts commit d12c5e2e27.
2010-09-07 15:38:08 -07:00
Brian Lopez
d12c5e2e27 remove cached values for better rbx compatibility (this may come back in the near future) 2010-09-04 11:52:10 -07:00
Brian Lopez
c110d0d263 rbx doesn't have rb_obj_dup yet 2010-09-04 11:52:09 -07:00
Brian Lopez
ae6c33a13f add cache_rows option to enable/disable internal row caching for results 2010-08-27 12:08:48 -07:00
Eric Wong
1100288eba avoid stack overflow when escaping large strings
Attempting to escape large, untrusted strings cause stack
overflows (easier under Ruby 1.9 using pthreads) leading to
SystemStackError on small overflows and segmentation faults on
large overflows.  Instead of allocating on the stack, we'll
allocate a string buffer from the heap.

This has the unfortunate effect of reducing escape performance
for common cases, but in my experience SQL escaping isn't much
of a bottleneck.

For reference, Ruby 1.9.2-p0 with pthreads gets a stack size of
512K and the default process stack size is 8MB on both x86 and
x86_64 Linux.
2010-08-24 05:24:35 +00:00
Luis Lavena
4f9625f877 Wrap fcntl to exclude Windows.
Naive implementation, get it compiled but crashes.
2010-08-23 11:59:11 -07:00
Brian Lopez
dd5f563554 make sure we respect application_timezone for DateTime values as well 2010-08-20 15:13:08 -07:00
Brian Lopez
e56c79894c fix compiler warning 2010-08-20 12:08:29 -07:00
Brian Lopez
a19888e939 Make sure we switch over to the DateTime class for DATETIME/TIMESTAMP columns that are out of the supported range for 32bit platforms 2010-08-20 12:07:27 -07:00
Aaron Patterson
ce77899848 connection flags can be passed to the constructor 2010-08-20 09:56:36 -07:00
Aaron Patterson
864cf0f291 exposing client flags 2010-08-20 09:36:15 -07:00
Eric Wong
8e81dcb053 retry connect if interrupted by signals
The MySQL client libraries normally retry system calls when
interrupted by signals.  The lone exception I've found is in the
(infrequent) connection setup where it'll propagate the
connect(2) syscall error all the way back up to the caller.
Fortunately inspection of the MySQL client library reveals it
properly preserves the global "errno" variable even with
debugging enabled.

Note that the net.last_errno member does NOT correspond to the
system "errno".
2010-08-19 15:55:32 -07:00
Eric Wong
8bfbfa2708 fix signal handling when waiting on queries
This reverts the single-threaded select() optimization from
commits 9a63a587c0 and
0190457dbd.

Under Ruby 1.9, the reverted optimization caused signal handlers
to be delayed until the socket became readable.

Under Ruby 1.8, matters are worse as receiving a signal during
select() causes Errno::EINTR to be raised.

There is now a (somewhat fragile) spec for testing signal
handling during a "SELECT sleep(2)" query.

Furthermore, the performance difference I measured on
benchmark/thread_alone.rb was negligible (over 1000 iterations)
between the two:

Ruby 1.8.7-p249
  Rehearsal ----------------------------------------------------
  select             0.040000   0.020000   0.060000 (  0.119448)
  rb_thread_select   0.050000   0.020000   0.070000 (  0.132091)
  ------------------------------------------- total: 0.130000sec

                         user     system      total        real
  select             0.030000   0.030000   0.060000 (  0.116471)
  rb_thread_select   0.050000   0.020000   0.070000 (  0.119874)

Ruby 1.9.2-p0
  Rehearsal ----------------------------------------------------
  select             0.050000   0.030000   0.080000 (  0.134208)
  rb_thread_select   0.080000   0.000000   0.080000 (  0.141316)
  ------------------------------------------- total: 0.160000sec

                         user     system      total        real
  select             0.050000   0.020000   0.070000 (  0.123325)
  rb_thread_select   0.060000   0.010000   0.070000 (  0.124075)

Benchmarks were performed on an _empty_ mysql2_test table to
maximize the relative time for the select(2)-related code path
(vs reading data).  The test was run on Debian Lenny, x86_64 and
a stock 2.6.35.2 Linux kernel.  Hardware was a Core2 Duo @
1.6GHz with the performance CPU governor while on AC power
to eliminate CPU speed fluctuations during the test.
2010-08-18 20:13:13 -07:00
Brian Lopez
cebf9af068 Wrap the MYSQL* again so we can:
1) let mysql_init/mysql_close take care of any/all allocation, thread state and freeing
2) for faster access to the encoding and active state variables for the connection
2010-08-16 02:03:19 -07:00
Lourens Naudé
2609783aeb Avoid INT2NUM overhead when coercing date specific elements for MYSQL_TYPE_TIME + introduce basic infrastructure for measuring GC overhead 2010-08-11 11:25:20 -07:00
Lourens Naudé
d9153b82fc Save on coercion overhead for zero value decimal and float column values 2010-08-11 11:25:20 -07:00
Lourens Naudé
c808e78028 Intern error_number= && sql_state= as well 2010-08-11 11:25:20 -07:00
Lourens Naudé
9a63a587c0 Declare the selector function pointer as per ISO C90 spec + address brian's concern / comment re. rb_thread_alone() 2010-08-11 11:25:20 -07:00
Lourens Naudé
0190457dbd Skip rb_thread_select overhead if we're running in single threaded mode 2010-08-11 11:25:20 -07:00
Lourens Naudé
80810f7e43 Extract a GET_CLIENT mactro to cleanup inline Data_Get_Struct etc. on methods that require client access 2010-08-11 11:25:20 -07:00
Lourens Naudé
f601c3cef8 Skip additional string length access in rb_mysql_client_escape and benchmark escaping "clean" strings as well 2010-08-11 11:25:20 -07:00
Lourens Naudé
931765ee05 Extract a GET_ENCODING macro 2010-08-11 11:25:20 -07:00
Luis Lavena
4c27a1e4fc extconf detect properly mingw. 2010-08-12 02:19:04 +08:00
Brian Lopez
5a9ca9c76f app_timezone defaults to nil 2010-08-09 14:50:58 -07:00
Brian Lopez
b448b98146 move -Wextra to development flags area 2010-08-06 11:19:34 -07:00
Brian Lopez
99af726a58 application_timezone is allowed to be nil 2010-08-06 00:01:09 -07:00
Brian Lopez
ad34357e57 convert :timezone option into two new ones
:database_timezone - the timezone (:utc or :local) Mysql2 will assume time/datetime fields are stored in the db. This modifies what initial timezone your Time objects will be in when creating them from libmysql in C
and
:application_timezone - the timezone (:utc or :local) you'd finally like the Time objects converted to before you get them
2010-08-05 22:50:45 -07:00
Brian Lopez
2514fafa53 add :cast_booleans option for automatically casting tinyint(1) fields into true/false for ruby 2010-08-05 00:39:11 -07:00
Brian Lopez
12c022c8aa move most previously global symbols to static to prevent conflicts (thanks for catching this Eric) 2010-08-04 19:32:14 -07:00
Brian Lopez
2bb8721e84 respect :symbolize_keys option for Mysql2::Result#fields if it's called before the first row is built 2010-08-04 00:54:05 -07:00
Brian Lopez
c0cf2f13a0 let's try that again - libmysql only allows one query be sent at a time per connection, bail early if that's attempted 2010-08-03 20:37:49 -07:00
Brian Lopez
1a70e83a74 Revert "libmysql only allows one query be sent at a time per connection, bail early if that's attempted"
This reverts commit 3ff7baa5f8.
2010-08-03 20:22:44 -07:00
Brian Lopez
3ff7baa5f8 libmysql only allows one query be sent at a time per connection, bail early if that's attempted 2010-08-03 20:21:51 -07:00
Brian Lopez
94ae2a781d no need to carry over options twice as we're already doing it up in rb_mysql_client_async_result 2010-08-03 19:04:30 -07:00
Brian Lopez
fc6c24a20c add support for configuring which timezone Time objects should be created in 2010-08-02 01:20:03 -07:00
Brian Lopez
6142336e59 use a default (year 2000) for TIME field casting to a Time object, like AR does 2010-08-01 20:23:27 -07:00
Brian Lopez
36c243be71 Add cascading options hash at Mysql2::Client.default_query_options, which can be overridden by passing options to Mysql2::Client#query and/or Mysql2::Result#each
Tune up specs, benchmarks and AR adapter to conform
2010-08-01 20:20:48 -07:00
Brian Lopez
c6230c3cec pluck out Mysql2::Client definition into it's own c/h file 2010-07-29 23:25:15 -07:00
Brian Lopez
dd138de8e1 invalidate the file descriptor on close 2010-07-28 11:31:32 -07:00
Brian Lopez
cd1a2bf9ff Revert "force reconnect behavior to true, remove open connection checks since libmysql will handle this for us now"
This reverts commit 70a7298dc3.
2010-07-21 12:13:27 -07:00