1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
3
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
4
<title>Evaluate An SQL Statement</title>
5
<style type="text/css">
8
font-family: Verdana, sans-serif;
13
a:visited { color: #734559 }
15
.logo { position:absolute; margin:3px; }
31
.toolbar a { color: white; text-decoration: none; padding: 6px 12px; }
32
.toolbar a:visited { color: white; }
33
.toolbar a:hover { color: #044a64; background: white; }
35
.content { margin: 5%; }
36
.content dt { font-weight:bold; }
37
.content dd { margin-bottom: 25px; margin-left:20%; }
38
.content ul { padding:0px; padding-left: 15px; margin:0px; }
41
.se { background: url(../images/se.gif) 100% 100% no-repeat #044a64}
42
.sw { background: url(../images/sw.gif) 0% 100% no-repeat }
43
.ne { background: url(../images/ne.gif) 100% 0% no-repeat }
44
.nw { background: url(../images/nw.gif) 0% 0% no-repeat }
46
/* Things for "fancyformat" documents start here. */
47
.fancy img+p {font-style:italic}
48
.fancy .codeblock i { color: darkblue; }
49
.fancy h1,.fancy h2,.fancy h3,.fancy h4 {font-weight:normal;color:#044a64}
50
.fancy h2 { margin-left: 10px }
51
.fancy h3 { margin-left: 20px }
52
.fancy h4 { margin-left: 30px }
53
.fancy th {white-space:nowrap;text-align:left;border-bottom:solid 1px #444}
54
.fancy th, .fancy td {padding: 0.2em 1ex; vertical-align:top}
55
.fancy #toc a { color: darkblue ; text-decoration: none }
56
.fancy .todo { color: #AA3333 ; font-style : italic }
57
.fancy .todo:before { content: 'TODO:' }
58
.fancy p.todo { border: solid #AA3333 1px; padding: 1ex }
59
.fancy img { display:block; }
60
.fancy :link:hover, .fancy :visited:hover { background: wheat }
61
.fancy p,.fancy ul,.fancy ol { margin: 1em 5ex }
62
.fancy li p { margin: 1em 0 }
63
/* End of "fancyformat" specific rules. */
69
<div><!-- container div to satisfy validator -->
71
<a href="../index.html">
72
<img class="logo" src="../images/sqlite370_banner.gif" alt="SQLite Logo"
74
<div><!-- IE hack to prevent disappearing logo--></div>
75
<div class="tagline">Small. Fast. Reliable.<br>Choose any three.</div>
77
<table width=100% style="clear:both"><tr><td>
78
<div class="se"><div class="sw"><div class="ne"><div class="nw">
79
<table width=100% style="padding:0;margin:0;cell-spacing:0"><tr>
82
<a href="../about.html">About</a>
83
<a href="../sitemap.html">Sitemap</a>
84
<a href="../docs.html">Documentation</a>
85
<a href="../download.html">Download</a>
86
<a href="../copyright.html">License</a>
87
<a href="../news.html">News</a>
88
<a href="../support.html">Support</a>
91
gMsg = "Search SQLite Docs..."
92
function entersearch() {
93
var q = document.getElementById("q");
94
if( q.value == gMsg ) { q.value = "" }
95
q.style.color = "black"
96
q.style.fontStyle = "normal"
98
function leavesearch() {
99
var q = document.getElementById("q");
100
if( q.value == "" ) {
102
q.style.color = "#044a64"
103
q.style.fontStyle = "italic"
108
<div style="padding:0 1em 0px 0;white-space:nowrap">
109
<form name=f method="GET" action="http://www.sqlite.org/search">
110
<input id=q name=q type=text
111
onfocus="entersearch()" onblur="leavesearch()" style="width:24ex;padding:1px 1ex; border:solid white 1px; font-size:0.9em ; font-style:italic;color:#044a64;" value="Search SQLite Docs...">
112
<input type=submit value="Go" style="border:solid white 1px;background-color:#044a64;color:white;font-size:0.9em;padding:0 1ex">
116
</div></div></div></div>
118
<div class=startsearch></div>
120
<a href="intro.html"><h2>SQLite C Interface</h2></a><h2>Evaluate An SQL Statement</h2><blockquote><pre>int sqlite3_step(sqlite3_stmt*);
121
</pre></blockquote><p>
122
After a <a href="../c3ref/stmt.html">prepared statement</a> has been prepared using either
123
<a href="../c3ref/prepare.html">sqlite3_prepare_v2()</a> or <a href="../c3ref/prepare.html">sqlite3_prepare16_v2()</a> or one of the legacy
124
interfaces <a href="../c3ref/prepare.html">sqlite3_prepare()</a> or <a href="../c3ref/prepare.html">sqlite3_prepare16()</a>, this function
125
must be called one or more times to evaluate the statement.</p>
127
<p>The details of the behavior of the sqlite3_step() interface depend
128
on whether the statement was prepared using the newer "v2" interface
129
<a href="../c3ref/prepare.html">sqlite3_prepare_v2()</a> and <a href="../c3ref/prepare.html">sqlite3_prepare16_v2()</a> or the older legacy
130
interface <a href="../c3ref/prepare.html">sqlite3_prepare()</a> and <a href="../c3ref/prepare.html">sqlite3_prepare16()</a>. The use of the
131
new "v2" interface is recommended for new applications but the legacy
132
interface will continue to be supported.</p>
134
<p>In the legacy interface, the return value will be either <a href="../c3ref/c_abort.html">SQLITE_BUSY</a>,
135
<a href="../c3ref/c_abort.html">SQLITE_DONE</a>, <a href="../c3ref/c_abort.html">SQLITE_ROW</a>, <a href="../c3ref/c_abort.html">SQLITE_ERROR</a>, or <a href="../c3ref/c_abort.html">SQLITE_MISUSE</a>.
136
With the "v2" interface, any of the other <a href="../c3ref/c_abort.html">result codes</a> or
137
<a href="../c3ref/c_abort_rollback.html">extended result codes</a> might be returned as well.</p>
139
<p><a href="../c3ref/c_abort.html">SQLITE_BUSY</a> means that the database engine was unable to acquire the
140
database locks it needs to do its job. If the statement is a <a href="../lang_transaction.html">COMMIT</a>
141
or occurs outside of an explicit transaction, then you can retry the
142
statement. If the statement is not a <a href="../lang_transaction.html">COMMIT</a> and occurs within an
143
explicit transaction then you should rollback the transaction before
146
<p><a href="../c3ref/c_abort.html">SQLITE_DONE</a> means that the statement has finished executing
147
successfully. sqlite3_step() should not be called again on this virtual
148
machine without first calling <a href="../c3ref/reset.html">sqlite3_reset()</a> to reset the virtual
149
machine back to its initial state.</p>
151
<p>If the SQL statement being executed returns any data, then <a href="../c3ref/c_abort.html">SQLITE_ROW</a>
152
is returned each time a new row of data is ready for processing by the
153
caller. The values may be accessed using the <a href="../c3ref/column_blob.html">column access functions</a>.
154
sqlite3_step() is called again to retrieve the next row of data.</p>
156
<p><a href="../c3ref/c_abort.html">SQLITE_ERROR</a> means that a run-time error (such as a constraint
157
violation) has occurred. sqlite3_step() should not be called again on
158
the VM. More information may be found by calling <a href="../c3ref/errcode.html">sqlite3_errmsg()</a>.
159
With the legacy interface, a more specific error code (for example,
160
<a href="../c3ref/c_abort.html">SQLITE_INTERRUPT</a>, <a href="../c3ref/c_abort.html">SQLITE_SCHEMA</a>, <a href="../c3ref/c_abort.html">SQLITE_CORRUPT</a>, and so forth)
161
can be obtained by calling <a href="../c3ref/reset.html">sqlite3_reset()</a> on the
162
<a href="../c3ref/stmt.html">prepared statement</a>. In the "v2" interface,
163
the more specific error code is returned directly by sqlite3_step().</p>
165
<p><a href="../c3ref/c_abort.html">SQLITE_MISUSE</a> means that the this routine was called inappropriately.
166
Perhaps it was called on a <a href="../c3ref/stmt.html">prepared statement</a> that has
167
already been <a href="../c3ref/finalize.html">finalized</a> or on one that had
168
previously returned <a href="../c3ref/c_abort.html">SQLITE_ERROR</a> or <a href="../c3ref/c_abort.html">SQLITE_DONE</a>. Or it could
169
be the case that the same database connection is being used by two or
170
more threads at the same moment in time.</p>
172
<p>For all versions of SQLite up to and including 3.6.23.1, a call to
173
<a href="../c3ref/reset.html">sqlite3_reset()</a> was required after sqlite3_step() returned anything
174
other than <a href="../c3ref/c_abort.html">SQLITE_ROW</a> before any subsequent invocation of
175
sqlite3_step(). Failure to reset the prepared statement using
176
<a href="../c3ref/reset.html">sqlite3_reset()</a> would result in an <a href="../c3ref/c_abort.html">SQLITE_MISUSE</a> return from
177
sqlite3_step(). But after version 3.6.23.1, sqlite3_step() began
178
calling <a href="../c3ref/reset.html">sqlite3_reset()</a> automatically in this circumstance rather
179
than returning <a href="../c3ref/c_abort.html">SQLITE_MISUSE</a>. This is not considered a compatibility
180
break because any application that ever receives an SQLITE_MISUSE error
181
is broken by definition. The <a href="../compile.html#omit_autoreset">SQLITE_OMIT_AUTORESET</a> compile-time option
182
can be used to restore the legacy behavior.</p>
184
<p><b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
185
API always returns a generic error code, <a href="../c3ref/c_abort.html">SQLITE_ERROR</a>, following any
186
error other than <a href="../c3ref/c_abort.html">SQLITE_BUSY</a> and <a href="../c3ref/c_abort.html">SQLITE_MISUSE</a>. You must call
187
<a href="../c3ref/reset.html">sqlite3_reset()</a> or <a href="../c3ref/finalize.html">sqlite3_finalize()</a> in order to find one of the
188
specific <a href="../c3ref/c_abort.html">error codes</a> that better describes the error.
189
We admit that this is a goofy design. The problem has been fixed
190
with the "v2" interface. If you prepare all of your SQL statements
191
using either <a href="../c3ref/prepare.html">sqlite3_prepare_v2()</a> or <a href="../c3ref/prepare.html">sqlite3_prepare16_v2()</a> instead
192
of the legacy <a href="../c3ref/prepare.html">sqlite3_prepare()</a> and <a href="../c3ref/prepare.html">sqlite3_prepare16()</a> interfaces,
193
then the more specific <a href="../c3ref/c_abort.html">error codes</a> are returned directly
194
by sqlite3_step(). The use of the "v2" interface is recommended.
195
</p><p>See also lists of
196
<a href="objlist.html">Objects</a>,
197
<a href="constlist.html">Constants</a>, and
198
<a href="funclist.html">Functions</a>.</p>