|
25 | 25 | importjava.sql.Types;
|
26 | 26 | importjava.util.Vector;
|
27 | 27 |
|
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 $ |
29 | 29 | * This class defines methods of the jdbc1 specification. This class is
|
30 | 30 | * extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
|
31 | 31 | * 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
|
1488 | 1488 | setString(parameterIndex,x.toString());
|
1489 | 1489 | break;
|
1490 | 1490 | 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 | +} |
1492 | 1498 | break;
|
1493 | 1499 | 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 | +} |
1495 | 1507 | break;
|
1496 | 1508 | 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 | +} |
1498 | 1516 | break;
|
1499 | 1517 | caseTypes.BIT:
|
1500 | 1518 | if (xinstanceofBoolean)
|
@@ -2032,7 +2050,113 @@ public boolean isUseServerPrepare()
|
2032 | 2050 | returnm_useServerPrepare;
|
2033 | 2051 | }
|
2034 | 2052 |
|
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 | + |
2036 | 2160 | privatestaticfinalStringPG_TEXT ="text";
|
2037 | 2161 | privatestaticfinalStringPG_INTEGER ="integer";
|
2038 | 2162 | privatestaticfinalStringPG_INT2 ="int2";
|
|