Created
September 6, 2013 16:41
-
-
Save Volune/6466408 to your computer and use it in GitHub Desktop.
Test strings with reverse solidus (backslash) in orientdb 1.5.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; | |
import com.orientechnologies.orient.core.record.impl.ODocument; | |
import com.orientechnologies.orient.core.sql.OCommandSQL; | |
import java.util.List; | |
public class TestEscaping { | |
private ODatabaseDocumentTx db; | |
public static void main(String... args) { | |
new TestEscaping().run(); | |
} | |
public TestEscaping() { | |
db = new ODatabaseDocumentTx("memory:testescaping"); | |
} | |
public void run() { | |
if (db.exists()) { | |
db.open("admin", "admin"); | |
db.drop(); | |
} | |
db.create(); | |
try { | |
test(); | |
} finally { | |
db.close(); | |
} | |
} | |
private void test() { | |
db.getMetadata().getSchema().createClass("Thing"); | |
//EXPECTED RESULTS WITH SIMPLE TESTS | |
//extected 2 | |
//prints 2 | |
List result0 = db.command(new OCommandSQL("select from cluster:internal where \"\\u005C\" == \"\\u005C\"")).execute(); | |
System.out.println(result0.size()); | |
//expected \ | |
//prints \ | |
ODocument document0 = db.command(new OCommandSQL("insert into Thing set value = \"\\u005C\"")).execute(); | |
System.out.println(document0.field("value")); | |
//FAILING TESTS | |
//expected \ | |
//prints \\ | |
ODocument document1 = db.command(new OCommandSQL("insert into Thing set value = \"\\\\\"")).execute(); | |
System.out.println(document1.field("value")); | |
//extected 2 | |
//prints 0 | |
List list1 = db.command(new OCommandSQL("select from cluster:internal where \"\\u005C\" == \"\\\\\"")).execute(); | |
System.out.println(list1.size()); | |
//extected some parsing exception | |
//prints \\ | |
try { | |
ODocument document2 = db.command(new OCommandSQL("insert into Thing set value = \"\\\"")).execute(); | |
System.out.println(document2.field("value")); | |
} catch (Exception e) { | |
System.out.println(e.getClass()); | |
} | |
//extected some parsing exception | |
//prints 2 | |
try { | |
List list2 = db.command(new OCommandSQL("select from cluster:internal where \"\\u005C\" == \"\\\"")).execute(); | |
System.out.println(list2.size()); | |
} catch (Exception e) { | |
System.out.println(e.getClass()); | |
} | |
//SUCCESSFUL TEST | |
//extected some parsing exception | |
//prints OCommandExecutionException | |
try { | |
List list3 = db.command(new OCommandSQL("select from cluster:internal where \"\\\" == \"\\u005C\"")).execute(); | |
System.out.println(list3.size()); | |
} catch (Exception e) { | |
System.out.println(e.getClass().getSimpleName()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why in this test you expected \ ?
ODocument document1 = database.command(new OCommandSQL("insert into Thing set value = "\"")).execute();