/*
* call-seq:
* res.fieldname( index )
*
* Returns the name of the field (column) corresponding to the index.
*
* res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable")
* puts res.fieldname(2) => 'jim'
* puts res.fieldname(1) => 'biggles'
*
* Equivalent to <tt>res.fields[_index_]</tt>.
*/
static VALUE
pgresult_fieldname(obj, index)
VALUE obj, index;
{
PGresult *result;
int i = NUM2INT(index);
char *name;
result = get_pgresult(obj);
if (i < 0 || i >= PQnfields(result)) {
rb_raise(rb_eArgError,"invalid field number %d", i);
}
name = PQfname(result, i);
return rb_tainted_str_new2(name);
}