Skip to content

Commit 1a1a1aa

Browse files
Linyu Chenwumpz
authored andcommitted
fixes #525 (#530)
* fixes #525 * Simply unit test.
1 parent e23d4bc commit 1a1a1aa

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/main/java/net/sf/jsqlparser/expression/TimestampValue.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@
2929
public class TimestampValue implements Expression {
3030

3131
private Timestamp value;
32-
32+
private char quotation = '\'';
3333
public TimestampValue(String value) {
34-
this.value = Timestamp.valueOf(value.substring(1, value.length() - 1));
34+
if (value == null) {
35+
throw new java.lang.IllegalArgumentException("null string");
36+
} else {
37+
if (value.charAt(0) == quotation) {
38+
this.value = Timestamp.valueOf(value.substring(1, value.length() - 1));
39+
} else {
40+
this.value = Timestamp.valueOf(value.substring(0, value.length()));
41+
}
42+
}
3543
}
3644

3745
@Override
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package net.sf.jsqlparser.expression;
2+
3+
import net.sf.jsqlparser.JSQLParserException;
4+
import org.junit.Test;
5+
6+
import java.text.DateFormat;
7+
import java.text.SimpleDateFormat;
8+
import java.util.Date;
9+
import java.util.Locale;
10+
11+
/**
12+
* @author Linyu Chen
13+
*/
14+
public class TimestampValueTest {
15+
16+
@Test
17+
public void testTimestampValue_issue525() throws JSQLParserException {
18+
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
19+
String currentDate = dateFormat.format(new Date());
20+
TimestampValue tv = new TimestampValue(currentDate);
21+
System.out.println(tv.toString());
22+
}
23+
24+
@Test
25+
public void testTimestampValueWithQuotation_issue525() throws JSQLParserException {
26+
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
27+
String currentDate = dateFormat.format(new Date());
28+
TimestampValue tv = new TimestampValue("'" + currentDate + "'");
29+
System.out.println(tv.toString());
30+
}
31+
}

0 commit comments

Comments
 (0)