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