* pqSaveParameterStatus - remember parameter status sent by backend */
| 1014 | * pqSaveParameterStatus - remember parameter status sent by backend |
| 1015 | */ |
| 1016 | void |
| 1017 | pqSaveParameterStatus(PGconn *conn, const char *name, const char *value) |
| 1018 | { |
| 1019 | pgParameterStatus *pstatus; |
| 1020 | pgParameterStatus *prev; |
| 1021 | |
| 1022 | /* |
| 1023 | * Forget any old information about the parameter |
| 1024 | */ |
| 1025 | for (pstatus = conn->pstatus, prev = NULL; |
| 1026 | pstatus != NULL; |
| 1027 | prev = pstatus, pstatus = pstatus->next) |
| 1028 | { |
| 1029 | if (strcmp(pstatus->name, name) == 0) |
| 1030 | { |
| 1031 | if (prev) |
| 1032 | prev->next = pstatus->next; |
| 1033 | else |
| 1034 | conn->pstatus = pstatus->next; |
| 1035 | free(pstatus); /* frees name and value strings too */ |
| 1036 | break; |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | /* |
| 1041 | * Store new info as a single malloc block |
| 1042 | */ |
| 1043 | pstatus = (pgParameterStatus *) malloc(sizeof(pgParameterStatus) + |
| 1044 | strlen(name) + strlen(value) + 2); |
| 1045 | if (pstatus) |
| 1046 | { |
| 1047 | char *ptr; |
| 1048 | |
| 1049 | ptr = ((char *) pstatus) + sizeof(pgParameterStatus); |
| 1050 | pstatus->name = ptr; |
| 1051 | strcpy(ptr, name); |
| 1052 | ptr += strlen(name) + 1; |
| 1053 | pstatus->value = ptr; |
| 1054 | strcpy(ptr, value); |
| 1055 | pstatus->next = conn->pstatus; |
| 1056 | conn->pstatus = pstatus; |
| 1057 | } |
| 1058 | |
| 1059 | /* |
| 1060 | * Save values of settings that are of interest to libpq in fields of the |
| 1061 | * PGconn object. We keep client_encoding and standard_conforming_strings |
| 1062 | * in static variables as well, so that PQescapeString and PQescapeBytea |
| 1063 | * can behave somewhat sanely (at least in single-connection-using |
| 1064 | * programs). |
| 1065 | */ |
| 1066 | if (strcmp(name, "client_encoding") == 0) |
| 1067 | { |
| 1068 | conn->client_encoding = pg_char_to_encoding(value); |
| 1069 | /* if we don't recognize the encoding name, fall back to SQL_ASCII */ |
| 1070 | if (conn->client_encoding < 0) |
| 1071 | conn->client_encoding = PG_SQL_ASCII; |
| 1072 | static_client_encoding = conn->client_encoding; |
| 1073 | } |
no test coverage detected