protected override SqlStatement ToSqlStatement(DbDialect dd, List<string> queryRequiredFields) { var dpc = new DataParameterCollection(); string sqlString = string.Format(StatementTemplate, dd.QuoteForTableName(_tableName), Where.ToSqlText(dpc, dd, queryRequiredFields)); var sql = new SqlStatement(CommandType.Text, sqlString, dpc); return sql; }
protected override SqlStatement ToSqlStatement(DbDialect dd, List<string> queryRequiredFields) { var sb = new StringBuilder("ALTER TABLE "); sb.Append(dd.QuoteForTableName(_from.MainTableName)); if(AddColumn != null) { sb.Append(" ADD "); sb.Append(dd.QuoteForColumnName(AddColumn.Key)); sb.Append(" "); sb.Append(dd.GetTypeName(AddColumn)); if(DefaultValue != null) { if (DefaultFirst) { sb.Append(" DEFAULT(").Append(DefaultValue).Append(")"); sb.Append(AddColumn.AllowNull ? " NULL" : " NOT NULL"); } else { sb.Append(AddColumn.AllowNull ? " NULL" : " NOT NULL"); sb.Append(" DEFAULT(").Append(DefaultValue).Append(")"); } } else { sb.Append(AddColumn.AllowNull ? " NULL" : " NOT NULL"); } sb.Append(";"); } return new SqlStatement(sb.ToString()); }
protected override SqlStatement ToSqlStatement(DbDialect dd, List<string> queryRequiredFields) { CheckIsMutiKey(dd); _sql.Append("CREATE TABLE "); _sql.Append(dd.QuoteForTableName(TableName)); _sql.Append(" ("); ProcessColumns(dd); ProcessForeignKeys(dd); ProcessPrimaryKey(); if (Columns.Count > 0) { _sql.Length--; } _sql.Append("\n);\n"); if (HasOneDbGenKey()) { _sql.Append(dd.GetCreateSequenceString(TableName)); } // Create Index AddCreateIndexStatement(_sql, dd); return new SqlStatement(CommandType.Text, _sql.ToString()); }
private void ProcessForeignKeys(DbDialect dd) { if(!DataSettings.UsingForeignKey) { return; } foreach (ColumnInfo ci in Columns) { if(ci.IsForeignKey) { _sql.Append("\n\tFOREIGN KEY("); _sql.Append(dd.QuoteForColumnName(ci.Key)); _sql.Append(") REFERENCES "); _sql.Append(dd.QuoteForTableName(ci.BelongsToTableName)); _sql.Append(" ([Id]) ,"); } } }