18 using System.Collections.Generic;
25 namespace Deveel.Data.Sql.Tables {
46 private Dictionary<int, DataObject>
values;
63 throw new ArgumentNullException(
"table");
68 throw new ArgumentException(
String.Format(
"The table ID {0} does not match the identifier specified by the row ID ({1})",
123 get {
return GetValue(columnOffset); }
124 set { SetValue(columnOffset, value); }
138 get {
return GetValue(columnName); }
139 set { SetValue(columnName, value); }
144 if (variableResolver == null) {
149 return variableResolver;
156 public int ColumnCount {
165 get {
return Table.Any(x => x.RowId.Equals(
RowId)); }
170 public bool CanBeCached {
172 if (canBeCached == null) {
173 canBeCached = values.All(value => value.Value.IsCacheable);
176 return canBeCached.Value;
205 throw new ArgumentOutOfRangeException(
"columnOffset");
207 if (values == null) {
209 throw new InvalidOperationException(
"Row was not established to any table.");
212 values =
new Dictionary<int, DataObject>(colCount);
214 for (
int i = 0; i < colCount; i++) {
220 if (!values.TryGetValue(columnOffset, out value)) {
251 throw new ArgumentOutOfRangeException(
"columnOffset");
254 values =
new Dictionary<int, DataObject>(colCount);
257 var columnType = column.ColumnType;
260 throw new ArgumentException(
261 String.Format(
"The specified value of type '{0}' is not comparable to '{1}' defined by '{2}'.",
262 value.
Type, columnType, column.FullColumnName));
265 values[columnOffset] = value;
286 if (
String.IsNullOrEmpty(columnName))
287 throw new ArgumentNullException(
"columnName");
291 throw new ArgumentException(
String.Format(
"Could not find column '{0}' in the table '{1}'.", columnName,
Table.
FullName));
293 return GetValue(offset);
297 if (
String.IsNullOrEmpty(columnName))
298 throw new ArgumentNullException(
"columnName");
302 throw new ArgumentException(
String.Format(
"Could not find column '{0}' in the table '{1}'.", columnName,
Table.
FullName));
304 SetValue(offset, value);
307 public void SetValue(
int columnIndex,
string value) {
315 public void SetValue(
int columnIndex,
long value) {
319 public void SetValue(
int columnIndex,
short value) {
323 public void SetValue(
int columnIndex,
float value) {
324 SetValue(columnIndex,
new SqlNumber(value));
327 public void SetValue(
int columnIndex,
double value) {
335 public void SetValue(
int columnIndex,
bool value) {
339 public void SetValue(
int columnIndex, byte[] bytes) {
354 throw new ArgumentOutOfRangeException(
"columnOffset");
357 SetValue(columnOffset,
new DataObject(columnType, null));
376 throw new ArgumentOutOfRangeException(
"columnOffset");
379 if (!column.HasDefaultExpression)
380 throw new InvalidOperationException(
String.Format(
"Column '{0}' in table '{1}' has no DEFAULT set.", column.ColumnName,
Table.
FullName));
382 var value = Evaluate(column.DefaultExpression, context);
383 SetValue(columnOffset, value);
395 if (!values.ContainsKey(i)) {
396 SetDefault(i, context);
402 var ignoreCase = queryContext.IgnoreIdentifiersCase();
407 var reduced = expression.
Evaluate(queryContext, vresolver, null);
409 throw new InvalidOperationException(
"The DEFAULT expression of the column cannot be reduced to a constant");
432 #region RowVariableResolver
447 get {
return assignmentCount; }
451 string colName = columnName.
Name;
453 int colIndex = row.Table.TableInfo.IndexOfColumn(colName);
455 throw new InvalidOperationException(
String.Format(
"Column '{0}' could not be found in table '{1}'", colName, row.Table.FullName));
458 if (!row.values.TryGetValue(colIndex, out value))
459 throw new InvalidOperationException(
"Column " + colName +
" hasn't been set yet.");
465 string colName = columnName.
Name;
467 int colIndex = row.Table.TableInfo.IndexOfColumn(colName);
469 throw new InvalidOperationException(
"Can't find column: " + colName);
471 return row.Table.TableInfo[colIndex].ColumnType;
503 var value = valueExp.EvaluateToConstant(context, VariableResolver);
506 var columnName = colRef.ReferenceName;
513 SetValue(column, value);
abstract DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
RowVariableResolver variableResolver
void SetFromTable()
Gathers the original values from the table for the row number corresponding and populates this row wi...
bool IsNull
Gets a boolean value indicating if the object equivales to a NULL.
static DataObject Integer(int value)
Defines the contract to access the data contained into a table of a database.
static DataObject Binary(SqlBinary binary)
SqlType Type
Gets the SqlType that defines the object properties
void SetValue(int columnIndex, byte[] bytes)
SqlExpression ValueExpression
void SetValue(int columnIndex, SqlBinary binary)
Row(ITable table)
Constructs a new row on the given table that is not established into that table.
An expression that references an object within a context.
A long string in the system.
void SetValue(int columnIndex, bool value)
Row(ITable table, RowId rowId)
Constructs a new row object for the table given, identified by the given RowId.
DataObject GetValue(string columnName)
Gets a value for a cell of the row that corresponds to the column of the table with the given name...
DataObject GetValue(int columnOffset)
Gets or the value of a cell of the row at the given offset.
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
static DataObject Number(SqlNumber value)
int Id
Gets a unique identifier of the table in a database system.
virtual bool IsComparable(SqlType type)
Verifies if a given SqlType is comparable to this data-type.
Represents a database object, such as a table, a trigger, a type or a column.
int FindColumn(ObjectName columnName)
void SetNull(int columnOffset)
Sets the value of a cell of the row at the given offset to NULL.
static DataObject Null(SqlType type)
ObjectName FullName
Gets the fully qualified name of the object used to resolve it uniquely within the database...
void SetValue(string columnName, DataObject value)
void SetDefault(IQuery context)
Sets the DEFAULT value of all cells in the row as configured in the columns definition corresponding ...
Describes the name of an object within a database.
Row(ITable table, int rowNumber)
A single row in a table of a database.
static DataObject String(string s)
void SetValue(int columnIndex, string value)
static DataObject Boolean(SqlBoolean value)
void EvaluateAssignment(SqlAssignExpression assignExpression, IQuery context)
DataObject Evaluate(SqlExpression expression, IQuery queryContext)
SqlExpressionType
All the possible type of SqlExpression supported
int RowNumber
Gets the number of the column within the table referenced.
void SetValue(int columnIndex, SqlNumber value)
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
void SetDefault(int columnOffset, IQuery context)
Sets the value of a cell of the row at the given offset to the DEFAULT set at the column definition...
void SetValue(int columnIndex, long value)
void SetNumber(int number)
Sets the row number part of the identificator
virtual SqlExpression Evaluate(EvaluateContext context)
When overridden by a derived class, this method evaluates the expression within the provided context...
void SetValue(int columnIndex, int value)
SqlType ReturnType(ObjectName columnName)
Returns the SqlType of object the given variable is.
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
DbObjectType ObjectType
Gets the type of database object that the implementation is for
Defines the properties of a specific SQL Type and handles the values compatible.
TableInfo TableInfo
Gets the metadata information of the table, used to resolve the column sources.
void SetValue(int columnIndex, short value)
int IndexOfColumn(string columnName)
Gets the offset of the column with the given name.
An interface to resolve a variable name to a constant object.
Defines the value of a ROWID object, that is a unique reference within a database system to a single ...
An expression that holds a constant value.
void SetValue(int columnOffset, DataObject value)
Sets the value of a cell of the row at the given offset.
void SetValue(int columnIndex, float value)
static DataObject BigInt(long value)
string Name
Gets the name of the object being referenced.
static DataObject SmallInt(short value)
int ColumnCount
Gets a count of the columns defined by this object.
DataObject Resolve(ObjectName columnName)
Returns the value of a given variable.
void SetValue(int columnIndex, double value)
void SetRowNumber(int rowNumber)
Sets the number component of the ID of this column.
Defines the base class for instances that represent SQL expression tree nodes.
DbObjectType
The kind of objects that can be handled by a database system and its managers
Defines the metadata properties of a table existing within a database.
RowVariableResolver(Row row)
int TableId
Gets the unique identifier of the table the row is contained.
Dictionary< int, DataObject > values
SqlExpression ResolveColumns(bool ignoreCase, SqlExpression expression)
SqlExpression ReferenceExpression
abstract TableInfo TableInfo