SQLiteException: database disk image is malformed
Using the example scenes everything works fine in the editor (5.1.2), but on a Droid Razor HD I'm getting the following error "SQLiteException: database disk image is malformed" after entering in the password. Any suggestions?
Does it work on Linux too..?
A little late, but I may have an answer. Maybe it can be useful for future users.
The problem is that the example copies the 'default' database (located in StreamingAssets) in the new location on the phone, but that database was crated in the Editor mode and it may be not read correctly on mobile devices, especially if it is encrypted.
The solution is to directly create a new database in the new position. I show a piece of my code:
private ISQLiteConnection _connection;
private DatabaseController()
{
// We check the existance of the database. If it does not exists we create a new one.
var factory = new ConnectionFactory();
// check if file exists in Application.persistentDataPath
filepath = string.Format("{0}/{1}", Application.persistentDataPath, DatabaseName);
if (!File.Exists(filepath))
{
// Creating new database
Debug.Log("Database not in Persistent path: creating new one");
_connection = factory.Create(filepath);
CreateScoreTable();
LockDB();
Debug.Log("Database written in " + filepath);
}
else {
dbPath = filepath;
firstCreation = false;
_connection = factory.Create(dbPath);
}
Debug.Log("Database succesfully load");
}
/// <summary>
/// Creating the score table. Method to use when we have created a new database.
/// </summary>
public void CreateScoreTable()
{
_connection.CreateTable<YourTable>();
}
/// <summary>
/// Encripts the database
/// </summary>
public void LockDB()
{
_connection.SetDbKey(Password);
}`