Example #1
0
 public TextRow(ResultSet resultSet)
     : base(resultSet)
 {
 }
Example #2
0
 public Row(ResultSet resultSet) => ResultSet = resultSet;
Example #3
0
 public BinaryRow(ResultSet resultSet)
     : base(resultSet)
 {
 }
Example #4
0
            static Row?ScanRowAsyncRemainder(ResultSet resultSet, PayloadData payload, Row?row)
            {
                if (payload.HeaderByte == EofPayload.Signature)
                {
                    var span = payload.Span;
                    if (resultSet.Session.SupportsDeprecateEof && OkPayload.IsOk(span, resultSet.Session.SupportsDeprecateEof))
                    {
                        var ok = OkPayload.Create(span, resultSet.Session.SupportsDeprecateEof, resultSet.Session.SupportsSessionTrack);
                        resultSet.BufferState = (ok.ServerStatus & ServerStatus.MoreResultsExist) == 0 ? ResultSetState.NoMoreData : ResultSetState.HasMoreData;
                        return(null);
                    }
                    if (!resultSet.Session.SupportsDeprecateEof && EofPayload.IsEof(payload))
                    {
                        var eof = EofPayload.Create(span);
                        resultSet.BufferState = (eof.ServerStatus & ServerStatus.MoreResultsExist) == 0 ? ResultSetState.NoMoreData : ResultSetState.HasMoreData;
                        return(null);
                    }
                }

                if (row is null)
                {
                    bool isBinaryRow = false;
                    if (payload.HeaderByte == 0 && !resultSet.Connection.IgnorePrepare)
                    {
                        // this might be a binary row, but it might also be a text row whose first column is zero bytes long; try reading
                        // the row as a series of length-encoded values (the text format) to see if this might plausibly be a text row
                        var isTextRow   = false;
                        var reader      = new ByteArrayReader(payload.Span);
                        var columnCount = 0;
                        while (reader.BytesRemaining > 0)
                        {
                            int length;
                            var firstByte = reader.ReadByte();
                            if (firstByte == 0xFB)
                            {
                                // NULL
                                length = 0;
                            }
                            else if (firstByte == 0xFC)
                            {
                                // two-byte length-encoded integer
                                if (reader.BytesRemaining < 2)
                                {
                                    break;
                                }
                                length = unchecked ((int)reader.ReadFixedLengthUInt32(2));
                            }
                            else if (firstByte == 0xFD)
                            {
                                // three-byte length-encoded integer
                                if (reader.BytesRemaining < 3)
                                {
                                    break;
                                }
                                length = unchecked ((int)reader.ReadFixedLengthUInt32(3));
                            }
                            else if (firstByte == 0xFE)
                            {
                                // eight-byte length-encoded integer
                                if (reader.BytesRemaining < 8)
                                {
                                    break;
                                }
                                length = checked ((int)reader.ReadFixedLengthUInt64(8));
                            }
                            else if (firstByte == 0xFF)
                            {
                                // invalid length prefix
                                break;
                            }
                            else
                            {
                                // single-byte length
                                length = firstByte;
                            }

                            if (reader.BytesRemaining < length)
                            {
                                break;
                            }
                            reader.Offset += length;
                            columnCount++;

                            if (columnCount == resultSet.ColumnDefinitions !.Length)
                            {
                                // if we used up all the bytes reading exactly 'ColumnDefinitions' length-encoded columns, then assume this is a text row
                                if (reader.BytesRemaining == 0)
                                {
                                    isTextRow = true;
                                }
                                break;
                            }
                        }

                        isBinaryRow = !isTextRow;
                    }
                    row = isBinaryRow ? (Row) new BinaryRow(resultSet) : new TextRow(resultSet);
                }
                row.SetData(payload.Memory);
                resultSet.m_hasRows   = true;
                resultSet.BufferState = ResultSetState.ReadingRows;
                return(row);
            }