18 using System.Collections.Generic;
23 namespace Deveel.Data.Sql.Tables {
27 private List<DataObject[]>
rows;
36 rows =
new List<DataObject[]>();
40 : this(null, name, sourceTableInfo) {
44 : this(context, sourceTableInfo.Alias(new
ObjectName(name))) {
48 : this(context, name, MakeTableInfo(name, columns)) {
52 get {
return tableInfo; }
55 public override int RowCount {
56 get {
return rowCount; }
59 public override void Lock() {
67 foreach (var columnInfo
in columns) {
81 throw new ArgumentNullException(
"row");
82 if (row.Length != ColumnCount)
83 throw new ArgumentException();
85 var rowNumber = NewRow();
86 for (
int i = 0; i < row.Length; i++) {
87 SetValue(rowNumber, i, row[i]);
94 if (rowNumber >= rows.Count)
95 throw new ArgumentOutOfRangeException(
"rowNumber");
96 if (columnOffset < 0 || columnOffset > ColumnCount)
97 throw new ArgumentOutOfRangeException(
"columnOffset");
99 var row = rows[(int) rowNumber];
100 return row[columnOffset];
104 if (rowNumber < 0 || rowNumber >= rows.Count)
105 throw new ArgumentOutOfRangeException(
"rowNumber");
106 if (columnOffset < 0 || columnOffset >= ColumnCount)
107 throw new ArgumentOutOfRangeException(
"columnOffset");
109 var row = rows[(int) rowNumber];
110 row[columnOffset] = value;
114 SetValue(rowCount - 1, columnOffset, value);
122 SetupIndexes(indexName);
124 for (
int i = 0; i < rowCount; i++) {
132 var columnNames =
new ObjectName[table.ColumnCount()];
133 for (
int i = 0; i < columnNames.Length; ++i) {
134 columnNames[i] = table.GetResolvedColumnName(i);
137 for (
int i = 0; i < ColumnCount; ++i) {
138 var v = GetResolvedColumnName(i);
139 var colName = v.Name;
142 int columnOffset = -1;
143 for (
int n = 0; n < columnNames.Length || columnOffset == -1; ++n) {
144 if (columnNames[n].Name.Equals(colName)) {
149 var value = table.
GetValue(row, columnOffset);
150 SetValue(rowCount-1, i, value);
151 }
catch (Exception e) {
152 throw new InvalidOperationException(e.Message, e);
164 tableInfo.AddColumn(columnName, columnType);
165 tableInfo = tableInfo.AsReadOnly();
TemporaryTable(IDatabaseContext context, string name, IEnumerable< ColumnInfo > columns)
Defines the contract to access the data contained into a table of a database.
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
TemporaryTable(IContext context, TableInfo tableInfo)
The context of a single database within a system.
Describes the name of an object within a database.
const string InsertSearch
DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
static TemporaryTable SingleColumnTable(IContext database, string columnName, SqlType columnType)
int NewRow(DataObject[] row)
void AddColumn(ColumnInfo column)
Adds a new column to the table at the last position of the columns list in the table metadata...
readonly TableInfo tableInfo
TemporaryTable(IDatabaseContext context, string name, TableInfo sourceTableInfo)
TableInfo AsReadOnly()
Creates a new instance of TableInfo as an immutable copy of this table metadata.
void BuildIndexes(string indexName)
TemporaryTable(TableInfo tableInfo)
static TableInfo MakeTableInfo(string tableName, IEnumerable< ColumnInfo > columns)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Defines the properties of a specific SQL Type and handles the values compatible.
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
void SetValue(long rowNumber, int columnOffset, DataObject value)
void SetValue(int columnOffset, DataObject value)
Defines the metadata properties of a table existing within a database.
TemporaryTable(string name, TableInfo sourceTableInfo)
void CopyFrom(ITable table, int row)
override IEnumerator< Row > GetEnumerator()