~ubuntu-branches/ubuntu/oneiric/libpgjava/oneiric

« back to all changes in this revision

Viewing changes to src/interfaces/jdbc/org/postgresql/core/Field.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2005-04-21 14:25:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050421142511-wibh5vc31fkrorx7
Tags: 7.4.7-3
Built with sources...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * Field.java
 
4
 *     Field is a class used to describe fields in a PostgreSQL ResultSet
 
5
 *
 
6
 * Copyright (c) 2003, PostgreSQL Global Development Group
 
7
 *
 
8
 * IDENTIFICATION
 
9
 *        $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/Field.java,v 1.2.4.1 2004/03/29 17:47:47 barry Exp $
 
10
 *
 
11
 *-------------------------------------------------------------------------
 
12
 */
 
13
package org.postgresql.core;
 
14
 
 
15
import java.sql.*;
 
16
import org.postgresql.core.BaseConnection;
 
17
 
 
18
/*
 
19
 */
 
20
public class Field
 
21
{
 
22
    //Constants for the two V3 protocol data formats
 
23
    public static final int TEXT_FORMAT = 0;
 
24
    public static final int BINARY_FORMAT = 1;
 
25
 
 
26
        private int length;             // Internal Length of this field
 
27
        private int oid;                // OID of the type
 
28
        private int mod;                // type modifier of this field
 
29
        private String name;            // Name of this field
 
30
        private int format = TEXT_FORMAT; // In the V3 protocol each field has a format
 
31
                                        // 0 = text, 1 = binary
 
32
                                        // In the V2 protocol all fields in a
 
33
                                        // binary cursor are binary and all 
 
34
                                        // others are text
 
35
 
 
36
        private BaseConnection conn;    // Connection Instantation
 
37
 
 
38
 
 
39
        /*
 
40
         * Construct a field based on the information fed to it.
 
41
         *
 
42
         * @param conn the connection this field came from
 
43
         * @param name the name of the field
 
44
         * @param oid the OID of the field
 
45
         * @param len the length of the field
 
46
         */
 
47
        public Field(BaseConnection conn, String name, int oid, int length, int mod)
 
48
        {
 
49
                this.conn = conn;
 
50
                this.name = name;
 
51
                this.oid = oid;
 
52
                this.length = length;
 
53
                this.mod = mod;
 
54
        }
 
55
 
 
56
        /*
 
57
         * Constructor without mod parameter.
 
58
         *
 
59
         * @param conn the connection this field came from
 
60
         * @param name the name of the field
 
61
         * @param oid the OID of the field
 
62
         * @param len the length of the field
 
63
         */
 
64
        public Field(BaseConnection conn, String name, int oid, int length)
 
65
        {
 
66
                this(conn, name, oid, length, 0);
 
67
        }
 
68
 
 
69
        /*
 
70
         * @return the oid of this Field's data type
 
71
         */
 
72
        public int getOID()
 
73
        {
 
74
                return oid;
 
75
        }
 
76
 
 
77
        /*
 
78
         * @return the mod of this Field's data type
 
79
         */
 
80
        public int getMod()
 
81
        {
 
82
                return mod;
 
83
        }
 
84
 
 
85
        /*
 
86
         * @return the name of this Field's data type
 
87
         */
 
88
        public String getName()
 
89
        {
 
90
                return name;
 
91
        }
 
92
 
 
93
        /*
 
94
         * @return the length of this Field's data type
 
95
         */
 
96
        public int getLength()
 
97
        {
 
98
                return length;
 
99
        }
 
100
 
 
101
        /*
 
102
         * @return the format of this Field's data (text=0, binary=1)
 
103
         */
 
104
        public int getFormat()
 
105
        {
 
106
                return format;
 
107
        }
 
108
 
 
109
        /*
 
110
         * @param format the format of this Field's data (text=0, binary=1)
 
111
         */
 
112
        public void setFormat(int format)
 
113
        {
 
114
                this.format = format;
 
115
        }
 
116
 
 
117
        /*
 
118
         * We also need to get the PG type name as returned by the back end.
 
119
         *
 
120
         * @return the String representation of the PG type of this field
 
121
         * @exception SQLException if a database access error occurs
 
122
         */
 
123
        public String getPGType() throws SQLException
 
124
        {
 
125
                return conn.getPGType(oid);
 
126
        }
 
127
 
 
128
        /*
 
129
         * We also need to get the java.sql.types type.
 
130
         *
 
131
         * @return the int representation of the java.sql.types type of this field
 
132
         * @exception SQLException if a database access error occurs
 
133
         */
 
134
        public int getSQLType() throws SQLException
 
135
        {
 
136
                return conn.getSQLType(oid);
 
137
        }
 
138
 
 
139
}