dnvThai
dnvThai

Reputation: 123

Creating class of SQLite

I'm sorry, I'm showing too many lines of code but I just have a small problem.

Take a look at the code file, you'll see two areas which I marked via comment [1] and [2] (Maybe you'll need [3]).

When I run the program, because this is a console program so the screen will have something like:

Befor callback: 0 
After callback: 0

It should be After callback: 99 that is what I need.

My question is Why doesn't iResult variable change after I modify it?

Update 1 The 1st agrument of callback function points to where (this) pointer (in [3])points to.

Thank you guys.

Upvotes: 0

Views: 78

Answers (2)

Dmitry Ledentsov
Dmitry Ledentsov

Reputation: 3660

It's just about everything not optimal about this code. If you're doing something simple, sonsider using an available wrapper, such as hiberlite. There are more low level ones as well.

Try to read about clean code first and about SOLID principles and then about patterns in enterprise software

This is also not what "modern" C++ is good for. Do you really want to do it in C++?

Then, you're doing something dangerous as well - you're assembling a query from a string by not using value binding.

Upvotes: 1

The Dark
The Dark

Reputation: 8514

When you call run_query to execute your query, it assigned the result of the sqlite3_exec call to iResult. This overwrites the 99 with the result of the query, which is 0.

Upvotes: 1

Related Questions