Beispiel #1
0
        private static void InitDatabase()
        {
            sqlite3Operate = SQLite3Factory.OpenOrCreate(MD5Utility.GetBytesMD5(Encoding.UTF8.GetBytes("SQLite3Prefs.db")));

            if (!sqlite3Operate.TableExists(tableName))
            {
                sqlite3Operate.Exec(sql);
            }
        }
Beispiel #2
0
 public static void DeleteAll()
 {
     if (null == sqlite3Operate)
     {
         InitDatabase();
     }
     sqlite3Operate.DeleteAll(tableName);
     sqlite3Operate.CloseDB();
     sqlite3Operate = null;
 }
    // Use this for initialization
    void Start()
    {
        SQLite3Operate operate = SQLite3Factory.OpenToReadOnly("Database.db", false);

        Achievement[] achvList = operate.SelectArrayT <Achievement>();

        for (int i = 0; i < achvList.Length; ++i)
        {
            Debug.LogError(achvList[i]);
        }

        Achievement achv = new Achievement(0, "abc", 0, "1001", "defg", "hij",
                                           new int[] { 1, 2, 3 },
                                           new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 } },
                                           new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }, new int[] { 7, 8, 9 } });

        //new int[][][] { new int[][] {new int[]{1, 2, 3}, new int[]{4, 5, 6} }, new int[][] { new int[]{7, 8, 9}, new int[]{10, 11, 12}} });
        Debug.LogError(achv);
    }
