Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions async_postgres/pg_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
Loading