コード例 #1
0
        public void LoadTable <T>(SQLiteTable <T> table)
            where T : ISQLiteData
        {
            try
            {
                DbConnection.Open();
                using (IDbCommand dbCmd = DbConnection.CreateCommand())
                {
                    string cmd = string.Format("SELECT * FROM {0}", table.TableName);
                    dbCmd.CommandText = cmd;
                    using (IDataReader reader = dbCmd.ExecuteReader())
                    {
                        table.Clear();
                        if (reader.Read())
                        {
                            do
                            {
                                int    fieldCount = reader.FieldCount;
                                string json       = "";
                                for (int i = 0; i < fieldCount; i++)
                                {
                                    json += MakeJSONValue
                                                (reader.GetName(i), reader.GetValue(i)) + ((i < fieldCount - 1) ? "," : "");
                                }
                                json = FormatJSON(json);

                                table.Add(JsonUtility.FromJson <T>(json));
                            } while (reader.Read());
                        }
                        else
                        {
#if UNITY_EDITOR
                            Debug.Log("Read failed ! " + table.TableName + " field count: " + reader.FieldCount);
#endif
                        }
                        reader.Close();
                        dbCmd.Dispose();
                    }
                    DbConnection.Close();
                }
            }
            catch (Exception e)
            {
                DbConnection.Close();
#if UNITY_EDITOR
                Debug.Log(e.ToString());
#endif
            }
        }