Skip to content

Commit 688098b

Browse files
committed
Merge origin/master
2 parents 686599b + 622f9ae commit 688098b

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
public class TimestampValue extends ASTNodeAccessImpl implements Expression {
2020

2121
private Timestamp value;
22-
private char quotation = '\'';
22+
private String rawValue;
23+
private static final char QUOTATION = '\'';
2324

2425
public TimestampValue() {
2526
// empty constructor
@@ -29,11 +30,7 @@ public TimestampValue(String value) {
2930
if (value == null) {
3031
throw new java.lang.IllegalArgumentException("null string");
3132
} else {
32-
if (value.charAt(0) == quotation) {
33-
this.value = Timestamp.valueOf(value.substring(1, value.length() - 1));
34-
} else {
35-
this.value = Timestamp.valueOf(value.substring(0, value.length()));
36-
}
33+
setRawValue(value);
3734
}
3835
}
3936

@@ -50,6 +47,19 @@ public void setValue(Timestamp d) {
5047
value = d;
5148
}
5249

50+
public String getRawValue() {
51+
return rawValue;
52+
}
53+
54+
public void setRawValue(String rawValue) {
55+
this.rawValue = rawValue;
56+
if (rawValue.charAt(0) == QUOTATION) {
57+
this.value = Timestamp.valueOf(rawValue.substring(1, rawValue.length() - 1));
58+
} else {
59+
this.value = Timestamp.valueOf(rawValue.substring(0, rawValue.length()));
60+
}
61+
}
62+
5363
@Override
5464
public String toString() {
5565
return "{ts '" + value + "'}";

src/test/java/net/sf/jsqlparser/expression/TimestampValueTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package net.sf.jsqlparser.expression;
1111

12+
import static org.junit.Assert.assertEquals;
1213
import net.sf.jsqlparser.JSQLParserException;
1314
import org.junit.Test;
1415

@@ -25,6 +26,7 @@ public void testTimestampValue_issue525() throws JSQLParserException {
2526
String currentDate = dateFormat.format(new Date());
2627
TimestampValue tv = new TimestampValue(currentDate);
2728
System.out.println(tv.toString());
29+
assertEquals(currentDate, tv.getRawValue());
2830
}
2931

3032
@Test
@@ -33,5 +35,6 @@ public void testTimestampValueWithQuotation_issue525() throws JSQLParserExceptio
3335
String currentDate = dateFormat.format(new Date());
3436
TimestampValue tv = new TimestampValue("'" + currentDate + "'");
3537
System.out.println(tv.toString());
38+
assertEquals("'" + currentDate + "'", tv.getRawValue());
3639
}
3740
}

0 commit comments

Comments
 (0)