|
9 | 9 | import java.sql.DatabaseMetaData;
|
10 | 10 | import java.sql.SQLException;
|
11 | 11 | import java.sql.Types;
|
| 12 | +import java.time.temporal.TemporalAccessor; |
| 13 | +import java.util.Calendar; |
| 14 | +import java.util.Date; |
| 15 | +import java.util.TimeZone; |
12 | 16 |
|
13 | 17 | import org.hibernate.boot.model.FunctionContributions;
|
14 | 18 | import org.hibernate.boot.model.TypeContributions;
|
|
64 | 68 |
|
65 | 69 | import jakarta.persistence.TemporalType;
|
66 | 70 |
|
| 71 | +import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate; |
| 72 | +import static org.hibernate.type.descriptor.DateTimeUtils.appendAsLocalTime; |
| 73 | +import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTime; |
| 74 | +import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMillis; |
| 75 | + |
67 | 76 |
|
68 | 77 | /**
|
69 | 78 | * Superclass for all Sybase dialects.
|
@@ -295,16 +304,95 @@ public String castPattern(CastType from, CastType to) {
|
295 | 304 | if ( to == CastType.STRING ) {
|
296 | 305 | switch ( from ) {
|
297 | 306 | case DATE:
|
298 |
| - return "str_replace(convert(varchar,?1,102),'.','-')"; |
| 307 | + return "substring(convert(varchar,?1,23),1,10)"; |
299 | 308 | case TIME:
|
300 |
| - return "convert(varchar,?1,108)"; |
| 309 | + return "convert(varchar,?1,8)"; |
301 | 310 | case TIMESTAMP:
|
302 |
| - return "str_replace(convert(varchar,?1,23),'T',' ')"; |
| 311 | + return "convert(varchar,?1,140)"; |
303 | 312 | }
|
304 | 313 | }
|
305 | 314 | return super.castPattern( from, to );
|
306 | 315 | }
|
307 | 316 |
|
| 317 | + /* Something odd is going on with the jConnect driver when using JDBC escape syntax, so let's use native functions */ |
| 318 | + |
| 319 | + @Override |
| 320 | + public void appendDateTimeLiteral( |
| 321 | + SqlAppender appender, |
| 322 | + TemporalAccessor temporalAccessor, |
| 323 | + TemporalType precision, |
| 324 | + TimeZone jdbcTimeZone) { |
| 325 | + switch ( precision ) { |
| 326 | + case DATE: |
| 327 | + appender.appendSql( "convert(date,'" ); |
| 328 | + appendAsDate( appender, temporalAccessor ); |
| 329 | + appender.appendSql( "',140)" ); |
| 330 | + break; |
| 331 | + case TIME: |
| 332 | + appender.appendSql( "convert(time,'" ); |
| 333 | + appendAsTime( appender, temporalAccessor, supportsTemporalLiteralOffset(), jdbcTimeZone ); |
| 334 | + appender.appendSql( "',8)" ); |
| 335 | + break; |
| 336 | + case TIMESTAMP: |
| 337 | + appender.appendSql( "convert(datetime,'" ); |
| 338 | + appendAsTimestampWithMillis( appender, temporalAccessor, supportsTemporalLiteralOffset(), jdbcTimeZone ); |
| 339 | + appender.appendSql( "',140)" ); |
| 340 | + break; |
| 341 | + default: |
| 342 | + throw new IllegalArgumentException(); |
| 343 | + } |
| 344 | + } |
| 345 | + |
| 346 | + @Override |
| 347 | + public void appendDateTimeLiteral(SqlAppender appender, Date date, TemporalType precision, TimeZone jdbcTimeZone) { |
| 348 | + switch ( precision ) { |
| 349 | + case DATE: |
| 350 | + appender.appendSql( "convert(date,'" ); |
| 351 | + appendAsDate( appender, date ); |
| 352 | + appender.appendSql( "',140)" ); |
| 353 | + break; |
| 354 | + case TIME: |
| 355 | + appender.appendSql( "convert(time,'" ); |
| 356 | + appendAsLocalTime( appender, date ); |
| 357 | + appender.appendSql( "',8)" ); |
| 358 | + break; |
| 359 | + case TIMESTAMP: |
| 360 | + appender.appendSql( "convert(datetime,'" ); |
| 361 | + appendAsTimestampWithMillis( appender, date, jdbcTimeZone ); |
| 362 | + appender.appendSql( "',140)" ); |
| 363 | + break; |
| 364 | + default: |
| 365 | + throw new IllegalArgumentException(); |
| 366 | + } |
| 367 | + } |
| 368 | + |
| 369 | + @Override |
| 370 | + public void appendDateTimeLiteral( |
| 371 | + SqlAppender appender, |
| 372 | + Calendar calendar, |
| 373 | + TemporalType precision, |
| 374 | + TimeZone jdbcTimeZone) { |
| 375 | + switch ( precision ) { |
| 376 | + case DATE: |
| 377 | + appender.appendSql( "convert(date,'" ); |
| 378 | + appendAsDate( appender, calendar ); |
| 379 | + appender.appendSql( "',140)" ); |
| 380 | + break; |
| 381 | + case TIME: |
| 382 | + appender.appendSql( "convert(time,'" ); |
| 383 | + appendAsLocalTime( appender, calendar ); |
| 384 | + appender.appendSql( "',8)" ); |
| 385 | + break; |
| 386 | + case TIMESTAMP: |
| 387 | + appender.appendSql( "convert(datetime,'" ); |
| 388 | + appendAsTimestampWithMillis( appender, calendar, jdbcTimeZone ); |
| 389 | + appender.appendSql( "',140)" ); |
| 390 | + break; |
| 391 | + default: |
| 392 | + throw new IllegalArgumentException(); |
| 393 | + } |
| 394 | + } |
| 395 | + |
308 | 396 | @Override
|
309 | 397 | public String translateExtractField(TemporalUnit unit) {
|
310 | 398 | switch ( unit ) {
|
|
0 commit comments