summaryrefslogtreecommitdiffstats
path: root/sql/src/main/java/SQLite/JDBC2y/JDBCResultSetMetaData.java
blob: 934ca78424535fb4687b49042c8ebaa8983388dc (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package SQLite.JDBC2y;

import java.sql.*;

public class JDBCResultSetMetaData implements java.sql.ResultSetMetaData {

    private JDBCResultSet r;
    
    public JDBCResultSetMetaData(JDBCResultSet r) {
    this.r = r;
    }
 
    public String getCatalogName(int column) throws java.sql.SQLException {
    return null;
    }

    public String getColumnClassName(int column) throws java.sql.SQLException {
    column--;
    if (r != null && r.tr != null) {
        if (column < 0 || column >= r.tr.ncolumns) {
        return null;
        }
        if (r.tr instanceof TableResultX) {
        switch (((TableResultX) r.tr).sql_type[column]) {
        case Types.SMALLINT:    return "java.lang.Short";
        case Types.INTEGER:    return "java.lang.Integer";
        case Types.DOUBLE:    return "java.lang.Double";
        case Types.FLOAT:    return "java.lang.Float";
        case Types.BIGINT:    return "java.lang.Long";
        case Types.DATE:    return "java.sql.Date";
        case Types.TIME:    return "java.sql.Time";
        case Types.TIMESTAMP:    return "java.sql.Timestamp";
        case Types.BINARY:
        case Types.VARBINARY:    return "[B";
        /* defaults to varchar below */
        }
        }
        return "java.lang.String";
    }
    return null;
    }

    public int getColumnCount() throws java.sql.SQLException {
    if (r != null && r.tr != null) {
        return r.tr.ncolumns;
    }
    return 0;
    }

    public int getColumnDisplaySize(int column) throws java.sql.SQLException {
    return 0;
    }

    public String getColumnLabel(int column) throws java.sql.SQLException {
    column--;
    String c = null;
    if (r != null && r.tr != null) {
        if (column < 0 || column >= r.tr.ncolumns) {
        return c;
        }
        c = r.tr.column[column];
    }
    return c;
    }

    public String getColumnName(int column) throws java.sql.SQLException {
    column--;
    String c = null;
    if (r != null && r.tr != null) {
        if (column < 0 || column >= r.tr.ncolumns) {
        return c;
        }
        c = r.tr.column[column];
        if (c != null) {
        int i = c.indexOf('.');
        if (i > 0) {
            return c.substring(i + 1);
        }
        }
    }
    return c;
    }

    public int getColumnType(int column) throws java.sql.SQLException {
    column--;
    if (r != null && r.tr != null) {
        if (column >= 0 && column < r.tr.ncolumns) {
        if (r.tr instanceof TableResultX) {
            return ((TableResultX) r.tr).sql_type[column];
        }
        return Types.VARCHAR;
        }
    }
    throw new SQLException("bad column index");
    }

    public String getColumnTypeName(int column) throws java.sql.SQLException {
    column--;
    if (r != null && r.tr != null) {
        if (column >= 0 && column < r.tr.ncolumns) {
        if (r.tr instanceof TableResultX) {
            switch (((TableResultX) r.tr).sql_type[column]) {
            case Types.SMALLINT:    return "smallint";
            case Types.INTEGER:        return "integer";
            case Types.DOUBLE:        return "double";
            case Types.FLOAT:        return "float";
            case Types.BIGINT:        return "bigint";
            case Types.DATE:        return "date";
            case Types.TIME:        return "time";
            case Types.TIMESTAMP:    return "timestamp";
            case Types.BINARY:        return "binary";
            case Types.VARBINARY:    return "varbinary";
            /* defaults to varchar below */
            }
        }
        return "varchar";
        }
    }
    throw new SQLException("bad column index");
    }

    public int getPrecision(int column) throws java.sql.SQLException {
    return 0;
    }

    public int getScale(int column) throws java.sql.SQLException {
    return 0;
    }

    public String getSchemaName(int column) throws java.sql.SQLException {
    return null;
    }

    public String getTableName(int column) throws java.sql.SQLException {
    column--;
    String c = null;
    if (r != null && r.tr != null) {
        if (column < 0 || column >= r.tr.ncolumns) {
        return c;
        }
        c = r.tr.column[column];
        if (c != null) {
        int i = c.indexOf('.');
        if (i > 0) {
            return c.substring(0, i);
        }
        c = null;
        }
    }
    return c;
    }

    public boolean isAutoIncrement(int column) throws java.sql.SQLException {
    return false;
    }

    public boolean isCaseSensitive(int column) throws java.sql.SQLException {
    return false;
    }

    public boolean isCurrency(int column) throws java.sql.SQLException {
    return false;
    }

    public boolean isDefinitelyWritable(int column) 
    throws java.sql.SQLException {
    return true;
    }

    public int isNullable(int column) throws java.sql.SQLException {
    return columnNullableUnknown;
    }

    public boolean isReadOnly(int column) throws java.sql.SQLException {
    return false;
    }

    public boolean isSearchable(int column) throws java.sql.SQLException {
    return true;
    }

    public boolean isSigned(int column) throws java.sql.SQLException {
    return false;
    }

    public boolean isWritable(int column) throws java.sql.SQLException {
    return true;
    }

    int findColByName(String columnName) throws java.sql.SQLException {
    String c = null;
    if (r != null && r.tr != null) {
        for (int i = 0; i < r.tr.ncolumns; i++) {
        c = r.tr.column[i];
        if (c != null) {
            if (c.compareToIgnoreCase(columnName) == 0) {
            return i + 1;
            }
            int k = c.indexOf('.');
            if (k > 0) {
            c = c.substring(k + 1);
            if (c.compareToIgnoreCase(columnName) == 0) {
                return i + 1;
            }
            }
        }
        c = null;
        }
    }
    throw new SQLException("column " + columnName + " not found");
    }
}