1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>PreparedStatement</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="libzdb.css">
</head><body>
<a href="" class="back" onclick="history.back();return false;">⬅</a>
<!-- Generated by Doxygen 1.11.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="namespacezdb.html">zdb</a></li><li class="navelem"><a class="el" href="classzdb_1_1PreparedStatement.html">PreparedStatement</a></li> </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
<div class="headertitle"><div class="title">PreparedStatement</div></div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Represents a pre-compiled SQL statement for later execution. </p>
<p>A <a class="el" href="classzdb_1_1PreparedStatement.html" title="Represents a pre-compiled SQL statement for later execution.">PreparedStatement</a> is created by calling <a class="el" href="classzdb_1_1Connection.html#af33971b5c1e0860dd86015bb9d9b01a9" title="Prepares a SQL statement for execution.">Connection::prepareStatement()</a>. The SQL statement may contain <em>in</em> parameters of the form "?". Such parameters represent unspecified literal values (or "wildcards") to be filled in later by the bind methods defined in this class. Each <em>in</em> parameter has an associated index number which is its sequence in the statement. The first <em>in</em> '?' parameter has index 1, the next has index 2 and so on.</p>
<p>Consider this statement: </p><div class="fragment"><div class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> employee(name, photo) <span class="keyword">VALUES</span>(?, ?)</div>
</div><!-- fragment --><p> There are two <em>in</em> parameters in this statement, the parameter for setting the name has index 1 and the one for the photo has index 2. To set the values for the <em>in</em> parameters we use <a class="el" href="#a8863f76c0f07aa5991fea801d4aef440" title="Binds multiple values to the Prepared Statement at once.">bindValues()</a> with two values, one for each <em>in</em> parameter. Or we can use <a class="el" href="#a079badc62e9efe3a37cd9f0b54fe30f9" title="Binds a value to the prepared statement.">bind()</a> to set the parameter values one by one.</p>
<h2><a class="anchor" id="autotoc_md44"></a>
Examples</h2>
<p>The following examples demonstrate how to create and use a <a class="el" href="classzdb_1_1PreparedStatement.html" title="Represents a pre-compiled SQL statement for later execution.">PreparedStatement</a>.</p>
<h3><a class="anchor" id="autotoc_md45"></a>
Example: Binding all values at once</h3>
<p>This example shows how to prepare a statement, bind multiple values at once, and execute it:</p>
<div class="fragment"><div class="line"><a class="code hl_class" href="classzdb_1_1Connection.html">Connection</a> con = pool.getConnection();</div>
<div class="line"><a class="code hl_class" href="classzdb_1_1PreparedStatement.html">PreparedStatement</a> stmt = con.<a class="code hl_function" href="classzdb_1_1Connection.html#af33971b5c1e0860dd86015bb9d9b01a9">prepareStatement</a>(<span class="stringliteral">"INSERT INTO employee(name, photo) VALUES(?, ?)"</span>);</div>
<div class="line">stmt.<a class="code hl_function" href="#a8863f76c0f07aa5991fea801d4aef440">bindValues</a>(<span class="stringliteral">"Kamiya Kaoru"</span>, jpeg);</div>
<div class="line">stmt.<a class="code hl_function" href="#a61af3e60b94ae3e748f6fbac1e794af7">execute</a>();</div>
<div class="ttc" id="aclasszdb_1_1Connection_html"><div class="ttname"><a href="classzdb_1_1Connection.html">zdb::Connection</a></div><div class="ttdoc">Represents a connection to a SQL database system.</div><div class="ttdef"><b>Definition</b> zdbpp.h:1331</div></div>
<div class="ttc" id="aclasszdb_1_1Connection_html_af33971b5c1e0860dd86015bb9d9b01a9"><div class="ttname"><a href="classzdb_1_1Connection.html#af33971b5c1e0860dd86015bb9d9b01a9">zdb::Connection::prepareStatement</a></div><div class="ttdeci">PreparedStatement prepareStatement(const std::string &sql)</div><div class="ttdoc">Prepares a SQL statement for execution.</div><div class="ttdef"><b>Definition</b> zdbpp.h:1617</div></div>
<div class="ttc" id="aclasszdb_1_1PreparedStatement_html"><div class="ttname"><a href="classzdb_1_1PreparedStatement.html">zdb::PreparedStatement</a></div><div class="ttdoc">Represents a pre-compiled SQL statement for later execution.</div><div class="ttdef"><b>Definition</b> zdbpp.h:1079</div></div>
<div class="ttc" id="aclasszdb_1_1PreparedStatement_html_a61af3e60b94ae3e748f6fbac1e794af7"><div class="ttname"><a href="#a61af3e60b94ae3e748f6fbac1e794af7">zdb::PreparedStatement::execute</a></div><div class="ttdeci">void execute()</div><div class="ttdoc">Executes the prepared SQL statement.</div><div class="ttdef"><b>Definition</b> zdbpp.h:1174</div></div>
<div class="ttc" id="aclasszdb_1_1PreparedStatement_html_a8863f76c0f07aa5991fea801d4aef440"><div class="ttname"><a href="#a8863f76c0f07aa5991fea801d4aef440">zdb::PreparedStatement::bindValues</a></div><div class="ttdeci">void bindValues(Args &&... args)</div><div class="ttdoc">Binds multiple values to the Prepared Statement at once.</div><div class="ttdef"><b>Definition</b> zdbpp.h:1159</div></div>
</div><!-- fragment --><h3><a class="anchor" id="autotoc_md46"></a>
Example: Binding values individually</h3>
<p>Instead of binding all values at once, we can also bind values one by one by specifying the parameter index we want to set a value for:</p>
<div class="fragment"><div class="line"><a class="code hl_class" href="classzdb_1_1PreparedStatement.html">PreparedStatement</a> stmt = con.<a class="code hl_function" href="classzdb_1_1Connection.html#af33971b5c1e0860dd86015bb9d9b01a9">prepareStatement</a>(<span class="stringliteral">"INSERT INTO employee(name, photo) VALUES(?, ?)"</span>);</div>
<div class="line">stmt.<a class="code hl_function" href="#a079badc62e9efe3a37cd9f0b54fe30f9">bind</a>(1, <span class="stringliteral">"Kamiya Kaoru"</span>);</div>
<div class="line">stmt.<a class="code hl_function" href="#a079badc62e9efe3a37cd9f0b54fe30f9">bind</a>(2, jpeg);</div>
<div class="line">stmt.<a class="code hl_function" href="#a61af3e60b94ae3e748f6fbac1e794af7">execute</a>();</div>
<div class="ttc" id="aclasszdb_1_1PreparedStatement_html_a079badc62e9efe3a37cd9f0b54fe30f9"><div class="ttname"><a href="#a079badc62e9efe3a37cd9f0b54fe30f9">zdb::PreparedStatement::bind</a></div><div class="ttdeci">void bind(int parameterIndex, T &&x)</div><div class="ttdoc">Binds a value to the prepared statement.</div><div class="ttdef"><b>Definition</b> zdbpp.h:1120</div></div>
</div><!-- fragment --><h2><a class="anchor" id="autotoc_md47"></a>
Reuse</h2>
<p>A <a class="el" href="classzdb_1_1PreparedStatement.html" title="Represents a pre-compiled SQL statement for later execution.">PreparedStatement</a> can be reused. That is, the method <a class="el" href="#a61af3e60b94ae3e748f6fbac1e794af7" title="Executes the prepared SQL statement.">execute()</a> can be called one or more times to execute the same statement. Clients can also set new <em>in</em> parameter values and re-execute the statement as shown in this example, where we also show use of a transaction and exception handling:</p>
<div class="fragment"><div class="line"><a class="code hl_class" href="classzdb_1_1PreparedStatement.html">PreparedStatement</a> stmt = con.<a class="code hl_function" href="classzdb_1_1Connection.html#af33971b5c1e0860dd86015bb9d9b01a9">prepareStatement</a>(<span class="stringliteral">"INSERT INTO employee(name, photo) VALUES(?, ?)"</span>);</div>
<div class="line"><span class="keywordflow">try</span> {</div>
<div class="line"> con.<a class="code hl_function" href="classzdb_1_1Connection.html#af5edd522c28907ba30c4cb98d742d3ff">beginTransaction</a>();</div>
<div class="line"> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span>& emp : employees) {</div>
<div class="line"> stmt.<a class="code hl_function" href="#a079badc62e9efe3a37cd9f0b54fe30f9">bind</a>(1, emp.name);</div>
<div class="line"> <span class="keywordflow">if</span> (emp.photo) {</div>
<div class="line"> stmt.<a class="code hl_function" href="#a079badc62e9efe3a37cd9f0b54fe30f9">bind</a>(2, *emp.photo);</div>
<div class="line"> } <span class="keywordflow">else</span> {</div>
<div class="line"> stmt.<a class="code hl_function" href="#a079badc62e9efe3a37cd9f0b54fe30f9">bind</a>(2, <span class="keyword">nullptr</span>); <span class="comment">// Set to SQL NULL if no photo</span></div>
<div class="line"> }</div>
<div class="line"> stmt.<a class="code hl_function" href="#a61af3e60b94ae3e748f6fbac1e794af7">execute</a>();</div>
<div class="line"> }</div>
<div class="line"> con.<a class="code hl_function" href="classzdb_1_1Connection.html#ad55316f5135cdae6aa6c5a763f6c3473">commit</a>();</div>
<div class="line">} <span class="keywordflow">catch</span> (<span class="keyword">const</span> sql_exception& e) {</div>
<div class="line"> con.<a class="code hl_function" href="classzdb_1_1Connection.html#a071de472f6ac976c658e4643f3fb3d0c">rollback</a>();</div>
<div class="line"> std::cerr << <span class="stringliteral">"Database error: "</span> << e.what() << std::endl;</div>
<div class="line">}</div>
<div class="ttc" id="aclasszdb_1_1Connection_html_a071de472f6ac976c658e4643f3fb3d0c"><div class="ttname"><a href="classzdb_1_1Connection.html#a071de472f6ac976c658e4643f3fb3d0c">zdb::Connection::rollback</a></div><div class="ttdeci">void rollback()</div><div class="ttdoc">Rolls back the current transaction.</div><div class="ttdef"><b>Definition</b> zdbpp.h:1478</div></div>
<div class="ttc" id="aclasszdb_1_1Connection_html_ad55316f5135cdae6aa6c5a763f6c3473"><div class="ttname"><a href="classzdb_1_1Connection.html#ad55316f5135cdae6aa6c5a763f6c3473">zdb::Connection::commit</a></div><div class="ttdeci">void commit()</div><div class="ttdoc">Commits the current transaction.</div><div class="ttdef"><b>Definition</b> zdbpp.h:1468</div></div>
<div class="ttc" id="aclasszdb_1_1Connection_html_af5edd522c28907ba30c4cb98d742d3ff"><div class="ttname"><a href="classzdb_1_1Connection.html#af5edd522c28907ba30c4cb98d742d3ff">zdb::Connection::beginTransaction</a></div><div class="ttdeci">void beginTransaction(TRANSACTION_TYPE type=TRANSACTION_DEFAULT)</div><div class="ttdoc">Begins a new transaction with optional isolation level.</div><div class="ttdef"><b>Definition</b> zdbpp.h:1452</div></div>
</div><!-- fragment --><h2><a class="anchor" id="autotoc_md48"></a>
Date and Time</h2>
<p><a class="el" href="#a8863f76c0f07aa5991fea801d4aef440" title="Binds multiple values to the Prepared Statement at once.">bindValues()</a> or <a class="el" href="#a079badc62e9efe3a37cd9f0b54fe30f9" title="Binds a value to the prepared statement.">bind()</a> can be used to set a Unix timestamp value as a <code>time_t</code> type. To set Date, Time or DateTime values, simply use one of the bind methods to set a time string in a format understood by your database. For instance to set a SQL Date value, </p><div class="fragment"><div class="line">stmt.<a class="code hl_function" href="#a079badc62e9efe3a37cd9f0b54fe30f9">bind</a>(parameterIndex, <span class="stringliteral">"2024-12-28"</span>);</div>
<div class="line"><span class="comment">// or using bindValues</span></div>
<div class="line">stmt.<a class="code hl_function" href="#a8863f76c0f07aa5991fea801d4aef440">bindValues</a>(<span class="stringliteral">"2019-12-28"</span>, ...);</div>
</div><!-- fragment --><h2><a class="anchor" id="autotoc_md49"></a>
Result Sets</h2>
<p>See <a class="el" href="classzdb_1_1Connection.html#af68e46ae0740c0b7db284465656a6b45" title="Executes a SQL query and returns a ResultSet.">Connection::executeQuery()</a></p>
<h2><a class="anchor" id="autotoc_md50"></a>
SQL Injection Prevention</h2>
<p>Prepared Statement is particularly useful when dealing with user-submitted data, as properly used Prepared Statements provide strong protection against SQL injection attacks. By separating SQL logic from data, PreparedStatements ensure that user input is treated as data only, not as part of the SQL command.</p>
<p><em>A <a class="el" href="classzdb_1_1PreparedStatement.html" title="Represents a pre-compiled SQL statement for later execution.">PreparedStatement</a> is reentrant, but not thread-safe and should only be used by one thread (at a time).</em></p>
<dl class="section note"><dt>Note</dt><dd>Remember that parameter indices in <a class="el" href="classzdb_1_1PreparedStatement.html" title="Represents a pre-compiled SQL statement for later execution.">PreparedStatement</a> are 1-based, not 0-based.</dd>
<dd>
To minimizes memory allocation and avoid unnecessary data copying, string and blob values are set by reference and <em>MUST</em> remain valid until <a class="el" href="#a61af3e60b94ae3e748f6fbac1e794af7" title="Executes the prepared SQL statement.">PreparedStatement::execute()</a> has been called.</dd></dl>
<dl class="section warning"><dt>Warning</dt><dd><a class="el" href="classzdb_1_1PreparedStatement.html" title="Represents a pre-compiled SQL statement for later execution.">PreparedStatement</a> objects are internally managed by the <a class="el" href="classzdb_1_1Connection.html" title="Represents a connection to a SQL database system.">Connection</a> that created them and are not copyable or movable. Always ensure that the originating <a class="el" href="classzdb_1_1Connection.html" title="Represents a connection to a SQL database system.">Connection</a> object remains valid for the entire duration of the <a class="el" href="classzdb_1_1PreparedStatement.html" title="Represents a pre-compiled SQL statement for later execution.">PreparedStatement</a>'s use. Basically, keep the <a class="el" href="classzdb_1_1Connection.html" title="Represents a connection to a SQL database system.">Connection</a> and <a class="el" href="classzdb_1_1PreparedStatement.html" title="Represents a pre-compiled SQL statement for later execution.">PreparedStatement</a> objects in the same scope. Do not attempt to use <a class="el" href="classzdb_1_1PreparedStatement.html" title="Represents a pre-compiled SQL statement for later execution.">PreparedStatement</a> objects (including through references or pointers) after their <a class="el" href="classzdb_1_1Connection.html" title="Represents a connection to a SQL database system.">Connection</a> has been closed and returned to the pool. </dd></dl>
</div>
<p>Represents a pre-compiled SQL statement for later execution.
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td colspan="2"><div class="groupHeader">Parameters</div></td></tr>
<tr class="memitem:a079badc62e9efe3a37cd9f0b54fe30f9" id="r_a079badc62e9efe3a37cd9f0b54fe30f9"><td class="memTemplParams" colspan="2">template<typename <a class="el" href="Connection_8h.html#a8dc1b239f8e305fbd1406ff041c89151">T</a> > </td></tr>
<tr class="memitem:a079badc62e9efe3a37cd9f0b54fe30f9"><td class="memTemplItemLeft" align="right" valign="top">void </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="#a079badc62e9efe3a37cd9f0b54fe30f9">bind</a> (int parameterIndex, <a class="el" href="Connection_8h.html#a8dc1b239f8e305fbd1406ff041c89151">T</a> &&x)</td></tr>
<tr class="memdesc:a079badc62e9efe3a37cd9f0b54fe30f9"><td class="mdescLeft"> </td><td class="mdescRight">Binds a value to the prepared statement. <br /></td></tr>
<tr class="separator:a079badc62e9efe3a37cd9f0b54fe30f9"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a8863f76c0f07aa5991fea801d4aef440" id="r_a8863f76c0f07aa5991fea801d4aef440"><td class="memTemplParams" colspan="2">template<typename... Args> </td></tr>
<tr class="memitem:a8863f76c0f07aa5991fea801d4aef440"><td class="memTemplItemLeft" align="right" valign="top">void </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="#a8863f76c0f07aa5991fea801d4aef440">bindValues</a> (Args &&... args)</td></tr>
<tr class="memdesc:a8863f76c0f07aa5991fea801d4aef440"><td class="mdescLeft"> </td><td class="mdescRight">Binds multiple values to the Prepared Statement at once. <br /></td></tr>
<tr class="separator:a8863f76c0f07aa5991fea801d4aef440"><td class="memSeparator" colspan="2"> </td></tr>
<tr><td colspan="2"><div class="groupHeader">Functions</div></td></tr>
<tr class="memitem:a61af3e60b94ae3e748f6fbac1e794af7" id="r_a61af3e60b94ae3e748f6fbac1e794af7"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="#a61af3e60b94ae3e748f6fbac1e794af7">execute</a> ()</td></tr>
<tr class="memdesc:a61af3e60b94ae3e748f6fbac1e794af7"><td class="mdescLeft"> </td><td class="mdescRight">Executes the prepared SQL statement. <br /></td></tr>
<tr class="separator:a61af3e60b94ae3e748f6fbac1e794af7"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a2f72484a003968e3ef14662256e118bd" id="r_a2f72484a003968e3ef14662256e118bd"><td class="memItemLeft" align="right" valign="top">long long </td><td class="memItemRight" valign="bottom"><a class="el" href="#a2f72484a003968e3ef14662256e118bd">rowsChanged</a> () noexcept</td></tr>
<tr class="memdesc:a2f72484a003968e3ef14662256e118bd"><td class="mdescLeft"> </td><td class="mdescRight">Gets the number of rows affected by the most recent SQL statement. <br /></td></tr>
<tr class="separator:a2f72484a003968e3ef14662256e118bd"><td class="memSeparator" colspan="2"> </td></tr>
<tr><td colspan="2"><div class="groupHeader">Properties</div></td></tr>
<tr class="memitem:a5e3a06bf066df01c2da19b5fc76f030f" id="r_a5e3a06bf066df01c2da19b5fc76f030f"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="#a5e3a06bf066df01c2da19b5fc76f030f">getParameterCount</a> () noexcept</td></tr>
<tr class="memdesc:a5e3a06bf066df01c2da19b5fc76f030f"><td class="mdescLeft"> </td><td class="mdescRight">Gets the number of parameters in the prepared statement. <br /></td></tr>
<tr class="separator:a5e3a06bf066df01c2da19b5fc76f030f"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a079badc62e9efe3a37cd9f0b54fe30f9" name="a079badc62e9efe3a37cd9f0b54fe30f9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a079badc62e9efe3a37cd9f0b54fe30f9">◆ </a></span>bind()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<typename <a class="el" href="Connection_8h.html#a8dc1b239f8e305fbd1406ff041c89151">T</a> > </div>
<table class="memname">
<tr>
<td class="memname">void bind </td>
<td>(</td>
<td class="paramtype">int</td> <td class="paramname"><span class="paramname"><em>parameterIndex</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="Connection_8h.html#a8dc1b239f8e305fbd1406ff041c89151">T</a> &&</td> <td class="paramname"><span class="paramname"><em>x</em></span> )</td>
</tr>
</table>
</div><div class="memdoc">
<p>Binds a value to the prepared statement. </p>
<p>This method can bind different types of values:</p><ul>
<li>String-like types (convertible to std::string_view)</li>
<li>Numeric types (integral or floating-point, excluding time_t)</li>
<li>Blob-like types (contiguous ranges of bytes)</li>
<li>time_t for timestamp values</li>
<li>nullptr_t for SQL NULL values</li>
</ul>
<dl class="tparams"><dt>Template Parameters</dt><dd>
<table class="tparams">
<tr><td class="paramname">T</td><td>The type of the value to bind </td></tr>
</table>
</dd>
</dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">parameterIndex</td><td>The index of the parameter to bind (1-based) </td></tr>
<tr><td class="paramname">x</td><td>The value to bind </td></tr>
</table>
</dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
<table class="exception">
<tr><td class="paramname"><a class="el" href="classzdb_1_1sql__exception.html" title="Exception class for SQL related errors.">sql_exception</a></td><td>If a database access error occurs or parameterIndex is invalid </td></tr>
</table>
</dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>For string-like and blob-like types, the data must remain valid until <a class="el" href="#a61af3e60b94ae3e748f6fbac1e794af7" title="Executes the prepared SQL statement.">execute()</a> is called. This method does not copy the data but stores a reference to it. </dd>
<dd>
This method will fail to compile for unsupported types, providing a clear error message. </dd></dl>
</div>
</div>
<a id="a8863f76c0f07aa5991fea801d4aef440" name="a8863f76c0f07aa5991fea801d4aef440"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8863f76c0f07aa5991fea801d4aef440">◆ </a></span>bindValues()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<typename... Args> </div>
<table class="memname">
<tr>
<td class="memname">void bindValues </td>
<td>(</td>
<td class="paramtype">Args &&...</td> <td class="paramname"><span class="paramname"><em>args</em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Binds multiple values to the Prepared Statement at once. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">args</td><td>Values to bind to the Prepared Statement. </td></tr>
</table>
</dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
<table class="exception">
<tr><td class="paramname"><a class="el" href="classzdb_1_1sql__exception.html" title="Exception class for SQL related errors.">sql_exception</a></td><td>If a database error occurs or if argument count is incorrect </td></tr>
</table>
</dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>Reference types must remain valid until <a class="el" href="#a61af3e60b94ae3e748f6fbac1e794af7" title="Executes the prepared SQL statement.">execute()</a> is called. This method does not copy any data. </dd></dl>
</div>
</div>
<a id="a61af3e60b94ae3e748f6fbac1e794af7" name="a61af3e60b94ae3e748f6fbac1e794af7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a61af3e60b94ae3e748f6fbac1e794af7">◆ </a></span>execute()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void execute </td>
<td>(</td>
<td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Executes the prepared SQL statement. </p>
<dl class="exception"><dt>Exceptions</dt><dd>
<table class="exception">
<tr><td class="paramname"><a class="el" href="classzdb_1_1sql__exception.html" title="Exception class for SQL related errors.">sql_exception</a></td><td>If a database access error occurs </td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a id="a2f72484a003968e3ef14662256e118bd" name="a2f72484a003968e3ef14662256e118bd"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2f72484a003968e3ef14662256e118bd">◆ </a></span>rowsChanged()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">long long rowsChanged </td>
<td>(</td>
<td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">nodiscard</span><span class="mlabel">noexcept</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Gets the number of rows affected by the most recent SQL statement. </p>
<p>If used with a transaction, this method should be called <em>before</em> commit is executed, otherwise 0 is returned.</p>
<dl class="section return"><dt>Returns</dt><dd>The number of rows changed. </dd></dl>
</div>
</div>
<a id="a5e3a06bf066df01c2da19b5fc76f030f" name="a5e3a06bf066df01c2da19b5fc76f030f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a5e3a06bf066df01c2da19b5fc76f030f">◆ </a></span>getParameterCount()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">int getParameterCount </td>
<td>(</td>
<td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">nodiscard</span><span class="mlabel">noexcept</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Gets the number of parameters in the prepared statement. </p>
<dl class="section return"><dt>Returns</dt><dd>The number of <em>in</em> parameters in this prepared statement </dd></dl>
</div>
</div>
</div><!-- contents -->
<p style="text-align:center;color:#808080;font-size:90%;margin:40px 0 20px 0;">
Copyright © <a href="https://tildeslash.com/">Tildeslash Ltd</a>. All
rights reserved.</p>
</body></html>
|