Beispiel #1
0
        private void FormColumns(ITable result)
        {
            // HACK: Read the contents of the first row so that we can pick up
            //   any errors with reading, and also to fix the 'uniquekey' bug
            //   that causes a new transaction to be started if 'uniquekey' is
            //   a column and the value is resolved later.
            var columnCount = result.TableInfo.ColumnCount;

            using (var rowEnum = result.GetEnumerator()) {
                if (rowEnum.MoveNext())
                {
                    int rowIndex = rowEnum.Current.RowId.RowNumber;
                    for (int c = 0; c < columnCount; ++c)
                    {
                        result.GetValue(rowIndex, c);
                    }
                }

                // If simple enum, note it here
                resultIsSimpleEnum = (rowEnum is SimpleRowEnumerator);
            }

            // Build 'row_index_map' if not a simple enum
            if (!resultIsSimpleEnum)
            {
                rowIndexMap = new List <int>(result.RowCount);

                var en = result.GetEnumerator();
                while (en.MoveNext())
                {
                    rowIndexMap.Add(en.Current.RowId.RowNumber);
                }
            }

            // This is a safe operation provides we are shared.
            // Copy all the TableField columns from the table to our own
            // QueryResultColumn array, naming each column by what is returned from
            // the 'GetResolvedVariable' method.
            int colCount = result.TableInfo.ColumnCount;

            columns = new QueryResultColumn[colCount];
            for (int i = 0; i < colCount; ++i)
            {
                var    v = result.GetResolvedColumnName(i);
                string fieldName;
                if (v.ParentName == null)
                {
                    // This means the column is an alias
                    fieldName = String.Format("@a{0}", v.Name);
                }
                else
                {
                    // This means the column is an schema/table/column reference
                    fieldName = String.Format("@f{0}", v);
                }

                columns[i] = new QueryResultColumn(fieldName, result.TableInfo[i]);
            }
        }
Beispiel #2
0
        private void CreateResults(IQueryResponse[] response)
        {
            results = new LocalQueryResult[response.Length];

            for (int i = 0; i < response.Length; i++) {
                var r = response[i];
                var columns = new QueryResultColumn[r.ColumnCount];
                for (int j = 0; j < columns.Length; j++) {
                    columns[j] = r.GetColumn(j);
                }

                var result = new LocalQueryResult(connection);
                result.QueryTime = r.QueryTimeMillis;

                result.Setup(r.ResultId, columns, r.RowCount);
                result.SetFetchSize(connection.Settings.FetchSize);
                result.SetMaxRowCount(connection.Settings.MaxFetchSize);

                // Does the result set contain large objects?  We can't cache a
                // result that contains binary data.

                bool hasLargeObject = result.HasLargeObject;

                // If the result row count < 40 then download and store locally in the
                // result set and dispose the resources on the server.
                if (!hasLargeObject && result.RowCount < 40) {
                    result.DownloadAndClose();
                } else {
                    result.Download(0, System.Math.Min(10, result.RowCount));
                }

                results[i] = result;
            }
        }
Beispiel #3
0
        private void FormColumns(StatementResult result)
        {
            if (result.Type == StatementResultType.Exception)
                return;

            IEnumerator<Row> enumerator = null;
            if (result.Type == StatementResultType.CursorRef) {
                enumerator = result.Cursor.GetEnumerator();
            } else if (result.Type == StatementResultType.Result) {
                enumerator = result.Result.GetEnumerator();
            }

            try {
                if (enumerator != null) {
                    if (enumerator.MoveNext()) {
                        var row = enumerator.Current;

                        if (row != null) {
                            for (int c = 0; c < row.ColumnCount; ++c) {
                                row.GetValue(c);
                            }
                        }
                    }
                }
            } finally {
                if (enumerator != null)
                    enumerator.Dispose();
            }

            TableInfo tableInfo;
            if (result.Type == StatementResultType.CursorRef) {
                tableInfo = result.Cursor.Source.TableInfo;
            } else {
                tableInfo = result.Result.TableInfo;
            }

            var columnCount = tableInfo.ColumnCount;

            ColumnCount = columnCount;

            columns = new QueryResultColumn[columnCount];

            ITable source = null;
            if (result.Type == StatementResultType.Result) {
                source = result.Result;
            } else if (result.Type == StatementResultType.CursorRef) {
                source = result.Cursor.Source;
            } else {
                return;
            }

            for (int i = 0; i < columnCount; ++i) {
                var v = source.GetResolvedColumnName(i);
                string fieldName;
                if (v.ParentName == null) {
                    // This means the column is an alias
                    fieldName = String.Format("@a{0}", v.Name);
                } else {
                    // This means the column is an schema/table/column reference
                    fieldName = String.Format("@f{0}", v);
                }

                columns[i] = new QueryResultColumn(fieldName, tableInfo[i]);

                if (IsKey(v))
                    columns[i].SetKey();
                if (IsUnique(v))
                    columns[i].SetUnique();
            }

            RowCount = source.RowCount;
        }
