Skip to content

Instantly share code, notes, and snippets.

@mmacfadden
Last active August 30, 2015 03:56
Show Gist options
  • Save mmacfadden/2be681114850ef30a6d0 to your computer and use it in GitHub Desktop.
Save mmacfadden/2be681114850ef30a6d0 to your computer and use it in GitHub Desktop.
Demonstrates issues in OrientDB 2.1 with UPDATING values with quotes in them.
import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
public class OrientUpdateSetWithQuotesTest {
public static final String STARTING_STRING = "initial value";
public static final String SINGLE_QUOTE_VALUE = "single \"";
public static final String QUOTED_STRING = "quoted \"value\" string";
@Test
public void testSingleQuoteInNamedParameter() throws Exception {
final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:testSingleQuoteInNamedParameter");
db.create();
db.command(new OCommandSQL("CREATE class test")).execute();
final ODocument test = new ODocument("test");
test.field("text", STARTING_STRING);
db.save(test);
ODocument queried = (ODocument) db.query(new OSQLSynchQuery<Object>("SELECT FROM test")).get(0);
assertEquals(queried.field("text"), STARTING_STRING);
OCommandSQL command = new OCommandSQL("UPDATE test SET text = :text");
Map<String, Object> params = new HashMap<>();
params.put("text", SINGLE_QUOTE_VALUE);
db.command(command).execute(params);
queried.reload();
assertEquals(queried.field("text"), SINGLE_QUOTE_VALUE);
db.close();
}
@Test
public void testQuotedStringInNamedParameter() throws Exception {
final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:testQuotedStringInNamedParameter");
db.create();
db.command(new OCommandSQL("CREATE class test")).execute();
final ODocument test = new ODocument("test");
test.field("text", STARTING_STRING);
db.save(test);
ODocument queried = (ODocument) db.query(new OSQLSynchQuery<Object>("SELECT FROM test")).get(0);
assertEquals(queried.field("text"), STARTING_STRING);
OCommandSQL command = new OCommandSQL("UPDATE test SET text = :text");
Map<String, Object> params = new HashMap<>();
params.put("text", QUOTED_STRING);
db.command(command).execute(params);
queried.reload();
assertEquals(queried.field("text"), QUOTED_STRING);
db.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment