/*
 * call-seq:
 *    res.fieldnum( name )
 *
 * Returns the index of the field specified by the string _name_.
 *
 *   res=conn.exec("SELECT foo,bar AS biggles,jim,jam FROM mytable;")
 *   puts res.fieldnum('foo') => 0
 *
 * Raises an ArgumentError if the specified _name_ isn't one of the field names;
 * raises a TypeError if _name_ is not a String.
 */
static VALUE
pgresult_fieldnum(obj, name)
  VALUE obj, name;
{
  int n;
  
  Check_Type(name, T_STRING);
  
  n = PQfnumber(get_pgresult(obj), STR2CSTR(name));
  if (n == -1) {
  rb_raise(rb_eArgError,"Unknown field: %s", STR2CSTR(name));
  }
  return INT2NUM(n);
}