Method: Mysql#query
- Defined in:
- ext/mysql_api/mysql.c
#query(sql) ⇒ Object
query(sql)
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 |
# File 'ext/mysql_api/mysql.c', line 743
static VALUE query(VALUE obj, VALUE sql)
{
int loop = 0;
MYSQL* m = GetHandler(obj);
Check_Type(sql, T_STRING);
if (GetMysqlStruct(obj)->connection == Qfalse) {
rb_raise(eMysql, "query: not connected");
}
if (rb_block_given_p()) {
if (mysql_real_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 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);
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;
}
|