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

An implementation of IFromTableSource that wraps around a SqlQueryExpression as a sub-query source. More...

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

Public Member Functions

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...
 

Package Functions

 FromTableSubQuerySource (bool caseInsensitive, string uniqueKey, SqlQueryExpression queryExpression, QueryExpressionFrom fromSet, ObjectName alias)
 

Properties

SqlQueryExpression QueryExpression [get, private set]
 
QueryExpressionFrom QueryFrom [get, private set]
 
ObjectName AliasName [get, private set]
 
bool IgnoreCase [get, private set]
 
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

void EnsureColumnNames ()
 Makes sure the columnNames list is created correctly. More...
 
bool StringCompare (string str1, string str2)
 
bool Matches (ObjectName name, string catalog, string schema, string table, string column)
 

Private Attributes

ObjectName[] columnNames
 

Detailed Description

An implementation of IFromTableSource that wraps around a SqlQueryExpression as a sub-query source.

Definition at line 27 of file FromTableSubQuerySource.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Query.FromTableSubQuerySource.FromTableSubQuerySource ( bool  caseInsensitive,
string  uniqueKey,
SqlQueryExpression  queryExpression,
QueryExpressionFrom  fromSet,
ObjectName  alias 
)
inlinepackage

Member Function Documentation

void Deveel.Data.Sql.Query.FromTableSubQuerySource.EnsureColumnNames ( )
inlineprivate

Makes sure the columnNames list is created correctly.

Definition at line 76 of file FromTableSubQuerySource.cs.

76  {
77  if (columnNames == null) {
79 
80  // Are the variables aliased to a table name?
81  if (AliasName != null) {
82  for (int i = 0; i < columnNames.Length; ++i) {
83  columnNames[i] = new ObjectName(AliasName, columnNames[i].Name);
84  }
85  }
86  }
87  }
bool Deveel.Data.Sql.Query.FromTableSubQuerySource.Matches ( ObjectName  name,
string  catalog,
string  schema,
string  table,
string  column 
)
inlineprivate

Definition at line 94 of file FromTableSubQuerySource.cs.

94  {
95  var tableName = name.Parent;
96  var schemaName = tableName == null ? null : tableName.Parent;
97  var catalogName = schemaName == null ? null : schemaName.Parent;
98  var columnName = name.Name;
99 
100  if (column == null)
101  return true;
102  if (!StringCompare(columnName, column))
103  return false;
104 
105  if (table == null)
106  return true;
107  if (tableName == null)
108  return false;
109 
110  string tname = tableName.Name;
111  if (tname != null && !StringCompare(tname, table))
112  return false;
113 
114  if (schema == null)
115  return true;
116 
117  string sname = schemaName != null ? schemaName.Name : null;
118  if (sname != null && !StringCompare(sname, schema))
119  return false;
120 
121  string cname = catalogName != null ? catalogName.Name : null;
122  if (cname != null && !StringCompare(cname, catalog))
123  return false;
124 
125  return true;
126  }
bool Deveel.Data.Sql.Query.FromTableSubQuerySource.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 39 of file FromTableSubQuerySource.cs.

39  {
40  if (schema == null && table == null)
41  return true;
42 
43  if (AliasName != null) {
44  string ts = AliasName.Parent.Name;
45  string tt = AliasName.Name;
46  if (schema == null)
47  return StringCompare(tt, table);
48  if (StringCompare(tt, table) && StringCompare(ts, schema))
49  return true;
50  }
51 
52  // No way to determine if there is a match
53  return false;
54  }
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.FromTableSubQuerySource.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 141 of file FromTableSubQuerySource.cs.

141  {
143 
144  var result = columnNames.FirstOrDefault(v => Matches(v, catalog, schema, table, column));
145  if (result == null)
146  throw new InvalidOperationException("Couldn't resolve to a column.");
147 
148  return result;
149  }
void EnsureColumnNames()
Makes sure the columnNames list is created correctly.
bool Matches(ObjectName name, string catalog, string schema, string table, string column)
int Deveel.Data.Sql.Query.FromTableSubQuerySource.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 128 of file FromTableSubQuerySource.cs.

128  {
130 
131  if (String.IsNullOrEmpty(catalog) &&
132  String.IsNullOrEmpty(schema) &&
133  String.IsNullOrEmpty(table) &&
134  String.IsNullOrEmpty(column))
135  return columnNames.Length;
136 
137  return columnNames.Count(v => Matches(v, catalog, schema, table, column));
138 
139  }
A long string in the system.
void EnsureColumnNames()
Makes sure the columnNames list is created correctly.
bool Matches(ObjectName name, string catalog, string schema, string table, string column)
bool Deveel.Data.Sql.Query.FromTableSubQuerySource.StringCompare ( string  str1,
string  str2 
)
inlineprivate

Definition at line 89 of file FromTableSubQuerySource.cs.

89  {
90  var comparison = IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
91  return String.Equals(str1, str2, comparison);
92  }
A long string in the system.

Member Data Documentation

ObjectName [] Deveel.Data.Sql.Query.FromTableSubQuerySource.columnNames
private

Definition at line 28 of file FromTableSubQuerySource.cs.

Property Documentation

ObjectName Deveel.Data.Sql.Query.FromTableSubQuerySource.AliasName
getprivate set

Definition at line 60 of file FromTableSubQuerySource.cs.

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

Definition at line 66 of file FromTableSubQuerySource.cs.

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

Definition at line 62 of file FromTableSubQuerySource.cs.

SqlQueryExpression Deveel.Data.Sql.Query.FromTableSubQuerySource.QueryExpression
getprivate set

Definition at line 56 of file FromTableSubQuerySource.cs.

QueryExpressionFrom Deveel.Data.Sql.Query.FromTableSubQuerySource.QueryFrom
getprivate set

Definition at line 58 of file FromTableSubQuerySource.cs.

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

Definition at line 64 of file FromTableSubQuerySource.cs.


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