Skip to content

Commit

Permalink
adding documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
charroch committed Dec 3, 2010
1 parent ed8017e commit 6950ab6
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="bin/scala_2.8.1/test-classes" path="tests/java"/>
<classpathentry including="**/*.java" kind="src" path="src"/>
<classpathentry kind="src" path="tests/java"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="libs/test/robolectric-0.9.2.jar"/>
<classpathentry kind="lib" path="libs/test/mockito-all-1.8.5.jar"/>
<classpathentry kind="lib" path="libs/test/junit-4.8.2.jar"/>
<classpathentry kind="output" path="bin/scala_2.8.1/classes"/>
<classpathentry kind="output" path="bin/"/>
</classpath>
11 changes: 6 additions & 5 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.scala-ide.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>

<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
Expand Down
119 changes: 118 additions & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1 +1,118 @@
A library module for SQLite.
An Android library as ContentProvider for SQLite
================================================


THIS IS A DUMP OF IDEAS - NOTHING IS IMPLEMENTED AT THE MOMENT



The library is meant to augment the ContentProvider interface to fit SQLite in a more pronounced way. The aim is
to set convention on queries via URI. A lot of facilities are added to ensure

The following Uris are intended to be supported:

### General Uri by convention

Generic table support:

Uri: content://<authority>/tableName
Sql: select * from "tableName"

Primary key support:

Uri: content://<authority>/tableName/1
Sql: select * from "tableName" where _id=1

One to many support:

Uri: content://<authority>/tableName/1/child
Sql: select * from "child" where tableName_id=1

Group by & having support:

Uri: content://<authority>/tableName?groupBy=col&having=value
Sql: select * from tableName group by col having value

limit support:

Uri: content://<authority>/tableName?limit=number
Sql: select * from tableName limit number

distinct support:

Uri: content://<authority>/tableName?distinct=true
Sql: select distinct * from tableName limit number


### Info Uri

Gives the ability to query information from the table SQLITE_MASTER and versionning.

content://<authority>/_info

Querying the above will yield the following cursor:

type TEXT | name TEXT | tbl_name TEXT | rootpage INTEGER | sql TEXT

If you are interested to only get the table name, the following should be helpful:

getContentResolver().query(Uri.parse("content://<authority>/_info"), new String[] {"name"}, null, null, null);


To get the current version of the database similar to "select sqlite_version() AS sqlite_version":

content://<authority>/_info?version

returns the following cursor:

sqlite_version TEXT

### Size management

Executing some file resizing using vacuum

content://<authority>/_vacuum

(TODO) set max size??

### Pragma Uris


Ability to execute Pragma calls against SQLite. This is handy to get further info on table or set values such as "PRAGMA synchronous=OFF"

content://<authority>/_pragma?<pragma_name>=<value>

For instance the following will exectute "PRAGMA synchronous=OFF"

content://<authority>/_pragma?synchronous=OFF

The following will give back table information for a specific table:

content://<authority>/_pragma?table_info("tableName")

The resulting cursor is

column name | data type | can be NULL? | the default value for the column


### Table creation

If you insert against

content://<authority>/_db?create=<tableName>&withId=<true|false>&foreignKey=[<comma_separated_list_of_parent_tables>]&createdAt=false&updatedAt=false

(TODO) alter?

tableName (mandatory): the table name
withId (optional): automatically add "_id PRIMARY KEY AUTOINCREMENT" - default is true
foreignKey (optional): automatically add <fk_name>_id as foreign key to table creation
createdAt (optional): will put a createdAt field which contains creation date - default to insert
updatedAt (optional): will put a updatedAt field which contains update date - default to insert

you should have content values put with "column name" mapped to a SQLite type (look at SQLiteType)

Uri uri = Uri.parse("content://authority/_db?create=table
ContentValues values = new ContentValues();
values.put("name", "TEXT");
values.put("rid", "INTEGER");
getContentResolver().insert(uri, values);
2 changes: 1 addition & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="app_name">ACTIVITY_ENTRY_NAME</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@

import static org.mockito.Mockito.verify;

import com.xtremelabs.robolectric.RobolectricTestRunner;
import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.util.Implementation;
import com.xtremelabs.robolectric.util.Implements;

import novoda.lib.sqliteprovider.util.RoboRunner;
import novoda.lib.sqliteprovider.util.ShadowSQLiteQueryBuilder;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import android.content.ContentUris;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;

@RunWith(RobolectricTestRunner.class)
@RunWith(RoboRunner.class)
public class SQLiteProviderLocalTest {

SQLiteProviderImpl provider;
Expand All @@ -37,6 +43,23 @@ public void testSelectTableFromUri() throws Exception {
// Simple directory listing against table test
query("test.com/test");
verify(builder).setTables("test");

Robolectric.bindShadowClass(ShadowContentUris.class);
}

@Implements(ContentUris.class)
public class ShadowContentUris {

@Implementation
public void appendWhere(CharSequence inWhere) {
System.out.println("TESTSGASD ");
}

@Implementation
public void setTable(String inWhere) {
System.out.println("TESTSGASD ");
}

}

@Test
Expand Down Expand Up @@ -65,9 +88,9 @@ protected SQLiteDatabase getReadableDatabase() {
return db;
}

@Override
SQLiteQueryBuilder getSQLiteQueryBuilder() {
return builder;
}
// @Override
// SQLiteQueryBuilder getSQLiteQueryBuilder() {
// return builder;
// }
}
}
2 changes: 2 additions & 0 deletions tests/java/novoda/lib/sqliteprovider/util/RoboRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public RoboRunner(Class<?> testClass) throws InitializationError {

@Override public void beforeTest(Method method) {
Robolectric.bindShadowClass(ShadowAndroidTestCase.class);
Robolectric.bindShadowClass(ShadowSQLiteQueryBuilder.class);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public void testGettingIds() throws Exception {
assertTrue(result.containsKey("parent") && result.containsKey("child"));
assertEquals("1", result.get("parent"));
assertEquals("2", result.get("child"));



}
}

0 comments on commit 6950ab6

Please sign in to comment.