Skip to content

Commit 631d8eb

Browse files
committed
Merge branch 'statement_compile'
2 parents e84933b + 8d194ac commit 631d8eb

File tree

8 files changed

+92
-87
lines changed

8 files changed

+92
-87
lines changed

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ environment:
2929
- ruby_version: "200-x64"
3030
- ruby_version: "21"
3131
- ruby_version: "21-x64"
32+
- ruby_version: "22"
33+
- ruby_version: "22-x64"
3234
cache:
3335
- vendor
3436
services:

ext/mysql2/client.c

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static VALUE rb_mysql_client_escape(RB_MYSQL_UNUSED VALUE klass, VALUE str) {
277277
oldLen = RSTRING_LEN(str);
278278
newStr = xmalloc(oldLen*2+1);
279279

280-
newLen = mysql_escape_string((char *)newStr, StringValuePtr(str), oldLen);
280+
newLen = mysql_escape_string((char *)newStr, RSTRING_PTR(str), oldLen);
281281
if (newLen == oldLen) {
282282
/* no need to return a new ruby string if nothing changed */
283283
xfree(newStr);
@@ -326,13 +326,13 @@ static VALUE rb_connect(VALUE self, VALUE user, VALUE pass, VALUE host, VALUE po
326326
VALUE rv;
327327
GET_CLIENT(self);
328328

329-
args.host = NIL_P(host) ? NULL : StringValuePtr(host);
330-
args.unix_socket = NIL_P(socket) ? NULL : StringValuePtr(socket);
331-
args.port = NIL_P(port) ? 0 : NUM2INT(port);
332-
args.user = NIL_P(user) ? NULL : StringValuePtr(user);
333-
args.passwd = NIL_P(pass) ? NULL : StringValuePtr(pass);
334-
args.db = NIL_P(database) ? NULL : StringValuePtr(database);
335-
args.mysql = wrapper->client;
329+
args.host = NIL_P(host) ? NULL : StringValueCStr(host);
330+
args.unix_socket = NIL_P(socket) ? NULL : StringValueCStr(socket);
331+
args.port = NIL_P(port) ? 0 : NUM2INT(port);
332+
args.user = NIL_P(user) ? NULL : StringValueCStr(user);
333+
args.passwd = NIL_P(pass) ? NULL : StringValueCStr(pass);
334+
args.db = NIL_P(database) ? NULL : StringValueCStr(database);
335+
args.mysql = wrapper->client;
336336
args.client_flag = NUM2ULONG(flags);
337337

338338
if (wrapper->connect_timeout)
@@ -663,7 +663,7 @@ static VALUE rb_query(VALUE self, VALUE sql, VALUE current) {
663663
#else
664664
args.sql = sql;
665665
#endif
666-
args.sql_ptr = StringValuePtr(args.sql);
666+
args.sql_ptr = RSTRING_PTR(args.sql);
667667
args.sql_len = RSTRING_LEN(args.sql);
668668
args.wrapper = wrapper;
669669

@@ -717,7 +717,7 @@ static VALUE rb_mysql_client_real_escape(VALUE self, VALUE str) {
717717
oldLen = RSTRING_LEN(str);
718718
newStr = xmalloc(oldLen*2+1);
719719

720-
newLen = mysql_real_escape_string(wrapper->client, (char *)newStr, StringValuePtr(str), oldLen);
720+
newLen = mysql_real_escape_string(wrapper->client, (char *)newStr, RSTRING_PTR(str), oldLen);
721721
if (newLen == oldLen) {
722722
/* no need to return a new ruby string if nothing changed */
723723
xfree(newStr);
@@ -781,17 +781,17 @@ static VALUE _mysql_client_options(VALUE self, int opt, VALUE value) {
781781
break;
782782

783783
case MYSQL_READ_DEFAULT_FILE:
784-
charval = (const char *)StringValuePtr(value);
784+
charval = (const char *)StringValueCStr(value);
785785
retval = charval;
786786
break;
787787

788788
case MYSQL_READ_DEFAULT_GROUP:
789-
charval = (const char *)StringValuePtr(value);
789+
charval = (const char *)StringValueCStr(value);
790790
retval = charval;
791791
break;
792792

793793
case MYSQL_INIT_COMMAND:
794-
charval = (const char *)StringValuePtr(value);
794+
charval = (const char *)StringValueCStr(value);
795795
retval = charval;
796796
break;
797797

@@ -881,14 +881,10 @@ static VALUE rb_mysql_client_server_info(VALUE self) {
881881
* Return the file descriptor number for this client.
882882
*/
883883
static VALUE rb_mysql_client_socket(VALUE self) {
884-
GET_CLIENT(self);
885884
#ifndef _WIN32
886-
{
887-
int fd_set_fd;
888-
REQUIRE_CONNECTED(wrapper);
889-
fd_set_fd = wrapper->client->net.fd;
890-
return INT2NUM(fd_set_fd);
891-
}
885+
GET_CLIENT(self);
886+
REQUIRE_CONNECTED(wrapper);
887+
return INT2NUM(wrapper->client->net.fd);
892888
#else
893889
rb_raise(cMysql2Error, "Raw access to the mysql file descriptor isn't supported on Windows");
894890
#endif
@@ -961,7 +957,7 @@ static VALUE rb_mysql_client_select_db(VALUE self, VALUE db)
961957
REQUIRE_CONNECTED(wrapper);
962958

963959
args.mysql = wrapper->client;
964-
args.db = StringValuePtr(db);
960+
args.db = StringValueCStr(db);
965961

966962
if (rb_thread_call_without_gvl(nogvl_select_db, &args, RUBY_UBF_IO, 0) == Qfalse)
967963
rb_raise_mysql2_error(wrapper);
@@ -1155,11 +1151,11 @@ static VALUE set_ssl_options(VALUE self, VALUE key, VALUE cert, VALUE ca, VALUE
11551151
GET_CLIENT(self);
11561152

11571153
mysql_ssl_set(wrapper->client,
1158-
NIL_P(key) ? NULL : StringValuePtr(key),
1159-
NIL_P(cert) ? NULL : StringValuePtr(cert),
1160-
NIL_P(ca) ? NULL : StringValuePtr(ca),
1161-
NIL_P(capath) ? NULL : StringValuePtr(capath),
1162-
NIL_P(cipher) ? NULL : StringValuePtr(cipher));
1154+
NIL_P(key) ? NULL : StringValueCStr(key),
1155+
NIL_P(cert) ? NULL : StringValueCStr(cert),
1156+
NIL_P(ca) ? NULL : StringValueCStr(ca),
1157+
NIL_P(capath) ? NULL : StringValueCStr(capath),
1158+
NIL_P(cipher) ? NULL : StringValueCStr(cipher));
11631159

11641160
return self;
11651161
}

ext/mysql2/result.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ static rb_encoding *binaryEncoding;
5050
#define MYSQL2_MIN_TIME 62171150401ULL
5151
#endif
5252

53+
#define GET_RESULT(obj) \
54+
mysql2_result_wrapper *wrapper; \
55+
Data_Get_Struct(self, mysql2_result_wrapper, wrapper);
56+
5357
typedef struct {
5458
int symbolizeKeys;
5559
int asArray;
@@ -141,9 +145,8 @@ static void *nogvl_stmt_fetch(void *ptr) {
141145

142146

143147
static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, short int symbolize_keys) {
144-
mysql2_result_wrapper * wrapper;
145148
VALUE rb_field;
146-
GetMysql2Result(self, wrapper);
149+
GET_RESULT(self);
147150

148151
if (wrapper->fields == Qnil) {
149152
wrapper->numberOfFields = mysql_num_fields(wrapper->result);
@@ -231,8 +234,7 @@ static unsigned int msec_char_to_uint(char *msec_char, size_t len)
231234

232235
static void rb_mysql_result_alloc_result_buffers(VALUE self, MYSQL_FIELD *fields) {
233236
unsigned int i;
234-
mysql2_result_wrapper * wrapper;
235-
GetMysql2Result(self, wrapper);
237+
GET_RESULT(self);
236238

237239
if (wrapper->result_buffers != NULL) return;
238240

@@ -309,14 +311,13 @@ static void rb_mysql_result_alloc_result_buffers(VALUE self, MYSQL_FIELD *fields
309311
static VALUE rb_mysql_result_fetch_row_stmt(VALUE self, MYSQL_FIELD * fields, const result_each_args *args)
310312
{
311313
VALUE rowVal;
312-
mysql2_result_wrapper *wrapper;
313314
unsigned int i = 0;
314315

315316
#ifdef HAVE_RUBY_ENCODING_H
316317
rb_encoding *default_internal_enc;
317318
rb_encoding *conn_enc;
318319
#endif
319-
GetMysql2Result(self, wrapper);
320+
GET_RESULT(self);
320321

321322
#ifdef HAVE_RUBY_ENCODING_H
322323
default_internal_enc = rb_default_internal_encoding();
@@ -509,7 +510,6 @@ static VALUE rb_mysql_result_fetch_row_stmt(VALUE self, MYSQL_FIELD * fields, co
509510
static VALUE rb_mysql_result_fetch_row(VALUE self, MYSQL_FIELD * fields, const result_each_args *args)
510511
{
511512
VALUE rowVal;
512-
mysql2_result_wrapper * wrapper;
513513
MYSQL_ROW row;
514514
unsigned int i = 0;
515515
unsigned long * fieldLengths;
@@ -518,7 +518,7 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, MYSQL_FIELD * fields, const r
518518
rb_encoding *default_internal_enc;
519519
rb_encoding *conn_enc;
520520
#endif
521-
GetMysql2Result(self, wrapper);
521+
GET_RESULT(self);
522522

523523
#ifdef HAVE_RUBY_ENCODING_H
524524
default_internal_enc = rb_default_internal_encoding();
@@ -729,12 +729,11 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, MYSQL_FIELD * fields, const r
729729
}
730730

731731
static VALUE rb_mysql_result_fetch_fields(VALUE self) {
732-
mysql2_result_wrapper * wrapper;
733732
unsigned int i = 0;
734733
short int symbolizeKeys = 0;
735734
VALUE defaults;
736735

737-
GetMysql2Result(self, wrapper);
736+
GET_RESULT(self);
738737

739738
defaults = rb_iv_get(self, "@query_options");
740739
Check_Type(defaults, T_HASH);
@@ -760,12 +759,11 @@ static VALUE rb_mysql_result_each_(VALUE self,
760759
VALUE(*fetch_row_func)(VALUE, MYSQL_FIELD *fields, const result_each_args *args),
761760
const result_each_args *args)
762761
{
763-
mysql2_result_wrapper *wrapper;
764762
unsigned long i;
765763
const char *errstr;
766764
MYSQL_FIELD *fields = NULL;
767765

768-
GetMysql2Result(self, wrapper);
766+
GET_RESULT(self);
769767

770768
if (wrapper->is_streaming) {
771769
/* When streaming, we will only yield rows, not return them. */
@@ -850,10 +848,9 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
850848
result_each_args args;
851849
VALUE defaults, opts, block, (*fetch_row_func)(VALUE, MYSQL_FIELD *fields, const result_each_args *args);
852850
ID db_timezone, app_timezone, dbTz, appTz;
853-
mysql2_result_wrapper * wrapper;
854851
int symbolizeKeys, asArray, castBool, cacheRows, cast;
855852

856-
GetMysql2Result(self, wrapper);
853+
GET_RESULT(self);
857854

858855
defaults = rb_iv_get(self, "@query_options");
859856
Check_Type(defaults, T_HASH);
@@ -870,15 +867,15 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
870867
cast = RTEST(rb_hash_aref(opts, sym_cast));
871868

872869
if (wrapper->is_streaming && cacheRows) {
873-
rb_warn("cacheRows is ignored if streaming is true");
870+
rb_warn(":cache_rows is ignored if :stream is true");
874871
}
875872

876873
if (wrapper->stmt && !cacheRows && !wrapper->is_streaming) {
877-
rb_warn("cacheRows is forced for prepared statements (if not streaming)");
874+
rb_warn(":cache_rows is forced for prepared statements (if not streaming)");
878875
}
879876

880877
if (wrapper->stmt && !cast) {
881-
rb_warn("cast is forced for prepared statements");
878+
rb_warn(":cast is forced for prepared statements");
882879
}
883880

884881
dbTz = rb_hash_aref(opts, sym_database_timezone);
@@ -931,9 +928,8 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
931928
}
932929

933930
static VALUE rb_mysql_result_count(VALUE self) {
934-
mysql2_result_wrapper *wrapper;
931+
GET_RESULT(self);
935932

936-
GetMysql2Result(self, wrapper);
937933
if (wrapper->is_streaming) {
938934
/* This is an unsigned long per result.h */
939935
return ULONG2NUM(wrapper->numberOfRows);
@@ -957,7 +953,6 @@ VALUE rb_mysql_result_to_obj(VALUE client, VALUE encoding, VALUE options, MYSQL_
957953
VALUE obj;
958954
mysql2_result_wrapper * wrapper;
959955

960-
961956
obj = Data_Make_Struct(cMysql2Result, mysql2_result_wrapper, rb_mysql_result_mark, rb_mysql_result_free, wrapper);
962957
wrapper->numberOfFields = 0;
963958
wrapper->numberOfRows = 0;

ext/mysql2/result.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ typedef struct {
2525
unsigned long *length;
2626
} mysql2_result_wrapper;
2727

28-
#define GetMysql2Result(obj, sval) (sval = (mysql2_result_wrapper*)DATA_PTR(obj));
29-
3028
#endif

0 commit comments

Comments
 (0)