~maria-captains/mariadb-java-client/trunk

« back to all changes in this revision

Viewing changes to src/test/java/org/mariadb/jdbc/DateTest.java

  • Committer: Massimo Siani
  • Date: 2014-03-26 16:19:30 UTC
  • mfrom: (502.1.1 timestamp-null)
  • Revision ID: massimo.siani@skysql.com-20140326161930-ijbxikqnbflihu0b
Merge from Massimo Siani: Return null for 'zero' timestamps

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package org.mariadb.jdbc;
2
2
 
3
 
import org.junit.Test;
 
3
import static junit.framework.Assert.assertEquals;
 
4
import static junit.framework.Assert.assertTrue;
4
5
 
5
 
import java.sql.*;
 
6
import java.sql.Connection;
6
7
import java.sql.Date;
7
 
import java.util.*;
 
8
import java.sql.DriverManager;
 
9
import java.sql.PreparedStatement;
 
10
import java.sql.ResultSet;
 
11
import java.sql.SQLException;
 
12
import java.sql.Statement;
 
13
import java.sql.Time;
 
14
import java.sql.Timestamp;
 
15
import java.sql.Types;
 
16
import java.util.Calendar;
 
17
import java.util.TimeZone;
8
18
import java.util.logging.Level;
9
19
import java.util.logging.Logger;
10
20
 
11
 
import static junit.framework.Assert.assertEquals;
12
 
import static junit.framework.Assert.assertTrue;
 
21
import org.junit.Test;
13
22
 
14
23
public class DateTest extends BaseTest{
15
24
    static { Logger.getLogger("").setLevel(Level.OFF); }
106
115
        Time t = rs.getTime(1,cal);
107
116
        assertEquals(t.toString(), "11:11:11");
108
117
    }
 
118
    
 
119
    @Test
 
120
    public void timestampZeroTest() throws SQLException {
 
121
        connection.createStatement().execute("drop table if exists timestampzerotest");
 
122
        connection.createStatement().execute("create table timestampzerotest (ts timestamp)");
 
123
        connection.createStatement().execute("insert into timestampzerotest values ('0000-00-00 00:00:00')");
 
124
        Statement stmt = connection.createStatement();
 
125
        ResultSet rs = stmt.executeQuery("select * from timestampzerotest");
 
126
        Timestamp ts = null;
 
127
        while(rs.next()) {
 
128
            System.out.println("--");
 
129
            System.out.println(rs.getObject(1));
 
130
            ts = rs.getTimestamp(1);
 
131
        }
 
132
        rs.close();
 
133
        assertEquals(ts, null);
 
134
    }
109
135
 
110
136
    @Test
111
137
    public void javaUtilDateInPreparedStatementAsTimeStamp() throws Exception {
163
189
        long offset = tz.getRawOffset();
164
190
        Connection c = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&serverTimezone=GMT") ;
165
191
        java.util.Date now = new java.util.Date();
 
192
        offset = tz.getOffset(now.getTime());
166
193
        PreparedStatement ps = c.prepareStatement("select now()");
167
194
        ResultSet rs = ps.executeQuery();
168
195
        rs.next();