unity怎麼引用mysqldata? SQLiteDB sqLiteDb = new SQLiteDB();
string Filename = Application.streamingAssetsPath "/gameSql.db";
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
sqLiteDb.Open(filename);
,下面我們就來聊聊關于unity怎麼引用mysqldata?接下來我們就一起去了解一下吧!
SQLiteDB sqLiteDb = new SQLiteDB();
string Filename = Application.streamingAssetsPath "/gameSql.db";
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
sqLiteDb.Open(filename);
//id INTEGER PRIMARY KEY設置自增Id,DataKey BIGINT, Data BLOB,Size INT表示 字段名稱 字段類型,字段名稱 字段類型,字段名稱 字段類型
string query_create = $"{CREATE TABLE IF NOT EXISTS}{表名}(id INTEGER PRIMARY KEY, DataKey BIGINT, Data BLOB,Size INT);";
SQLiteQuery query = new SQLiteQuery(sqLiteDb, password);
query.Step();
query.Release();
query = new SQLiteQuery(sqLiteDb, queryCreate);
query.Step();
query.Release();
string data = "需要存儲的數據";
long id
string queryInsert = $"INSERT INTO{tableName} (DataKey,Data) VALUES(?,?);";
SQLiteQuery query = new SQLiteQuery(sqLiteDb, password);
query.Step();
query.Release();
query = new SQLiteQuery(sqLiteDb, queryInsert);
query.Bind(id);
query.Bind(data);
query.Step();
query.Release();
netData.OnRecycling();
long id = 存儲數據的key值
string data = "需要存儲的數據";
string query_update = $"UPDATE {表名} SET Data = ? WHERE DataKey = ?;";//
SQLiteQuery query = new SQLiteQuery(sqLiteDb, password);
query.Step();
query.Release();
query = new SQLiteQuery(sqLiteDb, query_update);
query.Bind(data);
query.Bind(id);
query.Step();
query.Release();
string value = string.Empty;
long id = 存儲數據的key值
//若删除 WHERE DataKey = ?将查詢整張表内的數據
string query_select = $"SELECT * FROM {表名} WHERE DataKey = ?;";
SQLiteQuery query = new SQLiteQuery(sqLiteDb, password);
query.Step();
query.Release();
query = new SQLiteQuery(sqLiteDb, query_select);
query.Bind(id);
if (query.Step())
{
value = query.GetBlob("Data");
}
query.Release();
long id = 存儲數據的key值
//若删除 WHERE DataKey = ?将删除整張表内的數據
string query_delete = $"DELETE FROM {表名} WHERE DataKey = ?;";
SQLiteQuery query = new SQLiteQuery(sqLiteDb, password);
query.Step();
query.Release();
query = new SQLiteQuery(sqLiteDb, query_delete);
query.Bind(id);
query.Step();
query.Release();
sqLiteDb.Close();
string outFile = string.Empty;
#if UNITY_ANDROID
outFile = Application.persistentDataPath "/gameSql.db";
#elif UNITY_IPHONE
outFile = "file://" Application.persistentDataPath "/gameSql.db";
#endif
string resPath = Application.streamingAssetsPath "/gameSql.db";
if (File.Exists(outFile)) File.Delete(outFile);
UnityWebrequest request = UnityWebRequest.Get(resPath);
request.timeout = 30;
yield return request.SendWebRequest();
System.IO.File.WriteAllBytes(outFile,request.downloadHandler.data);
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!