* PQcmdTuples - * If the last command was INSERT/UPDATE/DELETE/MOVE/FETCH/COPY, return * a string containing the number of inserted/affected tuples. If not, * return "". * * XXX: this should probably return an int */
| 3625 | * XXX: this should probably return an int |
| 3626 | */ |
| 3627 | char * |
| 3628 | PQcmdTuples(PGresult *res) |
| 3629 | { |
| 3630 | char *p, |
| 3631 | *c; |
| 3632 | |
| 3633 | if (!res) |
| 3634 | return ""; |
| 3635 | |
| 3636 | if (strncmp(res->cmdStatus, "INSERT ", 7) == 0) |
| 3637 | { |
| 3638 | p = res->cmdStatus + 7; |
| 3639 | /* INSERT: skip oid and space */ |
| 3640 | while (*p && *p != ' ') |
| 3641 | p++; |
| 3642 | if (*p == 0) |
| 3643 | goto interpret_error; /* no space? */ |
| 3644 | p++; |
| 3645 | } |
| 3646 | else if (strncmp(res->cmdStatus, "SELECT ", 7) == 0 || |
| 3647 | strncmp(res->cmdStatus, "DELETE ", 7) == 0 || |
| 3648 | strncmp(res->cmdStatus, "UPDATE ", 7) == 0) |
| 3649 | p = res->cmdStatus + 7; |
| 3650 | else if (strncmp(res->cmdStatus, "FETCH ", 6) == 0) |
| 3651 | p = res->cmdStatus + 6; |
| 3652 | else if (strncmp(res->cmdStatus, "MOVE ", 5) == 0 || |
| 3653 | strncmp(res->cmdStatus, "COPY ", 5) == 0) |
| 3654 | p = res->cmdStatus + 5; |
| 3655 | else |
| 3656 | return ""; |
| 3657 | |
| 3658 | /* check that we have an integer (at least one digit, nothing else) */ |
| 3659 | for (c = p; *c; c++) |
| 3660 | { |
| 3661 | if (!isdigit((unsigned char) *c)) |
| 3662 | goto interpret_error; |
| 3663 | } |
| 3664 | if (c == p) |
| 3665 | goto interpret_error; |
| 3666 | |
| 3667 | return p; |
| 3668 | |
| 3669 | interpret_error: |
| 3670 | pqInternalNotice(&res->noticeHooks, |
| 3671 | "could not interpret result from server: %s", |
| 3672 | res->cmdStatus); |
| 3673 | return ""; |
| 3674 | } |
| 3675 | |
| 3676 | /* |
| 3677 | * PQgetvalue: |
no test coverage detected