Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not able to execute multiple queries at a time #62

Open
gopikrishnaParisa opened this issue Sep 23, 2019 · 4 comments
Open

not able to execute multiple queries at a time #62

gopikrishnaParisa opened this issue Sep 23, 2019 · 4 comments

Comments

@gopikrishnaParisa
Copy link

hi,
i was trying to execute INSERT and DELETE in a single command, but i couldn't do it using Sqlite3pp.
sample code:

query = "INSERT INTO Logs (logData) VALUES(?);"
"DELETE FROM Logs WHERE sequenceId=(SELECT MIN(sequenceId) FROM Logs)";
sqlite3pp::command cmd(clinicalDb_, query.c_str());
cmd.bind(1, (void *)&info, sizeof(info), sqlite3pp::copy);

     if ((rc = cmd.execute_all()) != NO_SQL_ERROR)
     {
        PX_ERRORF("Command Execution failed. rc = {}", rc);
     }

in this case i am getting rc value 1(SQLITE_ERROR).

if i pass some string to VALUES("some string), query executes successfully.

Please help me how to solve this.

@iwongu
Copy link
Owner

iwongu commented Sep 23, 2019

I don't remember exactly, but the bound params are applied to each statement. The second statement, DELETE, does not need a param.
Why don't you run them in separate commands?

@gopikrishnaParisa
Copy link
Author

gopikrishnaParisa commented Sep 23, 2019 via email

@iwongu
Copy link
Owner

iwongu commented Sep 23, 2019

Can you bake the value in the sql string instead of using bind? The current execute_all method is using the same bind params for each statement in the sql string.

@snej
Copy link

snej commented Nov 17, 2021

@gopikrishnaParisa You should use a SQLite transaction around the entire set of changes you're making. That will make your code much, much faster. If you don't do this, SQLite inserts a transaction around every statement.

Committing a transaction is fairly slow since it has to ensure durability by flushing all writes to the physical storage device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants