KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sqlmagic > tinysql > tinySQLResultSetMetaData


1 /*
2  * tinySQLResultSetMetaData
3  *
4  * This is the tinySQL Result Set Meta Data class.
5  *
6  * A lot of this code is based on or directly taken from
7  * George Reese's (borg@imaginary.com) mSQL driver.
8  *
9  * So, it's probably safe to say:
10  *
11  * Portions of this code Copyright (c) 1996 George Reese
12  *
13  * The rest of it:
14  *
15  * Copyright 1996, Brian C. Jepson
16  * (bjepson@ids.net)
17  * $Author: davis $
18  * $Date: 2004/12/18 21:32:53 $
19  * $Revision: 1.1 $
20  *
21  * This library is free software; you can redistribute it and/or
22  * modify it under the terms of the GNU Lesser General Public
23  * License as published by the Free Software Foundation; either
24  * version 2.1 of the License, or (at your option) any later version.
25  *
26  * This library is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29  * Lesser General Public License for more details.
30  *
31  * You should have received a copy of the GNU Lesser General Public
32  * License along with this library; if not, write to the Free Software
33  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34  *
35  */

36
37 package com.sqlmagic.tinysql;
38
39 import java.sql.SQLException JavaDoc;
40 import java.sql.Types JavaDoc;
41
42 public class tinySQLResultSetMetaData implements java.sql.ResultSetMetaData JavaDoc {
43
44   /**
45    *
46    * The result set.
47    *
48    */

49   private tsResultSet tsql;
50
51   /**
52    *
53    * Constructs a tinySQLResultSet; requires a tsResultSet object
54    * @param result the tsResultSet object
55    *
56    */

57   public tinySQLResultSetMetaData(tsResultSet result) {
58     tsql = result;
59   }
60
61   /**
62    *
63    * Returns the number of columns in this result set.
64    * @see java.sqlResultSetMetaData#getColumnCount
65    * @return number of columns
66    *
67    */

68   public int getColumnCount() throws SQLException JavaDoc {
69     return tsql.numcols();
70   }
71
72   /**
73    *
74    * Is the column an autoincrement (identity, counter) column?
75    * @see java.sql.ResultSetMetaData#isAutoIncrement
76    * @return false - tinySQL does not support autoincrement columns
77    *
78    */

79   public boolean isAutoIncrement(int column) throws SQLException JavaDoc {
80     return false;
81   }
82
83   /**
84    *
85    * Is case significant in column names?
86    * @see java.sql.ResultSetMetaData#isCaseSensitive
87    * @return true
88    *
89    */

90   public boolean isCaseSensitive(int column) throws SQLException JavaDoc {
91     return true;
92   }
93
94   /**
95    *
96    * Can the column be used in a where clause?
97    * @see java.sql.ResultSetMetaData#isSearchable
98    * @return
99    *
100    */

101   public boolean isSearchable(int column) throws SQLException JavaDoc {
102     return true;
103   }
104
105   /**
106    *
107    * Is the column some sort of currency?
108    * @see java.sql.ResultSetMetaData#isCurrency
109    * @return tinySQL doesn't have such things, so it's false
110    *
111    */

112   public boolean isCurrency(int column) throws SQLException JavaDoc {
113     return false;
114   }
115
116   /**
117    *
118    * Determines if the column in question is nullable. tinySQL
119    * does not yet support nulls.
120    * @see java.sql.ResultSetMetaData#isNullable
121    * @return columnNoNulls, columnNullable, or columnNullableUnknown
122    *
123    */

124   public int isNullable(int column) throws SQLException JavaDoc{
125     return columnNoNulls;
126   }
127
128   /**
129    *
130    * All tinySQL integers are signed, so this returns true.
131    * @see java.sql.ResultSetMetaData#isSigned
132    * @return true
133    *
134    */

135   public boolean isSigned(int column) throws SQLException JavaDoc {
136     return true;
137   }
138
139   /**
140    *
141    * Gives the display size for this column.
142    * @see java.sql.ResultSetMetaData#getColumnDisplaySize
143    *
144    */

145   public int getColumnDisplaySize(int column) throws SQLException JavaDoc {
146
147     // get a column object. Remember, tinySQL uses a column
148
// offset of zero, but JDBC columns start numbering at one.
149
// That's why there's a -1 in the columnAtIndex invocation.
150
//
151
tsColumn col = tsql.columnAtIndex(column-1);
152     return col.size;
153
154   }
155
156   /**
157    *
158    * This returns the column name in the form table_name.column_name.
159    * @see java.sql.ResultSetMetaData#getColumnLabel
160    * @param column the column whose label is wanted
161    * @return the fully qualified column name
162    *
163    */

164   public String JavaDoc getColumnLabel(int column)
165        throws SQLException JavaDoc {
166
167     // get the column, return its table and name, separated by a '.'
168
//
169
tsColumn col = tsql.columnAtIndex(column-1);
170     return (col.table + "." + col.name);
171   }
172
173   /**
174    * The name of a given column
175    * @see java.sql.ResultSetMetaData#getColumnName
176    * @param column the column whose name is wanted
177    * @return the name of the requested column
178    */

179   public String JavaDoc getColumnName(int column)
180        throws SQLException JavaDoc {
181
182     // get the column and return its name
183
//
184
int dotAt;
185     String JavaDoc msg;
186     tsColumn col = tsql.columnAtIndex(column-1);
187     if ( col.alias != (String JavaDoc)null ) return col.alias;
188     dotAt = col.name.indexOf(".");
189     if ( dotAt == -1 )
190        return col.name;
191     else return col.name.substring(dotAt+1);
192   }
193
194   /**
195    *
196    * What's the column's schema? This is not applicable to tinySQL,
197    * so it returns an empty string.
198    *
199    */

200   public String JavaDoc getSchemaName(int column)
201        throws SQLException JavaDoc {
202     return "";
203   }
204
205   /**
206    *
207    * What's the column's precision? Use size.
208    *
209    */

210   public int getPrecision(int column)
211        throws SQLException JavaDoc {
212     tsColumn col = tsql.columnAtIndex(column-1);
213     return col.size;
214   }
215
216   /**
217    *
218    * What's a column's number of digits to right of decimal?
219    *
220    */

221   public int getScale(int column) throws SQLException JavaDoc {
222     tsColumn col = tsql.columnAtIndex(column-1);
223     return col.decimalPlaces;
224   }
225
226   /**
227    *
228    * Gives the name of the table to which this column belongs.
229    * @see java.sql.ResultSetMetaData#getTableName
230    * @param column the column of the field this information is needed for
231    * @return the table name
232    *
233    */

234   public String JavaDoc getTableName(int column)
235        throws SQLException JavaDoc {
236
237     // retrieve the column info and return the table name
238
//
239
tsColumn col = tsql.columnAtIndex(column-1);
240     return col.table;
241   }
242
243   /**
244    *
245    * Return the column's table catalog name. Not supported by tinySQL
246    *
247    */

248   public String JavaDoc getCatalogName(int column)
249        throws SQLException JavaDoc {
250     throw new SQLException JavaDoc("tinySQL does not support catalogues.");
251   }
252
253   /**
254    *
255    * Gives the column type using the types in java.sql.Types.
256    * @see java.sqlTypes
257    * @see java.sql.ResultSetMetaData#getColumnType
258    * @exception SQLException thrown for any number of reasons
259    * @param column the column type information is needed on
260    * @return the type as listed in java.sql.Types
261    *
262    */

263   public int getColumnType(int column) throws SQLException JavaDoc {
264
265     // get the column info object
266
//
267
tsColumn col = tsql.columnAtIndex(column-1);
268     return col.type;
269   }
270
271   /**
272    *
273    * Gives the column type as a string.
274    * @see java.sql.ResultSetMetaData#getColumnTypeName
275    * @exception SQLException thrown at you
276    * @param column the column for which the type name is wanted
277    * @return the name of the column type
278    *
279    * @author Thomas Morgner <mgs@sherito.org>: This function does
280    * not properly return type names - everything except INTEGER or
281    * CHAR returns &quot;NULL&quot;
282    */

283   public String JavaDoc getColumnTypeName(int column)
284        throws SQLException JavaDoc {
285
286     // just call getColumnType, and report on what it said
287
//
288
switch(getColumnType(column)) {
289
290     case Types.INTEGER:
291       return "INT";
292
293     case Types.CHAR:
294       return "CHAR";
295
296     case Types.FLOAT:
297       return "FLOAT";
298
299     case Types.DATE:
300       return "DATE";
301     default:
302       return "NULL";
303     }
304   }
305
306   /**
307    *
308    * Is the column definitely not writable? This has no meaning
309    * in tinySQL
310    *
311    */

312   public boolean isReadOnly(int column) throws SQLException JavaDoc {
313     return false;
314   }
315
316   /**
317    *
318    * Is the column potentially writable? This has no meaning
319    * in tinySQL
320    *
321    */

322   public boolean isWritable(int column) throws SQLException JavaDoc {
323     return true;
324   }
325
326   /**
327    *
328    * Is the column definitely writable? This has no meaning
329    * in tinySQL
330    *
331    */

332   public boolean isDefinitelyWritable(int column) throws SQLException JavaDoc {
333     return true;
334   }
335
336     //--------------------------JDBC 2.0-----------------------------------
337

338     /**
339      * JDBC 2.0
340      *
341      * <p>Returns the fully-qualified name of the Java class whose instances
342      * are manufactured if the method <code>ResultSet.getObject</code>
343          * is called to retrieve a value
344      * from the column. <code>ResultSet.getObject</code> may return a subclass of the
345      * class returned by this method.
346          *
347          * @return the fully-qualified name of the class in the Java programming
348          * language that would be used by the method
349          * <code>ResultSet.getObject</code> to retrieve the value in the specified
350          * column. This is the class name used for custom mapping.
351      * @exception SQLException if a database access error occurs
352      */

353     public String JavaDoc getColumnClassName(int column) throws SQLException JavaDoc {
354       throw new SQLException JavaDoc("tinySQL does not support getColumnClassName.");
355     }
356 }
357
358
359
360
361
Popular Tags