18 using System.Collections.Generic;
26 namespace Deveel.Data.Sql.Statements {
29 if (columnNames == null)
30 throw new ArgumentNullException(
"columnNames");
32 throw new ArgumentNullException(
"values");
33 if (String.IsNullOrEmpty(tableName))
34 throw new ArgumentNullException(
"tableName");
36 TableName = tableName;
37 ColumnNames = columnNames;
41 public string TableName {
get;
private set; }
43 public IEnumerable<string> ColumnNames {
get;
private set; }
45 public IEnumerable<SqlExpression[]> Values {
get;
private set; }
48 var tableName = context.
Query.ResolveTableName(TableName);
50 var table = context.
Query.GetTable(tableName);
52 throw new InvalidOperationException();
55 throw new InvalidOperationException(
"Cannot set a value from a query.");
57 var columnInfos =
new List<ColumnInfo>();
58 foreach (var name
in ColumnNames) {
60 var colIndex = table.FindColumn(columnName);
62 throw new InvalidOperationException(String.Format(
"Cannot find column '{0}' in table '{1}'", columnName, table.FullName));
64 columnInfos.Add(table.TableInfo[colIndex]);
67 var assignments =
new List<SqlAssignExpression[]>();
69 foreach (var valueSet
in Values) {
72 for (
int i = 0; i < valueSet.Length; i++) {
73 var columnInfo = columnInfos[i];
75 var value = valueSet[i];
81 var expReturnType = value.ReturnType(context, null);
82 if (!columnInfo.ColumnType.IsComparable(expReturnType))
83 throw new InvalidOperationException();
89 assignments.
Add(valueAssign);
92 return new Prepared(tableName, assignments);
100 TableName = tableName;
101 Assignments = assignments;
106 int setCount = data.
GetInt32(
"SetCount");
108 for (
int i = 0; i < setCount; i++) {
112 Assignments = assignmenets;
117 public IList<SqlAssignExpression[]> Assignments {
get;
private set; }
120 data.
SetValue(
"TableName", TableName);
122 int setCount = Assignments.Count;
123 data.
SetValue(
"SetCount", setCount);
125 for (
int i = 0; i < setCount; i++) {
126 var set = Assignments[i];
127 data.
SetValue(String.Format(
"Assign[{0}]", i), set);
132 var insertCount = context.
Request.
Query.InsertIntoTable(TableName, Assignments);
139 #region PreparedSerializer
override void ExecuteStatement(ExecutionContext context)
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
InsertStatement(string tableName, IEnumerable< string > columnNames, IEnumerable< SqlExpression[]> values)
void SetValue(string key, Type type, object value)
Describes the name of an object within a database.
static SqlAssignExpression Assign(SqlExpression reference, SqlExpression valueExpression)
Represents the foundation class of SQL statements to be executed.
static SqlBinaryExpression Add(SqlExpression left, SqlExpression right)
Prepared(ObjectName tableName, IList< SqlAssignExpression[]> assignments)
void SetResult(ITable result)
override void GetData(SerializeData data)
static SqlBinaryExpression Any(SqlExpression left, SqlExpressionType anyType, SqlExpression right)
static SqlReferenceExpression Reference(ObjectName objectName)
object GetValue(string key)
IStatement Prepare(IRequest request)
Defines the base class for instances that represent SQL expression tree nodes.
Prepared(ObjectData data)