summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/org/postgresql/Field.java
blob: 88507311c970cfde3a05cb4b7b0325ed6600b971 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package org.postgresql;

import java.lang.*;
import java.sql.*;
import java.util.*;
import org.postgresql.*;
import org.postgresql.util.*;

/**
 * org.postgresql.Field is a class used to describe fields in a PostgreSQL
 * ResultSet
 */
public class Field
{
	private int length;		// Internal Length of this field
	private int oid;		// OID of the type
	private int mod;		// type modifier of this field
	private String name;		// Name of this field

	private Connection conn;	// Connection Instantation


	/**
	 * Construct a field based on the information fed to it.
	 *
	 * @param conn the connection this field came from
	 * @param name the name of the field
	 * @param oid the OID of the field
	 * @param len the length of the field
	 */
	public Field(Connection conn, String name, int oid, int length, int mod)
	{
		this.conn = conn;
		this.name = name;
		this.oid = oid;
		this.length = length;
		this.mod = mod;
	}

	/**
	 * Constructor without mod parameter.
	 *
	 * @param conn the connection this field came from
	 * @param name the name of the field
	 * @param oid the OID of the field
	 * @param len the length of the field
	 */
	public Field(Connection conn, String name, int oid, int length)
	{
		this(conn, name, oid, length, 0);
	}

	/**
	 * @return the oid of this Field's data type
	 */
	public int getOID()
	{
		return oid;
	}

	/**
	 * @return the mod of this Field's data type
	 */
	public int getMod()
	{
		return mod;
	}

	/**
	 * @return the name of this Field's data type
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * @return the length of this Field's data type
	 */
	public int getLength()
	{
		return length;
	}

	/**
	 * We also need to get the PG type name as returned by the back end.
	 *
	 * @return the String representation of the PG type of this field
	 * @exception SQLException if a database access error occurs
	 */
	public String getPGType() throws SQLException
	{
		return conn.getPGType(oid);
	}

	/**
	 * We also need to get the java.sql.types type.
	 *
	 * @return the int representation of the java.sql.types type of this field
	 * @exception SQLException if a database access error occurs
	 */
	public int getSQLType() throws SQLException
	{
		return conn.getSQLType(oid);
	}

}