Class: Mysql::Result
- Inherits:
-
Object
- Object
- Mysql::Result
- Defined in:
- lib/mysqlplus.rb,
ext/mysql.c
Instance Method Summary collapse
-
#all_hashes(*args) ⇒ Object
all_hashes(with_table=false) – returns an array of hashes, one hash per row.
-
#data_seek(offset) ⇒ Object
data_seek(offset).
-
#each ⇒ Object
each ….
-
#each_hash(*args) ⇒ Object
each_hash(with_table=false) ….
-
#fetch_field ⇒ Object
fetch_field().
-
#fetch_field_direct(nr) ⇒ Object
fetch_field_direct(nr).
-
#fetch_fields ⇒ Object
fetch_fields().
-
#fetch_hash(*args) ⇒ Object
fetch_hash(with_table=false).
-
#fetch_lengths ⇒ Object
fetch_lengths().
-
#fetch_row ⇒ Object
fetch_row().
-
#field_seek(offset) ⇒ Object
field_seek(offset).
-
#field_tell ⇒ Object
field_tell().
-
#free ⇒ Object
free().
-
#num_fields ⇒ Object
num_fields().
-
#num_rows ⇒ Object
num_rows().
-
#row_seek(offset) ⇒ Object
row_seek(offset).
-
#row_tell ⇒ Object
row_tell().
Instance Method Details
#all_hashes(*args) ⇒ Object
all_hashes(with_table=false) – returns an array of hashes, one hash per row
1349 1350 1351 1352 1353 |
# File 'ext/mysql.c', line 1349 def all_hashes rows = [] each_hash { |row| rows << row } rows end |
#data_seek(offset) ⇒ Object
data_seek(offset)
1041 1042 1043 1044 1045 1046 |
# File 'ext/mysql.c', line 1041
static VALUE data_seek(VALUE obj, VALUE offset)
{
check_free(obj);
mysql_data_seek(GetMysqlRes(obj), NUM2INT(offset));
return obj;
}
|
#each ⇒ Object
each …
1327 1328 1329 1330 1331 1332 1333 1334 |
# File 'ext/mysql.c', line 1327
static VALUE each(VALUE obj)
{
VALUE row;
check_free(obj);
while ((row = fetch_row(obj)) != Qnil)
rb_yield(row);
return obj;
}
|
#each_hash(*args) ⇒ Object
each_hash(with_table=false) …
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 |
# File 'ext/mysql.c', line 1337
static VALUE each_hash(int argc, VALUE* argv, VALUE obj)
{
VALUE with_table;
check_free(obj);
rb_scan_args(argc, argv, "01", &with_table);
if (with_table == Qnil)
with_table = Qfalse;
process_all_hashes(obj, with_table, 0, 1);
return obj;
}
|
#fetch_field ⇒ Object
fetch_field()
1049 1050 1051 1052 1053 |
# File 'ext/mysql.c', line 1049
static VALUE fetch_field(VALUE obj)
{
check_free(obj);
return make_field_obj(mysql_fetch_field(GetMysqlRes(obj)));
}
|
#fetch_field_direct(nr) ⇒ Object
fetch_field_direct(nr)
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 |
# File 'ext/mysql.c', line 1074
static VALUE fetch_field_direct(VALUE obj, VALUE nr)
{
MYSQL_RES* res;
unsigned int max;
unsigned int n;
check_free(obj);
res = GetMysqlRes(obj);
max = mysql_num_fields(res);
n = NUM2INT(nr);
if (n >= max)
rb_raise(eMysql, "%d: out of range (max: %d)", n, max-1);
#if MYSQL_VERSION_ID >= 32226
return make_field_obj(mysql_fetch_field_direct(res, n));
#else
return make_field_obj(&mysql_fetch_field_direct(res, n));
#endif
}
|
#fetch_fields ⇒ Object
fetch_fields()
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 |
# File 'ext/mysql.c', line 1056
static VALUE fetch_fields(VALUE obj)
{
MYSQL_RES* res;
MYSQL_FIELD* f;
unsigned int n;
VALUE ret;
unsigned int i;
check_free(obj);
res = GetMysqlRes(obj);
f = mysql_fetch_fields(res);
n = mysql_num_fields(res);
ret = rb_ary_new2(n);
for (i=0; i<n; i++)
rb_ary_store(ret, i, make_field_obj(&f[i]));
return ret;
}
|
#fetch_hash(*args) ⇒ Object
fetch_hash(with_table=false)
1257 1258 1259 1260 1261 1262 1263 1264 1265 |
# File 'ext/mysql.c', line 1257
static VALUE fetch_hash(int argc, VALUE* argv, VALUE obj)
{
VALUE with_table;
check_free(obj);
rb_scan_args(argc, argv, "01", &with_table);
if (with_table == Qnil)
with_table = Qfalse;
return fetch_hash2(obj, with_table);
}
|
#fetch_lengths ⇒ Object
fetch_lengths()
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 |
# File 'ext/mysql.c', line 1093
static VALUE fetch_lengths(VALUE obj)
{
MYSQL_RES* res;
unsigned int n;
unsigned long* lengths;
VALUE ary;
unsigned int i;
check_free(obj);
res = GetMysqlRes(obj);
n = mysql_num_fields(res);
lengths = mysql_fetch_lengths(res);
if (lengths == NULL)
return Qnil;
ary = rb_ary_new2(n);
for (i=0; i<n; i++)
rb_ary_store(ary, i, INT2NUM(lengths[i]));
return ary;
}
|
#fetch_row ⇒ Object
fetch_row()
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 |
# File 'ext/mysql.c', line 1113
static VALUE fetch_row(VALUE obj)
{
MYSQL_RES* res;
unsigned int n;
MYSQL_ROW row;
unsigned long* lengths;
VALUE ary;
unsigned int i;
check_free(obj);
res = GetMysqlRes(obj);
n = mysql_num_fields(res);
row = mysql_fetch_row(res);
lengths = mysql_fetch_lengths(res);
if (row == NULL)
return Qnil;
ary = rb_ary_new2(n);
for (i=0; i<n; i++)
rb_ary_store(ary, i, row[i]? rb_tainted_str_new(row[i], lengths[i]): Qnil);
return ary;
}
|
#field_seek(offset) ⇒ Object
field_seek(offset)
1268 1269 1270 1271 1272 |
# File 'ext/mysql.c', line 1268
static VALUE field_seek(VALUE obj, VALUE offset)
{
check_free(obj);
return INT2NUM(mysql_field_seek(GetMysqlRes(obj), NUM2INT(offset)));
}
|
#field_tell ⇒ Object
field_tell()
1275 1276 1277 1278 1279 |
# File 'ext/mysql.c', line 1275
static VALUE field_tell(VALUE obj)
{
check_free(obj);
return INT2NUM(mysql_field_tell(GetMysqlRes(obj)));
}
|
#free ⇒ Object
free()
1282 1283 1284 1285 1286 1287 1288 1289 1290 |
# File 'ext/mysql.c', line 1282
static VALUE res_free(VALUE obj)
{
struct mysql_res* resp = DATA_PTR(obj);
check_free(obj);
mysql_free_result(resp->res);
resp->freed = Qtrue;
store_result_count--;
return Qnil;
}
|
#num_fields ⇒ Object
num_fields()
1293 1294 1295 1296 1297 |
# File 'ext/mysql.c', line 1293
static VALUE num_fields(VALUE obj)
{
check_free(obj);
return INT2NUM(mysql_num_fields(GetMysqlRes(obj)));
}
|
#num_rows ⇒ Object
num_rows()
1300 1301 1302 1303 1304 |
# File 'ext/mysql.c', line 1300
static VALUE num_rows(VALUE obj)
{
check_free(obj);
return INT2NUM(mysql_num_rows(GetMysqlRes(obj)));
}
|
#row_seek(offset) ⇒ Object
row_seek(offset)
1307 1308 1309 1310 1311 1312 1313 1314 1315 |
# File 'ext/mysql.c', line 1307
static VALUE row_seek(VALUE obj, VALUE offset)
{
MYSQL_ROW_OFFSET prev_offset;
if (CLASS_OF(offset) != cMysqlRowOffset)
rb_raise(rb_eTypeError, "wrong argument type %s (expected Mysql::RowOffset)", rb_obj_classname(offset));
check_free(obj);
prev_offset = mysql_row_seek(GetMysqlRes(obj), DATA_PTR(offset));
return Data_Wrap_Struct(cMysqlRowOffset, 0, NULL, prev_offset);
}
|
#row_tell ⇒ Object
row_tell()
1318 1319 1320 1321 1322 1323 1324 |
# File 'ext/mysql.c', line 1318
static VALUE row_tell(VALUE obj)
{
MYSQL_ROW_OFFSET offset;
check_free(obj);
offset = mysql_row_tell(GetMysqlRes(obj));
return Data_Wrap_Struct(cMysqlRowOffset, 0, NULL, offset);
}
|