1 //
2 // Copyright 1998 CDS Networks, Inc., Medford Oregon
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // 1. Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // 3. All advertising materials mentioning features or use of this software
14 // must display the following acknowledgement:
15 // This product includes software developed by CDS Networks, Inc.
16 // 4. The name of CDS Networks, Inc. may not be used to endorse or promote
17 // products derived from this software without specific prior
18 // written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY CDS NETWORKS, INC. ``AS IS'' AND
21 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 // ARE DISCLAIMED. IN NO EVENT SHALL CDS NETWORKS, INC. BE LIABLE
24 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 // SUCH DAMAGE.
31 //
32
33
34 package com.internetcds.jdbc.tds;
35
36 import java.sql.*;
37
38
39 /***
40 * A ResultSetMetaData object can be used to find out about the types
41 * and properties of the columns in a ResultSet.
42 *
43 * @author Craig Spannring
44 * @version $Id: ResultSetMetaData.java,v 1.1 2007/07/18 07:31:06 dejan Exp $
45 */
46 public class ResultSetMetaData implements java.sql.ResultSetMetaData
47 {
48 public static final String cvsVersion = "$Id: ResultSetMetaData.java,v 1.1 2007/07/18 07:31:06 dejan Exp $";
49
50
51 /***
52 * Does not allow NULL values.
53 */
54 public static final int columnNoNulls = 0;
55
56 /***
57 * Allows NULL values.
58 */
59 public static final int columnNullable = 1;
60
61 /***
62 * Nullability unknown.
63 */
64 public static final int columnNullableUnknown = 2;
65
66
67 private Columns columnsInfo;
68
69
70 private void NotImplemented()
71 throws SQLException
72 {
73
74 throw new SQLException("Not implemented");
75 }
76
77 public ResultSetMetaData(Columns columns_)
78 {
79 columnsInfo = columns_;
80 }
81
82
83 /***
84 * What's a column's table's catalog name?
85 *
86 * @param column the first column is 1, the second is 2, ...
87 * @return column name or "" if not applicable.
88 * @exception SQLException if a database-access error occurs.
89 */
90 public String getCatalogName(int column) throws SQLException
91 {
92 NotImplemented(); return null;
93 }
94
95
96 /***
97 * What's the number of columns in the ResultSet?
98 *
99 * @return the number
100 * @exception SQLException if a database-access error occurs.
101 */
102 public int getColumnCount() throws SQLException
103 {
104 return columnsInfo.getColumnCount();
105 }
106
107
108 /***
109 * What's the column's normal max width in chars?
110 *
111 * @param column the first column is 1, the second is 2, ...
112 * @return max width
113 * @exception SQLException if a database-access error occurs.
114 */
115 public int getColumnDisplaySize(int column) throws SQLException
116 {
117 return columnsInfo.getDisplaySize(column);
118 }
119
120
121 /***
122 * What's the suggested column title for use in printouts and
123 * displays?
124 *
125 * @param column the first column is 1, the second is 2, ...
126 * @return true if so
127 * @exception SQLException if a database-access error occurs.
128 */
129 public String getColumnLabel(int column) throws SQLException
130 {
131 return columnsInfo.getLabel(column);
132 }
133
134
135 /***
136 * What's a column's name?
137 *
138 * @param column the first column is 1, the second is 2, ...
139 * @return column name
140 * @exception SQLException if a database-access error occurs.
141 */
142 public String getColumnName(int column) throws SQLException
143 {
144 return columnsInfo.getName(column);
145 }
146
147
148 /***
149 * What's a column's SQL type?
150 *
151 * @param column the first column is 1, the second is 2, ...
152 * @return SQL type
153 * @exception SQLException if a database-access error occurs.
154 * @see Types
155 */
156 public int getColumnType(int column) throws SQLException
157 {
158 int result;
159 try
160 {
161 result = Tds.cvtNativeTypeToJdbcType(columnsInfo.getType(column),
162 columnsInfo.getDisplaySize(column));
163 }
164 catch(TdsException e)
165 {
166 e.printStackTrace();
167 throw new SQLException("TDS error- " + e.getMessage());
168 }
169 return result;
170 } // getColumnType();
171
172
173 /***
174 * What's a column's data source specific type name?
175 *
176 * @param column the first column is 1, the second is 2, ...
177 * @return type name
178 * @exception SQLException if a database-access error occurs.
179 */
180 public String getColumnTypeName(int column) throws SQLException
181 {
182 String result = null;
183
184 switch (columnsInfo.getType(column))
185 {
186 case Tds.SYBVOID: {result = "VOID"; break;}
187 case Tds.SYBIMAGE: {result = "IMAGE"; break;}
188 case Tds.SYBTEXT: {result = "TEXT"; break;}
189 case Tds.SYBVARBINARY: {result = "VARBINARY"; break;}
190 case Tds.SYBINTN: {result = "INTN"; break;}
191 case Tds.SYBVARCHAR: {result = "VARCHAR"; break;}
192 //Sinisa
193 case Tds.SYBNVARCHAR: {result = "VARCHAR"; break;}
194 case Tds.SYBBINARY: {result = "BINARY"; break;}
195 case Tds.SYBCHAR: {result = "CHAR"; break;}
196 case Tds.SYBINT1: {result = "INT1"; break;}
197 case Tds.SYBBIT: {result = "BIT"; break;}
198 case Tds.SYBINT2: {result = "INT2"; break;}
199 case Tds.SYBINT4: {result = "INT4"; break;}
200 case Tds.SYBDATETIME4: {result = "DATETIME4"; break;}
201 case Tds.SYBREAL: {result = "REAL"; break;}
202 case Tds.SYBMONEY: {result = "MONEY"; break;}
203 case Tds.SYBDATETIME: {result = "DATETIME"; break;}
204 case Tds.SYBFLT8: {result = "FLT8"; break;}
205 case Tds.SYBDECIMAL: {result = "DECIMAL"; break;}
206 case Tds.SYBNUMERIC: {result = "NUMERIC"; break;}
207 case Tds.SYBFLTN: {result = "FLTN"; break;}
208 case Tds.SYBMONEYN: {result = "MONEYN"; break;}
209 case Tds.SYBDATETIMN: {result = "DATETIMN"; break;}
210 case Tds.SYBMONEY4: {result = "MONEY4"; break;}
211 default:
212 {
213 throw new SQLException("Unknown native type for column " + column);
214 }
215 }
216 return result;
217 }
218
219
220 /***
221 * What's a column's number of decimal digits?
222 *
223 * @param column the first column is 1, the second is 2, ...
224 * @return precision
225 * @exception SQLException if a database-access error occurs.
226 */
227 public int getPrecision(int column) throws SQLException
228 {
229 NotImplemented(); return 0;
230 }
231
232
233 /***
234 * What's a column's number of digits to right of the decimal point?
235 *
236 * @param column the first column is 1, the second is 2, ...
237 * @return scale
238 * @exception SQLException if a database-access error occurs.
239 */
240 public int getScale(int column) throws SQLException
241 {
242 return columnsInfo.getScale(column);
243 }
244
245
246 /***
247 * What's a column's table's schema?
248 *
249 * @param column the first column is 1, the second is 2, ...
250 * @return schema name or "" if not applicable
251 * @exception SQLException if a database-access error occurs.
252 */
253 public String getSchemaName(int column) throws SQLException
254 {
255 NotImplemented(); return null;
256 }
257
258
259 /***
260 * What's a column's table name?
261 *
262 * @return table name or "" if not applicable
263 * @exception SQLException if a database-access error occurs.
264 */
265 public String getTableName(int column) throws SQLException
266 {
267 NotImplemented(); return null;
268 }
269
270
271 /***
272 * Is the column automatically numbered, thus read-only?
273 *
274 * @param column the first column is 1, the second is 2, ...
275 * @return true if so
276 * @exception SQLException if a database-access error occurs.
277 */
278 public boolean isAutoIncrement(int column) throws SQLException
279 {
280 return columnsInfo.isAutoIncrement(column);
281 }
282
283
284 /***
285 * Does a column's case matter?
286 *
287 * @param column the first column is 1, the second is 2, ...
288 * @return true if so
289 * @exception SQLException if a database-access error occurs.
290 */
291 public boolean isCaseSensitive(int column) throws SQLException
292 {
293 NotImplemented(); return false;
294 }
295
296
297 /***
298 * Is the column a cash value?
299 *
300 * @param column the first column is 1, the second is 2, ...
301 * @return true if so
302 * @exception SQLException if a database-access error occurs.
303 */
304 public boolean isCurrency(int column) throws SQLException
305 {
306 switch (columnsInfo.getType(column))
307 {
308 case Tds.SYBMONEYN:
309 case Tds.SYBDATETIMN:
310 case Tds.SYBMONEY4:
311 {
312 return true;
313 }
314 default:
315 {
316 return false;
317 }
318 }
319 }
320
321
322 /***
323 * Will a write on the column definitely succeed?
324 *
325 * @param column the first column is 1, the second is 2, ...
326 * @return true if so
327 * @exception SQLException if a database-access error occurs.
328 */
329 public boolean isDefinitelyWritable(int column) throws SQLException
330 {
331 NotImplemented(); return false;
332 }
333
334
335 /***
336 * Can you put a NULL in this column?
337 *
338 * @param column the first column is 1, the second is 2, ...
339 * @return columnNoNulls, columnNullable or columnNullableUnknown
340 * @exception SQLException if a database-access error occurs.
341 */
342 public int isNullable(int column) throws SQLException
343 {
344 return columnsInfo.isNullable(column);
345 }
346
347
348 /***
349 * Is a column definitely not writable?
350 *
351 * @param column the first column is 1, the second is 2, ...
352 * @return true if so
353 * @exception SQLException if a database-access error occurs.
354 */
355 public boolean isReadOnly(int column) throws SQLException
356 {
357 return columnsInfo.isReadOnly(column);
358 }
359
360
361 /***
362 * Can the column be used in a where clause?
363 *
364 * @param column the first column is 1, the second is 2, ...
365 * @return true if so
366 * @exception SQLException if a database-access error occurs.
367 */
368 public boolean isSearchable(int column) throws SQLException
369 {
370 // XXX Is this true? Can all columns be used in a where clause?
371 return true;
372 }
373
374
375 /***
376 * Is the column a signed number?
377 *
378 * @param column the first column is 1, the second is 2, ...
379 * @return true if so
380 * @exception SQLException if a database-access error occurs.
381 */
382 public boolean isSigned(int column) throws SQLException
383 {
384 NotImplemented(); return false;
385 }
386
387
388 /***
389 * Is it possible for a write on the column to succeed?
390 *
391 * @param column the first column is 1, the second is 2, ...
392 * @return true if so
393 * @exception SQLException if a database-access error occurs.
394 */
395 public boolean isWritable(int column) throws SQLException
396 {
397 NotImplemented(); return false;
398 }
399
400 /***
401 * JDBC 2.0
402 *
403 * <p>Returns the fully-qualified name of the Java class whose instances
404 * are manufactured if the method <code>ResultSet.getObject</code>
405 * is called to retrieve a value
406 * from the column. <code>ResultSet.getObject</code> may return a subclass of the
407 * class returned by this method.
408 *
409 * @return the fully-qualified name of the class in the Java programming
410 * language that would be used by the method
411 * <code>ResultSet.getObject</code> to retrieve the value in the specified
412 * column. This is the class name used for custom mapping.
413 * @exception SQLException if a database access error occurs
414 */
415 public String getColumnClassName(int column) throws SQLException
416 {
417 NotImplemented();
418 return null;
419 }
420 }
This page was automatically generated by Maven