diff --git a/async_postgres/pg_types.nim b/async_postgres/pg_types.nim index ea454e7..8c02674 100644 --- a/async_postgres/pg_types.nim +++ b/async_postgres/pg_types.nim @@ -1912,12 +1912,10 @@ converter toRow*(cells: seq[Option[seq[byte]]]): Row = proc parseAffectedRows*(tag: string): int64 = ## Extract row count from command tag (e.g. "UPDATE 3" -> 3, "INSERT 0 1" -> 1). let parts = tag.split(' ') - if parts.len > 0: - try: - return parseBiggestInt(parts[^1]) - except ValueError: - return 0 - return 0 + try: + parseBiggestInt(parts[^1]) + except ValueError, OverflowDefect: + 0 proc initCommandResult*(tag: string): CommandResult {.inline.} = CommandResult(commandTag: tag) diff --git a/tests/test_types.nim b/tests/test_types.nim index 0d32526..8a8ce05 100644 --- a/tests/test_types.nim +++ b/tests/test_types.nim @@ -989,6 +989,27 @@ suite "parseAffectedRows": test "non-numeric tag": check parseAffectedRows("CREATE TABLE") == 0 + test "COPY tag": + check parseAffectedRows("COPY 100") == 100 + + test "MERGE tag": + check parseAffectedRows("MERGE 7") == 7 + + test "MOVE tag": + check parseAffectedRows("MOVE 12") == 12 + + test "FETCH tag": + check parseAffectedRows("FETCH 4") == 4 + + test "trailing whitespace falls back to 0": + check parseAffectedRows("UPDATE 3 ") == 0 + + test "overflow falls back to 0": + check parseAffectedRows("UPDATE 99999999999999999999999999") == 0 + + test "single-token DDL tag": + check parseAffectedRows("BEGIN") == 0 + suite "Option accessors": test "getStrOpt some": let row: Row = @[some(toBytes("hello"))]