Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix213 #28

Merged
merged 4 commits into from

1 participant

@jcookems

Fixes issue 213: TableRestProxy.buildFilterExpression does not properly encode constants

jcookems added some commits
@jcookems jcookems Fix #213 6243526
@jcookems jcookems Merge branch 'fix213' of github.com:jcookems/azure-sdk-for-java into …
…fix213
75762f3
@jcookems jcookems Replaced manual base16 conversion with Formatter call.
Use existing StringBuilder instead of concat when possible.
Add case for Byte[] (in addition to byte[])
Replace special case in String for UUID with seperate code path for UUID.
Add unit tests.
6a569ec
@jcookems

Made the suggested fixes, and added a unit test.

@jcookems jcookems merged commit d59baba into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 8, 2012
  1. @jcookems

    Fix #213

    jcookems authored
Commits on Apr 3, 2012
  1. @jcookems
  2. @jcookems

    Replaced manual base16 conversion with Formatter call.

    jcookems authored
    Use existing StringBuilder instead of concat when possible.
    Add case for Byte[] (in addition to byte[])
    Replace special case in String for UUID with seperate code path for UUID.
    Add unit tests.
Commits on Apr 4, 2012
  1. @jcookems
This page is out of date. Refresh to see the latest.
View
51 ...oft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java
@@ -21,8 +21,11 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Date;
import java.util.Enumeration;
+import java.util.Formatter;
import java.util.List;
+import java.util.UUID;
import javax.activation.DataSource;
import javax.inject.Inject;
@@ -205,9 +208,51 @@ private void buildFilterExpression(Filter filter, StringBuilder sb) {
sb.append(((LitteralFilter) filter).getLitteral());
}
else if (filter instanceof ConstantFilter) {
- sb.append("'");
- sb.append(((ConstantFilter) filter).getValue());
- sb.append("'");
+ Object value = ((ConstantFilter) filter).getValue();
+ if (value == null) {
+ sb.append("null");
+ }
+ else if (value.getClass() == Long.class) {
+ sb.append(value);
+ sb.append("L");
+ }
+ else if (value.getClass() == Date.class) {
+ ISO8601DateConverter dateConverter = new ISO8601DateConverter();
+ sb.append("datetime'");
+ sb.append(dateConverter.format((Date) value));
+ sb.append("'");
+ }
+ else if (value.getClass() == UUID.class) {
+ sb.append("(guid'");
+ sb.append(value);
+ sb.append("')");
+ }
+ else if (value.getClass() == String.class) {
+ sb.append("'");
+ sb.append(((String) value).replace("'", "''"));
+ sb.append("'");
+ }
+ else if (value.getClass() == byte[].class) {
+ sb.append("X'");
+ byte[] byteArray = (byte[]) value;
+ Formatter formatter = new Formatter(sb);
+ for (byte b : byteArray) {
+ formatter.format("%02x", b);
+ }
+ sb.append("'");
+ }
+ else if (value.getClass() == Byte[].class) {
+ sb.append("X'");
+ Byte[] byteArray = (Byte[]) value;
+ Formatter formatter = new Formatter(sb);
+ for (Byte b : byteArray) {
+ formatter.format("%02x", b);
+ }
+ sb.append("'");
+ }
+ else {
+ sb.append(value);
+ }
}
else if (filter instanceof UnaryFilter) {
sb.append(((UnaryFilter) filter).getOperator());
View
72 ...osoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java
@@ -610,13 +610,16 @@ public void queryEntitiesWithFilterWorks() throws Exception {
TableContract service = TableService.create(config);
String table = TEST_TABLE_5;
int numberOfEntries = 5;
+ Entity[] entities = new Entity[numberOfEntries];
for (int i = 0; i < numberOfEntries; i++) {
- Entity entity = new Entity().setPartitionKey("001").setRowKey("queryEntitiesWithFilterWorks-" + i)
- .setProperty("test", EdmType.BOOLEAN, true).setProperty("test2", EdmType.STRING, "value")
- .setProperty("test3", EdmType.INT32, 3).setProperty("test4", EdmType.INT64, 12345678901L)
- .setProperty("test5", EdmType.DATETIME, new Date());
-
- service.insertEntity(table, entity);
+ entities[i] = new Entity().setPartitionKey("001").setRowKey("queryEntitiesWithFilterWorks-" + i)
+ .setProperty("test", EdmType.BOOLEAN, (i % 2 == 0))
+ .setProperty("test2", EdmType.STRING, "'value'" + i).setProperty("test3", EdmType.INT32, i)
+ .setProperty("test4", EdmType.INT64, 12345678901L + i)
+ .setProperty("test5", EdmType.DATETIME, new Date(i * 1000))
+ .setProperty("test6", EdmType.GUID, UUID.randomUUID());
+
+ service.insertEntity(table, entities[i]);
}
{
@@ -641,6 +644,63 @@ public void queryEntitiesWithFilterWorks() throws Exception {
assertEquals(1, result.getEntities().size());
assertEquals("queryEntitiesWithFilterWorks-3", result.getEntities().get(0).getRowKey());
}
+
+ {
+ // Act
+ QueryEntitiesResult result = service.queryEntities(
+ table,
+ new QueryEntitiesOptions().setQuery(new Query().setFilter(Filter.eq(Filter.litteral("test"),
+ Filter.constant(true)))));
+
+ // Assert
+ assertNotNull(result);
+ assertEquals(3, result.getEntities().size());
+ }
+
+ {
+ // Act
+ QueryEntitiesResult result = service.queryEntities(table, new QueryEntitiesOptions().setQuery(new Query()
+ .setFilter(Filter.eq(Filter.litteral("test2"), Filter.constant("'value'3")))));
+
+ // Assert
+ assertNotNull(result);
+ assertEquals(1, result.getEntities().size());
+ assertEquals("queryEntitiesWithFilterWorks-3", result.getEntities().get(0).getRowKey());
+ }
+
+ {
+ // Act
+ QueryEntitiesResult result = service.queryEntities(table, new QueryEntitiesOptions().setQuery(new Query()
+ .setFilter(Filter.eq(Filter.litteral("test4"), Filter.constant(12345678903L)))));
+
+ // Assert
+ assertNotNull(result);
+ assertEquals(1, result.getEntities().size());
+ assertEquals("queryEntitiesWithFilterWorks-2", result.getEntities().get(0).getRowKey());
+ }
+
+ {
+ // Act
+ QueryEntitiesResult result = service.queryEntities(table, new QueryEntitiesOptions().setQuery(new Query()
+ .setFilter(Filter.eq(Filter.litteral("test5"), Filter.constant(new Date(3000))))));
+
+ // Assert
+ assertNotNull(result);
+ assertEquals(1, result.getEntities().size());
+ assertEquals("queryEntitiesWithFilterWorks-3", result.getEntities().get(0).getRowKey());
+ }
+
+ {
+ // Act
+ QueryEntitiesResult result = service.queryEntities(table, new QueryEntitiesOptions().setQuery(new Query()
+ .setFilter(Filter.eq(Filter.litteral("test6"),
+ Filter.constant(entities[3].getPropertyValue("test6"))))));
+
+ // Assert
+ assertNotNull(result);
+ assertEquals(1, result.getEntities().size());
+ assertEquals("queryEntitiesWithFilterWorks-3", result.getEntities().get(0).getRowKey());
+ }
}
@Test
Something went wrong with that request. Please try again.