Example #1
0
        public RequestFrame GetFrame(short streamId)
        {
            //protocol v2: <type><n><query_1>...<query_n><consistency>
            //protocol v3: <type><n><query_1>...<query_n><consistency><flags>[<serial_consistency>][<timestamp>]
            var wb = new BEBinaryWriter();

            wb.WriteFrameHeader((byte)ProtocolVersion, _headerFlags, streamId, OpCode);
            wb.WriteByte((byte)_type);
            wb.WriteInt16((short)_requests.Count);
            foreach (var br in _requests)
            {
                br.WriteToBatch((byte)ProtocolVersion, wb);
            }
            wb.WriteInt16((short)Consistency);
            if (ProtocolVersion >= 3)
            {
                wb.WriteByte((byte)_batchFlags);
            }
            if (_serialConsistency != null)
            {
                wb.WriteInt16((short)_serialConsistency.Value);
            }
            if (_timestamp != null)
            {
                //Expressed in microseconds
                wb.WriteLong(TypeCodec.ToUnixTime(_timestamp.Value).Ticks / 10);
            }
            return(wb.GetFrame());
        }
Example #2
0
        //TODO: Move to ExecuteRequest and QueryRequest
        internal void Write(FrameWriter wb, byte protocolVersion, bool isPrepared)
        {
            //protocol v1: <query><n><value_1>....<value_n><consistency>
            //protocol v2: <query><consistency><flags>[<n><value_1>...<value_n>][<result_page_size>][<paging_state>][<serial_consistency>]
            //protocol v3: <query><consistency><flags>[<n>[name_1]<value_1>...[name_n]<value_n>][<result_page_size>][<paging_state>][<serial_consistency>][<timestamp>]
            var flags = GetFlags();

            if (protocolVersion > 1)
            {
                wb.WriteUInt16((ushort)Consistency);
                wb.WriteByte((byte)flags);
            }

            if (flags.HasFlag(QueryFlags.Values))
            {
                wb.WriteUInt16((ushort)Values.Length);
                for (var i = 0; i < Values.Length; i++)
                {
                    if (flags.HasFlag(QueryFlags.WithNameForValues))
                    {
                        var name = ValueNames[i];
                        wb.WriteString(name);
                    }
                    var v     = Values[i];
                    var bytes = TypeCodec.Encode(protocolVersion, v);
                    wb.WriteBytes(bytes);
                }
            }
            else if (protocolVersion == 1 && isPrepared)
            {
                //n values is not optional on protocol v1
                //Write 0 values
                wb.WriteUInt16(0);
            }

            if (protocolVersion == 1)
            {
                //Protocol v1 ends here
                wb.WriteUInt16((ushort)Consistency);
                return;
            }
            if ((flags & QueryFlags.PageSize) == QueryFlags.PageSize)
            {
                wb.WriteInt32(PageSize);
            }
            if ((flags & QueryFlags.WithPagingState) == QueryFlags.WithPagingState)
            {
                wb.WriteBytes(PagingState);
            }
            if ((flags & QueryFlags.WithSerialConsistency) == QueryFlags.WithSerialConsistency)
            {
                wb.WriteUInt16((ushort)SerialConsistency);
            }
            if (Timestamp != null)
            {
                //Expressed in microseconds
                wb.WriteLong(TypeCodec.ToUnixTime(Timestamp.Value).Ticks / 10);
            }
        }
        public void SimpleStatementSetTimestamp()
        {
            var timestamp       = new DateTimeOffset(1999, 12, 31, 1, 2, 3, TimeSpan.Zero);
            var id              = Guid.NewGuid();
            var insertStatement = new SimpleStatement(String.Format("INSERT INTO {0} (id, text_sample) VALUES (?, ?)", AllTypesTableName), id, "sample text");

            Session.Execute(insertStatement.SetTimestamp(timestamp));
            var row = Session.Execute(new SimpleStatement(String.Format("SELECT id, text_sample, writetime(text_sample) FROM {0} WHERE id = ?", AllTypesTableName), id)).First();

            Assert.NotNull(row.GetValue <string>("text_sample"));
            Assert.AreEqual(TypeCodec.ToUnixTime(timestamp).Ticks / 10, row.GetValue <object>("writetime(text_sample)"));
        }
Example #4
0
        public int WriteFrame(short streamId, MemoryStream stream)
        {
            //protocol v2: <type><n><query_1>...<query_n><consistency>
            //protocol v3: <type><n><query_1>...<query_n><consistency><flags>[<serial_consistency>][<timestamp>]
            var wb = new FrameWriter(stream);

            if (Payload != null)
            {
                _headerFlags |= FrameHeader.HeaderFlag.CustomPayload;
            }
            wb.WriteFrameHeader((byte)ProtocolVersion, (byte)_headerFlags, streamId, OpCode);
            if (Payload != null)
            {
                //A custom payload for this request
                wb.WriteBytesMap(Payload);
            }
            wb.WriteByte((byte)_type);
            wb.WriteInt16((short)_requests.Count);
            foreach (var br in _requests)
            {
                br.WriteToBatch((byte)ProtocolVersion, wb);
            }
            wb.WriteInt16((short)Consistency);
            if (ProtocolVersion >= 3)
            {
                wb.WriteByte((byte)_batchFlags);
            }
            if (_serialConsistency != null)
            {
                wb.WriteInt16((short)_serialConsistency.Value);
            }
            if (_timestamp != null)
            {
                //Expressed in microseconds
                wb.WriteLong(TypeCodec.ToUnixTime(_timestamp.Value).Ticks / 10);
            }
            return(wb.Close());
        }