mirror of https://github.com/postgres/postgres
Tue Feb 13 16:33:00 GMT 2001 peter@retep.org.uk - More TestCases implemented. Refined the test suite api's. - Removed need for SimpleDateFormat in ResultSet.getDate() improving performance. - Rewrote ResultSet.getTime() so that it uses JDK api's better. Tue Feb 13 10:25:00 GMT 2001 peter@retep.org.uk - Added MiscTest to hold reported problems from users. - Fixed PGMoney. - JBuilder4/JDBCExplorer now works with Money fields. Patched Field & ResultSet (lots of methods) for this one. Also changed cash/money to return type DOUBLE not DECIMAL. This broke JBuilder as zero scale BigDecimal's can't have decimal places! - When a Statement is reused, the previous ResultSet is now closed. - Removed deprecated call in ResultSet.getTime() Thu Feb 08 18:53:00 GMT 2001 peter@retep.org.uk - Changed a couple of settings in DatabaseMetaData where 7.1 now supports those features - Implemented the DatabaseMetaData TestCase. Wed Feb 07 18:06:00 GMT 2001 peter@retep.org.uk - Added comment to Connection.isClosed() explaining why we deviate from the JDBC2 specification. - Fixed bug where the Isolation Level is lost while in autocommit mode. - Fixed bug where several calls to getTransactionIsolationLevel() returned the first call's result.REL7_1_STABLE
parent
2410963e8c
commit
3d21bf82c3
@ -0,0 +1,273 @@ |
||||
package org.postgresql.test.jdbc2; |
||||
|
||||
import org.postgresql.test.JDBC2Tests; |
||||
import junit.framework.TestCase; |
||||
import java.sql.*; |
||||
|
||||
/** |
||||
* TestCase to test the internal functionality of org.postgresql.jdbc2.DatabaseMetaData |
||||
* |
||||
* PS: Do you know how difficult it is to type on a train? ;-) |
||||
* |
||||
* $Id: DatabaseMetaDataTest.java,v 1.1 2001/02/13 16:39:05 peter Exp $ |
||||
*/ |
||||
|
||||
public class DatabaseMetaDataTest extends TestCase { |
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
public DatabaseMetaDataTest(String name) { |
||||
super(name); |
||||
} |
||||
|
||||
/** |
||||
* The spec says this may return null, but we always do! |
||||
*/ |
||||
public void testGetMetaData() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData(); |
||||
assert(dbmd!=null); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(SQLException ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Test default capabilities |
||||
*/ |
||||
public void testCapabilities() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData(); |
||||
assert(dbmd!=null); |
||||
|
||||
assert(dbmd.allProceduresAreCallable()==true); |
||||
assert(dbmd.allTablesAreSelectable()==true); // not true all the time
|
||||
|
||||
// This should always be false for postgresql (at least for 7.x)
|
||||
assert(!dbmd.isReadOnly()); |
||||
|
||||
// does the backend support this yet? The protocol does...
|
||||
assert(!dbmd.supportsMultipleResultSets()); |
||||
|
||||
// yes, as multiple backends can have transactions open
|
||||
assert(dbmd.supportsMultipleTransactions()); |
||||
|
||||
assert(dbmd.supportsMinimumSQLGrammar()); |
||||
assert(!dbmd.supportsCoreSQLGrammar()); |
||||
assert(!dbmd.supportsExtendedSQLGrammar()); |
||||
assert(!dbmd.supportsANSI92EntryLevelSQL()); |
||||
assert(!dbmd.supportsANSI92IntermediateSQL()); |
||||
assert(!dbmd.supportsANSI92FullSQL()); |
||||
|
||||
assert(!dbmd.supportsIntegrityEnhancementFacility()); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(SQLException ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
|
||||
public void testJoins() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData(); |
||||
assert(dbmd!=null); |
||||
|
||||
assert(dbmd.supportsOuterJoins()); |
||||
assert(dbmd.supportsFullOuterJoins()); |
||||
assert(dbmd.supportsLimitedOuterJoins()); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(SQLException ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
public void testCursors() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData(); |
||||
assert(dbmd!=null); |
||||
|
||||
assert(!dbmd.supportsPositionedDelete()); |
||||
assert(!dbmd.supportsPositionedUpdate()); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(SQLException ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
public void testNulls() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData(); |
||||
assert(dbmd!=null); |
||||
|
||||
// these need double checking
|
||||
assert(!dbmd.nullsAreSortedAtStart()); |
||||
assert(dbmd.nullsAreSortedAtEnd()); |
||||
assert(!dbmd.nullsAreSortedHigh()); |
||||
assert(!dbmd.nullsAreSortedLow()); |
||||
|
||||
assert(dbmd.nullPlusNonNullIsNull()); |
||||
|
||||
assert(dbmd.supportsNonNullableColumns()); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(SQLException ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
public void testLocalFiles() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData(); |
||||
assert(dbmd!=null); |
||||
|
||||
assert(!dbmd.usesLocalFilePerTable()); |
||||
assert(!dbmd.usesLocalFiles()); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(SQLException ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
public void testIdentifiers() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData(); |
||||
assert(dbmd!=null); |
||||
|
||||
assert(!dbmd.supportsMixedCaseIdentifiers()); // always false
|
||||
assert(dbmd.supportsMixedCaseQuotedIdentifiers()); // always true
|
||||
|
||||
assert(!dbmd.storesUpperCaseIdentifiers()); // always false
|
||||
assert(dbmd.storesLowerCaseIdentifiers()); // always true
|
||||
assert(!dbmd.storesUpperCaseQuotedIdentifiers()); // always false
|
||||
assert(!dbmd.storesLowerCaseQuotedIdentifiers()); // always false
|
||||
assert(!dbmd.storesMixedCaseQuotedIdentifiers()); // always false
|
||||
|
||||
assert(dbmd.getIdentifierQuoteString().equals("\"")); |
||||
|
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(SQLException ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
public void testTables() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData(); |
||||
assert(dbmd!=null); |
||||
|
||||
// we can add columns
|
||||
assert(dbmd.supportsAlterTableWithAddColumn()); |
||||
|
||||
// we can't drop columns (yet)
|
||||
assert(!dbmd.supportsAlterTableWithDropColumn()); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(SQLException ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
public void testSelect() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData(); |
||||
assert(dbmd!=null); |
||||
|
||||
// yes we can?: SELECT col a FROM a;
|
||||
assert(dbmd.supportsColumnAliasing()); |
||||
|
||||
// yes we can have expressions in ORDERBY
|
||||
assert(dbmd.supportsExpressionsInOrderBy()); |
||||
|
||||
assert(!dbmd.supportsOrderByUnrelated()); |
||||
|
||||
assert(dbmd.supportsGroupBy()); |
||||
assert(dbmd.supportsGroupByUnrelated()); |
||||
assert(dbmd.supportsGroupByBeyondSelect()); // needs checking
|
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(SQLException ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
public void testDBParams() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData(); |
||||
assert(dbmd!=null); |
||||
|
||||
assert(dbmd.getURL().equals(JDBC2Tests.getURL())); |
||||
assert(dbmd.getUserName().equals(JDBC2Tests.getUser())); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(SQLException ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
public void testDbProductDetails() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
assert(con instanceof org.postgresql.Connection); |
||||
org.postgresql.Connection pc = (org.postgresql.Connection) con; |
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData(); |
||||
assert(dbmd!=null); |
||||
|
||||
assert(dbmd.getDatabaseProductName().equals("PostgreSQL")); |
||||
assert(dbmd.getDatabaseProductVersion().startsWith(Integer.toString(pc.this_driver.getMajorVersion())+"."+Integer.toString(pc.this_driver.getMinorVersion()))); |
||||
assert(dbmd.getDriverName().equals("PostgreSQL Native Driver")); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(SQLException ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
public void testDriverVersioning() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
assert(con instanceof org.postgresql.Connection); |
||||
org.postgresql.Connection pc = (org.postgresql.Connection) con; |
||||
|
||||
DatabaseMetaData dbmd = con.getMetaData(); |
||||
assert(dbmd!=null); |
||||
|
||||
assert(dbmd.getDriverVersion().equals(pc.this_driver.getVersion())); |
||||
assert(dbmd.getDriverMajorVersion()==pc.this_driver.getMajorVersion()); |
||||
assert(dbmd.getDriverMinorVersion()==pc.this_driver.getMinorVersion()); |
||||
|
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(SQLException ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,126 @@ |
||||
package org.postgresql.test.jdbc2; |
||||
|
||||
import org.postgresql.test.JDBC2Tests; |
||||
import junit.framework.TestCase; |
||||
import java.sql.*; |
||||
|
||||
/** |
||||
* $Id: DateTest.java,v 1.1 2001/02/13 16:39:05 peter Exp $ |
||||
* |
||||
* Some simple tests based on problems reported by users. Hopefully these will |
||||
* help prevent previous problems from re-occuring ;-) |
||||
* |
||||
*/ |
||||
public class DateTest extends TestCase { |
||||
|
||||
public DateTest(String name) { |
||||
super(name); |
||||
} |
||||
|
||||
/** |
||||
* Tests the time methods in ResultSet |
||||
*/ |
||||
public void testGetDate() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
Statement st=con.createStatement(); |
||||
|
||||
JDBC2Tests.createTable(con,"dt date"); |
||||
|
||||
st.executeUpdate(JDBC2Tests.insert("'1950-02-07'")); |
||||
st.executeUpdate(JDBC2Tests.insert("'1970-06-02'")); |
||||
st.executeUpdate(JDBC2Tests.insert("'1999-08-11'")); |
||||
st.executeUpdate(JDBC2Tests.insert("'2001-02-13'")); |
||||
|
||||
// Fall through helper
|
||||
checkTimeTest(con,st); |
||||
|
||||
st.close(); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(Exception ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Tests the time methods in PreparedStatement |
||||
*/ |
||||
public void testSetDate() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
Statement st=con.createStatement(); |
||||
|
||||
JDBC2Tests.createTable(con,"dt date"); |
||||
|
||||
PreparedStatement ps = con.prepareStatement(JDBC2Tests.insert("?")); |
||||
|
||||
ps.setDate(1,getDate(1950,2,7)); |
||||
assert(!ps.execute()); // false as its an update!
|
||||
|
||||
ps.setDate(1,getDate(1970,6,2)); |
||||
assert(!ps.execute()); // false as its an update!
|
||||
|
||||
ps.setDate(1,getDate(1999,8,11)); |
||||
assert(!ps.execute()); // false as its an update!
|
||||
|
||||
ps.setDate(1,getDate(2001,2,13)); |
||||
assert(!ps.execute()); // false as its an update!
|
||||
|
||||
// Fall through helper
|
||||
checkTimeTest(con,st); |
||||
|
||||
ps.close(); |
||||
st.close(); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(Exception ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Helper for the TimeTests. It tests what should be in the db |
||||
*/ |
||||
private void checkTimeTest(Connection con,Statement st) throws SQLException { |
||||
ResultSet rs=null; |
||||
java.sql.Date t=null; |
||||
|
||||
rs=st.executeQuery(JDBC2Tests.select("dt")); |
||||
assert(rs!=null); |
||||
|
||||
assert(rs.next()); |
||||
t = rs.getDate(1); |
||||
assert(t!=null); |
||||
assert(t.equals(getDate(1950,2,7))); |
||||
|
||||
assert(rs.next()); |
||||
t = rs.getDate(1); |
||||
assert(t!=null); |
||||
assert(t.equals(getDate(1970,6,2))); |
||||
|
||||
assert(rs.next()); |
||||
t = rs.getDate(1); |
||||
assert(t!=null); |
||||
assert(t.equals(getDate(1999,8,11))); |
||||
|
||||
assert(rs.next()); |
||||
t = rs.getDate(1); |
||||
assert(t!=null); |
||||
assert(t.equals(getDate(2001,2,13))); |
||||
|
||||
assert(!rs.next()); |
||||
|
||||
rs.close(); |
||||
} |
||||
|
||||
/** |
||||
* Yes this is ugly, but it gets the test done ;-) |
||||
*/ |
||||
private java.sql.Date getDate(int y,int m,int d) { |
||||
return java.sql.Date.valueOf(JDBC2Tests.fix(y,4)+"-"+JDBC2Tests.fix(m,2)+"-"+JDBC2Tests.fix(d,2)); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,44 @@ |
||||
package org.postgresql.test.jdbc2; |
||||
|
||||
import org.postgresql.test.JDBC2Tests; |
||||
import junit.framework.TestCase; |
||||
import java.sql.*; |
||||
import java.math.BigDecimal; |
||||
|
||||
/** |
||||
* $Id: JBuilderTest.java,v 1.1 2001/02/13 16:39:05 peter Exp $ |
||||
* |
||||
* Some simple tests to check that the required components needed for JBuilder |
||||
* stay working |
||||
* |
||||
*/ |
||||
public class JBuilderTest extends TestCase { |
||||
|
||||
public JBuilderTest(String name) { |
||||
super(name); |
||||
} |
||||
|
||||
/** |
||||
* This tests that Money types work. JDBCExplorer barfs if this fails. |
||||
*/ |
||||
public void testMoney() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
Statement st=con.createStatement(); |
||||
ResultSet rs=st.executeQuery("select cost from test_c"); |
||||
assert(rs!=null); |
||||
|
||||
while(rs.next()){ |
||||
double bd = rs.getDouble(1); |
||||
} |
||||
|
||||
rs.close(); |
||||
st.close(); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(Exception ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@ |
||||
package org.postgresql.test.jdbc2; |
||||
|
||||
import org.postgresql.test.JDBC2Tests; |
||||
import junit.framework.TestCase; |
||||
import java.sql.*; |
||||
|
||||
/** |
||||
* $Id: MiscTest.java,v 1.1 2001/02/13 16:39:05 peter Exp $ |
||||
* |
||||
* Some simple tests based on problems reported by users. Hopefully these will |
||||
* help prevent previous problems from re-occuring ;-) |
||||
* |
||||
*/ |
||||
public class MiscTest extends TestCase { |
||||
|
||||
public MiscTest(String name) { |
||||
super(name); |
||||
} |
||||
|
||||
/** |
||||
* Some versions of the driver would return rs as a null? |
||||
* |
||||
* Sasha <ber0806@iperbole.bologna.it> was having this problem. |
||||
* |
||||
* Added Feb 13 2001 |
||||
*/ |
||||
public void testDatabaseSelectNullBug() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
Statement st=con.createStatement(); |
||||
ResultSet rs=st.executeQuery("select datname from pg_database"); |
||||
assert(rs!=null); |
||||
|
||||
while(rs.next()){ |
||||
String s = rs.getString(1); |
||||
} |
||||
|
||||
rs.close(); |
||||
st.close(); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(Exception ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,123 @@ |
||||
package org.postgresql.test.jdbc2; |
||||
|
||||
import org.postgresql.test.JDBC2Tests; |
||||
import junit.framework.TestCase; |
||||
import java.sql.*; |
||||
|
||||
/** |
||||
* $Id: TimeTest.java,v 1.1 2001/02/13 16:39:05 peter Exp $ |
||||
* |
||||
* Some simple tests based on problems reported by users. Hopefully these will |
||||
* help prevent previous problems from re-occuring ;-) |
||||
* |
||||
*/ |
||||
public class TimeTest extends TestCase { |
||||
|
||||
public TimeTest(String name) { |
||||
super(name); |
||||
} |
||||
|
||||
/** |
||||
* Tests the time methods in ResultSet |
||||
*/ |
||||
public void testGetTime() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
Statement st=con.createStatement(); |
||||
|
||||
JDBC2Tests.createTable(con,"tm time"); |
||||
|
||||
st.executeUpdate(JDBC2Tests.insert("'01:02:03'")); |
||||
st.executeUpdate(JDBC2Tests.insert("'23:59:59'")); |
||||
|
||||
// Fall through helper
|
||||
checkTimeTest(con,st); |
||||
|
||||
st.close(); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(Exception ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Tests the time methods in PreparedStatement |
||||
*/ |
||||
public void testSetTime() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
Statement st=con.createStatement(); |
||||
|
||||
JDBC2Tests.createTable(con,"tm time"); |
||||
|
||||
PreparedStatement ps = con.prepareStatement(JDBC2Tests.insert("?")); |
||||
|
||||
ps.setTime(1,getTime(1,2,3)); |
||||
assert(!ps.execute()); // false as its an update!
|
||||
|
||||
ps.setTime(1,getTime(23,59,59)); |
||||
assert(!ps.execute()); // false as its an update!
|
||||
|
||||
// Fall through helper
|
||||
checkTimeTest(con,st); |
||||
|
||||
ps.close(); |
||||
st.close(); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(Exception ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Helper for the TimeTests. It tests what should be in the db |
||||
*/ |
||||
private void checkTimeTest(Connection con,Statement st) throws SQLException { |
||||
ResultSet rs=null; |
||||
Time t=null; |
||||
|
||||
rs=st.executeQuery(JDBC2Tests.select("tm")); |
||||
assert(rs!=null); |
||||
|
||||
assert(rs.next()); |
||||
t = rs.getTime(1); |
||||
assert(t!=null); |
||||
assert(getHours(t)==1); |
||||
assert(getMinutes(t)==2); |
||||
assert(getSeconds(t)==3); |
||||
|
||||
assert(rs.next()); |
||||
t = rs.getTime(1); |
||||
assert(t!=null); |
||||
assert(getHours(t)==23); |
||||
assert(getMinutes(t)==59); |
||||
assert(getSeconds(t)==59); |
||||
|
||||
assert(!rs.next()); |
||||
|
||||
rs.close(); |
||||
} |
||||
|
||||
/** |
||||
* These implement depreciated methods in java.sql.Time |
||||
*/ |
||||
private static long getHours(Time t) { |
||||
return (t.getTime() % JDBC2Tests.DAYMILLIS)/3600000; |
||||
} |
||||
|
||||
private static long getMinutes(Time t) { |
||||
return ((t.getTime() % JDBC2Tests.DAYMILLIS)/60000)%60; |
||||
} |
||||
|
||||
private static long getSeconds(Time t) { |
||||
return ((t.getTime() % JDBC2Tests.DAYMILLIS)/1000)%60; |
||||
} |
||||
|
||||
private Time getTime(int h,int m,int s) { |
||||
return new Time(1000*(s+(m*60)+(h*3600))); |
||||
} |
||||
} |
||||
@ -0,0 +1,136 @@ |
||||
package org.postgresql.test.jdbc2; |
||||
|
||||
import org.postgresql.test.JDBC2Tests; |
||||
import junit.framework.TestCase; |
||||
import java.sql.*; |
||||
|
||||
/** |
||||
* $Id: TimestampTest.java,v 1.1 2001/02/13 16:39:05 peter Exp $ |
||||
* |
||||
* This has been the most controversial pair of methods since 6.5 was released! |
||||
* |
||||
* From now on, any changes made to either getTimestamp or setTimestamp |
||||
* MUST PASS this TestCase!!! |
||||
* |
||||
*/ |
||||
public class TimestampTest extends TestCase { |
||||
|
||||
public TimestampTest(String name) { |
||||
super(name); |
||||
} |
||||
|
||||
/** |
||||
* Tests the time methods in ResultSet |
||||
*/ |
||||
public void testGetTimestamp() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
Statement st=con.createStatement(); |
||||
|
||||
JDBC2Tests.createTable(con,"ts timestamp"); |
||||
|
||||
st.executeUpdate(JDBC2Tests.insert("'1950-02-07 15:00:00'")); |
||||
|
||||
// Before you ask why 8:13:00 and not 7:13:00, this is a problem with the
|
||||
// getTimestamp method in this TestCase. It's simple, brain-dead. It
|
||||
// simply doesn't know about summer time. As this date is in June, it's
|
||||
// summer (GMT wise).
|
||||
//
|
||||
// This case needs some work done on it.
|
||||
//
|
||||
st.executeUpdate(JDBC2Tests.insert("'"+getTimestamp(1970,6,2,8,13,0).toString()+"'")); |
||||
|
||||
//st.executeUpdate(JDBC2Tests.insert("'1950-02-07'"));
|
||||
|
||||
// Fall through helper
|
||||
checkTimeTest(con,st); |
||||
|
||||
st.close(); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(Exception ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Tests the time methods in PreparedStatement |
||||
*/ |
||||
public void testSetTimestamp() { |
||||
try { |
||||
Connection con = JDBC2Tests.openDB(); |
||||
|
||||
Statement st=con.createStatement(); |
||||
|
||||
JDBC2Tests.createTable(con,"ts timestamp"); |
||||
|
||||
PreparedStatement ps = con.prepareStatement(JDBC2Tests.insert("?")); |
||||
|
||||
ps.setTimestamp(1,getTimestamp(1950,2,7,15,0,0)); |
||||
assert(!ps.execute()); // false as its an update!
|
||||
|
||||
// Before you ask why 8:13:00 and not 7:13:00, this is a problem with the
|
||||
// getTimestamp method in this TestCase. It's simple, brain-dead. It
|
||||
// simply doesn't know about summer time. As this date is in June, it's
|
||||
// summer (GMT wise).
|
||||
//
|
||||
// This case needs some work done on it.
|
||||
//
|
||||
ps.setTimestamp(1,getTimestamp(1970,6,2,7,13,0)); |
||||
assert(!ps.execute()); // false as its an update!
|
||||
|
||||
// Fall through helper
|
||||
checkTimeTest(con,st); |
||||
|
||||
ps.close(); |
||||
st.close(); |
||||
|
||||
JDBC2Tests.closeDB(con); |
||||
} catch(Exception ex) { |
||||
assert(ex.getMessage(),false); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Helper for the TimeTests. It tests what should be in the db |
||||
*/ |
||||
private void checkTimeTest(Connection con,Statement st) throws SQLException { |
||||
ResultSet rs=null; |
||||
java.sql.Timestamp t=null; |
||||
|
||||
rs=st.executeQuery(JDBC2Tests.select("ts")); |
||||
assert(rs!=null); |
||||
|
||||
assert(rs.next()); |
||||
t = rs.getTimestamp(1); |
||||
assert(t!=null); |
||||
assert(t.equals(getTimestamp(1950,2,7,15,0,0))); |
||||
|
||||
assert(rs.next()); |
||||
t = rs.getTimestamp(1); |
||||
assert(t!=null); |
||||
|
||||
assert(t.equals(getTimestamp(1970,6,2,7,13,0))); |
||||
|
||||
assert(!rs.next()); // end of table. Fail if more entries exist.
|
||||
|
||||
rs.close(); |
||||
} |
||||
|
||||
/** |
||||
* These implement depreciated methods in java.sql.Time |
||||
*/ |
||||
private static final long dayms = 24*3600*1000; |
||||
|
||||
/** |
||||
* Yes this is ugly, but it gets the test done ;-) |
||||
* |
||||
* Actually its buggy. We need a better solution to this, then the hack of adding 1 hour to |
||||
* entries in June above don't need setting. |
||||
*/ |
||||
private java.sql.Timestamp getTimestamp(int y,int m,int d,int h,int mn,int se) { |
||||
return java.sql.Timestamp.valueOf(JDBC2Tests.fix(y,4)+"-"+JDBC2Tests.fix(m,2)+"-"+JDBC2Tests.fix(d,2)+" "+JDBC2Tests.fix(h,2)+":"+JDBC2Tests.fix(mn,2)+":"+JDBC2Tests.fix(se,2)+"."+JDBC2Tests.fix(0,9)); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue