Exemplo n.º 1
0
    public static DataTable RequestLoad(DB_ID id)
    {
        for (int i = 0; i < databseList.Count; i++)
        {
            DatabaseLoadData data = databseList[i];
            if (data.id != id)
            {
                continue;
            }
            if (data.isLoaded)
            {
                continue;
            }

            SqliteDatabase sqlDB       = new SqliteDatabase(data.dbName + ".db");
            string         selectQuery = "SELECT * FROM " + data.tableName;
            data.dataTable = sqlDB.ExecuteQuery(selectQuery);

            data.isLoaded = true;

            return(data.dataTable);
        }

        return(null);
    }
Exemplo n.º 2
0
    DatabaseLoadData GetData(DB_ID id, string dbName, string tableName)
    {
        DatabaseLoadData data = new DatabaseLoadData();

        data.dbName    = dbName;
        data.tableName = tableName;
        data.id        = id;


        return(data);
    }
Exemplo n.º 3
0
    public static bool IsLoaded(DB_ID id)
    {
        for (int i = 0; i < databseList.Count; i++)
        {
            DatabaseLoadData data = databseList[i];
            if (data.id != id)
            {
                continue;
            }

            return(data.isLoaded);
        }

        return(false);
    }
Exemplo n.º 4
0
 public override string ToString()
 {
     return(DB_ID.ToString());
 }
Exemplo n.º 5
0
    public HotFileDbFRAMIO(string key, string filePath)
    {
        if (GameMain.Singleton != null)
        {
            mMCU = GameMain.Singleton.ArcIO;
        }
        if (mMCU == null)
        {
            mMCU = INemoControlIOSinglton.Get();
        }
        //?????????????
        if (mConn == null)
        {
            if (DataBaseName == "")
            {
                DataBaseName = "GameDB.db";
            }

            string dataPath = System.Environment.CurrentDirectory + "/DataFiles";
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }


            mConn = new SqliteConnection("Data Source = DataFiles/" + DataBaseName + ";");
            mConn.Open();

            if (mCMD == null)
            {
                mCMD = mConn.CreateCommand();
                mCMD.Parameters.Add(new SqliteParameter());
            }

            mCMD.CommandText = "PRAGMA journal_mode =wal;";//wal??
            mCMD.ExecuteNonQuery();
        }



        mKey    = key;
        mDBType = GetDBType();
        //bool isInitFRAMByDB = false;
        //?????DB_FARM_ID
        if (mMCU.IsOpen() && DB_ID == System.Guid.Empty)
        {
            using (SqliteCommand cmd = mConn.CreateCommand())
            {
                cmd.CommandText = "CREATE TABLE IF NOT EXISTS _DB_GUID(Val BLOB);";
                //cmd.Parameters.Add("@data", System.Data.DbType.Binary).Value = System.Guid.Empty.ToByteArray();
                cmd.ExecuteNonQuery();
                cmd.CommandText = string.Format(" SELECT * FROM _DB_GUID;");
                SqliteDataReader r = cmd.ExecuteReader();
                r.Read();

                if (r.HasRows)//????????????????
                {
                    //???????????guid?
                    DB_ID = new System.Guid(r.GetValue(0) as byte[]);
                    //???FRAM??guid?
                    byte[] guidFRAMByte = null;
                    if (mMCU.Read_Block(0, 16, out guidFRAMByte))//??FRAM???guid???
                    {
                        System.Guid FRAMEGUID = new System.Guid(guidFRAMByte);
                        if (FRAMEGUID != DB_ID)                                      //FRAM??db??guid?????
                        {
                            mMCU.RequestReadWrite(true, 0, 16, DB_ID.ToByteArray()); //??dbid§Õ??FRAM
                            IsInitFRAMByDB = true;
                        }
                    }
                    r.Close();
                }
                else//?????????guid
                {
                    r.Close();
                    //??????dbGUID
                    DB_ID = System.Guid.NewGuid();
                    byte[] guidByteNew = DB_ID.ToByteArray();
                    //????db
                    cmd.CommandText = "INSERT INTO _DB_GUID VALUES (@data)";
                    cmd.Parameters.Add("@data", System.Data.DbType.Binary).Value = guidByteNew;
                    cmd.ExecuteNonQuery();

                    //?????????guid ????FRAM
                    mMCU.RequestReadWrite(true, 0, 16, guidByteNew);
                    IsInitFRAMByDB = true;
                }
            }
        }


        //??????(4294967295 == 0xffffffff)
        mCMD.CommandText = string.Format("CREATE TABLE IF NOT EXISTS {0:s}(Val {1:s} KEY DEFAULT {2:s},Address INTEGER DEFAULT 4294967295,Length INTEGER DEFAULT {3:d});", mKey, GetDBTypeString(), GetDefaultDBValString(), GetValLength());
        mCMD.ExecuteNonQuery();


        //???????????????
        mCMD.CommandText = string.Format(" SELECT * FROM {0:s};", mKey);
        SqliteDataReader reader = mCMD.ExecuteReader();

        reader.Read();

        //
        //System.Guid.NewGuid();

        if (reader.HasRows)//????????????????
        {
            //????????????????????????
            mAddress    = (uint)reader.GetInt64(1);
            mDataLength = (byte)reader.GetInt32(2);
            if (IsInitFRAMByDB)
            {
                WriteToFRAM(ObjectToVal(reader.GetValue(0)));
            }
            reader.Close();
        }
        else//????????????????,????????
        {
            mAddress    = CurrentUseAddress;
            mDataLength = (byte)GetValLength();
            reader.Close();

            //???????????
            mCMD.CommandText   = string.Format("INSERT INTO {0:s} VALUES({1:s},{2:d},{3:d})", mKey, GetDefaultDBValString(), mAddress, mDataLength);
            CurrentUseAddress += GetValLength();//???????
            mCMD.ExecuteNonQuery();

            //?????farm
            WriteToFRAM(GetDefaultVal());
        }

        mUpdateSQLText = "UPDATE " + mKey + " SET Val = ?;";

        ++SqliteConnRefCount;
        HotFileDBIOReleaser.HotFileDBReg(this);
        HotFileDBFRAM_Updater.Reg(this);
    }