Problem creating sqlite3 database

I found it was caused because the full path to the database file (including folders) was not created.
This method was throwing exception:

ODKSQLiteOpenHelper.getWritableDatabase:
db = SQLiteDatabase.openOrCreateDatabase(mPath + "/" + mName, mFactory);

So in the helper class constructor, I added this code:

public ODKSQLiteOpenHelper(String path, String name, CursorFactory factory, int version) {
if (version < 1)
throw new IllegalArgumentException("Version must be >= 1, was " + version);

    mPath = path;
    mName = name;
    mFactory = factory;
    mNewVersion = version;
    
    File dbFile = new File(path + "/");
	if(!dbFile.exists()){
		boolean created = dbFile.mkdirs();
		System.out.println("Folders created?: " + created);        		
	} else {
		System.out.println("File exists!");      
	}  
}

This way it doesn't fail.

However I'm getting another exception after completing the Widgets sample form. Also when I enter to view forms everyone is named 'title'. However I installed the application from market and I wasn't getting the database exception. This makes me think that I may have not downloaded the last available source code from repository.

Note: when I downloaded from mercurial, I had to use the --insecure option.

Someone can confirm this?

··· --- El mar, 24/5/11, spamproof_2011-1004@yahoo.es escribió:

De: spamproof_2011-1004@yahoo.es spamproof_2011-1004@yahoo.es
Asunto: Problem creating sqlite3 database
Para: opendatakit-developers@googlegroups.com
Fecha: martes, 24 de mayo, 2011 10:31
Hi
I've just downloaded the ODK Collect source code and I'm
trying to execute it in the android emulator.
I've created a Google APIs 9 new device with ADB, sdcard is
512MB.
However, when I enter the application and push the first
button, a RuntimeException is thrown. LogCat shows that
there's a problem creating the database:

05-24 08:25:42.815: ERROR/Database(423):
sqlite3_open_v2("/sdcard/odk/metadata/forms.db",
&handle, 6, NULL) failed
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
Couldn't open forms.db for writing (will try read-only):
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
android.database.sqlite.SQLiteException: unable to open
database file
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.database.sqlite.SQLiteDatabase.dbopen(Native
Method)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1829)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
org.odk.collect.android.database.ODKSQLiteOpenHelper.getWritableDatabase(ODKSQLiteOpenHelper.java:110)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
org.odk.collect.android.database.ODKSQLiteOpenHelper.getReadableDatabase(ODKSQLiteOpenHelper.java:175)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
org.odk.collect.android.provider.FormsProvider.query(FormsProvider.java:125)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.content.ContentProvider$Transport.query(ContentProvider.java:187)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.content.ContentResolver.query(ContentResolver.java:262)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.app.Activity.managedQuery(Activity.java:1550)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
org.odk.collect.android.activities.FormChooserList.onCreate(FormChooserList.java:58)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.os.Handler.dispatchMessage(Handler.java:99)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.os.Looper.loop(Looper.java:123)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
android.app.ActivityThread.main(ActivityThread.java:3647)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
java.lang.reflect.Method.invokeNative(Native Method)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
java.lang.reflect.Method.invoke(Method.java:507)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423):
at dalvik.system.NativeStart.main(Native
Method)

I've not modified the code, it's just fresh downloaded from
mercurial. Any hint about what could be happening?

Thanks.

trunk is very unstable these days.

carl has patched the folder creation issue in his local repo, but has
yet to push the changes.

the title issue is the first bug on my todo list today. didn't get to
it last night. but if you add proper title tag to your forms, it
should use that instead.

··· On Tue, May 24, 2011 at 03:32, wrote: > I found it was caused because the full path to the database file (including folders) was not created. > This method was throwing exception: > > ODKSQLiteOpenHelper.getWritableDatabase: > db = SQLiteDatabase.openOrCreateDatabase(mPath + "/" + mName, mFactory); > > So in the helper class constructor, I added this code: > > public ODKSQLiteOpenHelper(String path, String name, CursorFactory factory, int version) { > if (version < 1) > throw new IllegalArgumentException("Version must be >= 1, was " + version); > > mPath = path; > mName = name; > mFactory = factory; > mNewVersion = version; > > File dbFile = new File(path + "/"); > if(!dbFile.exists()){ > boolean created = dbFile.mkdirs(); > System.out.println("Folders created?: " + created); > } else { > System.out.println("File exists!"); > } > } > > This way it doesn't fail. > > However I'm getting another exception after completing the Widgets sample form. Also when I enter to view forms everyone is named 'title'. However I installed the application from market and I wasn't getting the database exception. This makes me think that I may have not downloaded the last available source code from repository. > > Note: when I downloaded from mercurial, I had to use the --insecure option. > > Someone can confirm this? > > > > --- El mar, 24/5/11, spamproof_2011-1004@yahoo.es escribió: > >> De: spamproof_2011-1004@yahoo.es >> Asunto: Problem creating sqlite3 database >> Para: opendatakit-developers@googlegroups.com >> Fecha: martes, 24 de mayo, 2011 10:31 >> Hi >> I've just downloaded the ODK Collect source code and I'm >> trying to execute it in the android emulator. >> I've created a Google APIs 9 new device with ADB, sdcard is >> 512MB. >> However, when I enter the application and push the first >> button, a RuntimeException is thrown. LogCat shows that >> there's a problem creating the database: >> >> 05-24 08:25:42.815: ERROR/Database(423): >> sqlite3_open_v2("/sdcard/odk/metadata/forms.db", >> &handle, 6, NULL) failed >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> Couldn't open forms.db for writing (will try read-only): >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> android.database.sqlite.SQLiteException: unable to open >> database file >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.database.sqlite.SQLiteDatabase.dbopen(Native >> Method) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1829) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> org.odk.collect.android.database.ODKSQLiteOpenHelper.getWritableDatabase(ODKSQLiteOpenHelper.java:110) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> org.odk.collect.android.database.ODKSQLiteOpenHelper.getReadableDatabase(ODKSQLiteOpenHelper.java:175) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> org.odk.collect.android.provider.FormsProvider.query(FormsProvider.java:125) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.content.ContentProvider$Transport.query(ContentProvider.java:187) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.content.ContentResolver.query(ContentResolver.java:262) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.app.Activity.managedQuery(Activity.java:1550) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> org.odk.collect.android.activities.FormChooserList.onCreate(FormChooserList.java:58) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.app.ActivityThread.access$1500(ActivityThread.java:117) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.app.ActivityThread$H.handleMessage(ActivityThread.java:928) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.os.Handler.dispatchMessage(Handler.java:99) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.os.Looper.loop(Looper.java:123) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> android.app.ActivityThread.main(ActivityThread.java:3647) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> java.lang.reflect.Method.invokeNative(Native Method) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> java.lang.reflect.Method.invoke(Method.java:507) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at >> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) >> 05-24 08:25:43.115: ERROR/ODKSQLiteOpenHelper(423): >> at dalvik.system.NativeStart.main(Native >> Method) >> >> I've not modified the code, it's just fresh downloaded from >> mercurial. Any hint about what could be happening? >> >> Thanks. >> >