Debian Codegraph @

doc/html/pgtcl-quote.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_quote</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_null_value_string" href="pgtcl-nullvaluestring.html">
12 <link rel="NEXT" title="pg_escape_string" href="pgtcl-pgescape-string.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-nullvaluestring.html" accesskey="P">Prev</a></td>
23 <td width="10%" align="left" valign="top"><a href="pgtcl-nullvaluestring.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-string.html">Fast Forward</a></td>
26 <td width="10%" align="right" valign="top"><a href="pgtcl-pgescape-string.html" accesskey="N">Next</a></td>
27 </tr>
28 </table>
29 <hr align="left" width="100%"></div>
30 <h1><a name="PGTCL-QUOTE" id="PGTCL-QUOTE"></a>pg_quote</h1>
31 <div class="REFNAMEDIV"><a name="AEN1763" id="AEN1763"></a>
32 <h2>Name</h2>
33 pg_quote&nbsp;--&nbsp;escapes a string for inclusion into SQL statements <a name="IX-PGTCL-QUOTE-2" id="IX-PGTCL-QUOTE-2"></a></div>
34 <div class="REFSYNOPSISDIV"><a name="AEN1768" id="AEN1768"></a>
35 <h2>Synopsis</h2>
36 <pre class="SYNOPSIS">pg_quote [<span class="OPTIONAL">-null</span>] [<span class="OPTIONAL"><code class="PARAMETER">connection</code></span>] <code class="PARAMETER">string</code></pre></div>
37 <div class="REFSECT1"><a name="AEN1774" id="AEN1774"></a>
38 <h2>Description</h2>
39 <p><code class="FUNCTION">pg_quote</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 a <code class="PARAMETER">connection</code> is provided, the connection is used to customize the quoting process for the database referenced by the connection.</p>
41 <p>If the [<span class="OPTIONAL">-null</span>] option is provided, then if the text matches the null string (either the empty string, or the null string specified in the <code class="PARAMETER">connection</code>) then the SQL keyword NULL is returned, rather than a quoted string.</p>
42 <p>If you're doing something like</p>
43 <pre class="PROGRAMLISTING"> pg_exec $conn "insert into foo values ('$name');" </pre>
44 <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_quote</code> will properly quote them for insertion into SQL commands.</p>
45 <pre class="PROGRAMLISTING"> pg_exec $conn "insert into foo values ([pg_quote $name]);" </pre>
46 <p>...will make sure that any special characters that occur in name, such as single quote or backslash, will be properly quoted.</p>
47 </div>
48 <div class="REFSECT1"><a name="AEN1789" id="AEN1789"></a>
49 <h2>Arguments</h2>
50 <div class="VARIABLELIST">
51 <dl>
52 <dt><code class="PARAMETER">string</code></dt>
53 <dd>
54 <p>The string to be escaped.</p>
55 </dd>
56 </dl>
57 </div>
58 </div>
59 <div class="REFSECT1"><a name="AEN1797" id="AEN1797"></a>
60 <h2>Return Value</h2>
61 <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>
62 </div>
63 <div class="REFSECT1"><a name="AEN1800" id="AEN1800"></a>
64 <h2>See Also</h2>
65 <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>
66 </div>
67 <div class="NAVFOOTER">
68 <hr align="left" width="100%">
69 <table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
70 <tr>
71 <td width="33%" align="left" valign="top"><a href="pgtcl-nullvaluestring.html" accesskey="P">Prev</a></td>
72 <td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">Home</a></td>
73 <td width="33%" align="right" valign="top"><a href="pgtcl-pgescape-string.html" accesskey="N">Next</a></td>
74 </tr>
75 <tr>
76 <td width="33%" align="left" valign="top">pg_null_value_string</td>
77 <td width="34%" align="center" valign="top"><a href="libpgtcl-ref.html" accesskey="U">Up</a></td>
78 <td width="33%" align="right" valign="top">pg_escape_string</td>
79 </tr>
80 </table>
81 </div>
82 </body>
83 </html>