public async Task SimpleQueryMultipleRows() { var endpoint = IPEndPoint.Parse(EndPoint); using var db = await PgDB.OpenAsync(endpoint, UserName, Password, Database); var rows = 42; await db.ExecuteSimpleAsync($"SELECT * FROM generate_series(1, {rows})"); await db.EnsureSinglePacketAsync(); var response = db.ReadPacket(); PgDB.ValidateResponseMessage(response, BackendMessageCode.RowDescription); for (var i = 1; i <= rows; i++) { var iStr = i.ToString(); await db.EnsureSinglePacketAsync(); response = db.ReadPacket(); PgDB.ValidateResponseMessage(response, BackendMessageCode.DataRow); var columnCount = BinaryPrimitives.ReadInt16BigEndian(response.Slice(5, 2).Span); Assert.AreEqual(1, columnCount); var columnLength = BinaryPrimitives.ReadInt32BigEndian(response.Slice(7, 4).Span); Assert.AreEqual(iStr.Length, columnLength); var columnValueString = PgDB.ParseSimpleQueryDataRowColumn(response.Slice(11)); Assert.AreEqual(iStr, columnValueString); } await db.EnsureSinglePacketAsync(); response = db.ReadPacket(); PgDB.ValidateResponseMessage(response, BackendMessageCode.CommandComplete); await db.EnsureSinglePacketAsync(); response = db.ReadPacket(); PgDB.ValidateResponseMessage(response, BackendMessageCode.ReadyForQuery); }
public async Task SimpleQuerySingleRow() { var endpoint = IPEndPoint.Parse(EndPoint); using var db = await PgDB.OpenAsync(endpoint, UserName, Password, Database); await db.ExecuteSimpleAsync("SELECT 1"); await db.EnsureSinglePacketAsync(); var response = db.ReadPacket(); PgDB.ValidateResponseMessage(response, BackendMessageCode.RowDescription); await db.EnsureSinglePacketAsync(); response = db.ReadPacket(); PgDB.ValidateResponseMessage(response, BackendMessageCode.DataRow); var columnCount = BinaryPrimitives.ReadInt16BigEndian(response.Slice(5, 2).Span); Assert.AreEqual(1, columnCount); var columnLength = BinaryPrimitives.ReadInt32BigEndian(response.Slice(7, 4).Span); Assert.AreEqual(1, columnLength); var columnValueChar = (char)response.Span[11]; Assert.AreEqual('1', columnValueChar); var columnValueString = PgDB.ParseSimpleQueryDataRowColumn(response.Slice(11)); Assert.AreEqual("1", columnValueString); await db.EnsureSinglePacketAsync(); response = db.ReadPacket(); PgDB.ValidateResponseMessage(response, BackendMessageCode.CommandComplete); await db.EnsureSinglePacketAsync(); response = db.ReadPacket(); PgDB.ValidateResponseMessage(response, BackendMessageCode.ReadyForQuery); }