DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Sql.Query.FromTableDirectSource Class Reference

An implementation of IFromTableSource that wraps around a ObjectName/ITable object. More...

Inheritance diagram for Deveel.Data.Sql.Query.FromTableDirectSource:
Deveel.Data.Sql.Query.IFromTableSource

Public Member Functions

 FromTableDirectSource (bool caseInsensitive, ITableQueryInfo tableQuery, string uniqueName, ObjectName givenName, ObjectName rootName)
 Constructs the source. More...
 
bool MatchesReference (string catalog, string schema, string table)
 Checks if the table matches the given catalog, schema and table. More...
 
int ResolveColumnCount (string catalog, string schema, string table, string column)
 Returns the number of instances we can resolve the given catalog, schema, table and column name to a column or columns within the current source. More...
 
ObjectName ResolveColumn (string catalog, string schema, string table, string column)
 Resolves a variable within the current source. More...
 

Properties

bool IgnoreCase [get, private set]
 
ObjectName GivenTableName [get, private set]
 
ObjectName RootTableName [get, private set]
 
IQueryPlanNode QueryPlan [get]
 
string UniqueName [get, private set]
 
ObjectName[] ColumnNames [get]
 
- Properties inherited from Deveel.Data.Sql.Query.IFromTableSource
string UniqueName [get]
 Gets a unique name given to this table source. More...
 
ObjectName[] ColumnNames [get]
 Returns an array of ObjectName objects that references each column available in the table set item in order from left column to right column. More...
 

Private Member Functions

bool StringCompare (string str1, string str2)
 

Private Attributes

readonly ITableQueryInfo tableQuery
 
readonly TableInfo tableInfo
 

Detailed Description

An implementation of IFromTableSource that wraps around a ObjectName/ITable object.

The handles case insensitive resolution.

Definition at line 30 of file FromTableDirectSource.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Query.FromTableDirectSource.FromTableDirectSource ( bool  caseInsensitive,
ITableQueryInfo  tableQuery,
string  uniqueName,
ObjectName  givenName,
ObjectName  rootName 
)
inline

Constructs the source.

Parameters
caseInsensitive
tableQuery
uniqueName
givenName
rootName

Definition at line 42 of file FromTableDirectSource.cs.

42  {
43  this.UniqueName = uniqueName;
45  RootTableName = rootName;
46  if (givenName != null) {
47  GivenTableName = givenName;
48  } else {
49  GivenTableName = rootName;
50  }
51 
52  IgnoreCase = caseInsensitive;
53  this.tableQuery = tableQuery;
54  }
TableInfo TableInfo
Gets a read-only TableInfo that describes the columns in this table source, and the name of the table...

Member Function Documentation

bool Deveel.Data.Sql.Query.FromTableDirectSource.MatchesReference ( string  catalog,
string  schema,
string  table 
)
inline

Checks if the table matches the given catalog, schema and table.

Parameters
catalogThe catalog name used for the matching.
schemaThe schema name used for the matching.
tableThe table name used for the maching.

If any arguments are null then it is not included in the match.

Used for 'Part.*' type glob searches.

Returns
Returns true if this source matches the given catalog, schema and table, otherwise false.

Implements Deveel.Data.Sql.Query.IFromTableSource.

Definition at line 85 of file FromTableDirectSource.cs.

85  {
86  var schemaName = GivenTableName.Parent;
87  var catalogName = schemaName == null ? null : schemaName.Parent;
88 
89  // Does this table name represent the correct schema?
90  var givenSchema = schemaName != null ? schemaName.Name : null;
91  if (schema != null && !StringCompare(schema, givenSchema)) {
92  // If schema is present and we can't resolve to this schema then false
93  return false;
94  }
95 
96  var givenCatalog = catalogName != null ? catalogName.Name : null;
97  if (catalog != null && !StringCompare(catalog, givenCatalog))
98  return false;
99 
100  if (table != null && !StringCompare(table, GivenTableName.Name)) {
101  // If table name is present and we can't resolve to this table name
102  // then return false
103  return false;
104  }
105 
106  // Match was successful,
107  return true;
108  }
bool StringCompare(string str1, string str2)
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
ObjectName Deveel.Data.Sql.Query.FromTableDirectSource.ResolveColumn ( string  catalog,
string  schema,
string  table,
string  column 
)
inline

Resolves a variable within the current source.

Parameters
catalog
schema
table
column

This method does not have to check whether the parameters reference more than one column. If more than one column is referenced, the actual column returned is implementation specific.

Returns
Returns a ObjectName that is a fully resolved form of the given column in the current table set.

Implements Deveel.Data.Sql.Query.IFromTableSource.

Definition at line 145 of file FromTableDirectSource.cs.

