Got problem with prepare statement in sqlite
-
wrote on 15 Nov 2017, 19:29 last edited by mark_ua_1999
this is my code the prepare statement return false but why
do you have any ideas how to resolve the problem (I notice that my code dont execute step by step the Add function is executed last although is first(db functions is eqecuted firstly) why ) -
wrote on 15 Nov 2017, 19:50 last edited by
93. if( r_3.prepare("INSERT INTO "+dataB+" (depart_city,arrival_city,firstname,lastname,bot,vagon,place,privileges,distance,ticket_price)" 94. "VALUES (?,?,?,?,?,?,?,?,?,?)"))// return false
Where do you bind the values for the
INSERT
? -
Hi,
You should check that all your
prepare
andexec
call are successful and if its not the case, print the error. That's the only way we might be able to help you.You should also consider re-writing your string building code. It's hard to read and easily error prone. Take advantage of QString's arg methods to help build your query strings.
On a side note, why are you re-creating the same database connection again and again ?
-
93. if( r_3.prepare("INSERT INTO "+dataB+" (depart_city,arrival_city,firstname,lastname,bot,vagon,place,privileges,distance,ticket_price)" 94. "VALUES (?,?,?,?,?,?,?,?,?,?)"))// return false
Where do you bind the values for the
INSERT
?wrote on 15 Nov 2017, 20:03 last edited by@JNBarchan It must return true but return false
-
Did you print the error ?
-
wrote on 15 Nov 2017, 20:37 last edited by
@SGaist I rearrange my code an it began to work but I have got another problem my working code the code is to slow from user vision (firstly it inserts new records to db table and only than add the row (Add function although) it goes first and returns bool result)
what is your ideas about it
-
You are trying to open your database twice.
Again, like already wrote before: open your connection once at application startup and then just do your queries. You'll avoid losing time with that.
As for performance, what else is your application doing ?
-
You are trying to open your database twice.
Again, like already wrote before: open your connection once at application startup and then just do your queries. You'll avoid losing time with that.
As for performance, what else is your application doing ?
wrote on 15 Nov 2017, 20:47 last edited by@SGaist I understand you but I failed to do it it doesnt see the db as opened (I opened it in constructor)
-
Then fix your database initialisation in the constructor rather than trying to work around.
-
Then fix your database initialisation in the constructor rather than trying to work around.
wrote on 15 Nov 2017, 20:53 last edited by@SGaist And what about not line by line code execution?
-
What do you mean by that ?
-
wrote on 15 Nov 2017, 20:59 last edited by
-
There's no way to evaluate why your application is slow based only on one function.
Do some profiling on your application to understand what takes so much time.
-
There's no way to evaluate why your application is slow based only on one function.
Do some profiling on your application to understand what takes so much time.
wrote on 15 Nov 2017, 21:08 last edited by@SGaist ADD function must execute first!!! But not
-
Full uppercased words and many exclamation marks are not the best way to communicate when people are trying to help you on their own time.
You are only providing a small part of your code and stating that your users find it slow. I already gave you some suggestions to make it a bit faster but you said that you couldn't make it work in some other unknown part of your code.
Now, how can you expect anybody to provide you with advices based on that ?
-
Full uppercased words and many exclamation marks are not the best way to communicate when people are trying to help you on their own time.
You are only providing a small part of your code and stating that your users find it slow. I already gave you some suggestions to make it a bit faster but you said that you couldn't make it work in some other unknown part of your code.
Now, how can you expect anybody to provide you with advices based on that ?
wrote on 15 Nov 2017, 21:26 last edited by mark_ua_1999@SGaist yes you are right sorry
1/16