Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Date and time in quotes.

  • Loading branch information...
commit 4ff5a5e3687a547f8a385bee5c1edf5c4ebd3ecf 1 parent 181af8c
@avinashreddy authored
View
9 src/main/java/org/sqlrecorder/events/event/ExecuteEvent.java
@@ -3,11 +3,12 @@
import java.util.Collections;
import java.util.List;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+
public final class ExecuteEvent {
private final String sql;
@@ -52,6 +53,10 @@ public String getFinalSql() {
String paramValue = context.getValue();
if (context.getType().equals(String.class)) {
paramValue = "'" + paramValue + "'";
+ } else if (context.getType().equals(java.sql.Date.class) || context.getType().equals(java.sql.Timestamp.class)) {
+ paramValue = "'" + paramValue + "'";
+ }else {
+
}
sb = sb.replace(questionMarkPosition, questionMarkPosition + 1, paramValue);
currentPosition = questionMarkPosition + paramValue.length();
View
13 src/test/java/org/sqlrecorder/integration/SqlRecorderIntegrationTest.java
@@ -10,6 +10,7 @@
import java.nio.charset.Charset;
import java.sql.CallableStatement;
import java.sql.Connection;
+import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -47,8 +48,8 @@ public void setUp() throws SQLException, ClassNotFoundException {
connection = DriverManager.getConnection(jdbcUrl, username, password);
Statement s = connection.createStatement();
- s.executeUpdate("create table sqlrecuser(name varchar(20),age int,postcode smallint)");
- s.execute("insert into sqlrecuser values('gokul',20,3000) ");
+ s.executeUpdate("create table sqlrecuser(name varchar(20),age int,postcode smallint, created_date date)");
+ s.execute("insert into sqlrecuser values('gokul',20,3000, null) ");
connection.commit();
s.execute("CREATE PROCEDURE sp1() LANGUAGE JAVA NO SQL EXTERNAL NAME 'CLASSPATH:org.sqlrecorder.storedprocedure.HsqlDbStoredProcedure.spWithoutParams'");
s.execute("CREATE PROCEDURE sp2(IN name varchar(20),IN age int, IN createDate double) LANGUAGE JAVA NO SQL EXTERNAL NAME 'CLASSPATH:org.sqlrecorder.storedprocedure.HsqlDbStoredProcedure.spWithParams'");
@@ -140,15 +141,17 @@ public void validatePreparedStatement() throws SQLException {
public void validateBatchPreparedStatement() throws SQLException {
List<String> linesBeforeExecution = returnLinesFromFile();
- PreparedStatement pstmt = connection.prepareStatement("insert into sqlrecuser (name, age,postcode) values (?,?,?)");
+ PreparedStatement pstmt = connection.prepareStatement("insert into sqlrecuser (name, age,postcode, created_date) values (?,?,?,?)");
pstmt.setString(1, "gokul");
pstmt.setInt(2, 50);
pstmt.setInt(3, 3000);
+ pstmt.setDate(4, new Date((new java.util.Date(11, 2, 1)).getTime()));
pstmt.addBatch();
pstmt.addBatch();
pstmt.setInt(2, 40);
pstmt.setInt(3, 2000);
+ pstmt.setTimestamp(4, new java.sql.Timestamp((new java.util.Date(11, 2, 1)).getTime()));
pstmt.addBatch();
pstmt.executeBatch();
@@ -158,8 +161,8 @@ public void validateBatchPreparedStatement() throws SQLException {
assertThat(lineCount, equalTo(3));
int zeroIndex = linesBeforeExecution.size();
- String query1 = "insert into sqlrecuser (name, age,postcode) values ('gokul',50,3000)";
- String query2 = "insert into sqlrecuser (name, age,postcode) values ('gokul',40,2000)";
+ String query1 = "insert into sqlrecuser (name, age,postcode, created_date) values ('gokul',50,3000,'1911-03-01')";
+ String query2 = "insert into sqlrecuser (name, age,postcode, created_date) values ('gokul',40,2000,'1911-03-01 00:00:00.0')";
String firstQuery = linesAfterExecution.get(zeroIndex);
String secondQuery = linesAfterExecution.get(zeroIndex + 1);
Please sign in to comment.
Something went wrong with that request. Please try again.