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.DbDataA开发者_开发技巧dapter: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
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.
精彩评论