Beispiel #1
0
        private void AddFieldForFunctionCall(SqlBuiltinScalarFunctionCallExpression functionCall, string name, MemoryDbDataReader.ResultBatch batch, RawData rawData)
        {
            var select = new SelectDataBuilder(  ).Build(functionCall, rawData);

            AddFieldFromSelectData(name, batch, select);
        }
Beispiel #2
0
        private void AddFieldFromColumn(Column column, string tableName, MemoryDbDataReader.ResultBatch batch, RawData rawData)
        {
            var readerField = new MemoryDbDataReader.ReaderFieldData
            {
                Name            = column.Name,
                DbType          = column.DbDataType.ToString(),
                NetType         = column.NetDataType,
                FieldIndex      = batch.Fields.Count,
                SelectFieldData = new SelectDataFromColumn(new TableColumn {
                    Column = column, TableName = tableName
                }, rawData)
            };

            batch.Fields.Add(readerField);
        }
Beispiel #3
0
 private void AddFieldFromLiteral(SqlLiteralExpression literalExpression, string name, MemoryDbDataReader.ResultBatch batch, RawData rawData)
 {
     if (_InsertColumns != null)
     {
         var column      = _InsertColumns[batch.Fields.Count];
         var value       = Helper.GetValueFromString(column.NetDataType, literalExpression);
         var readerField = new MemoryDbDataReader.ReaderFieldData
         {
             Name       = column.Name,
             DbType     = column.DbDataType.ToString(),
             NetType    = column.NetDataType,
             FieldIndex = batch.Fields.Count
         };
         readerField.SelectFieldData = new SelectDataFromObject(value, readerField.DbType);
         batch.Fields.Add(readerField);
     }
     else
     {
         if (literalExpression.Type == LiteralValueType.Null)
         {
             var nullField = Helper.BuildFieldFromNullValue(name, batch.Fields.Count);
             batch.Fields.Add(nullField);
             return;
         }
         var readerField = Helper.BuildFieldFromLiteral(literalExpression.Type, name, batch.Fields.Count);
         var value       = Helper.GetValueFromString(readerField.NetType, literalExpression);
         readerField.SelectFieldData = new SelectDataFromObject(value, readerField.DbType);
         batch.Fields.Add(readerField);
     }
 }
Beispiel #4
0
        private void AddFieldFromColumn(SqlObjectIdentifier objectIdentifier, string name, MemoryDbDataReader.ResultBatch batch, RawData rawData)
        {
            var tableColumn = Helper.GetTableColumn(objectIdentifier, rawData);
            var readerField = new MemoryDbDataReader.ReaderFieldData
            {
                Name            = name,
                DbType          = tableColumn.Column.DbDataType.ToString(),
                NetType         = tableColumn.Column.NetDataType,
                FieldIndex      = batch.Fields.Count,
                SelectFieldData = new SelectDataFromColumn(tableColumn, rawData)
            };

            batch.Fields.Add(readerField);
        }
Beispiel #5
0
        private void AddFieldFromVariable(SqlScalarVariableRefExpression variableRef, string name, MemoryDbDataReader.ResultBatch batch, RawData rawData)
        {
            var select = new SelectDataFromVariables(variableRef, _Command);

            AddFieldFromSelectData(name, batch, select);
        }
Beispiel #6
0
        private void AddFieldFromGlobalVariable(SqlGlobalScalarVariableRefExpression globalRef, string name, MemoryDbDataReader.ResultBatch batch, RawData rawData)
        {
            var select = new SelectDataBuilder(  ).BuildGlobalVariable(globalRef.VariableName, rawData);

            AddFieldFromSelectData(name, batch, select);
        }
Beispiel #7
0
 public void InitializeFields(MemoryDbDataReader.ResultBatch batch, List <SqlCodeObject> columns, RawData rawData)
 {
     foreach (var column in columns)
     {
         if (column is SqlSelectScalarExpression scalarExpression)
         {
             var name = Helper.GetColumnAlias(scalarExpression);
             InitializeField(batch, rawData, scalarExpression.Expression, name);
         }
         else if (column is SqlTopSpecification topSpecification)
         {
             if (topSpecification.Value.Sql.All(char.IsDigit))
             {
                 batch.MaxRowsCount = int.Parse(topSpecification.Value.Sql);
             }
             else if (topSpecification.Value is SqlScalarVariableRefExpression variableRef)
             {
                 batch.MaxRowsCount = (int?)Helper.GetValueFromParameter(variableRef.VariableName, rawData.Parameters, rawData.Command.Variables);
             }
             else
             {
                 throw new NotImplementedException($"top specification of type { topSpecification.Value.GetType()} is not implemented");
             }
         }
         else if (column is SqlSelectStarExpression selectStarExpression)
         {
             foreach (var tableAlias in rawData.TableAliasList)
             {
                 foreach (var valueColumn in tableAlias.Value.Columns)
                 {
                     AddFieldFromColumn(valueColumn, tableAlias.Key, batch, rawData);
                 }
             }
         }
         else
         {
             throw new NotImplementedException($"Not implemented column specification {column}");
         }
     }
 }
Beispiel #8
0
        public MemoryDbDataReader.ResultBatch Execute(Dictionary <string, Table> tables, RawData rawData,
                                                      SqlQuerySpecification sqlQuery,
                                                      SqlOrderByClause orderByClause = null)
        {
            if (sqlQuery.FromClause != null)
            {
                rawData.AddTablesFromClause(sqlQuery.FromClause, tables);
                if (sqlQuery.WhereClause != null)
                {
                    rawData.ExecuteWhereClause(sqlQuery.WhereClause);
                }
            }
            else
            {
                // We do not select data from any table, so we insert an empty row to trigger a result in AddData().
                rawData.RawRowList.Add(new RawTableJoinRow());
            }

            var batch = InitializeBatch(rawData, sqlQuery);

            if (sqlQuery.GroupByClause != null)
            {
                rawData.AddGroupByClause(sqlQuery.GroupByClause);
            }

            rawData.HavingClause = sqlQuery.HavingClause?.Expression;
            rawData.SortOrder    = GetSortOrder(orderByClause, sqlQuery);

            new QueryResultBuilder(rawData, sqlQuery.SelectClause.IsDistinct).AddData(batch);
            if (sqlQuery.IntoClause != null)
            {
                InsertIntoTable(sqlQuery.IntoClause, tables, batch);
            }
            return(batch);
        }