private IReadOnlyList <ColumnInfo> PrepareUpdateSql(bool skipSelect) { var whereSql = PrepareWhereSql(); SqlText.AppendFormat("Update {0} set ", TableName); Separator = null; for (var index = 0; index < SqlColumns.Count; index++) { var columnInfo = SqlColumns[index]; if (columnInfo.IsInPrimaryKey || columnInfo.IsDatabaseGenerated) { continue; } AddSeparator(", "); SqlText.Append(Encode(columnInfo.ColumnName) + "=@p" + ParameterValues.Count); ParameterValues.Add(columnInfo.ValueReader.ReadPropertyValue(Entity)); } SqlText.Append(whereSql); if (skipSelect) { return(new ColumnInfo[0]); } var returned = SqlColumns.Where(a => a.IsDatabaseGenerated && !a.IsInPrimaryKey).ToList(); if (!returned.Any()) { return(returned); } SqlText.Append("; select " + string.Join(",", returned.Select(q => Encode(q.ColumnName)))); SqlText.Append(" from " + TableName); SqlText.Append(whereSql); return(returned); }
private void PrepareUpdateSql() { SqlText.AppendFormat("Update {0} set ", TableName); Separator = null; for (var index = 0; index < SqlColumns.Length; index++) { var columnInfo = SqlColumns[index]; if (columnInfo.IsInPrimaryKey || columnInfo.IsDatabaseGenerated) { continue; } AddSeparator(", "); SqlText.Append(Encode(columnInfo.ColumnName) + "=@p" + ParameterValues.Count); ParameterValues.Add(columnInfo.ValueReader.ReadPropertyValue(Entity)); } SqlText.Append(" where "); Separator = null; foreach (var i in SqlColumns) { if (!i.IsInPrimaryKey) { continue; } AddSeparator(" AND "); SqlText.Append(Encode(i.ColumnName) + "=@p" + ParameterValues.Count); ParameterValues.Add(i.ValueReader.ReadPropertyValue(Entity)); } }
private List <ColumnInfo> PrepareSelectSql() { var returned = SqlColumns.Where(a => a.IsDatabaseGenerated).ToList(); if (!returned.Any()) { return(null); } Separator = " AND "; SqlText.Append("select " + string.Join(",", returned.Select(q => Encode(q.ColumnName)))); SqlText.Append(" from " + TableName + " WHERE @@ROWCOUNT=1"); if (IdentityColumn != null) { AddSeparator(Separator); SqlText.Append(Encode(IdentityColumn.ColumnName) + "=scope_identity();"); } else { for (var index = 0; index < SqlColumns.Length; index++) { var col = SqlColumns[index]; if (!col.IsInPrimaryKey) { continue; } var pn = AddPropertyValue(index); AddSeparator(Separator); SqlText.Append(Encode(col.ColumnName) + "=" + pn); } } return(returned); }
protected void AddSeparator(string newSeparator) { if (Separator == null) { Separator = newSeparator; } else { SqlText.Append(Separator); } }
private void PrepareUpdateSql(IReadOnlyDictionary <string, object> keys) { SqlText.AppendFormat("delete from {0} ", TableName); SqlText.Append(" where "); Separator = null; foreach (var i in keys) { AddSeparator(" AND "); SqlText.Append(Encode(i.Key) + "=@p" + ParameterValues.Count); ParameterValues.Add(i.Value); } }
private string PrepareWhereSql() { SqlText.Append(" where "); Separator = null; foreach (var i in SqlColumns) { if (!i.IsInPrimaryKey) { continue; } AddSeparator(" AND "); SqlText.Append(Encode(i.ColumnName) + "=@p" + ParameterValues.Count); ParameterValues.Add(i.ValueReader.ReadPropertyValue(Entity)); } var whereSql = SqlText.ToString(); SqlText.Clear(); return(whereSql); }
private void PrepareInsertSql() { SqlText.AppendFormat("INSERT INTO {0} (", TableName); Separator = null; for (var index = 0; index < SqlColumns.Count; index++) { var col = SqlColumns[index]; if (col.IsIdentity || col.IsDatabaseGenerated) { continue; } AddSeparator(", "); SqlText.Append(Encode(col.ColumnName)); AddPropertyValue(index); } SqlText.Append(") values ("); Separator = null; for (var parameterIdx = 0; parameterIdx < ParameterValues.Count; parameterIdx++) { AddSeparator(", "); SqlText.Append($"@p{parameterIdx}"); } SqlText.AppendLine(");"); }
public Expression(string sql) { SqlText.Append(sql); }
public Command AddSqlText(string sql) { SqlText.Append(sql); return(this); }