|
1 | 1 | <!--
|
2 |
| -$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.68 2001/09/04 00:18:18 petere Exp $ |
| 2 | +$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.69 2001/09/07 22:02:32 momjian Exp $ |
3 | 3 | -->
|
4 | 4 |
|
5 | 5 | <chapter id="libpq">
|
@@ -827,6 +827,42 @@ as with a PGresult returned by libpq itself.
|
827 | 827 | </itemizedlist>
|
828 | 828 | </sect2>
|
829 | 829 |
|
| 830 | +<sect2 id="libpq-exec-escape-string"> |
| 831 | + <title>Escaping strings for inclusion in SQL queries</title> |
| 832 | +<para> |
| 833 | +<function>PQescapeString</function> |
| 834 | + Escapes a string for use within an SQL query. |
| 835 | +<synopsis> |
| 836 | +size_t PQescapeString (char *to, const char *from, size_t length); |
| 837 | +</synopsis> |
| 838 | +If you want to include strings which have been received |
| 839 | +from a source which is not trustworthy (for example, because they were |
| 840 | +transmitted across a network), you cannot directly include them in SQL |
| 841 | +queries for security reasons. Instead, you have to quote special |
| 842 | +characters which are otherwise interpreted by the SQL parser. |
| 843 | +</para> |
| 844 | +<para> |
| 845 | +<function>PQescapeString</> performs this operation. The |
| 846 | +<parameter>from</> points to the first character of the string which |
| 847 | +is to be escaped, and the <parameter>length</> parameter counts the |
| 848 | +number of characters in this string (a terminating NUL character is |
| 849 | +neither necessary nor counted). <parameter>to</> shall point to a |
| 850 | +buffer which is able to hold at least one more character than twice |
| 851 | +the value of <parameter>length</>, otherwise the behavior is |
| 852 | +undefined. A call to <function>PQescapeString</> writes an escaped |
| 853 | +version of the <parameter>from</> string to the <parameter>to</> |
| 854 | +buffer, replacing special characters so that they cannot cause any |
| 855 | +harm, and adding a terminating NUL character. The single quotes which |
| 856 | +must surround PostgreSQL string literals are not part of the result |
| 857 | +string. |
| 858 | +</para> |
| 859 | +<para> |
| 860 | +<function>PQescapeString</> returns the number of characters written |
| 861 | +to <parameter>to</>, not including the terminating NUL character. |
| 862 | +Behavior is undefined when the <parameter>to</> and <parameter>from</> |
| 863 | +strings overlap. |
| 864 | +</para> |
| 865 | + |
830 | 866 | <sect2 id="libpq-exec-select-info">
|
831 | 867 | <title>Retrieving SELECT Result Information</title>
|
832 | 868 |
|
|
0 commit comments