Inheritance: IDisposable
Exemplo n.º 1
0
        public QueryEvent(SqlQuery query, QueryEventType eventType, StatementResult[] result)
        {
            if (query == null)
                throw new ArgumentNullException("query");

            Query = query;
            EventType = eventType;
            Result = result;
        }
Exemplo n.º 2
0
        internal QueryResult(SqlQuery query, StatementResult result, bool readAll)
        {
            Query = query;
            Result = result;

            FormColumns(Result);

            if (readAll && Result.Type == StatementResultType.CursorRef)
                ReadAll();
        }
Exemplo n.º 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;
        }