1 /*
2 * CsvJdbc - a JDBC driver for CSV files
3 * Copyright (C) 2001 Jonathan Ackerman
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 */
16 package org.relique.jdbc.csv;
17
18 import java.sql.ResultSetMetaData;
19 import java.sql.SQLException;
20 import java.sql.Types;
21
22 /***
23 *This class implements the ResultSetMetaData interface for the CsvJdbc driver.
24 *
25 * @author Jonathan Ackerman
26 * @author JD Evora
27 * @version $Id: CsvResultSetMetaData.html,v 1.1 2003/05/12 16:19:47 sinisa Exp $
28 */
29 public class CsvResultSetMetaData implements ResultSetMetaData
30 {
31 /*** Default value for getColumnDisplaySize */
32 final static int DISPLAY_SIZE = 20;
33 /*** Names of columns */
34 protected String[] columnNames;
35 /*** Name of table */
36 protected String tableName;
37
38 /***Constructor for the CsvResultSetMetaData object
39 *
40 * @param tableName Name of table
41 * @param columnNames Names of columns in table
42 */
43 CsvResultSetMetaData(String tableName, String[] columnNames)
44 {
45 this.tableName = tableName;
46 this.columnNames = columnNames;
47 }
48
49
50 /***Returns the name of the class for the specified column. Always returns
51 * String.
52 *
53 * @param column The column number
54 * @return The name of the class for the requested column
55 * @exception SQLException Thrown if there was a problem
56 */
57 public String getColumnClassName(int column) throws SQLException
58 {
59 return String.class.getName();
60 }
61
62
63 /*** Returns the number of columns in the table.
64 *
65 * @return The number of columns in the table
66 * @exception SQLException Thrown if there is a a problem
67 */
68 public int getColumnCount() throws SQLException
69 {
70 return columnNames.length;
71 }
72
73
74 /*** Returns the name of the catalog for the specified column. Returns "".
75 *
76 * @param column The column to get the catalog for
77 * @return The catalog name (always "")
78 * @exception SQLException Thrown if there is a problem
79 */
80 public String getCatalogName(int column) throws SQLException
81 {
82 return "";
83 }
84
85
86 /***Returns the display column size for the specified column. Always returns 20.
87 *
88 * @param column The column to get the size of
89 * @return The size of the requested column
90 * @exception SQLException Thrown if there is a problem.
91 */
92 public int getColumnDisplaySize(int column) throws SQLException
93 {
94 return DISPLAY_SIZE;
95 }
96
97
98 /***Gets the auto increment falg for the specfied column.
99 *
100 * @param column The column to get the flag for
101 * @return The autoIncrement flag (always false)
102 * @exception SQLException Thrown if there is a problem
103 */
104 public boolean isAutoIncrement(int column) throws SQLException
105 {
106 return false;
107 }
108
109
110 /***Returns the case sensitivity flag for the specfied column
111 *
112 * @param column The column to return the flag for
113 * @return The caseSensitive flag (always false)
114 * @exception SQLException Thrown if there is a problem
115 */
116 public boolean isCaseSensitive(int column) throws SQLException
117 {
118 //all columns are uppercase
119 return false;
120 }
121
122
123 /*** Returns the searchable flag for the specified column
124 *
125 * @param column the column to return the flag form
126 * @return The searchable flag (always false)
127 * @exception SQLException Thrown if there is a problem
128 */
129 public boolean isSearchable(int column) throws SQLException
130 {
131 // the implementation doesn't support the where clause
132 return false;
133 }
134
135
136 /***Returns the currency flag for the specified column
137 *
138 * @param column The column to get the flag for
139 * @return The currency flag (always false)
140 * @exception SQLException Thrown if there is a problem
141 */
142 public boolean isCurrency(int column) throws SQLException
143 {
144 return false;
145 }
146
147
148 /*** Returns the nullable flag for the specfied column
149 *
150 * @param column The column to return the flag for
151 * @return The nullable flag (always unknown)
152 * @exception SQLException Thrown if there is a problem
153 */
154 public int isNullable(int column) throws SQLException
155 {
156 return ResultSetMetaData.columnNullableUnknown;
157 }
158
159
160 /***Returns the signed flag for the specfied column
161 *
162 * @param column The column to return the flag for
163 * @return The signed flag (always false)
164 * @exception SQLException Thrown if there is a problem
165 */
166 public boolean isSigned(int column) throws SQLException
167 {
168 return false;
169 }
170
171
172 /*** Returns the label for the specified column
173 *
174 * @param column The column to get the label for
175 * @return the label for the specified column
176 * @exception SQLException Thrown if there is a problem
177 */
178 public String getColumnLabel(int column) throws SQLException
179 {
180 // SQL column numbers start at 1
181 return columnNames[column-1];
182 }
183
184
185 /***Returns the name of the specified column
186 *
187 * @param column The column to get the name of
188 * @return The name of the column
189 * @exception SQLException Thrown if there is a problem
190 */
191 public String getColumnName(int column) throws SQLException
192 {
193 // SQL column numbers start at 1
194 return columnNames[column-1];
195 }
196
197
198 /***Comments to be done
199 */
200 public String getSchemaName(int column) throws SQLException
201 {
202 return "";
203 }
204
205
206 /***Comments to be done
207 */
208 public int getPrecision(int column) throws SQLException
209 {
210 // All the fields are text, should this throw an SQLException?
211 return 0;
212 }
213
214
215 /***Comments to be done
216 */
217 public int getScale(int column) throws SQLException
218 {
219 // All the fields are text, should this throw an SQLException?
220 return 0;
221 }
222
223
224 /***Comments to be done
225 */
226 public String getTableName(int column) throws SQLException
227 {
228 return tableName;
229 }
230
231
232 /***Comments to be done
233 */
234 public int getColumnType(int column) throws SQLException
235 {
236 return Types.VARCHAR;
237 }
238
239
240 /***Comments to be done
241 */
242 public String getColumnTypeName(int column) throws SQLException
243 {
244 return String.class.getName();
245 }
246
247
248 /***Comments to be done
249 */
250 public boolean isReadOnly(int column) throws SQLException
251 {
252 return true;
253 }
254
255
256 /***Comments to be done
257 */
258 public boolean isWritable(int column) throws SQLException
259 {
260 return false;
261 }
262
263
264 /***Comments to be done
265 */
266 public boolean isDefinitelyWritable(int column) throws SQLException
267 {
268 return false;
269 }
270
271 }
272
This page automatically generated by Maven