1 | /* |
2 | Copyright (C) 2002-2004 MySQL AB |
3 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of version 2 of the GNU General Public License as |
6 | published by the Free Software Foundation. |
7 | |
8 | There are special exceptions to the terms and conditions of the GPL |
9 | as it is applied to this software. View the full text of the |
10 | exception in file EXCEPTIONS-CONNECTOR-J in the directory of this |
11 | software distribution. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | |
22 | |
23 | |
24 | */ |
25 | package com.mysql.jdbc; |
26 | |
27 | import java.sql.SQLException; |
28 | import java.sql.Types; |
29 | |
30 | /** |
31 | * A ResultSetMetaData object can be used to find out about the types and |
32 | * properties of the columns in a ResultSet |
33 | * |
34 | * @author Mark Matthews |
35 | * @version $Id: ResultSetMetaData.java,v 1.1.2.1 2005/05/13 18:58:38 mmatthews |
36 | * Exp $ |
37 | * |
38 | * @see java.sql.ResultSetMetaData |
39 | */ |
40 | public class ResultSetMetaData implements java.sql.ResultSetMetaData { |
41 | private static int clampedGetLength(Field f) { |
42 | long fieldLength = f.getLength(); |
43 | |
44 | if (fieldLength > Integer.MAX_VALUE) { |
45 | fieldLength = Integer.MAX_VALUE; |
46 | } |
47 | |
48 | return (int) fieldLength; |
49 | } |
50 | |
51 | /** |
52 | * Checks if the SQL Type is a Decimal/Number Type |
53 | * |
54 | * @param type |
55 | * SQL Type |
56 | * |
57 | * @return ... |
58 | */ |
59 | private static final boolean isDecimalType(int type) { |
60 | switch (type) { |
61 | case Types.BIT: |
62 | case Types.TINYINT: |
63 | case Types.SMALLINT: |
64 | case Types.INTEGER: |
65 | case Types.BIGINT: |
66 | case Types.FLOAT: |
67 | case Types.REAL: |
68 | case Types.DOUBLE: |
69 | case Types.NUMERIC: |
70 | case Types.DECIMAL: |
71 | return true; |
72 | } |
73 | |
74 | return false; |
75 | } |
76 | |
77 | Field[] fields; |
78 | |
79 | /** |
80 | * Initialise for a result with a tuple set and a field descriptor set |
81 | * |
82 | * @param fields |
83 | * the array of field descriptors |
84 | */ |
85 | public ResultSetMetaData(Field[] fields) { |
86 | this.fields = fields; |
87 | } |
88 | |
89 | /** |
90 | * What's a column's table's catalog name? |
91 | * |
92 | * @param column |
93 | * the first column is 1, the second is 2... |
94 | * |
95 | * @return catalog name, or "" if not applicable |
96 | * |
97 | * @throws SQLException |
98 | * if a database access error occurs |
99 | */ |
100 | public String getCatalogName(int column) throws SQLException { |
101 | Field f = getField(column); |
102 | |
103 | String database = f.getDatabaseName(); |
104 | |
105 | return (database == null) ? "" : database; //$NON-NLS-1$ |
106 | } |
107 | |
108 | /** |
109 | * What's the Java character encoding name for the given column? |
110 | * |
111 | * @param column |
112 | * the first column is 1, the second is 2, etc. |
113 | * |
114 | * @return the Java character encoding name for the given column, or null if |
115 | * no Java character encoding maps to the MySQL character set for |
116 | * the given column. |
117 | * |
118 | * @throws SQLException |
119 | * if an invalid column index is given. |
120 | */ |
121 | public String getColumnCharacterEncoding(int column) throws SQLException { |
122 | String mysqlName = getColumnCharacterSet(column); |
123 | |
124 | String javaName = null; |
125 | |
126 | if (mysqlName != null) { |
127 | javaName = CharsetMapping.getJavaEncodingForMysqlEncoding( |
128 | mysqlName, null); |
129 | } |
130 | |
131 | return javaName; |
132 | } |
133 | |
134 | /** |
135 | * What's the MySQL character set name for the given column? |
136 | * |
137 | * @param column |
138 | * the first column is 1, the second is 2, etc. |
139 | * |
140 | * @return the MySQL character set name for the given column |
141 | * |
142 | * @throws SQLException |
143 | * if an invalid column index is given. |
144 | */ |
145 | public String getColumnCharacterSet(int column) throws SQLException { |
146 | return getField(column).getCharacterSet(); |
147 | } |
148 | |
149 | // --------------------------JDBC 2.0----------------------------------- |
150 | |
151 | /** |
152 | * Whats the number of columns in the ResultSet? |
153 | * |
154 | * @return the number |
155 | * |
156 | * @throws SQLException |
157 | * if a database access error occurs |
158 | */ |
159 | public int getColumnCount() throws SQLException { |
160 | return this.fields.length; |
161 | } |
162 | |
163 | /** |
164 | * What is the column's normal maximum width in characters? |
165 | * |
166 | * @param column |
167 | * the first column is 1, the second is 2, etc. |
168 | * |
169 | * @return the maximum width |
170 | * |
171 | * @throws SQLException |
172 | * if a database access error occurs |
173 | */ |
174 | public int getColumnDisplaySize(int column) throws SQLException { |
175 | Field f = getField(column); |
176 | |
177 | int lengthInBytes = clampedGetLength(f); |
178 | |
179 | return lengthInBytes / f.getMaxBytesPerCharacter(); |
180 | } |
181 | |
182 | /** |
183 | * What is the suggested column title for use in printouts and displays? |
184 | * |
185 | * @param column |
186 | * the first column is 1, the second is 2, etc. |
187 | * |
188 | * @return the column label |
189 | * |
190 | * @throws SQLException |
191 | * if a database access error occurs |
192 | */ |
193 | public String getColumnLabel(int column) throws SQLException { |
194 | return getColumnName(column); |
195 | } |
196 | |
197 | /** |
198 | * What's a column's name? |
199 | * |
200 | * @param column |
201 | * the first column is 1, the second is 2, etc. |
202 | * |
203 | * @return the column name |
204 | * |
205 | * @throws SQLException |
206 | * if a databvase access error occurs |
207 | */ |
208 | public String getColumnName(int column) throws SQLException { |
209 | return getField(column).getName(); |
210 | } |
211 | |
212 | /** |
213 | * What is a column's SQL Type? (java.sql.Type int) |
214 | * |
215 | * @param column |
216 | * the first column is 1, the second is 2, etc. |
217 | * |
218 | * @return the java.sql.Type value |
219 | * |
220 | * @throws SQLException |
221 | * if a database access error occurs |
222 | * |
223 | * @see java.sql.Types |
224 | */ |
225 | public int getColumnType(int column) throws SQLException { |
226 | return getField(column).getSQLType(); |
227 | } |
228 | |
229 | /** |
230 | * Whats is the column's data source specific type name? |
231 | * |
232 | * @param column |
233 | * the first column is 1, the second is 2, etc. |
234 | * |
235 | * @return the type name |
236 | * |
237 | * @throws SQLException |
238 | * if a database access error occurs |
239 | */ |
240 | public String getColumnTypeName(int column) throws java.sql.SQLException { |
241 | Field field = getField(column); |
242 | |
243 | int mysqlType = field.getMysqlType(); |
244 | |
245 | switch (mysqlType) { |
246 | case MysqlDefs.FIELD_TYPE_BIT: |
247 | return "BIT"; |
248 | case MysqlDefs.FIELD_TYPE_DECIMAL: |
249 | case MysqlDefs.FIELD_TYPE_NEW_DECIMAL: |
250 | return field.isUnsigned() ? "DECIMAL UNSIGNED" : "DECIMAL"; |
251 | |
252 | case MysqlDefs.FIELD_TYPE_TINY: |
253 | return field.isUnsigned() ? "TINYINT UNSIGNED" : "TINYINT"; |
254 | |
255 | case MysqlDefs.FIELD_TYPE_SHORT: |
256 | return field.isUnsigned() ? "SMALLINT UNSIGNED" : "SMALLINT"; |
257 | |
258 | case MysqlDefs.FIELD_TYPE_LONG: |
259 | return field.isUnsigned() ? "INTEGER UNSIGNED" : "INTEGER"; |
260 | |
261 | case MysqlDefs.FIELD_TYPE_FLOAT: |
262 | return field.isUnsigned() ? "FLOAT UNSIGNED" : "FLOAT"; |
263 | |
264 | case MysqlDefs.FIELD_TYPE_DOUBLE: |
265 | return field.isUnsigned() ? "DOUBLE UNSIGNED" : "DOUBLE"; |
266 | |
267 | case MysqlDefs.FIELD_TYPE_NULL: |
268 | return "NULL"; //$NON-NLS-1$ |
269 | |
270 | case MysqlDefs.FIELD_TYPE_TIMESTAMP: |
271 | return "TIMESTAMP"; //$NON-NLS-1$ |
272 | |
273 | case MysqlDefs.FIELD_TYPE_LONGLONG: |
274 | return field.isUnsigned() ? "BIGINT UNSIGNED" : "BIGINT"; |
275 | |
276 | case MysqlDefs.FIELD_TYPE_INT24: |
277 | return field.isUnsigned() ? "MEDIUMINT UNSIGNED" : "MEDIUMINT"; |
278 | |
279 | case MysqlDefs.FIELD_TYPE_DATE: |
280 | return "DATE"; //$NON-NLS-1$ |
281 | |
282 | case MysqlDefs.FIELD_TYPE_TIME: |
283 | return "TIME"; //$NON-NLS-1$ |
284 | |
285 | case MysqlDefs.FIELD_TYPE_DATETIME: |
286 | return "DATETIME"; //$NON-NLS-1$ |
287 | |
288 | case MysqlDefs.FIELD_TYPE_TINY_BLOB: |
289 | return "TINYBLOB"; //$NON-NLS-1$ |
290 | |
291 | case MysqlDefs.FIELD_TYPE_MEDIUM_BLOB: |
292 | return "MEDIUMBLOB"; //$NON-NLS-1$ |
293 | |
294 | case MysqlDefs.FIELD_TYPE_LONG_BLOB: |
295 | return "LONGBLOB"; //$NON-NLS-1$ |
296 | |
297 | case MysqlDefs.FIELD_TYPE_BLOB: |
298 | if (getField(column).isBinary()) { |
299 | return "BLOB";//$NON-NLS-1$ |
300 | } |
301 | |
302 | return "TEXT";//$NON-NLS-1$ |
303 | |
304 | case MysqlDefs.FIELD_TYPE_VARCHAR: |
305 | return "VARCHAR"; //$NON-NLS-1$ |
306 | |
307 | case MysqlDefs.FIELD_TYPE_VAR_STRING: |
308 | return "VARCHAR"; //$NON-NLS-1$ |
309 | |
310 | case MysqlDefs.FIELD_TYPE_STRING: |
311 | return "CHAR"; //$NON-NLS-1$ |
312 | |
313 | case MysqlDefs.FIELD_TYPE_ENUM: |
314 | return "ENUM"; //$NON-NLS-1$ |
315 | |
316 | case MysqlDefs.FIELD_TYPE_YEAR: |
317 | return "YEAR"; // $NON_NLS-1$ |
318 | |
319 | case MysqlDefs.FIELD_TYPE_SET: |
320 | return "SET"; //$NON-NLS-1$ |
321 | |
322 | default: |
323 | return "UNKNOWN"; //$NON-NLS-1$ |
324 | } |
325 | } |
326 | |
327 | /** |
328 | * Returns the field instance for the given column index |
329 | * |
330 | * @param columnIndex |
331 | * the column number to retrieve a field instance for |
332 | * |
333 | * @return the field instance for the given column index |
334 | * |
335 | * @throws SQLException |
336 | * if an error occurs |
337 | */ |
338 | protected Field getField(int columnIndex) throws SQLException { |
339 | if ((columnIndex < 1) || (columnIndex > this.fields.length)) { |
340 | throw new SQLException(Messages.getString("ResultSetMetaData.46"), //$NON-NLS-1$ |
341 | SQLError.SQL_STATE_INVALID_COLUMN_NUMBER); |
342 | } |
343 | |
344 | return this.fields[columnIndex - 1]; |
345 | } |
346 | |
347 | /** |
348 | * What is a column's number of decimal digits. |
349 | * |
350 | * @param column |
351 | * the first column is 1, the second is 2... |
352 | * |
353 | * @return the precision |
354 | * |
355 | * @throws SQLException |
356 | * if a database access error occurs |
357 | */ |
358 | public int getPrecision(int column) throws SQLException { |
359 | Field f = getField(column); |
360 | |
361 | // if (f.getMysqlType() == MysqlDefs.FIELD_TYPE_NEW_DECIMAL) { |
362 | // return f.getLength(); |
363 | // } |
364 | |
365 | if (isDecimalType(f.getSQLType())) { |
366 | if (f.getDecimals() > 0) { |
367 | return clampedGetLength(f) - 1 + f.getPrecisionAdjustFactor(); |
368 | } |
369 | |
370 | return clampedGetLength(f) + f.getPrecisionAdjustFactor(); |
371 | } |
372 | |
373 | switch (f.getMysqlType()) { |
374 | case MysqlDefs.FIELD_TYPE_TINY_BLOB: |
375 | case MysqlDefs.FIELD_TYPE_BLOB: |
376 | case MysqlDefs.FIELD_TYPE_MEDIUM_BLOB: |
377 | case MysqlDefs.FIELD_TYPE_LONG_BLOB: |
378 | return clampedGetLength(f); // this may change in the future |
379 | // for now, the server only |
380 | // returns FIELD_TYPE_BLOB for _all_ |
381 | // BLOB types, but varying lengths |
382 | // indicating the _maximum_ size |
383 | // for each BLOB type. |
384 | default: |
385 | return clampedGetLength(f) / f.getMaxBytesPerCharacter(); |
386 | |
387 | } |
388 | } |
389 | |
390 | /** |
391 | * What is a column's number of digits to the right of the decimal point? |
392 | * |
393 | * @param column |
394 | * the first column is 1, the second is 2... |
395 | * |
396 | * @return the scale |
397 | * |
398 | * @throws SQLException |
399 | * if a database access error occurs |
400 | */ |
401 | public int getScale(int column) throws SQLException { |
402 | Field f = getField(column); |
403 | |
404 | if (isDecimalType(f.getSQLType())) { |
405 | return f.getDecimals(); |
406 | } |
407 | |
408 | return 0; |
409 | } |
410 | |
411 | /** |
412 | * What is a column's table's schema? This relies on us knowing the table |
413 | * name. The JDBC specification allows us to return "" if this is not |
414 | * applicable. |
415 | * |
416 | * @param column |
417 | * the first column is 1, the second is 2... |
418 | * |
419 | * @return the Schema |
420 | * |
421 | * @throws SQLException |
422 | * if a database access error occurs |
423 | */ |
424 | public String getSchemaName(int column) throws SQLException { |
425 | return ""; //$NON-NLS-1$ |
426 | } |
427 | |
428 | /** |
429 | * Whats a column's table's name? |
430 | * |
431 | * @param column |
432 | * the first column is 1, the second is 2... |
433 | * |
434 | * @return column name, or "" if not applicable |
435 | * |
436 | * @throws SQLException |
437 | * if a database access error occurs |
438 | */ |
439 | public String getTableName(int column) throws SQLException { |
440 | return getField(column).getTableName(); |
441 | } |
442 | |
443 | /** |
444 | * Is the column automatically numbered (and thus read-only) |
445 | * |
446 | * @param column |
447 | * the first column is 1, the second is 2... |
448 | * |
449 | * @return true if so |
450 | * |
451 | * @throws SQLException |
452 | * if a database access error occurs |
453 | */ |
454 | public boolean isAutoIncrement(int column) throws SQLException { |
455 | Field f = getField(column); |
456 | |
457 | return f.isAutoIncrement(); |
458 | } |
459 | |
460 | /** |
461 | * Does a column's case matter? |
462 | * |
463 | * @param column |
464 | * the first column is 1, the second is 2... |
465 | * |
466 | * @return true if so |
467 | * |
468 | * @throws java.sql.SQLException |
469 | * if a database access error occurs |
470 | */ |
471 | public boolean isCaseSensitive(int column) throws java.sql.SQLException { |
472 | Field field = getField(column); |
473 | |
474 | int sqlType = field.getSQLType(); |
475 | |
476 | switch (sqlType) { |
477 | case Types.BIT: |
478 | case Types.TINYINT: |
479 | case Types.SMALLINT: |
480 | case Types.INTEGER: |
481 | case Types.BIGINT: |
482 | case Types.FLOAT: |
483 | case Types.REAL: |
484 | case Types.DOUBLE: |
485 | case Types.DATE: |
486 | case Types.TIME: |
487 | case Types.TIMESTAMP: |
488 | return false; |
489 | |
490 | case Types.CHAR: |
491 | case Types.VARCHAR: |
492 | case Types.LONGVARCHAR: |
493 | |
494 | if (field.isBinary()) { |
495 | return true; |
496 | } |
497 | |
498 | String collationName = field.getCollation(); |
499 | |
500 | return ((collationName != null) && !collationName.endsWith("_ci")); |
501 | |
502 | default: |
503 | return true; |
504 | } |
505 | } |
506 | |
507 | /** |
508 | * Is the column a cash value? |
509 | * |
510 | * @param column |
511 | * the first column is 1, the second is 2... |
512 | * |
513 | * @return true if its a cash column |
514 | * |
515 | * @throws SQLException |
516 | * if a database access error occurs |
517 | */ |
518 | public boolean isCurrency(int column) throws SQLException { |
519 | return false; |
520 | } |
521 | |
522 | /** |
523 | * Will a write on this column definately succeed? |
524 | * |
525 | * @param column |
526 | * the first column is 1, the second is 2, etc.. |
527 | * |
528 | * @return true if so |
529 | * |
530 | * @throws SQLException |
531 | * if a database access error occurs |
532 | */ |
533 | public boolean isDefinitelyWritable(int column) throws SQLException { |
534 | return isWritable(column); |
535 | } |
536 | |
537 | /** |
538 | * Can you put a NULL in this column? |
539 | * |
540 | * @param column |
541 | * the first column is 1, the second is 2... |
542 | * |
543 | * @return one of the columnNullable values |
544 | * |
545 | * @throws SQLException |
546 | * if a database access error occurs |
547 | */ |
548 | public int isNullable(int column) throws SQLException { |
549 | if (!getField(column).isNotNull()) { |
550 | return java.sql.ResultSetMetaData.columnNullable; |
551 | } |
552 | |
553 | return java.sql.ResultSetMetaData.columnNoNulls; |
554 | } |
555 | |
556 | /** |
557 | * Is the column definitely not writable? |
558 | * |
559 | * @param column |
560 | * the first column is 1, the second is 2, etc. |
561 | * |
562 | * @return true if so |
563 | * |
564 | * @throws SQLException |
565 | * if a database access error occurs |
566 | */ |
567 | public boolean isReadOnly(int column) throws SQLException { |
568 | return getField(column).isReadOnly(); |
569 | } |
570 | |
571 | /** |
572 | * Can the column be used in a WHERE clause? Basically for this, I split the |
573 | * functions into two types: recognised types (which are always useable), |
574 | * and OTHER types (which may or may not be useable). The OTHER types, for |
575 | * now, I will assume they are useable. We should really query the catalog |
576 | * to see if they are useable. |
577 | * |
578 | * @param column |
579 | * the first column is 1, the second is 2... |
580 | * |
581 | * @return true if they can be used in a WHERE clause |
582 | * |
583 | * @throws SQLException |
584 | * if a database access error occurs |
585 | */ |
586 | public boolean isSearchable(int column) throws SQLException { |
587 | return true; |
588 | } |
589 | |
590 | /** |
591 | * Is the column a signed number? |
592 | * |
593 | * @param column |
594 | * the first column is 1, the second is 2... |
595 | * |
596 | * @return true if so |
597 | * |
598 | * @throws SQLException |
599 | * if a database access error occurs |
600 | */ |
601 | public boolean isSigned(int column) throws SQLException { |
602 | Field f = getField(column); |
603 | int sqlType = f.getSQLType(); |
604 | |
605 | switch (sqlType) { |
606 | case Types.TINYINT: |
607 | case Types.SMALLINT: |
608 | case Types.INTEGER: |
609 | case Types.BIGINT: |
610 | case Types.FLOAT: |
611 | case Types.REAL: |
612 | case Types.DOUBLE: |
613 | case Types.NUMERIC: |
614 | case Types.DECIMAL: |
615 | return !f.isUnsigned(); |
616 | |
617 | case Types.DATE: |
618 | case Types.TIME: |
619 | case Types.TIMESTAMP: |
620 | return false; |
621 | |
622 | default: |
623 | return false; |
624 | } |
625 | } |
626 | |
627 | // ********************************************************************* |
628 | // |
629 | // END OF PUBLIC INTERFACE |
630 | // |
631 | // ********************************************************************* |
632 | |
633 | /** |
634 | * Is it possible for a write on the column to succeed? |
635 | * |
636 | * @param column |
637 | * the first column is 1, the second is 2, etc. |
638 | * |
639 | * @return true if so |
640 | * |
641 | * @throws SQLException |
642 | * if a database access error occurs |
643 | */ |
644 | public boolean isWritable(int column) throws SQLException { |
645 | return !isReadOnly(column); |
646 | } |
647 | |
648 | /** |
649 | * Returns a string representation of this object |
650 | * |
651 | * @return ... |
652 | */ |
653 | public String toString() { |
654 | StringBuffer toStringBuf = new StringBuffer(); |
655 | toStringBuf.append(super.toString()); |
656 | toStringBuf.append(" - Field level information: "); //$NON-NLS-1$ |
657 | |
658 | for (int i = 0; i < this.fields.length; i++) { |
659 | toStringBuf.append("\n\t"); //$NON-NLS-1$ |
660 | toStringBuf.append(this.fields[i].toString()); |
661 | } |
662 | |
663 | return toStringBuf.toString(); |
664 | } |
665 | |
666 | static String getClassNameForJavaType(int javaType, |
667 | boolean isUnsigned, int mysqlTypeIfKnown, |
668 | boolean isBinaryOrBlob, |
669 | boolean isOpaqueBinary) { |
670 | switch (javaType) { |
671 | case Types.BIT: |
672 | case Types.BOOLEAN: |
673 | return "java.lang.Boolean"; //$NON-NLS-1$ |
674 | |
675 | case Types.TINYINT: |
676 | |
677 | if (isUnsigned) { |
678 | return "java.lang.Integer"; //$NON-NLS-1$ |
679 | } |
680 | |
681 | return "java.lang.Integer"; //$NON-NLS-1$ |
682 | |
683 | case Types.SMALLINT: |
684 | |
685 | if (isUnsigned) { |
686 | return "java.lang.Integer"; //$NON-NLS-1$ |
687 | } |
688 | |
689 | return "java.lang.Integer"; //$NON-NLS-1$ |
690 | |
691 | case Types.INTEGER: |
692 | |
693 | if (!isUnsigned || |
694 | mysqlTypeIfKnown == MysqlDefs.FIELD_TYPE_INT24) { |
695 | return "java.lang.Integer"; //$NON-NLS-1$ |
696 | } |
697 | |
698 | return "java.lang.Long"; //$NON-NLS-1$ |
699 | |
700 | case Types.BIGINT: |
701 | |
702 | if (!isUnsigned) { |
703 | return "java.lang.Long"; //$NON-NLS-1$ |
704 | } |
705 | |
706 | return "java.math.BigInteger"; //$NON-NLS-1$ |
707 | |
708 | case Types.DECIMAL: |
709 | case Types.NUMERIC: |
710 | return "java.math.BigDecimal"; //$NON-NLS-1$ |
711 | |
712 | case Types.REAL: |
713 | return "java.lang.Float"; //$NON-NLS-1$ |
714 | |
715 | case Types.FLOAT: |
716 | case Types.DOUBLE: |
717 | return "java.lang.Double"; //$NON-NLS-1$ |
718 | |
719 | case Types.CHAR: |
720 | case Types.VARCHAR: |
721 | case Types.LONGVARCHAR: |
722 | if (!isOpaqueBinary) { |
723 | return "java.lang.String"; //$NON-NLS-1$ |
724 | } |
725 | |
726 | return "[B"; |
727 | |
728 | case Types.BINARY: |
729 | case Types.VARBINARY: |
730 | case Types.LONGVARBINARY: |
731 | |
732 | if (mysqlTypeIfKnown == MysqlDefs.FIELD_TYPE_GEOMETRY) { |
733 | return "[B"; |
734 | } else if (isBinaryOrBlob) { |
735 | return "[B"; |
736 | } else { |
737 | return "java.lang.String"; |
738 | } |
739 | |
740 | case Types.DATE: |
741 | return "java.sql.Date"; //$NON-NLS-1$ |
742 | |
743 | case Types.TIME: |
744 | return "java.sql.Time"; //$NON-NLS-1$ |
745 | |
746 | case Types.TIMESTAMP: |
747 | return "java.sql.Timestamp"; //$NON-NLS-1$ |
748 | |
749 | default: |
750 | return "java.lang.Object"; //$NON-NLS-1$ |
751 | } |
752 | } |
753 | |
754 | // --------------------------JDBC 2.0----------------------------------- |
755 | |
756 | /** |
757 | * JDBC 2.0 |
758 | * |
759 | * <p> |
760 | * Return the fully qualified name of the Java class whose instances are |
761 | * manufactured if ResultSet.getObject() is called to retrieve a value from |
762 | * the column. ResultSet.getObject() may return a subClass of the class |
763 | * returned by this method. |
764 | * </p> |
765 | * |
766 | * @param column |
767 | * the column number to retrieve information for |
768 | * |
769 | * @return the fully qualified name of the Java class whose instances are |
770 | * manufactured if ResultSet.getObject() is called to retrieve a |
771 | * value from the column. |
772 | * |
773 | * @throws SQLException |
774 | * if an error occurs |
775 | */ |
776 | public String getColumnClassName(int column) throws SQLException { |
777 | Field f = getField(column); |
778 | |
779 | return getClassNameForJavaType(f.getSQLType(), |
780 | f.isUnsigned(), |
781 | f.getMysqlType(), |
782 | f.isBinary() || f.isBlob(), |
783 | f.isOpaqueBinary()); |
784 | } |
785 | } |