Beispiel #4
0
        public void Setup(int id, QueryResultColumn[] columnList, int totalRowCount)
        {
            ResultId = id;
            columns = columnList;
            resultRowCount = totalRowCount;
            blockTopRow = -1;
            resultBlock = null;

            realIndex = -1;
            fetchSize = connection.Settings.FetchSize;
            Closed = false;
        }
Beispiel #5
0
        /// <summary>
        /// Constructs the result set.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="result"></param>
        public QueryResult(SqlQuery query, Table result)
        {
            this.query = query;
            this.result = result;
            streamableBlobMap = new Dictionary<long, StreamableObject>();

            resultRowCount = result.RowCount;

            // HACK: Read the contents of the first row so that we can pick up
            //   any errors with reading, and also to fix the 'uniquekey' bug
            //   that causes a new transaction to be started if 'uniquekey' is
            //   a column and the value is resolved later.
            IRowEnumerator rowEnum = result.GetRowEnumerator();
            if (rowEnum.MoveNext()) {
                int rowIndex = rowEnum.RowIndex;
                for (int c = 0; c < result.ColumnCount; ++c) {
                    result.GetCell(c, rowIndex);
                }
            }

            // If simple enum, note it here
            resultIsSimpleEnum = (rowEnum is SimpleRowEnumerator);
            rowEnum = null;

            // Build 'row_index_map' if not a simple enum
            if (!resultIsSimpleEnum) {
                rowIndexMap = new List<int>(result.RowCount);

                IRowEnumerator en = result.GetRowEnumerator();
                while (en.MoveNext()) {
                    rowIndexMap.Add(en.RowIndex);
                }
            }

            // This is a safe operation provides we are shared.
            // Copy all the TableField columns from the table to our own
            // QueryResultColumn array, naming each column by what is returned from
            // the 'GetResolvedVariable' method.
            int colCount = result.ColumnCount;
            colDesc = new QueryResultColumn[colCount];
            for (int i = 0; i < colCount; ++i) {
                VariableName v = result.GetResolvedVariable(i);
                string fieldName;
                if (v.TableName == null) {
                    // This means the column is an alias
                    fieldName = String.Format("@a{0}", v.Name);
                } else {
                    // This means the column is an schema/table/column reference
                    fieldName = String.Format("@f{0}", v);
                }

                colDesc[i] = new QueryResultColumn(fieldName, result.GetColumnInfo(i));
            }

            locked = 0;
        }
