|
1 | | -<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.212 2006/06/27 00:03:41 momjian Exp $ --> |
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.213 2006/07/04 13:22:15 momjian Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="libpq"> |
4 | 4 | <title><application>libpq</application> - C Library</title> |
@@ -2279,68 +2279,6 @@ in favor of <function>PQescapeStringConn</>. |
2279 | 2279 | </para> |
2280 | 2280 | </sect2> |
2281 | 2281 |
|
2282 | | -<sect2 id="libpq-exec-escape-identifier"> |
2283 | | - <title>Escaping Identifier for Inclusion in SQL Commands</title> |
2284 | | - |
2285 | | - <indexterm zone="libpq-exec-escape-identifier"><primary>PQescapeIdentifier</></> |
2286 | | - <indexterm zone="libpq-exec-escape-identifier"><primary>escaping strings</></> |
2287 | | - |
2288 | | -<para> |
2289 | | -<function>PQescapeIdentifier</function> escapes a string for use |
2290 | | -as an identifier name within an SQL command. For example; table names, |
2291 | | -column names, view names and user names are all identifiers. |
2292 | | -Double quotes (") must be escaped to prevent them from being interpreted |
2293 | | -specially by the SQL parser. <function>PQescapeIdentifier</> performs this |
2294 | | -operation. |
2295 | | -</para> |
2296 | | - |
2297 | | -<tip> |
2298 | | -<para> |
2299 | | -It is especially important to do proper escaping when handling strings that |
2300 | | -were received from an untrustworthy source. Otherwise there is a security |
2301 | | -risk: you are vulnerable to <quote>SQL injection</> attacks wherein unwanted |
2302 | | -SQL commands are fed to your database. |
2303 | | -</para> |
2304 | | -</tip> |
2305 | | - |
2306 | | -<para> |
2307 | | -Note that it is still necessary to do escaping of identifiers when |
2308 | | -using functions that support parameterized queries such as <function>PQexecParams</> or |
2309 | | -its sibling routines. Only literal values are automatically escaped |
2310 | | -using these functions, not identifiers. |
2311 | | - |
2312 | | -<synopsis> |
2313 | | -size_t PQescapeIdentifier (char *to, const char *from, size_t length); |
2314 | | -</synopsis> |
2315 | | -</para> |
2316 | | - |
2317 | | -<para> |
2318 | | -The parameter <parameter>from</> points to the first character of the |
2319 | | -string that is to be escaped, and the <parameter>length</> parameter |
2320 | | -gives the number of characters in this string. A terminating zero byte |
2321 | | -is not required, and should not be counted in <parameter>length</>. (If |
2322 | | -a terminating zero byte is found before <parameter>length</> bytes are |
2323 | | -processed, <function>PQescapeIdentifier</> stops at the zero; the |
2324 | | -behavior is thus rather like <function>strncpy</>.) <parameter>to</> |
2325 | | -shall point to a buffer that is able to hold at least one more character |
2326 | | -than twice the value of <parameter>length</>, otherwise the behavior is |
2327 | | -undefined. A call to <function>PQescapeIdentifier</> writes an escaped |
2328 | | -version of the <parameter>from</> string to the <parameter>to</> buffer, |
2329 | | -replacing special characters so that they cannot cause any harm, and |
2330 | | -adding a terminating zero byte. The double quotes that may surround |
2331 | | -<productname>PostgreSQL</> identifiers are not included in the result |
2332 | | -string; they should be provided in the SQL command that the result is |
2333 | | -inserted into. |
2334 | | -</para> |
2335 | | -<para> |
2336 | | -<function>PQescapeIdentifier</> returns the number of characters written |
2337 | | -to <parameter>to</>, not including the terminating zero byte. |
2338 | | -</para> |
2339 | | -<para> |
2340 | | -Behavior is undefined if the <parameter>to</> and <parameter>from</> |
2341 | | -strings overlap. |
2342 | | -</para> |
2343 | | -</sect2> |
2344 | 2282 |
|
2345 | 2283 | <sect2 id="libpq-exec-escape-bytea"> |
2346 | 2284 | <title>Escaping Binary Strings for Inclusion in SQL Commands</title> |
|