1. Make Connection.


  1. private IDbConnection dbcon;
  2. ...
  3.  
  4. public void OpenDB(string p)
  5.  
  6. {
  7.  
  8.     connection = "URI=file:" + Application.persistentDataPath + "/" + p; // we set the connection to our database
  9.  
  10.     //connection = "URI=file:" + p; // like this will NOT work on android
  11.  
  12.     Debug.Log(connection);
  13.  
  14.     dbcon = new SqliteConnection(connection);
  15.  
  16.     dbcon.Open();
  17.  
  18. }

2. load an already populated db in android dev.

  1. // check if file exists in Application.persistentDataPath
  2.  
  3. string filepath = Application.persistentDataPath + "/" + p;
  4.  
  5. if(!File.Exists(filepath))
  6.  
  7. {
  8.  
  9.     // if it doesn't ->
  10.  
  11.     // open StreamingAssets directory and load the db ->
  12.  
  13.     WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/" + p);  // this is the path to your StreamingAssets in android
  14.  
  15.     while(!loadDB.isDone) {}  // CAREFUL here, for safety reasons you shouldn't let this while loop unattended, place a timer and error check
  16.  
  17.     // then save to Application.persistentDataPath
  18.  
  19.     File.WriteAllBytes(filepath, loadDB.bytes);
  20.  
  21. }
  22.  
  23.        
  24.  
  25. //open db connection
  26.  
  27. connection = "URI=file:" + filepath;
  28.  
  29. dbcon = new SqliteConnection(connection);
  30.  
  31. dbcon.Open();

in unity3d 5, there is a problem with sqlite3.dll ( it is 32bit version )


Posted by 바람도리
,