Debian Codegraph @

doc/html/pgtcl-pgescape-string.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.6.0">
6 <title>pg_escape_string</title>
7 <meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.79">
8 <link rev="MADE" href="mailto:[email protected]">
9 <link rel="HOME" title="PostgreSQL Tcl Interface Documentation" href="index.html">
10 <link rel="UP" title="pgtcl Command Reference" href="libpgtcl-ref.html">
11 <link rel="PREVIOUS" title="pg_quote" href="pgtcl-quote.html">
12 <link rel="NEXT" title="pg_escape_bytea" href="pgtcl-pgescape-bytea.html">
13 <link rel="STYLESHEET" type="text/css" href="stylesheet.css">
14 </head>
15 <body class="REFENTRY">
16 <div class="NAVHEADER">
17 <table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
18 <tr>
19 <th colspan="5" align="center" valign="bottom">PostgreSQL Tcl Interface Documentation</th>
20 </tr>
21 <tr>
22 <td width="10%" align="left" valign="top"><a href="pgtcl-quote.html" accesskey="P">Prev</a></td>
23 <td width="10%" align="left" valign="top"><a href="pgtcl-quote.html">Fast Backward</a></td>
24 <td width="60%" align="center" valign="bottom"></td>
25 <td width="10%" align="right" valign="top"><a href="pgtcl-pgescape-bytea.html">Fast Forward</a></td>
26 <td width="10%" align="right" valign="top"><a href="pgtcl-pgescape-bytea.html" accesskey="N">Next</a></td>
27 </tr>
28 </table>
29 <hr align="left" width="100%"></div>
30 <h1><a name="PGTCL-PGESCAPE-STRING" id="PGTCL-PGESCAPE-STRING"></a>pg_escape_string</h1>
31 <div class="REFNAMEDIV"><a name="AEN1806" id="AEN1806"></a>
32 <h2>Name</h2>
33 pg_escape_string&nbsp;--&nbsp;escapes a string for inclusion into SQL statements. This is the same as pg_quote. It was added for consistency. <a name="IX-PGTCL-PGESCAPE-STRING-2" id="IX-PGTCL-PGESCAPE-STRING-2"></a></div>
34 <div class="REFSYNOPSISDIV"><a name="AEN1811" id="AEN1811"></a>
35 <h2>Synopsis</h2>
36 <pre class="SYNOPSIS">pg_escape_string <code class="PARAMETER">string</code></pre></div>
37 <div class="REFSECT1"><a name="AEN1814" id="AEN1814"></a>
38 <h2>Description</h2>
39 <p><code class="FUNCTION">pg_escape_string</code> quotes a string and escapes single quotes and backslashes within the string, making it safe for inclusion into SQL statements.</p>
40 <p>If you're doing something like</p>
41 <pre class="PROGRAMLISTING"> pg_exec $conn "insert into foo values ('$name');" </pre>
42 <p>and <code class="VARNAME">name</code> contains text includeng an unescaped single quote, such as <tt class="LITERAL">Bob's House</tt>, at best the insert will fail, and at worst your software will be exploited via an SQL injection attack. Passing value strings through <code class="FUNCTION">pg_escape_string</code> will properly quote them for insertion into SQL commands.</p>
43 <pre class="PROGRAMLISTING"> pg_exec $conn "insert into foo values ([pg_escape_string $name]);" </pre>
44 <p>...will make sure that any special characters that occur in name, such as single quote or backslash, will be properly quoted.</p>
45 </div>
46 <div class="REFSECT1"><a name="AEN1824" id="AEN1824"></a>
47 <h2>Arguments</h2>
48 <div class="VARIABLELIST">
49 <dl>
50 <dt><code class="PARAMETER">string</code></dt>
51 <dd>
52 <p>The string to be escaped.</p>
53 </dd>
54 </dl>
55 </div>
56 </div>
57 <div class="REFSECT1"><a name="AEN1832" id="AEN1832"></a>
58 <h2>Return Value</h2>
59 <p>Returns the string, escaped for inclusion into SQL queries. Note that it adds a set of single quotes around the outside of the string as well.</p>
60 </div>
61 <div class="REFSECT1"><a name="AEN1835" id="AEN1835"></a>
62 <h2>See Also</h2>
63 <p>In most cases, with recent versions of SQL, it is better to use the native parameter insertion capabilities of the SQL server and protocol. If you are using a version of PostgreSQL more recent then 7.4, consider the optional parameter arguments to pg_exec and pg_sendquery, and the paramarray option to pg_exec, pg_sendquery, and pg_select.</p>
64 </div>
65 <div class="NAVFOOTER">
66 <hr align="left" width="100%">
67 <table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
68 <tr>
69 <td width="33%" align="left" valign="top"><a href="pgtcl-quote.html" accesskey="P">Prev</a></td>
70 <td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">Home</a></td>
71 <td width="33%" align="right" valign="top"><a href="pgtcl-pgescape-bytea.html" accesskey="N">Next</a></td>
72 </tr>
73 <tr>
74 <td width="33%" align="left" valign="top">pg_quote</td>
75 <td width="34%" align="center" valign="top"><a href="libpgtcl-ref.html" accesskey="U">Up</a></td>
76 <td width="33%" align="right" valign="top">pg_escape_bytea</td>
77 </tr>
78 </table>
79 </div>
80 </body>
81 </html>