public
Rubygem
Description: An enhanced mysql driver with an async interface and threaded access support
Homepage:
Clone URL: git://github.com/oldmoe/mysqlplus.git
Selective enable || disable GC for result retrieval with Mysql#disable_gc = 
true|false
methodmissing (author)
Wed Oct 08 14:11:14 -0700 2008
commit  35d2545c17f385a9cf524bfea39606524d75c009
tree    fc06dc3c76bbaa2008fe6e263eaa0cb81395a026
parent  8e6f300f9db75f07c03049efd00a6b91fe16538d
...
60
61
62
 
63
64
65
...
181
182
183
184
 
185
186
187
...
191
192
193
194
195
 
 
 
196
197
198
...
228
229
230
 
231
232
233
...
646
647
648
649
 
650
651
652
...
656
657
658
659
 
660
661
662
...
750
751
752
753
 
754
755
756
...
766
767
768
769
 
770
771
772
...
788
789
790
791
 
792
793
794
...
859
860
861
 
 
 
 
 
 
 
 
 
 
 
 
 
 
862
863
864
...
1986
1987
1988
1989
 
1990
1991
1992
...
2254
2255
2256
 
 
2257
2258
2259
...
60
61
62
63
64
65
66
...
182
183
184
 
185
186
187
188
...
192
193
194
 
 
195
196
197
198
199
200
...
230
231
232
233
234
235
236
...
649
650
651
 
652
653
654
655
...
659
660
661
 
662
663
664
665
...
753
754
755
 
756
757
758
759
...
769
770
771
 
772
773
774
775
...
791
792
793
 
794
795
796
797
...
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
...
2003
2004
2005
 
2006
2007
2008
2009
...
2271
2272
2273
2274
2275
2276
2277
2278
0
@@ -60,6 +60,7 @@ struct mysql {
0
     MYSQL handler;
0
     char connection;
0
     char query_with_result;
0
+    char gc_disabled;
0
     char blocking;
0
     int async_in_progress;
0
 };
0
@@ -181,7 +182,7 @@ static void mysql_raise(MYSQL* m)
0
     rb_exc_raise(e);
0
 }
0
 
0
-static VALUE mysqlres2obj(MYSQL_RES* res)
0
+static VALUE mysqlres2obj(MYSQL_RES* res, VALUE gc_disabled)
0
 {
0
     VALUE obj;
0
     struct mysql_res* resp;
0
@@ -191,8 +192,9 @@ static VALUE mysqlres2obj(MYSQL_RES* res)
0
     resp->res = res;
0
     resp->freed = Qfalse;
0
     rb_obj_call_init(obj, 0, NULL);
0
-    if (++store_result_count > GC_STORE_RESULT_LIMIT)
0
-  rb_gc();
0
+    if (++store_result_count > GC_STORE_RESULT_LIMIT && gc_disabled == Qfalse){
0
+      rb_gc();
0
+  }
0
     return obj;
0
 }
0
 
0
@@ -228,6 +230,7 @@ static VALUE init(VALUE klass)
0
     mysql_init(&myp->handler);
0
     myp->connection = Qfalse;
0
     myp->query_with_result = Qtrue;
0
+    myp->gc_disabled = Qfalse;
0
     rb_obj_call_init(obj, 0, NULL);
0
     return obj;
0
 }
0
@@ -646,7 +649,7 @@ static VALUE list_fields(int argc, VALUE* argv, VALUE obj)
0
     res = mysql_list_fields(m, StringValuePtr(table), NILorSTRING(field));
0
     if (res == NULL)
0
   mysql_raise(m);
0
-    return mysqlres2obj(res);
0
+    return mysqlres2obj(res, GetMysqlStruct(obj)->gc_disabled);
0
 }
0
 
0
 /*  list_processes()  */
0
@@ -656,7 +659,7 @@ static VALUE list_processes(VALUE obj)
0
     MYSQL_RES* res = mysql_list_processes(m);
0
     if (res == NULL)
0
   mysql_raise(m);
0
-    return mysqlres2obj(res);
0
+    return mysqlres2obj(res, GetMysqlStruct(obj)->gc_disabled);
0
 }
0
 
0
 /*  list_tables(table=nil)  */
0
@@ -750,7 +753,7 @@ static VALUE store_result(VALUE obj)
0
     MYSQL_RES* res = mysql_store_result(m);
0
     if (res == NULL)
0
   mysql_raise(m);
0
-    return mysqlres2obj(res);
0
+    return mysqlres2obj(res, GetMysqlStruct(obj)->gc_disabled);
0
 }
0
 
0
 /*  thread_id()  */
0
@@ -766,7 +769,7 @@ static VALUE use_result(VALUE obj)
0
     MYSQL_RES* res = mysql_use_result(m);
0
     if (res == NULL)
0
   mysql_raise(m);
0
-    return mysqlres2obj(res);
0
+    return mysqlres2obj(res, GetMysqlStruct(obj)->gc_disabled);
0
 }
0
 
0
 static VALUE res_free(VALUE);
0
@@ -788,7 +791,7 @@ static VALUE query(VALUE obj, VALUE sql)
0
     if (mysql_field_count(m) != 0)
0
         mysql_raise(m);
0
       } else {
0
-    VALUE robj = mysqlres2obj(res);
0
+    VALUE robj = mysqlres2obj(res, GetMysqlStruct(obj)->gc_disabled);
0
     rb_ensure(rb_yield, robj, res_free, robj);
0
       }
0
 #if MYSQL_VERSION_ID >= 40101
0
@@ -859,6 +862,20 @@ static VALUE reconnected( VALUE obj ){
0
     return ( current_connection_id == mysql_thread_id( m ) ) ? Qfalse : Qtrue;
0
 }
0
 
0
+/* disable_gc(true|false) */
0
+static VALUE disable_gc_set(VALUE obj, VALUE flag)
0
+{
0
+    if (TYPE(flag) != T_TRUE && TYPE(flag) != T_FALSE)
0
+        rb_raise(rb_eTypeError, "invalid type, required true or false.");
0
+    GetMysqlStruct(obj)->gc_disabled = flag;
0
+    return flag;
0
+}
0
+
0
+/* gc_disabled */
0
+static VALUE gc_disabled( VALUE obj ){
0
+    return GetMysqlStruct(obj)->gc_disabled ? Qtrue: Qfalse;  
0
+}
0
+
0
 static void validate_async_query( VALUE obj )
0
 {
0
     MYSQL* m = GetHandler(obj);
0
@@ -1986,7 +2003,7 @@ static VALUE stmt_result_metadata(VALUE obj)
0
   mysql_stmt_raise(s->stmt);
0
       return Qnil;
0
     }
0
-    return mysqlres2obj(res);
0
+    return mysqlres2obj(res, Qfalse);
0
 }
0
 
0
 /*  row_seek(offset)  */
0
@@ -2254,6 +2271,8 @@ void Init_mysql(void)
0
     rb_define_method(cMysql, "retry?", retry, 0);
0
     rb_define_method(cMysql, "interrupted?", interrupted, 0);
0
     rb_define_method(cMysql, "blocking?", blocking, 0);
0
+    rb_define_method(cMysql, "gc_disabled?", gc_disabled, 0);
0
+    rb_define_method(cMysql, "disable_gc=", disable_gc_set, 1);
0
     rb_define_method(cMysql, "socket", socket, 0);
0
     rb_define_method(cMysql, "refresh", refresh, 1);
0
     rb_define_method(cMysql, "reload", reload, 0);

Comments