Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6896bfa

Browse files
author
Barry Lind
committed
Applied patch from Kim Ho @ redhat.com to make support for setObject() more
spec complient with regards to various data/time/timestamp objects Modified Files: jdbc/org/postgresql/errors.properties jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java
1 parentf207718 commit6896bfa

File tree

2 files changed

+132
-5
lines changed

2 files changed

+132
-5
lines changed

‎src/interfaces/jdbc/org/postgresql/errors.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,6 @@ postgresql.call.wrongrtntype:A CallableStatement Function was executed and the r
100100
postgresql.input.fetch.gt0:Fetch size must be a value greater than or equal to 0.
101101
postgresql.input.query.gt0:Query Timeout must be a value greater than or equal to 0.
102102
postgresql.input.rows.gt0:Maximum number of rows must be a value greater than or equal to 0.
103+
postgresql.format.baddate:The date given: {0} does not match the format required: {1}.
104+
postgresql.format.badtime:The time given: {0} does not match the format required: {1}.
105+
postgresql.format.badtimestamp:The timestamp given {0} does not match the format required: {1}.

‎src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java

Lines changed: 129 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
importjava.sql.Types;
2626
importjava.util.Vector;
2727

28-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.26 2003/06/30 21:10:55 davec Exp $
28+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.27 2003/07/09 05:12:04 barry Exp $
2929
* This class defines methods of the jdbc1 specification. This class is
3030
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
3131
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
@@ -1488,13 +1488,31 @@ public void setObject(int parameterIndex, Object x, int targetSqlType, int scale
14881488
setString(parameterIndex,x.toString());
14891489
break;
14901490
caseTypes.DATE:
1491-
setDate(parameterIndex, (java.sql.Date)x);
1491+
if (xinstanceofjava.sql.Date)
1492+
setDate(parameterIndex, (java.sql.Date)x);
1493+
else
1494+
{
1495+
java.sql.Datetmpd = (xinstanceofjava.util.Date) ?newjava.sql.Date(((java.util.Date)x).getTime()) :dateFromString(x.toString());
1496+
setDate(parameterIndex,tmpd);
1497+
}
14921498
break;
14931499
caseTypes.TIME:
1494-
setTime(parameterIndex, (Time)x);
1500+
if (xinstanceofjava.sql.Time)
1501+
setTime(parameterIndex, (java.sql.Time)x);
1502+
else
1503+
{
1504+
java.sql.Timetmpt = (xinstanceofjava.util.Date) ?newjava.sql.Time(((java.util.Date)x).getTime()) :timeFromString(x.toString());
1505+
setTime(parameterIndex,tmpt);
1506+
}
14951507
break;
14961508
caseTypes.TIMESTAMP:
1497-
setTimestamp(parameterIndex, (Timestamp)x);
1509+
if (xinstanceofjava.sql.Timestamp)
1510+
setTimestamp(parameterIndex ,(java.sql.Timestamp)x);
1511+
else
1512+
{
1513+
java.sql.Timestamptmpts = (xinstanceofjava.util.Date) ?newjava.sql.Timestamp(((java.util.Date)x).getTime()) :timestampFromString(x.toString());
1514+
setTimestamp(parameterIndex,tmpts);
1515+
}
14981516
break;
14991517
caseTypes.BIT:
15001518
if (xinstanceofBoolean)
@@ -2032,7 +2050,113 @@ public boolean isUseServerPrepare()
20322050
returnm_useServerPrepare;
20332051
}
20342052