Beispiel #6
0
        private void FormColumns(ITable result)
        {
            // HACK: Read the contents of the first row so that we can pick up
            //   any errors with reading, and also to fix the 'uniquekey' bug
            //   that causes a new transaction to be started if 'uniquekey' is
            //   a column and the value is resolved later.
            var columnCount = result.TableInfo.ColumnCount;
            using (var rowEnum = result.GetEnumerator()) {
                if (rowEnum.MoveNext()) {
                    int rowIndex = rowEnum.Current.RowId.RowNumber;
                    for (int c = 0; c < columnCount; ++c) {
                        result.GetValue(rowIndex, c);
                    }
                }

                // If simple enum, note it here
                resultIsSimpleEnum = (rowEnum is SimpleRowEnumerator);
            }

            // Build 'row_index_map' if not a simple enum
            if (!resultIsSimpleEnum) {
                rowIndexMap = new List<int>(result.RowCount);

                var en = result.GetEnumerator();
                while (en.MoveNext()) {
                    rowIndexMap.Add(en.Current.RowId.RowNumber);
                }
            }

            // This is a safe operation provides we are shared.
            // Copy all the TableField columns from the table to our own
            // QueryResultColumn array, naming each column by what is returned from
            // the 'GetResolvedVariable' method.
            int colCount = result.TableInfo.ColumnCount;
            columns = new QueryResultColumn[colCount];
            for (int i = 0; i < colCount; ++i) {
                var v = result.GetResolvedColumnName(i);
                string fieldName;
                if (v.ParentName == null) {
                    // This means the column is an alias
                    fieldName = String.Format("@a{0}", v.Name);
                } else {
                    // This means the column is an schema/table/column reference
                    fieldName = String.Format("@f{0}", v);
                }

                columns[i] = new QueryResultColumn(fieldName, result.TableInfo[i]);
            }
        }
        /// <summary>
        /// Constructs the result set.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="result"></param>
        public QueryResult(SqlQuery query, Table result)
        {
            this.query        = query;
            this.result       = result;
            streamableBlobMap = new Dictionary <long, StreamableObject>();

            resultRowCount = result.RowCount;

            // HACK: Read the contents of the first row so that we can pick up
            //   any errors with reading, and also to fix the 'uniquekey' bug
            //   that causes a new transaction to be started if 'uniquekey' is
            //   a column and the value is resolved later.
            IRowEnumerator rowEnum = result.GetRowEnumerator();

            if (rowEnum.MoveNext())
            {
                int rowIndex = rowEnum.RowIndex;
                for (int c = 0; c < result.ColumnCount; ++c)
                {
                    result.GetCell(c, rowIndex);
                }
            }

            // If simple enum, note it here
            resultIsSimpleEnum = (rowEnum is SimpleRowEnumerator);
            rowEnum            = null;

            // Build 'row_index_map' if not a simple enum
            if (!resultIsSimpleEnum)
            {
                rowIndexMap = new List <int>(result.RowCount);

                IRowEnumerator en = result.GetRowEnumerator();
                while (en.MoveNext())
                {
                    rowIndexMap.Add(en.RowIndex);
                }
            }

            // This is a safe operation provides we are shared.
            // Copy all the TableField columns from the table to our own
            // QueryResultColumn array, naming each column by what is returned from
            // the 'GetResolvedVariable' method.
            int colCount = result.ColumnCount;

            colDesc = new QueryResultColumn[colCount];
            for (int i = 0; i < colCount; ++i)
            {
                VariableName v = result.GetResolvedVariable(i);
                string       fieldName;
                if (v.TableName == null)
                {
                    // This means the column is an alias
                    fieldName = String.Format("@a{0}", v.Name);
                }
                else
                {
                    // This means the column is an schema/table/column reference
                    fieldName = String.Format("@f{0}", v);
                }

                colDesc[i] = new QueryResultColumn(fieldName, result.GetColumnInfo(i));
            }

            locked = 0;
        }
Beispiel #8
0
        private void FormColumns(StatementResult result)
        {
            if (result.Type == StatementResultType.Exception)
            {
                return;
            }

            IEnumerator <Row> enumerator = null;

            if (result.Type == StatementResultType.CursorRef)
            {
                enumerator = result.Cursor.GetEnumerator();
            }
            else if (result.Type == StatementResultType.Result)
            {
                enumerator = result.Result.GetEnumerator();
            }

            try {
                if (enumerator != null)
                {
                    if (enumerator.MoveNext())
                    {
                        var row = enumerator.Current;

                        if (row != null)
                        {
                            for (int c = 0; c < row.ColumnCount; ++c)
                            {
                                row.GetValue(c);
                            }
                        }
                    }
                }
            } finally {
                if (enumerator != null)
                {
                    enumerator.Dispose();
                }
            }


            TableInfo tableInfo;

            if (result.Type == StatementResultType.CursorRef)
            {
                tableInfo = result.Cursor.Source.TableInfo;
            }
            else
            {
                tableInfo = result.Result.TableInfo;
            }

            var columnCount = tableInfo.ColumnCount;

            ColumnCount = columnCount;

            columns = new QueryResultColumn[columnCount];

            ITable source = null;

            if (result.Type == StatementResultType.Result)
            {
                source = result.Result;
            }
            else if (result.Type == StatementResultType.CursorRef)
            {
                source = result.Cursor.Source;
            }
            else
            {
                return;
            }

            for (int i = 0; i < columnCount; ++i)
            {
                var    v = source.GetResolvedColumnName(i);
                string fieldName;
                if (v.ParentName == null)
                {
                    // This means the column is an alias
                    fieldName = String.Format("@a{0}", v.Name);
                }
                else
                {
                    // This means the column is an schema/table/column reference
                    fieldName = String.Format("@f{0}", v);
                }

                columns[i] = new QueryResultColumn(fieldName, tableInfo[i]);

                if (IsKey(v))
                {
                    columns[i].SetKey();
                }
                if (IsUnique(v))
                {
                    columns[i].SetUnique();
                }
            }

            RowCount = source.RowCount;
        }