* pqSetResultError - * assign a new error message to a PGresult */
| 686 | * assign a new error message to a PGresult |
| 687 | */ |
| 688 | void |
| 689 | pqSetResultError(PGresult *res, PQExpBuffer errorMessage) |
| 690 | { |
| 691 | char *msg; |
| 692 | |
| 693 | if (!res) |
| 694 | return; |
| 695 | |
| 696 | /* |
| 697 | * We handle two OOM scenarios here. The errorMessage buffer might be |
| 698 | * marked "broken" due to having previously failed to allocate enough |
| 699 | * memory for the message, or it might be fine but pqResultStrdup fails |
| 700 | * and returns NULL. In either case, just make res->errMsg point directly |
| 701 | * at a constant "out of memory" string. |
| 702 | */ |
| 703 | if (!PQExpBufferBroken(errorMessage)) |
| 704 | msg = pqResultStrdup(res, errorMessage->data); |
| 705 | else |
| 706 | msg = NULL; |
| 707 | if (msg) |
| 708 | res->errMsg = msg; |
| 709 | else |
| 710 | res->errMsg = libpq_gettext("out of memory\n"); |
| 711 | } |
| 712 | |
| 713 | /* |
| 714 | * PQclear - |
no test coverage detected