Home > other >  Unity development encountered a small problem database management class
Unity development encountered a small problem database management class

Time:09-18

Use Unity2017.4.2 version development, management class encapsulates a database code below
using UnityEngine;
using System;
using System.Collections;
Using Mono. Data. SqliteClient;
using System.IO;
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//function: Sqlite database management class
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Public class DBManager: TF_Singleton & lt; DBManager> {

# region field
Private SqliteConnection mConn;
Private SqliteCommand mComd;
Private SqliteDataReader mReader;

Private string mDBPath;
Private string mStremingPath;
Private string mDBFilePath;
Private string mDBName="Test";
# endregion

# region method

Void InitDBPath ()
{
//AnZhuoDuan path
MDBFilePath=Application. PersistentDataPath + "/" + mDBName;
MDBPath="URI=file:" + mDBFilePath;
MStremingPath="is the jar: file://" + Application. DataPath + "!"/assets/" + mDBName;

//editor path
If (Application) platform==RuntimePlatform) WindowsEditor)
{
MDBFilePath=Application. StreamingAssetsPath + "/" + mDBName;
MDBPath="Data Source=" + mDBFilePath;
}

}

Void the Open ()
{
If (mConn==null)
{
InitDBPath ();
//for the first time in AnZhuoDuan start
If (System. IO. File. The Exists (mDBFilePath))
{
WWW WWW=new WWW (mStremingPath);
while (! www.isDone)
{

}
System. IO. File. WriteAllBytes (mDBFilePath, www.bytes);
}
MConn=new SqliteConnection (mDBPath);
}
MConn. The Open ();
MComd=mConn. CreateCommand ();//that this error is that the
How to change? Error content is: can't will type
System.Data.Com mon. DbCommand command implicitly converted to
Mono. Data. SpliteClient SqliteCommand, there
A display translation (whether lack of casting)
}

Void the Close ()
{
If (mConn!=null)
{
//close the database
MConn. Close ();
}
If (mComd!=null)
{
//release the memory
MComd. The Dispose ();
}
}


# endregion
}

CodePudding user response:

MConn. CreateCommand (); This sentence must return is mon. System.Data.Com DbCommand command this gadget, mon. Then when you meet with System.Data.Com DbCommand command this type joint
  • Related