예제 #1
0
        public void MakeTable <T>()
        {
            _mappings = CreateTableDictionary <T>();

            string sql = "";

            foreach (var map in _mappings)
            {
                sql += map.Key + " ";

                if (map.Value == "Int32" || map.Value == "Int64" || map.Value == "Int16")
                {
                    sql += "INTEGER ";
                }
                else if (map.Value == "Single")
                {
                    sql += "REAL";
                }
                else if (map.Value == "Boolean")
                {
                    sql += "INTEGER ";
                }
                else if (map.Value == "String")
                {
                    sql += "VARCHAR ";
                }
                else
                {
                    sql += map.Value + " ";
                }

                if (map.Key == "ID")
                {
                    sql += " PRIMARY KEY AUTOINCREMENT ";
                }
                sql += ", ";
            }

            sql = sql.Substring(0, sql.Length - 2);

            using (var cmd = new SQLiteCommand($"CREATE TABLE IF NOT EXISTS {typeof(T).Name} ({sql}) ", Conn.CreateConnection()))
            {
                cmd.ExecuteNonQuery();
                cmd.Connection.Close();
            }
        }