#include "sqlite3.h"
#include <stdio.h>
void main(int argc, char** argv)
{
sqlite3* db = 0;
sqlite3_stmt* stmt = 0;
char* rest = 0;
int rc = 0;
int value = 0;
sqlite3_open(":memory:", &db);
rc = sqlite3_prepare_v2(db, "select value from generate_series where
start=1 and stop=10;", -1, &stmt, (void*)&rest);
if (rc != SQLITE_OK)
{
printf("Error %d during prepare\n", rc);
return;
}
printf("\nLoop 1, no reset, reset at 5\n");
for (;;)
{
rc = sqlite3_step(stmt);
if (rc == SQLITE_DONE | value == 5)
{
printf("!\n");
rc = sqlite3_reset(stmt);
printf("sqlite3_reset returns %d\n", rc);
break;
}
if (rc == SQLITE_ROW)
{
value = sqlite3_column_int(stmt, 0);
printf("%d ", value);
continue;
}
printf("Error during stepping %d\n", rc);
rc = sqlite3_reset(stmt);
printf("sqlite3_reset returns %d\n", rc);
break;
}
printf("\nLoop 2, After Reset\n");
for (;;)
{
rc = sqlite3_step(stmt);
if (rc == SQLITE_DONE)
{
printf("!\n");
// rc = sqlite3_reset(stmt);
// printf("sqlite3_reset returns %d\n", rc);
break;
}
if (rc == SQLITE_ROW)
{
value = sqlite3_column_int(stmt, 0);
printf("%d ", value);
continue;
}
printf("Error during stepping %d\n", rc);
rc = sqlite3_reset(stmt);
printf("sqlite3_reset returns %d\n", rc);
break;
}
printf("\nLoop 3, No Reset, Got SQLITE_DONE\n");
for (;;)
{
rc = sqlite3_step(stmt);
if (rc == SQLITE_DONE)
{
printf("!\n");
rc = sqlite3_reset(stmt);
printf("sqlite3_reset returns %d\n", rc);
break;
}
if (rc == SQLITE_ROW)
{
value = sqlite3_column_int(stmt, 0);
printf("%d ", value);
continue;
}
printf("Error during stepping %d\n", rc);
rc = sqlite3_reset(stmt);
printf("sqlite3_reset returns %d\n", rc);
break;
}
}
2018-06-04 11:32:12 MinGW [D:\work]
>test
Loop 1, no reset, reset at 5
1 2 3 4 5 !
sqlite3_reset returns 0
Loop 2, After Reset
1 2 3 4 5 6 7 8 9 10 !
Loop 3, No Reset, Got SQLITE_DONE
1 2 3 4 5 6 7 8 9 10 !
sqlite3_reset returns 0
---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a
lot about anticipated traffic volume.
>-----Original Message-----
>From: sqlite-users [mailto:sqlite-users-
>[email protected]] On Behalf Of Keith Medcalf
>Sent: Monday, 4 June, 2018 11:25
>To: SQLite mailing list
>Subject: Re: [sqlite] Reset the cursor
>
>
>Note also that you do not need to do an sqlite3_reset after
>sqlite3_step returns SQLITE_DONE as reset is called automatically the
>next time you call sqlite3_step. You only need to call sqlite3_reset
>if you want to reset the statement before all the rows have been
>retrieved (this is documented somewhere, and I believe there is a
>compile time #define to turn off the auto-reset). Yes, it is
>documented in the sqlite3_step documentation
>
>"For all versions of SQLite up to and including 3.6.23.1, a call to
>sqlite3_reset() was required after sqlite3_step() returned anything
>other than SQLITE_ROW before any subsequent invocation of
>sqlite3_step(). Failure to reset the prepared statement using
>sqlite3_reset() would result in an SQLITE_MISUSE return from
>sqlite3_step(). But after version 3.6.23.1 (2010-03-26,
>sqlite3_step() began calling sqlite3_reset() automatically in this
>circumstance rather than returning SQLITE_MISUSE. This is not
>considered a compatibility break because any application that ever
>receives an SQLITE_MISUSE error is broken by definition. The
>SQLITE_OMIT_AUTORESET compile-time option can be used to restore the
>legacy behavior."
>
>Neither the automatic nor the manual sqlite3_reset reset any bindings
>-- if you want to do this I believe you must call the
>sqlite3_clear_bindings()
>
>---
>The fact that there's a Highway to Hell but only a Stairway to Heaven
>says a lot about anticipated traffic volume.
>
>
>>-----Original Message-----
>>From: sqlite-users [mailto:sqlite-users-
>>[email protected]] On Behalf Of Keith Medcalf
>>Sent: Monday, 4 June, 2018 11:06
>>To: SQLite mailing list
>>Subject: Re: [sqlite] Reset the cursor
>>
>>
>>>Currently running w/MSVC 2010 under Win 8.1.
>>
>>>I also presume you are testing under the latest SQLite source?
>>
>>Yes, I believe so ...
>>SQLite 3.24.0 2018-06-02 19:14:58
>>1ecb3aa13de5c8dc611b814ff34010de0bd90aae73d88aa37a59c4627be4alt2
>>
>>Using GCC (MinGW-w64 8.1.0) on Windows 10 Pro for Workstations
>>version 1803 build 17134.81 (current)
>>
>>MSVC (the one I have, I think VS 2008) also works fine ... though
>the
>>.dll is still compiled with GCC MinGW-w64 8.1.0 (with -O3 and then
>>some).
>>
>>Microsoft (R) 32-bit C/C++ Optimizing Compiler Version
>15.00.21022.08
>>for 80x86
>>Copyright (C) Microsoft Corporation. All rights reserved.
>>
>>test.c
>>Microsoft (R) Incremental Linker Version 9.00.21022.08
>>Copyright (C) Microsoft Corporation. All rights reserved.
>>
>>/out:test.exe
>>test.obj
>>sqlite3.lib
>>
>>
>>2018-06-04 10:59:24 MinGW [D:\work]
>>>test.exe
>>
>>Loop 1, no reset
>>1 2 3 4 5 6 7 8 9 10 !
>>sqlite3_reset returns 0
>>
>>Loop 2, after reset
>>1 2 3 4 5 6 7 8 9 10 !
>>sqlite3_reset returns 0
>>
>>---
>>The fact that there's a Highway to Hell but only a Stairway to
>Heaven
>>says a lot about anticipated traffic volume.
>>
>>
>>
>>
>>_______________________________________________
>>sqlite-users mailing list
>>[email protected]
>>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
>
>
>_______________________________________________
>sqlite-users mailing list
>[email protected]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users