Beispiel #4
0
 public void Init()
 {
     ConfigSQLite3Operate = SQLite3Factory.OpenToRead("Database.db");
     LocalSQLite3Operate  = SQLite3Factory.OpenToWrite("Dynamic.db");
     CheckTable();
     IPlayer.Init();
     IPlayerBattle.Init();
     ICharacter.Init();
     IEquipment.Init();
     IPlayerBattle.Init();
     IPlayerClearStage.Init();
     IPlayerCurrency.Init();
     IPlayerFormation.Init();
     IPlayerHasCharacters.Init();
     IPlayerHasEquips.Init();
     IPlayerOtherItem.Init();
     IPlayerStamina.Init();
     IPlayerUnlockItem.Init();
     //IPlayerHasEquips.InsertNewEquips("2001");
     //IPlayerHasCharacters.InsertNewCharacter("1001");
 }
    void OnGUI()
    {
        GUI.skin.button.fontSize = 32;
        if (GUILayout.Button("Load Sqlite3 Data"))
        {
            SQLite3Data data = Resources.Load <SQLite3Data>("Sqlite3Data");
            foreach (SQLite3SingleData singleData in data.AllData)
            {
                Debug.LogError(singleData);
            }
        }

        if (GUILayout.Button("Load Static Data"))
        {
            SQLite3Operate operate = SQLite3Factory.OpenToRead("Static.db");
            Debug.LogError(operate.SelectTbyId <LevelConfig>(40000));
        }

        if (GUILayout.Button("Load Dynamic Data"))
        {
            SQLite3Operate operate = SQLite3Factory.OpenToRead("Dynamic.db");
            Debug.LogError(operate.SelectTbyId <LevelConfig>(40002));
        }
    }
        public static void Creator(ref TableData InTableData, string InDatabasePath)
        {
            string path = Application.dataPath + "/" + InDatabasePath;

            SQLite3Operate handle = new SQLite3Operate(path, SQLite3OpenFlags.Create | SQLite3OpenFlags.ReadWrite);

            StringBuilder sb = new StringBuilder(256);

            handle.Exec("DROP TABLE IF EXISTS " + InTableData.TableName);

            sb.Append("CREATE TABLE ")
            .Append(InTableData.TableName)
            .Append("(");

            int length = InTableData.ColumnName.Length;

            for (int i = 0; i < length; i++)
            {
                if (InTableData.IsColumnEnables[i])
                {
                    sb.Append(InTableData.ColumnName[i])
                    .Append(" ")
                    .Append(InTableData.SQLite3Types[i])
                    .Append(GetConnstraint(InTableData.SQLite3Constraints[i]))
                    .Append(", ");
                }
            }
            sb.Remove(sb.Length - 2, 2);
            sb.Append(")");
            handle.Exec(sb.ToString());

            if (null != InTableData.ExcelContents)
            {
                length = InTableData.ExcelContents.Length;
                int   subLength;
                ICell cell;
                for (int i = 0; i < length; i++)
                {
                    subLength = InTableData.ExcelContents[i].Length;
                    sb.Remove(0, sb.Length);
                    sb.Append("INSERT INTO ").Append(InTableData.TableName).Append(" VALUES(");
                    for (int j = 0; j < subLength; j++)
                    {
                        if (InTableData.IsColumnEnables[j])
                        {
                            cell = InTableData.ExcelContents[i][j];
                            switch (InTableData.SQLite3Types[j])
                            {
                            case SQLite3ValueType.INTEGER:
                                if (null == cell)
                                {
                                    sb.Append(0);
                                }
                                else
                                {
                                    switch (cell.CellType)
                                    {
                                    case CellType.Numeric:
                                        sb.Append((int)cell.NumericCellValue);
                                        break;

                                    case CellType.String:
                                        int result;
                                        sb.Append(int.TryParse(cell.StringCellValue, out result)
                                                    ? result
                                                    : 0);
                                        break;

                                    case CellType.Boolean:
                                        sb.Append(cell.BooleanCellValue ? 1 : 0);
                                        break;

                                    default:
                                        sb.Append(0);
                                        break;
                                    }
                                }
                                break;

                            case SQLite3ValueType.REAL:
                                if (null == cell)
                                {
                                    sb.Append(0);
                                }
                                else
                                {
                                    switch (cell.CellType)
                                    {
                                    case CellType.Numeric:
                                        sb.Append(cell.NumericCellValue);
                                        break;

                                    case CellType.String:
                                        double result;
                                        sb.Append(double.TryParse(cell.StringCellValue, out result)
                                                    ? result
                                                    : 0);
                                        break;

                                    case CellType.Boolean:
                                        sb.Append(cell.BooleanCellValue ? 1 : 0);
                                        break;

                                    default:
                                        sb.Append(0);
                                        break;
                                    }
                                }
                                break;

                            default:
                                if (null == cell)
                                {
                                    sb.Append("''");
                                }
                                else
                                {
                                    switch (cell.CellType)
                                    {
                                    case CellType.Numeric:
                                        sb.Append("\'")
                                        .Append(cell.NumericCellValue)
                                        .Append("\'");
                                        break;

                                    case CellType.String:
                                        sb.Append(ConvertTypeUtility.CheckSingleQuoteMatch(cell.StringCellValue));
                                        break;

                                    case CellType.Boolean:
                                        sb.Append("\'")
                                        .Append(cell.BooleanCellValue.ToString())
                                        .Append("\'");
                                        break;

                                    default:
                                        sb.Append("''");
                                        break;
                                    }
                                }
                                break;
                            }
                            sb.Append(", ");
                        }
                    }
                    sb.Remove(sb.Length - 2, 2);
                    sb.Append(")");
                    handle.Exec(sb.ToString());
                }
            }

            handle.CloseDB();
        }
        public static void Creator(ref TableData InTableData, string InDatabasePath)
        {
            SQLite3Operate handle = new SQLite3Operate(InDatabasePath, SQLite3OpenFlags.Create | SQLite3OpenFlags.ReadWrite);

            StringBuilder sb = new StringBuilder(256);

            handle.Exec("DROP TABLE IF EXISTS " + InTableData.TableName);

            sb.Append("CREATE TABLE ")
            .Append(InTableData.TableName)
            .Append("(");

            int length = InTableData.ColumnName.Length;

            for (int i = 0; i < length; i++)
            {
                if (InTableData.IsColumnEnables[i])
                {
                    sb.Append(InTableData.ColumnName[i])
                    .Append(" ")
                    .Append(InTableData.SQLite3Types[i])
                    .Append(GetConstraint(InTableData.SQLite3Constraints[i]))
                    .Append(", ");
                }
            }
            sb.Remove(sb.Length - 2, 2);
            sb.Append(")");
            handle.Exec(sb.ToString());

            if (null != InTableData.ExcelContents)
            {
                length = InTableData.ExcelContents.Length;
                for (int i = 0; i < length; i++)
                {
                    var subLength = InTableData.ExcelContents[i].Length;
                    sb.Remove(0, sb.Length);
                    sb.Append("INSERT INTO ").Append(InTableData.TableName).Append(" VALUES(");
                    for (int j = 0; j < subLength; j++)
                    {
                        if (InTableData.IsColumnEnables[j])
                        {
                            var cell = InTableData.ExcelContents[i][j];
                            switch (InTableData.SQLite3Types[j])
                            {
                            case SQLite3ValueType.Integer:
                                if (null == cell)
                                {
                                    sb.Append(0);
                                }
                                else
                                {
                                    switch (cell.CellType)
                                    {
                                    case CellType.Numeric:
                                        sb.Append((int)cell.NumericCellValue);
                                        break;

                                    case CellType.String:
                                    {
                                        int result;
                                        sb.Append(int.TryParse(cell.StringCellValue, out result)
                                                        ? result
                                                        : 0);
                                    }
                                    break;

                                    case CellType.Formula:
                                        switch (cell.CachedFormulaResultType)
                                        {
                                        case CellType.Numeric:
                                            sb.Append((int)cell.NumericCellValue);
                                            break;

                                        case CellType.String:
                                        {
                                            int result;
                                            sb.Append(int.TryParse(cell.StringCellValue, out result)
                                                                ? result
                                                                : 0);
                                        }
                                        break;

                                        case CellType.Boolean:
                                            sb.Append(cell.BooleanCellValue ? 1 : 0);
                                            break;

                                        default:
                                            sb.Append(0);
                                            break;
                                        }
                                        break;

                                    case CellType.Boolean:
                                        sb.Append(cell.BooleanCellValue ? 1 : 0);
                                        break;

                                    default:
                                        sb.Append(0);
                                        break;
                                    }
                                }
                                break;

                            case SQLite3ValueType.Real:
                                if (null == cell)
                                {
                                    sb.Append(0);
                                }
                                else
                                {
                                    switch (cell.CellType)
                                    {
                                    case CellType.Numeric:
                                        sb.Append(cell.NumericCellValue);
                                        break;

                                    case CellType.String:
                                    {
                                        double result;
                                        sb.Append(double.TryParse(cell.StringCellValue, out result)
                                                        ? result
                                                        : 0);
                                    }

                                    break;

                                    case CellType.Formula:
                                        switch (cell.CachedFormulaResultType)
                                        {
                                        case CellType.Numeric:
                                            sb.Append(cell.NumericCellValue);
                                            break;

                                        case CellType.String:
                                        {
                                            double result;
                                            sb.Append(double.TryParse(cell.StringCellValue, out result)
                                                                ? result
                                                                : 0);
                                        }
                                        break;

                                        case CellType.Boolean:
                                            sb.Append(cell.BooleanCellValue ? 1 : 0);
                                            break;

                                        default:
                                            sb.Append(0);
                                            break;
                                        }
                                        break;

                                    case CellType.Boolean:
                                        sb.Append(cell.BooleanCellValue ? 1 : 0);
                                        break;

                                    default:
                                        sb.Append(0);
                                        break;
                                    }
                                }
                                break;

                            case SQLite3ValueType.Text:
                                if (null == cell)
                                {
                                    sb.Append("''");
                                }
                                else
                                {
                                    switch (cell.CellType)
                                    {
                                    case CellType.Numeric:
                                        sb.Append("\'")
                                        .Append(cell.NumericCellValue)
                                        .Append("\'");
                                        break;

                                    case CellType.String:
                                        sb.Append(SQLite3Utility.CheckSqlValue(cell.StringCellValue));
                                        break;

                                    case CellType.Formula:
                                        switch (cell.CachedFormulaResultType)
                                        {
                                        case CellType.Numeric:
                                            sb.Append("\'")
                                            .Append(cell.NumericCellValue)
                                            .Append("\'");
                                            break;

                                        case CellType.String:
                                            sb.Append(SQLite3Utility.CheckSqlValue(cell.StringCellValue));
                                            break;

                                        case CellType.Boolean:
                                            sb.Append("\'")
                                            .Append(cell.BooleanCellValue.ToString())
                                            .Append("\'");
                                            break;

                                        default:
                                            sb.Append("''");
                                            break;
                                        }
                                        break;

                                    case CellType.Boolean:
                                        sb.Append("\'")
                                        .Append(cell.BooleanCellValue.ToString())
                                        .Append("\'");
                                        break;

                                    default:
                                        sb.Append("''");
                                        break;
                                    }
                                }
                                break;
                            }
                            sb.Append(", ");
                        }
                    }
                    sb.Remove(sb.Length - 2, 2);
                    sb.Append(")");
                    handle.Exec(sb.ToString());
                }
            }

            handle.CloseDb();

            UpdateSQLite3Version(InDatabasePath);
        }