* Convert a string value to an SQL string literal and append it to * the given buffer. Encoding and string syntax rules are as indicated * by current settings of the PGconn. */
| 464 | * by current settings of the PGconn. |
| 465 | */ |
| 466 | void |
| 467 | appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn) |
| 468 | { |
| 469 | size_t length = strlen(str); |
| 470 | |
| 471 | /* |
| 472 | * XXX This is a kluge to silence escape_string_warning in our utility |
| 473 | * programs. It should go away someday. |
| 474 | */ |
| 475 | if (strchr(str, '\\') != NULL && PQserverVersion(conn) >= 80100) |
| 476 | { |
| 477 | /* ensure we are not adjacent to an identifier */ |
| 478 | if (buf->len > 0 && buf->data[buf->len - 1] != ' ') |
| 479 | appendPQExpBufferChar(buf, ' '); |
| 480 | appendPQExpBufferChar(buf, ESCAPE_STRING_SYNTAX); |
| 481 | appendStringLiteral(buf, str, PQclientEncoding(conn), false); |
| 482 | return; |
| 483 | } |
| 484 | /* XXX end kluge */ |
| 485 | |
| 486 | if (!enlargePQExpBuffer(buf, 2 * length + 2)) |
| 487 | return; |
| 488 | appendPQExpBufferChar(buf, '\''); |
| 489 | buf->len += PQescapeStringConn(conn, buf->data + buf->len, |
| 490 | str, length, NULL); |
| 491 | appendPQExpBufferChar(buf, '\''); |
| 492 | } |
| 493 | |
| 494 | |
| 495 | /* |
no test coverage detected