Esempio n. 1
0
 protected string GenerateCreateDatabaseSql(EntityAdapter adapter)
 {
     return($"CREATE SCHEMA IF NOT EXISTS `{adapter.Table.Database}` DEFAULT CHARACTER SET utf8mb4;");
 }
Esempio n. 2
0
 protected string GenerateIfDatabaseExistsSql(EntityAdapter adapter)
 {
     return($"SELECT COUNT(*) FROM information_schema.SCHEMATA where SCHEMA_NAME='{adapter.Table.Database}';");
 }
 protected abstract string GenerateCreateDatabaseSql(EntityAdapter adapter, string serverVersion);
 protected abstract string GenerateIfDatabaseExistsSql(EntityAdapter adapter, string serverVersion);
 protected abstract string GenerateSelectSql(EntityAdapter adapter);
 protected abstract string GenerateCreateTableSql(EntityAdapter adapter);
Esempio n. 7
0
        protected override string GenerateCreateTableSql(EntityAdapter adapter)
        {
            var           tableName   = adapter.Table.CalculateTableName();
            StringBuilder builder     = new StringBuilder($"USE {adapter.Table.Database}; IF OBJECT_ID('{tableName}', 'U') IS NULL CREATE table {tableName} (");
            StringBuilder columnNames = new StringBuilder();

            foreach (var p in adapter.Columns)
            {
                columnNames.Append($",[{p.Name}] {GetDataTypeSql(p)}");
            }

            builder.Append(columnNames.ToString().Substring(1, columnNames.Length - 1));
            builder.Append(",[CDate] DATETIME DEFAULT(GETDATE())");

            if (Env.IdColumn.ToLower() == adapter.Table.Primary.ToLower())
            {
                builder.Append($", [{Env.IdColumn}] [bigint] IDENTITY(1,1) NOT NULL");
            }

            builder.Append(",");
            StringBuilder primaryKey = new StringBuilder();

            if (string.IsNullOrEmpty(adapter.Table.Primary))
            {
                primaryKey.Append($"[{Env.IdColumn}] ASC,");
            }
            else
            {
                var columns = adapter.Table.Primary.Split(',');
                foreach (var column in columns)
                {
                    primaryKey.Append($"[{column}] ASC,");
                }
            }

            builder.Append(
                $" CONSTRAINT [PK_{tableName}] PRIMARY KEY CLUSTERED ({primaryKey.ToString(0, primaryKey.Length - 1)})WITH(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY]) ON[PRIMARY];");

            if (adapter.Table.Indexs != null)
            {
                foreach (var index in adapter.Table.Indexs)
                {
                    var    columns         = index.Split(',');
                    string name            = string.Join("_", columns.Select(c => c));
                    string indexColumNames = string.Join(", ", columns.Select(c => $"[{c}]"));
                    builder.Append($"CREATE NONCLUSTERED INDEX [index_{name}] ON {tableName} ({indexColumNames.Substring(0, indexColumNames.Length)});");
                }
            }

            if (adapter.Table.Uniques != null)
            {
                foreach (var unique in adapter.Table.Uniques)
                {
                    var    columns          = unique.Split(',');
                    string name             = string.Join("_", columns.Select(c => c));
                    string uniqueColumNames = string.Join(", ", columns.Select(c => $"[{c}]"));
                    builder.Append($"CREATE UNIQUE NONCLUSTERED INDEX [unique_{name}] ON {tableName} ({uniqueColumNames.Substring(0, uniqueColumNames.Length)});");
                }
            }
            return(builder.ToString());
        }
 protected abstract string GenerateInsertSql(EntityAdapter adapter);
Esempio n. 9
0
 protected abstract void InitAllSqlOfEntity(EntityAdapter adapter);
 protected override void InitAllSqlOfEntity(EntityAdapter adapter)
 {
 }
Esempio n. 11
0
 private string GenerateIfDatabaseExistsSql(EntityAdapter adapter, string serverVersion)
 {
     return($"SELECT COUNT(*) FROM information_schema.SCHEMATA where SCHEMA_NAME='{adapter.Table.Database}';");
 }
Esempio n. 12
0
 private string GenerateCreateDatabaseSql(EntityAdapter adapter, string serverVersion)
 {
     return($"CREATE SCHEMA IF NOT EXISTS `{adapter.Table.Database}` DEFAULT CHARACTER SET utf8mb4;");
 }
Esempio n. 13
0
 private string GenerateUpdateSql(EntityAdapter adapter)
 {
     return(null);
 }