/*
 * call-seq:
 *    res.type( index )
 *
 * Returns the data type associated with the given column number.
 *
 * The integer returned is the internal +OID+ number (in PostgreSQL) of the type.
 * If you have the PostgreSQL source available, you can see the OIDs for every column type in the file <tt>src/include/catalog/pg_type.h</tt>.
 *
 * Alternatively, you can look up the type direcly with:
 *    oid = res.type(2)
 *    typename = conn.exec("select typname from pg_type where oid=#{oid}")
 *
 * <i>Note that there is no *e* in the field name '+typname+'.</i>
 */
static VALUE
pgresult_type(obj, index)
  VALUE obj, index;
{
  PGresult *result;
  int i = NUM2INT(index);
  int type;

  result = get_pgresult(obj);
  if (i < 0 || i >= PQnfields(result)) {
  rb_raise(rb_eArgError,"invalid field number %d", i);
  }
  type = PQftype(result, i);
  return INT2NUM(type);
}