DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Classes | Public Member Functions | Properties | Private Member Functions | List of all members
Deveel.Data.Sql.Statements.InsertStatement Class Reference
Inheritance diagram for Deveel.Data.Sql.Statements.InsertStatement:
Deveel.Data.Sql.Statements.SqlStatement Deveel.Data.Sql.Statements.IPreparableStatement Deveel.Data.Sql.Statements.IStatement Deveel.Data.Serialization.ISerializable Deveel.Data.Sql.Statements.IStatement Deveel.Data.Sql.IExecutable Deveel.Data.Sql.IExecutable

Classes

class  Prepared
 

Public Member Functions

 InsertStatement (string tableName, IEnumerable< string > columnNames, IEnumerable< SqlExpression[]> values)
 
- Public Member Functions inherited from Deveel.Data.Sql.Statements.SqlStatement
ITable Execute (IRequest context)
 Prepares and evaluates this statement into a tabular result. More...
 

Properties

string TableName [get, private set]
 
IEnumerable< string > ColumnNames [get, private set]
 
IEnumerable< SqlExpression[]> Values [get, private set]
 
- Properties inherited from Deveel.Data.Sql.Statements.SqlStatement
SqlQuery SourceQuery [get, set]
 Gets the SqlQuery that is the origin of this statement. More...
 
bool IsFromQuery [get, private set]
 Gets a boolean value indicating if this object was formed from the parsing of a SqlQuery or if it was manually created. More...
 
- Properties inherited from Deveel.Data.Sql.Statements.IStatement
SqlQuery SourceQuery [get]
 

Private Member Functions

IStatement IPreparableStatement. Prepare (IRequest context)
 

Additional Inherited Members

- Static Public Member Functions inherited from Deveel.Data.Sql.Statements.SqlStatement
static IEnumerable< SqlStatementParse (string sqlSource)
 Parses a given string into one of more statements. More...
 
static IEnumerable< SqlStatementParse (IContext context, string sqlSource)
 Parses a given string into one of more statements. More...
 
static IEnumerable< SqlStatementParse (IContext context, SqlQuery query)
 
- Protected Member Functions inherited from Deveel.Data.Sql.Statements.SqlStatement
 SqlStatement ()
 
 SqlStatement (ObjectData data)
 
virtual void ExecuteStatement (ExecutionContext context)
 
virtual void GetData (SerializeData data)
 
- Package Functions inherited from Deveel.Data.Sql.Statements.SqlStatement
void SetSource (SqlQuery query)
 

Detailed Description

Definition at line 27 of file InsertStatement.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Statements.InsertStatement.InsertStatement ( string  tableName,
IEnumerable< string >  columnNames,
IEnumerable< SqlExpression[]>  values 
)
inline

Definition at line 28 of file InsertStatement.cs.

28  {
29  if (columnNames == null)
30  throw new ArgumentNullException("columnNames");
31  if (values == null)
32  throw new ArgumentNullException("values");
33  if (String.IsNullOrEmpty(tableName))
34  throw new ArgumentNullException("tableName");
35 
36  TableName = tableName;
37  ColumnNames = columnNames;
38  Values = values;
39  }
A long string in the system.
IEnumerable< SqlExpression[]> Values

Member Function Documentation

IStatement IPreparableStatement. Deveel.Data.Sql.Statements.InsertStatement.Prepare ( IRequest  context)
inlineprivate

Implements Deveel.Data.Sql.Statements.IPreparableStatement.

Definition at line 47 of file InsertStatement.cs.

47  {
48  var tableName = context.Query.ResolveTableName(TableName);
49 
50  var table = context.Query.GetTable(tableName);
51  if (table == null)
52  throw new InvalidOperationException();
53 
54  if (Values.Any(x => x.OfType<SqlQueryExpression>().Any()))
55  throw new InvalidOperationException("Cannot set a value from a query.");
56 
57  var columnInfos = new List<ColumnInfo>();
58  foreach (var name in ColumnNames) {
59  var columnName = ObjectName.Parse(name);
60  var colIndex = table.FindColumn(columnName);
61  if (colIndex < 0)
62  throw new InvalidOperationException(String.Format("Cannot find column '{0}' in table '{1}'", columnName, table.FullName));
63 
64  columnInfos.Add(table.TableInfo[colIndex]);
65  }
66 
67  var assignments = new List<SqlAssignExpression[]>();
68 
69  foreach (var valueSet in Values) {
70  var valueAssign = new SqlAssignExpression[valueSet.Length];
71 
72  for (int i = 0; i < valueSet.Length; i++) {
73  var columnInfo = columnInfos[i];
74 
75  var value = valueSet[i];
76  if (value != null) {
77  // TODO: Deference columns with a preparer
78  }
79 
80  if (value != null) {
81  var expReturnType = value.ReturnType(context, null);
82  if (!columnInfo.ColumnType.IsComparable(expReturnType))
83  throw new InvalidOperationException();
84  }
85 
86  valueAssign[i] = SqlExpression.Assign(SqlExpression.Reference(columnInfo.FullColumnName), value);
87  }
88 
89  assignments.Add(valueAssign);
90  }
91 
92  return new Prepared(tableName, assignments);
93  }
A long string in the system.
static SqlAssignExpression Assign(SqlExpression reference, SqlExpression valueExpression)
static SqlBinaryExpression Add(SqlExpression left, SqlExpression right)
IEnumerable< SqlExpression[]> Values
static SqlBinaryExpression Any(SqlExpression left, SqlExpressionType anyType, SqlExpression right)
static SqlReferenceExpression Reference(ObjectName objectName)
Defines the base class for instances that represent SQL expression tree nodes.

Property Documentation

IEnumerable<string> Deveel.Data.Sql.Statements.InsertStatement.ColumnNames
getprivate set

Definition at line 43 of file InsertStatement.cs.

string Deveel.Data.Sql.Statements.InsertStatement.TableName
getprivate set

Definition at line 41 of file InsertStatement.cs.

IEnumerable<SqlExpression[]> Deveel.Data.Sql.Statements.InsertStatement.Values
getprivate set

Definition at line 45 of file InsertStatement.cs.


The documentation for this class was generated from the following file: