protected override Expression VisitAssign(SqlAssignExpression expression) { this.Visit(expression.Target); this.Write(" = "); this.Visit(expression.Value); return(expression); }
protected override Expression VisitAssign(SqlAssignExpression expression) { var newValue = this.Visit(expression.Value); if (newValue != expression.Value) { return(new SqlAssignExpression(expression.Target, newValue)); } return(expression); }
protected virtual Expression VisitAssign(SqlAssignExpression expression) { var newTarget = this.Visit(expression.Target); var newValue = this.Visit(expression.Value); if (newValue != expression.Value) { return(new SqlAssignExpression(newTarget, newValue)); } return(expression); }
private Prepared(ObjectData data) { TableName = data.GetValue <ObjectName>("TableName"); int setCount = data.GetInt32("SetCount"); var assignmenets = new SqlAssignExpression[setCount][]; for (int i = 0; i < setCount; i++) { assignmenets[i] = data.GetValue <SqlAssignExpression[]>(String.Format("Assign[{0}]", i)); } Assignments = assignmenets; }
public void InsertRegular() { var tableName = ObjectName.Parse("APP.people"); var assignments = new SqlAssignExpression[] { SqlExpression.Assign(SqlExpression.Reference(new ObjectName(tableName, "id")), SqlExpression.Constant(1)), SqlExpression.Assign(SqlExpression.Reference(new ObjectName(tableName, "first_name")), SqlExpression.Constant("Antonello")), SqlExpression.Assign(SqlExpression.Reference(new ObjectName(tableName, "last_name")), SqlExpression.Constant("Provenzano")) }; Query.InsertIntoTable(tableName, assignments); }
private Prepared(SerializationInfo info, StreamingContext context) { TableName = (ObjectName)info.GetValue("TableName", typeof(ObjectName)); int setCount = info.GetInt32("SetCount"); var assignmenets = new SqlAssignExpression[setCount][]; for (int i = 0; i < setCount; i++) { assignmenets[i] = (SqlAssignExpression[])info.GetValue(String.Format("Assign[{0}]", i), typeof(SqlAssignExpression[])); } Assignments = assignmenets; }
public void EvaluateAssignment(SqlAssignExpression assignExpression, IRequest context) { var colRef = (SqlReferenceExpression)assignExpression.ReferenceExpression; var valueExp = assignExpression.ValueExpression; var value = valueExp.EvaluateToConstant(context, VariableResolver); // Check the column name is within this row. var columnName = colRef.ReferenceName; int column = Table.FindColumn(columnName); if (column == -1) { throw new ObjectNotFoundException(columnName, String.Format("Table '{0}' has none column named '{1}': cannot assign.", Table.TableInfo.TableName, columnName)); } SetValue(column, value); }
IStatement IPreparableStatement.Prepare(IRequest context) { var values = Values.ToArray(); int firstLen = -1; for (int n = 0; n < values.Length; ++n) { var expList = (IList)values[n]; if (firstLen == -1 || firstLen == expList.Count) { firstLen = expList.Count; } else { throw new InvalidOperationException("The insert data list varies in size."); } } var tableName = context.Query.ResolveTableName(TableName); var table = context.Query.GetTable(tableName); if (table == null) { throw new ObjectNotFoundException(TableName); } if (Values.Any(x => x.OfType <SqlQueryExpression>().Any())) { throw new InvalidOperationException("Cannot set a value from a query."); } var tableQueryInfo = context.Query.GetTableQueryInfo(tableName, null); var fromTable = new FromTableDirectSource(context.Query.IgnoreIdentifiersCase(), tableQueryInfo, "INSERT_TABLE", tableName, tableName); var columns = new string[0]; if (ColumnNames != null) { columns = ColumnNames.ToArray(); } if (columns.Length == 0) { columns = new string[table.TableInfo.ColumnCount]; for (int i = 0; i < columns.Length; i++) { columns[i] = table.TableInfo[i].ColumnName; } } var colIndices = new int[columns.Length]; var colResolved = new ObjectName[columns.Length]; for (int i = 0; i < columns.Length; ++i) { var inVar = new ObjectName(columns[i]); var col = ResolveColumn(fromTable, inVar); int index = table.FindColumn(col); if (index == -1) { throw new InvalidOperationException(String.Format("Cannot find column '{0}' in table '{1}'.", col, tableName)); } colIndices[i] = index; colResolved[i] = col; } var columnInfos = new List <ColumnInfo>(); foreach (var name in columns) { var columnName = new ObjectName(tableName, name); var colIndex = table.FindColumn(columnName); if (colIndex < 0) { throw new InvalidOperationException(String.Format("Cannot find column '{0}' in table '{1}'", columnName, table.FullName)); } columnInfos.Add(table.TableInfo[colIndex]); } var assignments = new List <SqlAssignExpression[]>(); foreach (var valueSet in values) { var valueAssign = new SqlAssignExpression[valueSet.Length]; for (int i = 0; i < valueSet.Length; i++) { var columnInfo = columnInfos[i]; var value = valueSet[i]; if (value != null) { // TODO: Deference columns with a preparer } if (value != null) { var expReturnType = value.ReturnType(context, null); if (!columnInfo.ColumnType.IsComparable(expReturnType)) { var sb = new StringBuilder(); sb.AppendFormat("Unable to convert type {0} of {1} into type {2} of column {3}", expReturnType, value, columnInfo.ColumnType, columnInfo.FullColumnName.FullName); var ioe = new InvalidOperationException(sb.ToString()); throw ioe; } } valueAssign[i] = SqlExpression.Assign(SqlExpression.Reference(columnInfo.FullColumnName), value); } assignments.Add(valueAssign); } return(new Prepared(tableName, assignments)); }