diff --git a/core/src/main/java/com/orientechnologies/orient/core/serialization/serializer/OStringSerializerHelper.java b/core/src/main/java/com/orientechnologies/orient/core/serialization/serializer/OStringSerializerHelper.java index 52732cba0ec..e3f293f8ab2 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/serialization/serializer/OStringSerializerHelper.java +++ b/core/src/main/java/com/orientechnologies/orient/core/serialization/serializer/OStringSerializerHelper.java @@ -607,11 +607,14 @@ public static int getCollection(final String iText, final int iStartPosition, fi if (buffer.length() == 0 && c == ' ') continue; - if (c == iCollectionBegin) { + if (insideQuote == ' ' && (c == iCollectionBegin || c == '(')) { // BEGIN buffer.append(c); deep++; - } else if (c == iCollectionEnd) { + } else if (insideQuote == ' ' && c == ')') { + buffer.append(c); + deep--; + } else if (insideQuote == ' ' && c == iCollectionEnd) { // END if (deep > 1) buffer.append(c); @@ -743,7 +746,9 @@ public static Map<String, String> getMap(final String iText) { * Transforms, only if needed, the source string escaping the characters \ and ". * * @param iText Input String + * * @return Modified string if needed, otherwise the same input object + * * @see OStringSerializerHelper#decode(String) */ public static String encode(final String iText) { @@ -782,7 +787,9 @@ public static String encode(final String iText) { * Transforms, only if needed, the source string un-escaping the characters \ and ". * * @param iText Input String + * * @return Modified string if needed, otherwise the same input object + * * @see OStringSerializerHelper#encode(String) */ public static String decode(final String iText) { @@ -854,9 +861,11 @@ public static OClass getRecordClassName(final String iValue, OClass iLinkedClass * Use OIOUtils.getStringContent(iValue) instead. * * @param iValue + * * @return */ - @Deprecated public static String getStringContent(final Object iValue) { + @Deprecated + public static String getStringContent(final Object iValue) { // MOVED return OIOUtils.getStringContent(iValue); } @@ -891,6 +900,7 @@ else if (iValue instanceof String) { * Checks if a string contains alphanumeric only characters. * * @param iContent String to check + * * @return true is all the content is alphanumeric, otherwise false */ public static boolean isAlphanumeric(final String iContent) { diff --git a/core/src/test/java/com/orientechnologies/orient/core/sql/TestListOfDates.java b/core/src/test/java/com/orientechnologies/orient/core/sql/TestListOfDates.java new file mode 100644 index 00000000000..4ea36c687e3 --- /dev/null +++ b/core/src/test/java/com/orientechnologies/orient/core/sql/TestListOfDates.java @@ -0,0 +1,97 @@ +package com.orientechnologies.orient.core.sql; + +/** + * Created by luigidellaquila on 20/07/17. + */ + +import com.orientechnologies.orient.core.db.document.ODatabaseDocument; +import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; +import com.orientechnologies.orient.core.metadata.schema.OClass; +import com.orientechnologies.orient.core.metadata.schema.OType; +import com.orientechnologies.orient.core.record.impl.ODocument; +import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +import static org.junit.Assert.assertTrue; + +public class TestListOfDates { + + private final String className = "TestListOfDates"; + private final String dateField = "date"; + private final String dateTimeField = "dateTime"; + private final String dateFormat = "yyyy-MM-dd"; + private final String dateTimeFormat = "yyyy-MM-dd HH:mm:ss"; + private final String dbUrl = "memory:TestListOfDates"; + private final String dateValue = "2017-07-17"; + private final String dateTimeValue = "2017-07-17 23:09:00"; + + private ODatabaseDocument db; + + @Before + public void initDatabase() { + db = new ODatabaseDocumentTx(dbUrl); + if (!db.exists()) { + db.create(); + } + openDatabase(); + createClass(); + + } + + @After + public void dropDatabase() { + openDatabase(); + db.drop(); + } + + private void createClass() { + OClass testClass = db.getMetadata().getSchema().createClass(className); + testClass.createProperty(dateField, OType.DATE); + testClass.createProperty(dateTimeField, OType.DATETIME); + ODocument document = new ODocument(testClass.getName()); + + try { + document.field(dateField, new SimpleDateFormat(dateFormat).parse(dateValue)); + document.field(dateTimeField, new SimpleDateFormat(dateTimeFormat).parse(dateTimeValue)); + document.save(); + } catch (ParseException e) { + e.printStackTrace(); + } + db.commit(); + } + + @Test + public void testDateTimeCollectionPreparedStatement() throws ParseException { + openDatabase(); + OSQLSynchQuery<List<ODocument>> query = new OSQLSynchQuery( + String.format("SELECT FROM %s WHERE %s IN :%s", className, dateTimeField, dateTimeField)); + Map<String, Object> params = new HashMap(); + Date date = new SimpleDateFormat(dateTimeFormat).parse(dateTimeValue); + params.put(dateTimeField, Arrays.asList(date)); + assertTrue(db.query(query, params).size() == 1); + } + + @Test + public void testDateCollectionPreparedStatement() throws ParseException { + openDatabase(); + OSQLSynchQuery<List<ODocument>> query = new OSQLSynchQuery( + String.format("SELECT FROM %s WHERE %s IN :%s", className, dateField, dateField)); + + Map<String, Object> params = new HashMap(); + Date date = new SimpleDateFormat(dateFormat).parse(dateValue); + params.put(dateField, Arrays.asList(date)); + assertTrue(db.query(query, params).size() == 1); + } + + private void openDatabase() { + if (db.isClosed()) { + db.open("admin", "admin"); + } + } +} \ No newline at end of file