diff --git a/integration_tests/client.zig b/integration_tests/client.zig index 05ba0c2..e070192 100644 --- a/integration_tests/client.zig +++ b/integration_tests/client.zig @@ -246,7 +246,7 @@ test "prepare execute with result" { { const query = - \\SELECT 42,null,'hello' + \\SELECT 1,3,5,7 ; const prep_res = try c.prepare(allocator, query); defer prep_res.deinit(allocator); @@ -256,7 +256,6 @@ test "prepare execute with result" { const rows = (try expectRows(query_res.value)).iter(); while (try rows.next(allocator)) |row| { defer row.deinit(allocator); - // std.debug.print("rows.next: {any}\n", .{row}); } } } diff --git a/src/conn.zig b/src/conn.zig index 9c71fe5..250d088 100644 --- a/src/conn.zig +++ b/src/conn.zig @@ -59,14 +59,11 @@ pub const Conn = struct { constants.OK => .{ .ok = OkPacket.initFromPacket(&response_packet, conn.client_capabilities) }, constants.ERR => .{ .err = ErrorPacket.initFromPacket(false, &response_packet, conn.client_capabilities) }, constants.LOCAL_INFILE_REQUEST => _ = @panic("not implemented"), - else => .{ - .rows = blk: { - var packet_reader = PacketReader.initFromPacket(&response_packet); - const column_count = packet_reader.readLengthEncodedInteger(); - var result_set = try ResultSet(TextResultRow).init(allocator, conn, column_count); - break :blk result_set; - }, - }, + else => .{ .rows = blk: { + var packet_reader = PacketReader.initFromPacket(&response_packet); + const column_count = packet_reader.readLengthEncodedInteger(); + break :blk try ResultSet(TextResultRow).init(allocator, conn, column_count); + } }, }, }; } @@ -95,22 +92,17 @@ pub const Conn = struct { const execute_request: ExecuteRequest = .{ .prep_ok = &prep_ok, .capabilities = conn.client_capabilities }; try conn.sendPacketUsingSmallPacketWriter(execute_request); - if (prep_ok.num_columns > 0) { - return .{ - .packet = .{ .payload_length = 0, .sequence_id = 0, .payload = &.{} }, // create phantom packet to make the result type happy - .value = .{ - .rows = try ResultSet(BinaryResultRow).init(allocator, conn, prep_ok.num_columns), - }, - }; - } - const response_packet = try conn.readPacket(allocator); return .{ .packet = response_packet, .value = switch (response_packet.payload[0]) { constants.OK => .{ .ok = OkPacket.initFromPacket(&response_packet, conn.client_capabilities) }, constants.ERR => .{ .err = ErrorPacket.initFromPacket(false, &response_packet, conn.client_capabilities) }, - else => return response_packet.asError(conn.client_capabilities), + else => .{ .rows = blk: { + var packet_reader = PacketReader.initFromPacket(&response_packet); + const column_count = packet_reader.readLengthEncodedInteger(); + break :blk try ResultSet(BinaryResultRow).init(allocator, conn, column_count); + } }, }, }; } diff --git a/src/result.zig b/src/result.zig index bf88e21..1f5ad85 100644 --- a/src/result.zig +++ b/src/result.zig @@ -45,10 +45,8 @@ pub fn ResultSet(comptime ResultRowType: type) type { t.column_definitions = try allocator.alloc(ColumnDefinition41, column_count); errdefer allocator.free(t.column_definitions); for (0..column_count) |i| { - const packet = try conn.readPacket(allocator); - errdefer packet.deinit(allocator); - t.column_packets[i] = packet; - t.column_definitions[i] = ColumnDefinition41.initFromPacket(&packet); + t.column_packets[i] = try conn.readPacket(allocator); + t.column_definitions[i] = ColumnDefinition41.initFromPacket(&t.column_packets[i]); } const eof_packet = try conn.readPacket(allocator);