Andrews 15 data storage device, loading

Store and load:

public void ConnectToSqlite (string DBName)
    {    // determine whether the name specification, if it is not standard suffix 
        IF (! DBName.Contains ( " .sqlite " )) {
            DBName += ".sqlite";
        }
        // If running in the editor 
        #if UNITY_EDITOR
         // get the path 
        sqlitePath = " the Data the Source = " + Application.streamingAssetsPath + " / " + DBName;
         // instance connection object 
        Connection = new new SqliteConnection (sqlitePath);
         // If operation in Android device 
        #elif UNITY_ANDROID
         // string database connection 
        string connectionStr = " the URI = File: " + Application.persistentDataPath + " / " + DBName;
        // path of the database file APK Android 
        String androidPath = " JAR: File: // " + Application.dataPath + " / Assets /! " + DBName;
         // Android sandbox path 
        String androidFilePath = Application.persistentDataPath + " / " + DBName;
         // If there is no database files Android project source file, the description is not loaded, and needed to load the 
        IF (! File.Exists (androidFilePath))
        {
        // get APK Sqlite database file from the path, download 
        the WWW WWW = new new the WWW (androidPath);
         // downloading is not completed, a wait is held 
        the while (! Www.isDone) {}
         // the download is complete, the write IO to flow sand box path 
        File.WriteAllBytes (androidFilePath, www.bytes);
        }
        // Examples connection object 
        Connection = new new SqliteConnection (connectionStr);
         #endif  

        // Create Object Database Command 
        Command = connection.CreateCommand ();
         the try {
             // Open Database 
            Connection.Open ();
        } The catch (System.Exception EX) {
             // output error information 
            print (ex);
        }
    }

 

Guess you like

Origin www.cnblogs.com/zpy1993-09/p/11880178.html