145  {
146  var schemaName = GivenTableName.Parent;
147  var catalogName = schemaName == null ? null : schemaName.Parent;
148 
149  var givenCatalog = catalogName != null ? catalogName.Name : null;
150  if (catalog != null && !StringCompare(catalog, givenCatalog))
151  throw new InvalidOperationException("Incorrect catalog.");
152 
153  // Does this table name represent the correct schema?
154  var givenSchema = GivenTableName.Parent != null ? GivenTableName.Parent.Name : null;
155  if (schema != null && !StringCompare(schema, givenSchema))
156  // If schema is present and we can't resolve to this schema
157  throw new InvalidOperationException("Incorrect schema.");
158 
159  if (table != null && !StringCompare(table, GivenTableName.Name))
160  // If table name is present and we can't resolve to this table name
161  throw new InvalidOperationException("Incorrect table.");
162 
163  if (column != null) {
164  if (!IgnoreCase) {
165  // Can we resolve the column in this table?
166  int i = tableInfo.IndexOfColumn(column);
167  if (i == -1)
168  throw new InvalidOperationException("Could not resolve '" + column + "'");
169 
170  return new ObjectName(GivenTableName, column);
171  }
172 
173  // Case insensitive search (this is slower than case sensitive).
174  var columnName =
175  tableInfo.Where(x => StringCompare(x.ColumnName, column))
176  .Select(x => x.ColumnName)
177  .FirstOrDefault();
178 
179  if (String.IsNullOrEmpty(columnName))
180  throw new InvalidOperationException(String.Format("Could not resolve column '{0}' within the table '{1}'.", column,
181  GivenTableName));
182 
183  return new ObjectName(GivenTableName, columnName);
184  }
185 
186  // Return the first column in the table
187  return new ObjectName(GivenTableName, tableInfo[0].ColumnName);
188  }
bool StringCompare(string str1, string str2)
A long string in the system.
int IndexOfColumn(string columnName)
Gets the offset of the column with the given name.
Definition: TableInfo.cs:310
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
int Deveel.Data.Sql.Query.FromTableDirectSource.ResolveColumnCount ( string  catalog,
string  schema,
string  table,
string  column 
)
inline

Returns the number of instances we can resolve the given catalog, schema, table and column name to a column or columns within the current source.

Parameters
catalog
schema
table
column

Note that if catalog, schema, table or column is null then it means it doesn't matter.

Note that parameters of null, null, null, null, null, null, null, not null, null, null, not null, not null, null, not null, not null, not null, and not null, not null, not null, not null are only accepted.

For example, say we need to resolve the column 'id' the arguments are null, null, null, "id". This may resolve to multiple columns if there is a mixture of tables with "id" as a column.

Returns

Implements Deveel.Data.Sql.Query.IFromTableSource.

Definition at line 110 of file FromTableDirectSource.cs.

110  {
111  // NOTE: With this type, we can only ever return either 1 or 0 because
112  // it's impossible to have an ambiguous reference
113 
114  var schemaName = GivenTableName.Parent;
115  var catalogName = schemaName == null ? null : schemaName.Parent;
116 
117  var givenCatalog = catalogName != null ? catalogName.Name : null;
118  if (catalog != null && !StringCompare(catalog, givenCatalog))
119  return 0;
120 
121  var givenSchema = schemaName != null ? schemaName.Name : null;
122  if (schema != null && !StringCompare(schema, givenSchema))
123  return 0;
124 
125  if (table != null && !StringCompare(table, GivenTableName.Name)) {
126  return 0;
127  }
128 
129  if (column != null) {
130  // TODO: the case-insensitive search in TableInfo
131  if (!IgnoreCase) {
132  // Can we resolve the column in this table?
133  int i = tableInfo.IndexOfColumn(column);
134  // If i doesn't equal -1 then we've found our column
135  return i == -1 ? 0 : 1;
136  }
137 
138  return tableInfo.Count(columnInfo => StringCompare(columnInfo.ColumnName, column));
139  }
140 
141  // Return the column count
142  return tableInfo.ColumnCount;
143  }
bool StringCompare(string str1, string str2)
int IndexOfColumn(string columnName)
Gets the offset of the column with the given name.
Definition: TableInfo.cs:310
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
int ColumnCount
Gets a count of the columns defined by this object.
Definition: TableInfo.cs:159
bool Deveel.Data.Sql.Query.FromTableDirectSource.StringCompare ( string  str1,
string  str2 
)
inlineprivate

Definition at line 79 of file FromTableDirectSource.cs.

79  {
80  var comparison = IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
81  return String.Equals(str1, str2, comparison);
82  }
A long string in the system.

Member Data Documentation

readonly TableInfo Deveel.Data.Sql.Query.FromTableDirectSource.tableInfo
private

Definition at line 32 of file FromTableDirectSource.cs.

readonly ITableQueryInfo Deveel.Data.Sql.Query.FromTableDirectSource.tableQuery
private

Definition at line 31 of file FromTableDirectSource.cs.

Property Documentation

ObjectName [] Deveel.Data.Sql.Query.FromTableDirectSource.ColumnNames
get

Definition at line 68 of file FromTableDirectSource.cs.

ObjectName Deveel.Data.Sql.Query.FromTableDirectSource.GivenTableName
getprivate set

Definition at line 58 of file FromTableDirectSource.cs.

bool Deveel.Data.Sql.Query.FromTableDirectSource.IgnoreCase
getprivate set

Definition at line 56 of file FromTableDirectSource.cs.

IQueryPlanNode Deveel.Data.Sql.Query.FromTableDirectSource.QueryPlan
get

Definition at line 62 of file FromTableDirectSource.cs.

ObjectName Deveel.Data.Sql.Query.FromTableDirectSource.RootTableName
getprivate set

Definition at line 60 of file FromTableDirectSource.cs.

string Deveel.Data.Sql.Query.FromTableDirectSource.UniqueName
getprivate set

Definition at line 66 of file FromTableDirectSource.cs.


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