File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed
main/java/net/sf/jsqlparser/expression
test/java/net/sf/jsqlparser/expression Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change 1919public 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 + "'}" ;
Original file line number Diff line number Diff line change 99 */
1010package net .sf .jsqlparser .expression ;
1111
12+ import static org .junit .Assert .assertEquals ;
1213import net .sf .jsqlparser .JSQLParserException ;
1314import 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}
You can’t perform that action at this time.
0 commit comments