2035-
2053+
privatejava.sql.DatedateFromString (Strings)throwsSQLException
2054+
{
2055+
inttimezone =0;
2056+
longmillis =0;
2057+
longlocaloffset =0;
2058+
inttimezoneLocation = (s.indexOf('+') == -1) ?s.lastIndexOf("-") :s.indexOf('+');
2059+
//if the last index of '-' or '+' is past 8. we are guaranteed that it is a timezone marker
2060+
//shortest = yyyy-m-d
2061+
//longest = yyyy-mm-dd
2062+
try
2063+
{
2064+
timezone = (timezoneLocation>7) ?timezoneLocation :s.length();
2065+
millis =java.sql.Date.valueOf(s.substring(0,timezone)).getTime();
2066+
}
2067+
catch (Exceptione)
2068+
{
2069+
thrownewPSQLException("postgresql.format.baddate",s ,"yyyy-MM-dd[-tz]");
2070+
}
2071+
timezone =0;
2072+
if (timezoneLocation>7 &&timezoneLocation+3 ==s.length())
2073+
{
2074+
timezone =Integer.parseInt(s.substring(timezoneLocation+1,s.length()));
2075+
localoffset =java.util.Calendar.getInstance().getTimeZone().getOffset(millis);
2076+
if (s.charAt(timezoneLocation)=='+')
2077+
timezone*=-1;
2078+
}
2079+
millis =millis +timezone*60*60*1000 +localoffset;
2080+
returnnewjava.sql.Date(millis);
2081+
}
2082+
2083+
privatejava.sql.TimetimeFromString (Strings)throwsSQLException
2084+
{
2085+
inttimezone =0;
2086+
longmillis =0;
2087+
longlocaloffset =0;
2088+
inttimezoneLocation = (s.indexOf('+') == -1) ?s.lastIndexOf("-") :s.indexOf('+');
2089+
//if the index of the last '-' or '+' is greater than 0 that means this time has a timezone.
2090+
//everything earlier than that position, we treat as the time and parse it as such.
2091+
try
2092+
{
2093+
timezone = (timezoneLocation==-1) ?s.length() :timezoneLocation;
2094+
millis =java.sql.Time.valueOf(s.substring(0,timezone)).getTime();
2095+
}
2096+
catch (Exceptione)
2097+
{
2098+
thrownewPSQLException("postgresql.format.badtime",s,"HH:mm:ss[-tz]");
2099+
}
2100+
timezone =0;
2101+
if (timezoneLocation != -1 &&timezoneLocation+3 ==s.length())
2102+
{
2103+
timezone =Integer.parseInt(s.substring(timezoneLocation+1,s.length()));
2104+
localoffset =java.util.Calendar.getInstance().getTimeZone().getOffset(millis);
2105+
if (s.charAt(timezoneLocation)=='+')
2106+
timezone*=-1;
2107+
}
2108+
millis =millis +timezone*60*60*1000 +localoffset;
2109+
returnnewjava.sql.Time(millis);
2110+
}
2111+
2112+
privatejava.sql.TimestamptimestampFromString (Strings)throwsSQLException
2113+
{
2114+
inttimezone =0;
2115+
longmillis =0;
2116+
longlocaloffset =0;
2117+
intnanosVal =0;
2118+
inttimezoneLocation = (s.indexOf('+') == -1) ?s.lastIndexOf("-") :s.indexOf('+');
2119+
intnanospos =s.indexOf(".");
2120+
//if there is a '.', that means there are nanos info, and we take the timestamp up to that point
2121+
//if not, then we check to see if the last +/- (to indicate a timezone) is greater than 8
2122+
//8 is because the shortest date, will have last '-' at position 7. e.g yyyy-x-x
2123+
try
2124+
{
2125+
if (nanospos != -1)
2126+
timezone =nanospos;
2127+
elseif (timezoneLocation >8)
2128+
timezone =timezoneLocation;
2129+
else
2130+
timezone =s.length();
2131+
millis =java.sql.Timestamp.valueOf(s.substring(0,timezone)).getTime();
2132+
}
2133+
catch (Exceptione)
2134+
{
2135+
thrownewPSQLException("postgresql.format.badtimestamp",s,"yyyy-MM-dd HH:mm:ss[.xxxxxx][-tz]");
2136+
}
2137+
timezone =0;
2138+
if (nanospos != -1)
2139+
{
2140+
inttmploc = (timezoneLocation >8) ?timezoneLocation :s.length();
2141+
nanosVal =Integer.parseInt(s.substring(nanospos+1,tmploc));
2142+
intdiff =8-((tmploc-1)-(nanospos+1));
2143+
for (inti=0;i<diff;i++)
2144+
nanosVal*=10;
2145+
}
2146+
if (timezoneLocation>8 &&timezoneLocation+3 ==s.length())
2147+
{
2148+
timezone =Integer.parseInt(s.substring(timezoneLocation+1,s.length()));
2149+
localoffset =java.util.Calendar.getInstance().getTimeZone().getOffset(millis);
2150+
if (s.charAt(timezoneLocation)=='+')
2151+
timezone*=-1;
2152+
}
2153+
millis =millis +timezone*60*60*1000 +localoffset;
2154+
java.sql.Timestamptmpts =newjava.sql.Timestamp(millis);
2155+
tmpts.setNanos(nanosVal);
2156+
returntmpts;
2157+
}
2158+
2159+
20362160
privatestaticfinalStringPG_TEXT ="text";
20372161
privatestaticfinalStringPG_INTEGER ="integer";
20382162
privatestaticfinalStringPG_INT2 ="int2";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp