Reputation: 85975
When I execute a SQL command via libpq
, it reports error message if there's some error something like this.
Error Domain=PQConnection Code=1 "ERROR: syntax error at or near "fef"
LINE 1: fef
^
This is string message. I can parse the message - because it's very regular - to get line/column number, but that's unreliable. Is there any other API to get line/column numbers? Any regularized integer form would be nice.
Upvotes: 1
Views: 1217
Reputation: 85975
Use PQresultErrorField
function with key PG_DIAG_STATEMENT_POSITION
.
From manual
PG_DIAG_STATEMENT_POSITION A string containing a decimal integer indicating an error cursor position as an index into the original statement string. The first character has index 1, and positions are measured in characters not bytes.
Upvotes: 1