3

We are using Visual Studio 2010, Monodroid and SQLite

We create a database at path myContext.GetDatabasePath("mydb.db3").AbsolutePath using the SqliteConnection.CreateFile(...) method.

So our connection string is "Data Source=/data/data/myapp.myapplication/databases/mydb.db3temp;"

We create a table and insert several records using SqliteCommand.ExecuteNonQuery().

We can run select queries with SqliteCommand.ExecuteScalar() immediately after inserting.

SqliteDataAdapter.Fill(table) method does not run successfully and gives us this exception:

System.EntryPointNotFoundException: sqlite3_column_origin_name
 at (wrapper managed-to-native) Mono.Data.Sqlite.UnsafeNativeMethods:sqlite3_column_origin_name (intptr,int)
 at Mono.Data.Sqlite.SQLite3.ColumnOriginalName (Mono.Data.Sqlite.SqliteStatement stmt, Int32 index) [0x00000] in <filename unknown>:0 
 at Mono.Data.Sqlite.SqliteDataReader.GetSchemaTable (Boolean wantUniqueInfo, Boolean wantDefaultValue) [0x00000] in <filename unknown>:0 
 at Mono.Data.Sqlite.SqliteDataReader.GetSchemaTable () [0x00000] in <filename unknown>:0 
 at System.Data.Common.DataAdapter.BuildSchema (IDataReader reader, System.Data.DataTable table, SchemaType schemaType, MissingSchemaAction missingSchAction, MissingMappingAction missingMapAction, System.Data.Common.DataTableMappingCollection dtMapping) [0x00000] in <filename unknown>:0 
 at System.Data.Common.DataAdapter.BuildSchema (IDataReader reader, System.Data.DataTable table, SchemaType schemaType) [0x00000] in <filename unknown>:0 
 at System.Data.Common.DataAdapter.FillTable (System.Data.DataTable dataTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords, System.Int32& counter) [0x00000] in <filename unknown>:0 
 at System.Data.Common.DataAdapter.FillInternal (System.Data.DataTable dataTable, IDataReader dataReader) [0x00000] in <filename unknown>:0 
 at System.Data.Common.DataAdapter.Fill (System.Data.DataTable dataTable, IDataReader dataReader) [0x00000] in <filename unknown>:0 
 at System.Data.Common.DbDataAdapter.Fill (System.Data.DataTable dataTable, IDbCommand command, CommandBehavior behavior) [0x00000] in <filename unknown>:0 
 at System.Data.Common.DbDataAdapter.Fill (System.Data.DataTable dataTable) [0x00000] in <filename unknown>:0 
 at (wrapper remoting-invoke-with-check) System.Data.Common.DbDataAdapter:Fill (System.Data.DataTable)
 at ...

If we make any changes to the application code and redeploy, then the db file still exists on the android device but SqliteCommand.ExecuteScalar() and SqliteDataAdapter.Fill(table) will throw exceptions that say that the table does not exist:

Mono.Data.Sqlite.SqliteException: SQLite error
no such table: MyTable
 at Mono.Data.Sqlite.SQLite3.Prepare (Mono.Data.Sqlite.SqliteConnection cnn, System.String strSql, Mono.Data.Sqlite.SqliteStatement previous, UInt32 timeoutMS, System.String& strRemain) [0x00000] in <filename unknown>:0 
 at Mono.Data.Sqlite.SqliteCommand.BuildNextCommand () [0x00000] in <filename unknown>:0  

Is this expected Monodroid behavior? Should we lose the tables after re-deploying the application? How should we use SqliteDataAdapter.Fill()?

Thanks

Joel
  • 1,033
  • 2
  • 12
  • 23
  • Have you tried pulling the database file of the device and opening it in a database browser and seeing if the table exists? – Ian Dallas Oct 06 '11 at 03:23
  • I hadn't tried it before. I just tried it now, the tables do not exist. – Joel Oct 06 '11 at 13:59

1 Answers1

3

By default, files you create get deleted when you uninstall the app on Android. In Visual Studio, go to Tools->Options->Mono for Android and turn on "Preserve data between application deploys". This will pass a flag to uninstall that tells it to leave your data on the device.

jpobst
  • 9,982
  • 1
  • 29
  • 33
  • Why doesn't it do this by default? What is the motivation for this being an option and not the default behavior? Also, this does not explain the db being present but the tables going missing. – CF_Maintainer Oct 06 '11 at 13:13
  • It's the Android default that apps don't leave a bunch of crap on your device when you uninstall them. – jpobst Oct 06 '11 at 14:15
  • Ok. Agreed. Real question I should have asked was as to why this deployment behavior differs from how IntelliJ Idea/eclipse (android) or even xcode (iOS) deploy where they do not erase user data on subsequent runs. They seem to not reinstall the application it has been has been deployed already. – CF_Maintainer Oct 06 '11 at 16:34