Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/jdbc/MonetResultSetMetaData.java @ 888:549225b7be85
Corrected ResultSetMetaData methods getPrecision(), getColumnDisplaySize() and ParameterMetaData method getPrecision() for the interval data types. They now return more precise information for the 13 possible interval data types.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 04 Apr 2024 15:14:53 +0200 (13 months ago) |
parents | 674f9ed21308 |
children | d416e9b6b3d0 |
comparison
equal
deleted
inserted
replaced
887:674f9ed21308 | 888:549225b7be85 |
---|---|
409 */ | 409 */ |
410 @Override | 410 @Override |
411 public int getColumnDisplaySize(final int column) throws SQLException { | 411 public int getColumnDisplaySize(final int column) throws SQLException { |
412 checkColumnIndexValidity(column); | 412 checkColumnIndexValidity(column); |
413 try { | 413 try { |
414 int len = lengths[column - 1]; | 414 // Special handling for interval types |
415 final String monettype = types[column - 1]; | |
416 if (monettype != null && monettype.endsWith("_interval")) { | |
417 /* for interval types, precisions[] contains the interval subtype code */ | |
418 int prec = -1; | |
419 if (precisions != null) { | |
420 prec = precisions[column - 1]; | |
421 } | |
422 switch (prec) { | |
423 case 1: return 4; // interval year | |
424 case 2: return 6; // interval year to month | |
425 case 3: return 6; // interval month | |
426 case 4: return 9; // interval day | |
427 case 5: return 11; // interval day to hour | |
428 case 6: return 13; // interval day to minute | |
429 case 7: return 15; // interval day to second | |
430 case 8: return 11; // interval hour | |
431 case 9: return 13; // interval hour to minute | |
432 case 10: return 15; // interval hour to second | |
433 case 11: return 13; // interval minute | |
434 case 12: return 15; // interval minute to second | |
435 case 13: return 15; // interval second | |
436 default: | |
437 { // fall back to the 3 available monettype names | |
438 if ("sec_interval".equals(monettype)) | |
439 return 15; | |
440 if ("day_interval".equals(monettype)) | |
441 return 9; | |
442 if ("month_interval".equals(monettype)) | |
443 return 6; | |
444 } | |
445 } | |
446 } | |
447 final int len = lengths[column - 1]; | |
415 if (len == 0) { | 448 if (len == 0) { |
416 final String monettype = types[column - 1]; | |
417 // in case of inet it always has 0 as length. we need to correct it. | 449 // in case of inet it always has 0 as length. we need to correct it. |
418 if ("inet".equals(monettype)) { | 450 if ("inet".equals(monettype)) { |
419 len = 18; // 128.127.126.125/24 | 451 return 18; // 128.127.126.125/24 |
420 } | 452 } |
421 } | 453 } |
422 return len; | 454 return len; |
423 } catch (IndexOutOfBoundsException e) { | 455 } catch (IndexOutOfBoundsException e) { |
424 throw MonetResultSet.newSQLInvalidColumnIndexException(column); | 456 throw MonetResultSet.newSQLInvalidColumnIndexException(column); |
541 final String monettype = types[column - 1]; | 573 final String monettype = types[column - 1]; |
542 if (monettype != null && monettype.endsWith("_interval")) { | 574 if (monettype != null && monettype.endsWith("_interval")) { |
543 /* convert the interval type names to valid SQL data type names, | 575 /* convert the interval type names to valid SQL data type names, |
544 * such that generic applications can use them in create table statements | 576 * such that generic applications can use them in create table statements |
545 */ | 577 */ |
578 /* for interval types, precisions[] contains the interval subtype code */ | |
546 int prec = -1; | 579 int prec = -1; |
547 if (precisions != null) { | 580 if (precisions != null) { |
548 prec = precisions[column - 1]; | 581 prec = precisions[column - 1]; |
549 } | 582 } |
550 switch (prec) { | 583 switch (prec) { |
612 case Types.DECIMAL: | 645 case Types.DECIMAL: |
613 case Types.NUMERIC: | 646 case Types.NUMERIC: |
614 // these data types have a variable precision (max precision is 38) | 647 // these data types have a variable precision (max precision is 38) |
615 if (precisions != null) { | 648 if (precisions != null) { |
616 try { | 649 try { |
650 // Special handling for: day_interval and sec_interval as they are | |
651 // mapped to Types.NUMERIC and Types.DECIMAL types (see MonetDriver typeMap) | |
652 final String monettype = types[column - 1]; | |
653 if (monettype != null && monettype.endsWith("_interval")) { | |
654 /* for interval types, precisions[] contains the interval subtype code */ | |
655 switch (precisions[column - 1]) { | |
656 case 1: return 4; // interval year | |
657 case 2: return 6; // interval year to month | |
658 case 3: return 6; // interval month | |
659 case 4: return 9; // interval day | |
660 case 5: return 11; // interval day to hour | |
661 case 6: return 13; // interval day to minute | |
662 case 7: return 15; // interval day to second | |
663 case 8: return 11; // interval hour | |
664 case 9: return 13; // interval hour to minute | |
665 case 10: return 15; // interval hour to second | |
666 case 11: return 13; // interval minute | |
667 case 12: return 15; // interval minute to second | |
668 case 13: return 15; // interval second | |
669 default: | |
670 { // fall back to the 3 available monettype names | |
671 if ("sec_interval".equals(monettype)) | |
672 return 15; | |
673 if ("day_interval".equals(monettype)) | |
674 return 9; | |
675 if ("month_interval".equals(monettype)) | |
676 return 6; | |
677 } | |
678 } | |
679 } | |
617 return precisions[column - 1]; | 680 return precisions[column - 1]; |
618 } catch (IndexOutOfBoundsException e) { | 681 } catch (IndexOutOfBoundsException e) { |
619 throw MonetResultSet.newSQLInvalidColumnIndexException(column); | 682 throw MonetResultSet.newSQLInvalidColumnIndexException(column); |
620 } | 683 } |
621 } | 684 } |