namespace SHNDecrypt
{
    using System;
    using System.Data;

    public class SQLConv
    {
        public static string CreateHeader(string name, bool drop)
        {
            string str = "";
            if (drop)
            {
                str = str + "DROP TABLE IF EXISTS `" + name + "`;\r\n";
            }
            return (str + "CREATE TABLE `" + name + "` (");
        }

        public static string GetPrefix(Type type)
        {
            string str = "";
            if (type == typeof(string))
            {
                str = "'";
            }
            return str;
        }

        public static string GetSQLType(Type type)
        {
            if (type == typeof(byte))
            {
                return "TINYINT(1)";
            }
            if (type == typeof(sbyte))
            {
                return "TINYINT(1) UNSIGNED";
            }
            if (type == typeof(uint))
            {
                return "INT(11) UNSIGNED";
            }
            if (type == typeof(ushort))
            {
                return "SMALLINT(5) UNSIGNED";
            }
            if (type == typeof(float))
            {
                return "FLOAT(10)";
            }
            if (type == typeof(short))
            {
                return "SMALLINT(5)";
            }
            if (type == typeof(int))
            {
                return "INT(11)";
            }
            return "TEXT";
        }

        public static string InsterInto(string table, DataColumnCollection columns)
        {
            string str = "";
            str = str + "INSERT INTO `" + table + "` (";
            for (int i = 0; i < columns.Count; i++)
            {
                str = str + "`" + columns[i].Caption + "`";
                if ((i + 1) != columns.Count)
                {
                    str = str + ",";
                }
            }
            return (str + ") VALUES \r\n");
        }
    }
}

