Skip to content

Commit

Permalink
Merge branch 'master' into kevin_local
Browse files Browse the repository at this point in the history
Conflicts:
	tests/java/novoda/lib/sqliteprovider/util/UriToSqlAttributesInspectorTest.java
  • Loading branch information
kevinmcdonagh committed Dec 3, 2010
2 parents 90393d5 + 4ec97b7 commit 0fb47c6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
18 changes: 11 additions & 7 deletions src/novoda/lib/sqliteprovider/provider/SQLiteProvider.java
Expand Up @@ -15,6 +15,11 @@
public class SQLiteProvider extends ContentProvider {

private ExtendedSQLiteOpenHelper db;

private static final String ID = "_id";
private static final String GROUP_BY = "groupBy";
private static final String HAVING = "having";
private static final String LIMIT = "limit";

/**
* @see android.content.ContentProvider#delete(Uri,String,String[])
Expand Down Expand Up @@ -79,21 +84,20 @@ public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
final SQLiteQueryBuilder builder = getSQLiteQueryBuilder();
final String tableName = UriUtils.getItemDirID(uri);
String groupBy=null;
if (uri.getEncodedQuery()!=null){
groupBy = uri.getEncodedQuery().split("=")[1];
}
String groupBy = uri.getQueryParameter(GROUP_BY);
String having = uri.getQueryParameter(HAVING);
String limit = uri.getQueryParameter(LIMIT);
builder.setTables(tableName);
if (UriUtils.isItem(uri)) {
builder.appendWhere("_id=" + uri.getLastPathSegment());
builder.appendWhere(ID + "=" + uri.getLastPathSegment());
} else {
if (UriUtils.hasParent(uri)) {
builder.appendWhereEscapeString(UriUtils.getParentName(uri)
+ "_id=" + UriUtils.getParentId(uri));
+ ID + "=" + UriUtils.getParentId(uri));
}
}
return builder.query(getReadableDatabase(), projection, selection,
selectionArgs, groupBy, null, sortOrder, null);
selectionArgs, groupBy, having, sortOrder, limit);
}

/**
Expand Down
Expand Up @@ -88,10 +88,20 @@ public void testInsertAgainstOneToManyShouldInputCorrectParam() throws Exception

@Test
public void testGroupByQuery() throws Exception {
query("test.com/table?orderBy=table");
//verify(builder).query(db, projectionIn, selection, selectionArgs, "table", having, sortOrder);

// having
query("test.com/table?groupBy=table");
verify(builder).query((SQLiteDatabase) anyObject(), (String[])anyObject(), anyString(), (String[])anyObject(), eq("table"), anyString(), anyString(), anyString());
}

@Test
public void testHavingQuery() throws Exception {
query("test.com/table?having=g");
verify(builder).query((SQLiteDatabase) anyObject(), (String[])anyObject(), anyString(), (String[])anyObject(), anyString(), eq("g"), anyString(), anyString());
}

@Test
public void testLimitQuery() throws Exception {
query("test.com/table?limit=100");
verify(builder).query((SQLiteDatabase) anyObject(), (String[])anyObject(), anyString(), (String[])anyObject(), anyString(), anyString(), anyString(), eq("100"));
}

@Implements(ContentUris.class)
Expand Down
22 changes: 11 additions & 11 deletions tests/java/novoda/lib/sqliteprovider/util/SQLFileTest.java
Expand Up @@ -22,17 +22,17 @@ public class SQLFileTest extends AndroidTestCase {

String two = "CREATE TABLE 'child' (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, parent_id INTEGER NOT NULL, FOREIGN KEY(parent_id) REFERENCES parent(_id));";

// @Test
// public void testSimpleSQLFile() throws Exception {
// BufferedReader reader = new BufferedReader( new InputStreamReader(getClass().getResourceAsStream("/create.sql")));
// new InputStreamReader(new FileInputStream("create.sql"));
// List<String> statements = SQLFile.statementsFrom(reader);
// List<String> expected = new ArrayList<String>();
// expected.add(one);
// expected.add(two);
// assertSameList(statements, expected);
// assertNotNull(this.getContext().getAssets());
// }
@Test
public void testSimpleSQLFile() throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/create.sql")));
new InputStreamReader(new FileInputStream("create.sql"));
List<String> statements = SQLFile.statementsFrom(reader);
List<String> expected = new ArrayList<String>();
expected.add(one);
expected.add(two);
assertSameList(statements, expected);
assertNotNull(this.getContext().getAssets());
}

private void assertSameList(List<String> first, List<String> second) {
if (first.size() != second.size())
Expand Down

0 comments on commit 0fb47c6

Please sign in to comment.