File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed
main/java/net/sf/jsqlparser/expression
test/java/net/sf/jsqlparser/expression Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change 29
29
public class TimestampValue implements Expression {
30
30
31
31
private Timestamp value ;
32
-
32
+ private char quotation = '\'' ;
33
33
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
+ }
35
43
}
36
44
37
45
@ Override
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments