System.Data.SQLite.Linq A strongly-typed resource class, for looking up localized strings, etc. Returns the cached ResourceManager instance used by this class. Overrides the current thread's CurrentUICulture property for all resource lookups using this strongly typed resource class. Looks up a localized string similar to CREATE TEMP VIEW SCHEMACONSTRAINTCOLUMNS AS SELECT CONSTRAINT_CATALOG, NULL AS CONSTRAINT_SCHEMA, CONSTRAINT_NAME, TABLE_CATALOG, NULL AS TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME FROM TEMP.SCHEMAINDEXCOLUMNS UNION SELECT CONSTRAINT_CATALOG, NULL, CONSTRAINT_NAME, TABLE_CATALOG, NULL, TABLE_NAME, FKEY_FROM_COLUMN FROM TEMP.SCHEMAFOREIGNKEYS;. Looks up a localized string similar to CREATE TEMP VIEW SCHEMACONSTRAINTS AS SELECT INDEX_CATALOG AS CONSTRAINT_CATALOG, NULL AS CONSTRAINT_SCHEMA, INDEX_NAME AS CONSTRAINT_NAME, TABLE_CATALOG, NULL AS TABLE_SCHEMA, TABLE_NAME, 'PRIMARY KEY' AS CONSTRAINT_TYPE, 0 AS IS_DEFERRABLE, 0 AS INITIALLY_DEFERRED, NULL AS CHECK_CLAUSE FROM TEMP.SCHEMAINDEXES WHERE PRIMARY_KEY = 1 UNION SELECT INDEX_CATALOG, NULL, INDEX_NAME, TABLE_CATALOG, NULL, TABLE_NAME, 'UNIQUE', 0, 0, NULL FROM TEMP.SCHEMAINDEXES WHERE PRIMARY_KEY = 0 AND [UNIQUE] = 1 UNION [rest of string was truncated]";. Class generating SQL for a DML command tree. Generates SQL fragment returning server-generated values. Requires: translator knows about member values so that we can figure out how to construct the key predicate. Sample SQL: select IdentityValue from dbo.MyTable where @@ROWCOUNT > 0 and IdentityValue = scope_identity() or select TimestamptValue from dbo.MyTable where @@ROWCOUNT > 0 and Id = 1 Note that we filter on rowcount to ensure no rows are returned if no rows were modified. Builder containing command text Modification command tree Translator used to produce DML SQL statement for the tree Returning expression. If null, the method returns immediately without producing a SELECT statement. Lightweight expression translator for DML expression trees, which have constrained scope and support. Initialize a new expression translator populating the given string builder with command text. Command text builder and command tree must not be null. Command text with which to populate commands Command tree generating SQL Indicates whether the translator should preserve member values while compiling t-SQL (only needed for server generation) Call this method to register a property value pair so the translator "remembers" the values for members of the row being modified. These values can then be used to form a predicate for server-generation (based on the key of the row) DbExpression containing the column reference (property expression). DbExpression containing the value of the column. Represents the sql fragment for any node in the query tree. The nodes in a query tree produce various kinds of sql A select statement. A reference to an extent. (symbol) A raw string. We have this interface to allow for a common return type for the methods in the expression visitor At the end of translation, the sql fragments are converted into real strings. Write the string represented by this fragment into the stream. The stream that collects the strings. Context information used for renaming. The global lists are used to generated new names without collisions. A Join symbol is a special kind of Symbol. It has to carry additional information ColumnList for the list of columns in the select clause if this symbol represents a sql select statement. This is set by . ExtentList is the list of extents in the select clause. FlattenedExtentList - if the Join has multiple extents flattened at the top level, we need this information to ensure that extent aliases are renamed correctly in NameToExtent has all the extents in ExtentList as a dictionary. This is used by to flatten record accesses. IsNestedJoin - is used to determine whether a JoinSymbol is an ordinary join symbol, or one that has a corresponding SqlSelectStatement. All the lists are set exactly once, and then used for lookups/enumerated. This class represents an extent/nested select statement, or a column. The important fields are Name, Type and NewName. NewName starts off the same as Name, and is then modified as necessary. The rest are used by special symbols. e.g. NeedsRenaming is used by columns to indicate that a new name must be picked for the column in the second phase of translation. IsUnnest is used by symbols for a collection expression used as a from clause. This allows to add the column list after the alias. Write this symbol out as a string for sql. This is just the new name of the symbol (which could be the same as the old name). We rename columns here if necessary. A set of static helpers for type metadata Name of the Nullable Facet Cast the EdmType of the given type usage to the given TEdmType Gets the TypeUsage of the elment if the given type is a collection type Retrieves the properties of in the EdmType underlying the input type usage, if that EdmType is a structured type (EntityType, RowType). Retrieves the properties of the given EdmType, if it is a structured type (EntityType, RowType). Is the given type usage over a collection type Is the given type a collection type Is the given type usage over a primitive type Is the given type a primitive type Is the given type usage over a row type Is the given type a row type Gets the type of the given type usage if it is a primitive type Gets the value for the metadata property with the given name Name of the MaxLength Facet Name of the Unicode Facet Name of the FixedLength Facet Name of the PreserveSeconds Facet Name of the Precision Facet Name of the Scale Facet Name of the DefaultValue Facet Get the value specified on the given type usage for the given facet name. If the faces does not have a value specifid or that value is null returns the default value for that facet. Given a facet name and an EdmType, tries to get that facet's description. SkipClause represents the a SKIP expression in a SqlSelectStatement. It has a count property, which indicates how many rows should be skipped. Creates a SkipClause with the given skipCount. Creates a SkipClause with the given skipCount. Write out the SKIP part of sql select statement It basically writes OFFSET (X). How many rows should be skipped. This class is like StringBuilder. While traversing the tree for the first time, we do not know all the strings that need to be appended e.g. things that need to be renamed, nested select statements etc. So, we use a builder that can collect all kinds of sql fragments. Add an object to the list - we do not verify that it is a proper sql fragment since this is an internal method. This is to pretty print the SQL. The writer needs to know about new lines so that it can add the right amount of indentation at the beginning of lines. We delegate the writing of the fragment to the appropriate type. Whether the builder is empty. This is used by the to determine whether a sql statement can be reused. Translates the command object into a SQL string that can be executed on SQLite. The translation is implemented as a visitor over the query tree. It makes a single pass over the tree, collecting the sql fragments for the various nodes in the tree . The major operations are Select statement minimization. Multiple nodes in the query tree that can be part of a single SQL select statement are merged. e.g. a Filter node that is the input of a Project node can typically share the same SQL statement. Alpha-renaming. As a result of the statement minimization above, there could be name collisions when using correlated subqueries Filter( b = Project( c.x c = Extent(foo) ) exists ( Filter( c = Extent(foo) b.x = c.x ) ) ) The first Filter, Project and Extent will share the same SQL select statement. The alias for the Project i.e. b, will be replaced with c. If the alias c for the Filter within the exists clause is not renamed, we will get c.x = c.x, which is incorrect. Instead, the alias c within the second filter should be renamed to c1, to give c.x = c1.x i.e. b is renamed to c, and c is renamed to c1. Join flattening. In the query tree, a list of join nodes is typically represented as a tree of Join nodes, each with 2 children. e.g. a = Join(InnerJoin b = Join(CrossJoin c = Extent(foo) d = Extent(foo) ) e = Extent(foo) on b.c.x = e.x ) If translated directly, this will be translated to FROM ( SELECT c.*, d.* FROM foo as c CROSS JOIN foo as d) as b INNER JOIN foo as e on b.x' = e.x It would be better to translate this as FROM foo as c CROSS JOIN foo as d INNER JOIN foo as e on c.x = e.x This allows the optimizer to choose an appropriate join ordering for evaluation. Select * and column renaming. In the example above, we noticed that in some cases we add SELECT * FROM ... to complete the SQL statement. i.e. there is no explicit PROJECT list. In this case, we enumerate all the columns available in the FROM clause This is particularly problematic in the case of Join trees, since the columns from the extents joined might have the same name - this is illegal. To solve this problem, we will have to rename columns if they are part of a SELECT * for a JOIN node - we do not need renaming in any other situation. . Renaming issues. When rows or columns are renamed, we produce names that are unique globally with respect to the query. The names are derived from the original names, with an integer as a suffix. e.g. CustomerId will be renamed to CustomerId1, CustomerId2 etc. Since the names generated are globally unique, they will not conflict when the columns of a JOIN SELECT statement are joined with another JOIN. Record flattening. SQL server does not have the concept of records. However, a join statement produces records. We have to flatten the record accesses into a simple alias.column form. Building the SQL. There are 2 phases Traverse the tree, producing a sql builder Write the SqlBuilder into a string, renaming the aliases and columns as needed. In the first phase, we traverse the tree. We cannot generate the SQL string right away, since The WHERE clause has to be visited before the from clause. extent aliases and column aliases need to be renamed. To minimize renaming collisions, all the names used must be known, before any renaming choice is made. To defer the renaming choices, we use symbols . These are renamed in the second phase. Since visitor methods cannot transfer information to child nodes through parameters, we use some global stacks, A stack for the current SQL select statement. This is needed by to create a list of free variables used by a select statement. This is needed for alias renaming. A stack for the join context. When visiting a , we need to know whether we are inside a join or not. If we are inside a join, we do not create a new SELECT statement. Global state. To enable renaming, we maintain The set of all extent aliases used. The set of all column aliases used. Finally, we have a symbol table to lookup variable references. All references to the same extent have the same symbol. Sql select statement sharing. Each of the relational operator nodes Project Filter GroupBy Sort/OrderBy can add its non-input (e.g. project, predicate, sort order etc.) to the SQL statement for the input, or create a new SQL statement. If it chooses to reuse the input's SQL statement, we play the following symbol table trick to accomplish renaming. The symbol table entry for the alias of the current node points to the symbol for the input in the input's SQL statement. Project(b.x b = Filter( c = Extent(foo) c.x = 5) ) The Extent node creates a new SqlSelectStatement. This is added to the symbol table by the Filter as {c, Symbol(c)}. Thus, c.x is resolved to Symbol(c).x. Looking at the project node, we add {b, Symbol(c)} to the symbol table if the SQL statement is reused, and {b, Symbol(b)}, if there is no reuse. Thus, b.x is resolved to Symbol(c).x if there is reuse, and to Symbol(b).x if there is no reuse. Every relational node has to pass its SELECT statement to its children This allows them (DbVariableReferenceExpression eventually) to update the list of outer extents (free variables) used by this select statement. Nested joins and extents need to know whether they should create a new Select statement, or reuse the parent's. This flag indicates whether the parent is a join or not. VariableReferenceExpressions are allowed only as children of DbPropertyExpression or MethodExpression. The cheapest way to ensure this is to set the following property in DbVariableReferenceExpression and reset it in the allowed parent expressions. All special built-in functions and their handlers All special non-aggregate canonical functions and their handlers Valid datepart values Initializes the mapping from functions to T-SQL operators for all functions that translate to T-SQL operators Basic constructor. General purpose static function that can be called from System.Data assembly command tree Parameters to add to the command tree corresponding to constants in the command tree. Used only in ModificationCommandTrees. The string representing the SQL to be executed. Translate a command tree to a SQL string. The input tree could be translated to either a SQL SELECT statement or a SELECT expression. This choice is made based on the return type of the expression CollectionType => select statement non collection type => select expression The string representing the SQL to be executed. Translate a function command tree to a SQL string. Convert the SQL fragments to a string. We have to setup the Stream for writing. A string representing the SQL to be executed. Translate(left) AND Translate(right) A . An apply is just like a join, so it shares the common join processing in A . For binary expressions, we delegate to . We handle the other expressions directly. A If the ELSE clause is null, we do not write it out. A The parser generates Not(Equals(...)) for <>. A . Constants will be send to the store as part of the generated TSQL, not as parameters A . Strings are wrapped in single quotes and escaped. Numbers are written literally. is illegal at this stage The DISTINCT has to be added to the beginning of SqlSelectStatement.Select, but it might be too late for that. So, we use a flag on SqlSelectStatement instead, and add the "DISTINCT" in the second phase. A An element expression returns a scalar - so it is translated to ( Select ... ) Only concrete expression types will be visited. If we are in a Join context, returns a with the extent name, otherwise, a new with the From field set. Gets escaped TSql identifier describing this entity set. The bodies of , , , are similar. Each does the following. Visit the input expression Determine if the input's SQL statement can be reused, or a new one must be created. Create a new symbol table scope Push the Sql statement onto a stack, so that children can update the free variable list. Visit the non-input expression. Cleanup A Lambda functions are not supported. The functions supported are: Canonical Functions - We recognize these by their dataspace, it is DataSpace.CSpace Store Functions - We recognize these by the BuiltInAttribute and not being Canonical User-defined Functions - All the rest except for Lambda functions We handle Canonical and Store functions the same way: If they are in the list of functions that need special handling, we invoke the appropriate handler, otherwise we translate them to FunctionName(arg1, arg2, ..., argn). We translate user-defined functions to NamespaceName.FunctionName(arg1, arg2, ..., argn). A is illegal at this stage is illegal at this stage for general details. We modify both the GroupBy and the Select fields of the SqlSelectStatement. GroupBy gets just the keys without aliases, and Select gets the keys and the aggregates with aliases. Whenever there exists at least one aggregate with an argument that is not is not a simple over , we create a nested query in which we alias the arguments to the aggregates. That is due to the following two limitations of Sql Server: If an expression being aggregated contains an outer reference, then that outer reference must be the only column referenced in the expression Sql Server cannot perform an aggregate function on an expression containing an aggregate or a subquery. The default translation, without inner query is: SELECT kexp1 AS key1, kexp2 AS key2,... kexpn AS keyn, aggf1(aexpr1) AS agg1, .. aggfn(aexprn) AS aggn FROM input AS a GROUP BY kexp1, kexp2, .. kexpn When we inject an innner query, the equivalent translation is: SELECT key1 AS key1, key2 AS key2, .. keyn AS keys, aggf1(agg1) AS agg1, aggfn(aggn) AS aggn FROM ( SELECT kexp1 AS key1, kexp2 AS key2,... kexpn AS keyn, aexpr1 AS agg1, .. aexprn AS aggn FROM input AS a ) as a GROUP BY key1, key2, keyn A Not(IsEmpty) has to be handled specially, so we delegate to . A . [NOT] EXISTS( ... ) Not(IsNull) is handled specially, so we delegate to A IS [NOT] NULL is illegal at this stage A A . A . A Translates to TOP expression. A DbNewInstanceExpression is allowed as a child of DbProjectExpression only. If anyone else is the parent, we throw. We also perform special casing for collections - where we could convert them into Unions for the actual implementation. The Not expression may cause the translation of its child to change. These children are NOT(Not(x)) becomes x NOT EXISTS becomes EXISTS IS NULL becomes IS NOT NULL = becomes<> A is illegal at this stage A A A for the general ideas. A This method handles record flattening, which works as follows. consider an expression Prop(y, Prop(x, Prop(d, Prop(c, Prop(b, Var(a))))) where a,b,c are joins, d is an extent and x and y are fields. b has been flattened into a, and has its own SELECT statement. c has been flattened into b. d has been flattened into c. We visit the instance, so we reach Var(a) first. This gives us a (join)symbol. Symbol(a).b gives us a join symbol, with a SELECT statement i.e. Symbol(b). From this point on , we need to remember Symbol(b) as the source alias, and then try to find the column. So, we use a SymbolPair. We have reached the end when the symbol no longer points to a join symbol. A if we have not reached the first Join node that has a SELECT statement. A if we have seen the JoinNode, and it has a SELECT statement. A with {Input}.propertyName otherwise. Any(input, x) => Exists(Filter(input,x)) All(input, x) => Not Exists(Filter(input, not(x)) is illegal at this stage is illegal at this stage For Sql9 it translates to: SELECT Y.x1, Y.x2, ..., Y.xn FROM ( SELECT X.x1, X.x2, ..., X.xn, row_number() OVER (ORDER BY sk1, sk2, ...) AS [row_number] FROM input as X ) as Y WHERE Y.[row_number] > count ORDER BY sk1, sk2, ... A A is illegal at this stage A This code is shared by and Since the left and right expression may not be Sql select statements, we must wrap them up to look like SQL select statements. This method determines whether an extent from an outer scope(free variable) is used in the CurrentSelectStatement. An extent in an outer scope, if its symbol is not in the FromExtents of the CurrentSelectStatement. A . Aggregates are not visited by the normal visitor walk. The aggreate to be translated The translated aggregate argument This is called by the relational nodes. It does the following If the input is not a SqlSelectStatement, it assumes that the input is a collection expression, and creates a new SqlSelectStatement A and the main fromSymbol for this select statement. Was the parent a DbNotExpression? Translate a NewInstance(Element(X)) expression into "select top(1) * from X" Was the parent a DbNotExpression? This handles the processing of join expressions. The extents on a left spine are flattened, while joins not on the left spine give rise to new nested sub queries. Joins work differently from the rest of the visiting, in that the parent (i.e. the join node) creates the SqlSelectStatement for the children to use. The "parameter" IsInJoinContext indicates whether a child extent should add its stuff to the existing SqlSelectStatement, or create a new SqlSelectStatement By passing true, we ask the children to add themselves to the parent join, by passing false, we ask the children to create new Select statements for themselves. This method is called from and . A This is called from . This is responsible for maintaining the symbol table after visiting a child of a join expression. The child's sql statement may need to be completed. The child's result could be one of The same as the parent's - this is treated specially. A sql select statement, which may need to be completed An extent - just copy it to the from clause Anything else (from a collection-valued expression) - unnest and copy it. If the input was a Join, we need to create a new join symbol, otherwise, we create a normal symbol. We then call AddFromSymbol to add the AS clause, and update the symbol table. If the child's result was the same as the parent's, we have to clean up the list of symbols in the FromExtents list, since this contains symbols from the children of both the parent and the child. The happens when the child visited is a Join, and is the leftmost child of the parent. We assume that this is only called as a child of a Project. This replaces , since we do not allow DbNewInstanceExpression as a child of any node other than DbProjectExpression. We write out the translation of each of the columns in the record. A Determines whether the given function is a built-in function that requires special handling Determines whether the given function is a canonical function that requires special handling Default handling for functions Translates them to FunctionName(arg1, arg2, ..., argn) Default handling for functions with a given name. Translates them to functionName(arg1, arg2, ..., argn) Default handling on function arguments Appends the list of arguments to the given result If the function is niladic it does not append anything, otherwise it appends (arg1, arg2, ..., argn) Handler for special built in functions Handler for special canonical functions Dispatches the special function processing to the appropriate handler Handles functions that are translated into TSQL operators. The given function should have one or two arguments. Functions with one arguemnt are translated into op arg Functions with two arguments are translated into arg0 op arg1 Also, the arguments can be optionaly enclosed in parethesis Whether the arguments should be enclosed in parethesis Handles special case in which datepart 'type' parameter is present. all the functions handles here have *only* the 1st parameter as datepart. datepart value is passed along the QP as string and has to be expanded as TSQL keyword. DateAdd(datetime, secondsToAdd) -> DATEADD ( seconds , number, date) DateSubtract(datetime1, datetime2) -> DATEDIFF ( seconds , startdate , enddate ) Handler for canonical functions for extracting date parts. For example: Year(date) -> DATEPART( year, date) Function rename IndexOf -> CHARINDEX Function rename NewGuid -> NEWID Length(arg) -> LEN(arg + '.') - LEN('.') Round(numericExpression) -> Round(numericExpression, 0); TRIM(string) -> LTRIM(RTRIM(string)) LEFT(string, length) -> SUBSTR(string, 1, length) RIGHT(string, length) -> SUBSTR(string, -(length), length) Function rename ToLower -> LOWER Function rename ToUpper -> UPPER Add the column names from the referenced extent/join to the select statement. If the symbol is a JoinSymbol, we recursively visit all the extents, halting at real extents and JoinSymbols that have an associated SqlSelectStatement. The column names for a real extent can be derived from its type. The column names for a Join Select statement can be got from the list of columns that was created when the Join's select statement was created. We do the following for each column. Add the SQL string for each column to the SELECT clause Add the column to the list of columns - so that it can become part of the "type" of a JoinSymbol Check if the column name collides with a previous column added to the same select statement. Flag both the columns for renaming if true. Add the column to a name lookup dictionary for collision detection. The select statement that started off as SELECT * The symbol containing the type information for the columns to be added. Columns that have been added to the Select statement. This is created in . A dictionary of the columns above. Comma or nothing, depending on whether the SELECT clause is empty. Expands Select * to "select the_list_of_columns" If the columns are taken from an extent, they are written as {original_column_name AS Symbol(original_column)} to allow renaming. If the columns are taken from a Join, they are written as just {original_column_name}, since there cannot be a name collision. We concatenate the columns from each of the inputs to the select statement. Since the inputs may be joins that are flattened, we need to recurse. The inputs are inferred from the symbols in FromExtents. This method is called after the input to a relational node is visited. and There are 2 scenarios The fromSymbol is new i.e. the select statement has just been created, or a join extent has been added. The fromSymbol is old i.e. we are reusing a select statement. If we are not reusing the select statement, we have to complete the FROM clause with the alias -- if the input was an extent FROM = [SchemaName].[TableName] -- if the input was a Project FROM = (SELECT ... FROM ... WHERE ...) These become -- if the input was an extent FROM = [SchemaName].[TableName] AS alias -- if the input was a Project FROM = (SELECT ... FROM ... WHERE ...) AS alias and look like valid FROM clauses. Finally, we have to add the alias to the global list of aliases used, and also to the current symbol table. The alias to be used. Translates a list of SortClauses. Used in the translation of OrderBy The SqlBuilder to which the sort keys should be appended A new select statement, with the old one as the from clause. This is called after a relational node's input has been visited, and the input's sql statement cannot be reused. When the input's sql statement cannot be reused, we create a new sql statement, with the old one as the from clause of the new statement. The old statement must be completed i.e. if it has an empty select list, the list of columns must be projected out. If the old statement being completed has a join symbol as its from extent, the new statement must have a clone of the join symbol as its extent. We cannot reuse the old symbol, but the new select statement must behave as though it is working over the "join" record. A new select statement, with the old one as the from clause. Before we embed a string literal in a SQL string, we should convert all ' to '', and enclose the whole string in single quotes. The escaped sql string. Returns the sql primitive/native type name. It will include size, precision or scale depending on type information present in the type facets Handles the expression represending DbLimitExpression.Limit and DbSkipExpression.Count. If it is a constant expression, it simply does to string thus avoiding casting it to the specific value (which would be done if is called) This is used to determine if a particular expression is an Apply operation. This is only the case when the DbExpressionKind is CrossApply or OuterApply. This is used to determine if a particular expression is a Join operation. This is true for DbCrossJoinExpression and DbJoinExpression, the latter of which may have one of several different ExpressionKinds. This is used to determine if a calling expression needs to place round brackets around the translation of the expression e. Constants, parameters and properties do not require brackets, everything else does. true, if the expression needs brackets Determine if the owner expression can add its unique sql to the input's SqlSelectStatement The SqlSelectStatement of the input to the relational node. The kind of the expression node(not the input's) We use the normal box quotes for SQL server. We do not deal with ANSI quotes i.e. double quotes. Simply calls with addDefaultColumns set to true This is called from and nodes which require a select statement as an argument e.g. , . SqlGenerator needs its child to have a proper alias if the child is just an extent or a join. The normal relational nodes result in complete valid SQL statements. For the rest, we need to treat them as there was a dummy -- originally {expression} -- change that to SELECT * FROM {expression} as c DbLimitExpression needs to start the statement but not add the default columns This method is called by and This is passed from in the All(...) case. If the sql fragment for an input expression is not a SqlSelect statement or other acceptable form (e.g. an extent as a SqlBuilder), we need to wrap it in a form acceptable in a FROM clause. These are primarily the The set operation expressions - union all, intersect, except TVFs, which are conceptually similar to tables Is this a builtin function (ie) does it have the builtinAttribute specified? Helper method for the Group By visitor Returns true if at least one of the aggregates in the given list has an argument that is not a over Determines whether the given expression is a over The top of the stack The top of the stack A SqlSelectStatement represents a canonical SQL SELECT statement. It has fields for the 5 main clauses SELECT FROM WHERE GROUP BY ORDER BY We do not have HAVING, since it does not correspond to anything in the DbCommandTree. Each of the fields is a SqlBuilder, so we can keep appending SQL strings or other fragments to build up the clause. We have a IsDistinct property to indicate that we want distict columns. This is given out of band, since the input expression to the select clause may already have some columns projected out, and we use append-only SqlBuilders. The DISTINCT is inserted when we finally write the object into a string. Also, we have a Top property, which is non-null if the number of results should be limited to certain number. It is given out of band for the same reasons as DISTINCT. The FromExtents contains the list of inputs in use for the select statement. There is usually just one element in this - Select statements for joins may temporarily have more than one. If the select statement is created by a Join node, we maintain a list of all the extents that have been flattened in the join in AllJoinExtents in J(j1= J(a,b), c) FromExtents has 2 nodes JoinSymbol(name=j1, ...) and Symbol(name=c) AllJoinExtents has 3 nodes Symbol(name=a), Symbol(name=b), Symbol(name=c) If any expression in the non-FROM clause refers to an extent in a higher scope, we add that extent to the OuterExtents list. This list denotes the list of extent aliases that may collide with the aliases used in this select statement. It is set by . An extent is an outer extent if it is not one of the FromExtents. Write out a SQL select statement as a string. We have to Check whether the aliases extents we use in this statement have to be renamed. We first create a list of all the aliases used by the outer extents. For each of the FromExtents( or AllJoinExtents if it is non-null), rename it if it collides with the previous list. Write each of the clauses (if it exists) as a string Do we need to add a DISTINCT at the beginning of the SELECT This extends StringWriter primarily to add the ability to add an indent to each line that is written out. Reset atBeginningofLine if we detect the newline string. Add as many tabs as the value of indent if we are at the beginning of a line. The number of tabs to be added at the beginning of each new line. The SymbolPair exists to solve the record flattening problem. Consider a property expression D(v, "j3.j2.j1.a.x") where v is a VarRef, j1, j2, j3 are joins, a is an extent and x is a columns. This has to be translated eventually into {j'}.{x'} The source field represents the outermost SqlStatement representing a join expression (say j2) - this is always a Join symbol. The column field keeps moving from one join symbol to the next, until it stops at a non-join symbol. This is returned by , but never makes it into a SqlBuilder. The symbol table is quite primitive - it is a stack with a new entry for each scope. Lookups search from the top of the stack to the bottom, until an entry is found. The symbols are of the following kinds represents tables (extents/nested selects/unnests) represents Join nodes columns. Symbols represent names to be resolved, or things to be renamed. TopClause represents the a TOP expression in a SqlSelectStatement. It has a count property, which indicates how many TOP rows should be selected and a boolen WithTies property. Creates a TopClause with the given topCount and withTies. Creates a TopClause with the given topCount and withTies. Write out the TOP part of sql select statement It basically writes LIMIT (X). Do we need to add a WITH_TIES to the top statement How many top rows should be selected. SQLite implementation of . Static instance member which returns an instanced class. Constructs a new instance. Creates and returns a new object. The new object. Creates and returns a new object. The new object. Creates and returns a new object. The new object. Creates and returns a new object. The new object. Creates and returns a new object. The new object. Creates and returns a new object. The new object. The Provider Manifest for SQL Server Constructs the provider manifest. We pass the token as a DateTimeFormat enum text, because all the datetime functions are vastly different depending on how the user is opening the connection A token used to infer the capabilities of the store Returns manifest information for the provider The name of the information to be retrieved. An XmlReader at the begining of the information requested. This method takes a type and a set of facets and returns the best mapped equivalent type in EDM. A TypeUsage encapsulating a store type and a set of facets A TypeUsage encapsulating an EDM type and a set of facets This method takes a type and a set of facets and returns the best mapped equivalent type A TypeUsage encapsulating an EDM type and a set of facets A TypeUsage encapsulating a store type and a set of facets Creates a SQLiteParameter given a name, type, and direction Determines DbType for the given primitive type. Extracts facet information as well. Determines preferred value for SqlParameter.Size. Returns null where there is no preference. Chooses the appropriate DbType for the given string type. Chooses the appropriate DbType for the given binary type. Creates temporary tables on the connection so schema information can be queried There's a lot of work involved in getting schema information out of SQLite, but LINQ expects to be able to query on schema tables. Therefore we need to "fake" it by generating temporary tables filled with the schema of the current connection. We get away with making this information static because schema information seems to always be queried on a new connection object, so the schema is always fresh. The connection upon which to build the schema tables Turn a datatable into a table in the temporary database for the connection The connection to make the temporary table in The table to write out The temporary table name to write to