You have to do all the binds together, THEN step. This works for me.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sqlite3.h"
int main()
{
sqlite3 *db;
sqlite3_stmt *stmt;
int status;
char *create = "create table
ONTTable(slotId,ponChannelId,onuType,onuId,adminStatus);";
char *query = "insert into ONTTable
(slotId,ponChannelId,onuType,onuId,adminStatus) values (?1,?2,?3,?4,?5);";
status=sqlite3_open_v2("test.db",&db,SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE,NULL);
if (status != SQLITE_OK) {
printf("open error:%s\n",sqlite3_errmsg(db));
exit(1);
}
sqlite3_exec(db,create,NULL,NULL,NULL);
status=sqlite3_prepare_v2(db,query,strlen(query)+1, &stmt, NULL);
if (status != SQLITE_OK) {
printf("prepare error:%s\n",sqlite3_errmsg(db));
exit(1);
}
status=sqlite3_bind_int(stmt,1,1);
if (status != SQLITE_OK) {
printf("bind1 error:%s\n",sqlite3_errmsg(db));
exit(1);
}
status=sqlite3_bind_int(stmt,2,2);
if (status != SQLITE_OK) {
printf("bind2 error:%s\n",sqlite3_errmsg(db));
exit(1);
}
status=sqlite3_bind_int(stmt,3,3);
if (status != SQLITE_OK) {
printf("bind3 error:%s\n",sqlite3_errmsg(db));
exit(1);
}
status=sqlite3_bind_int(stmt,4,4);
if (status != SQLITE_OK) {
printf("bind4 error:%s\n",sqlite3_errmsg(db));
exit(1);
}
status=sqlite3_bind_int(stmt,5,5);
if (status != SQLITE_OK) {
printf("bind5 error:%s\n",sqlite3_errmsg(db));
exit(1);
}
status=sqlite3_step(stmt);
if (status != SQLITE_DONE) {
printf("step error:%s\n",sqlite3_errmsg(db));
exit(1);
}
return 0;
}
Michael D. Black
Senior Scientist
Advanced Analytics Directorate
Advanced GEOINT Solutions Operating Unit
Northrop Grumman Information Systems
________________________________
From: [email protected] [[email protected]] on
behalf of bhaskarReddy [[email protected]]
Sent: Monday, January 16, 2012 7:46 AM
To: [email protected]
Subject: EXT :[sqlite] sqlite3_bind. error as library routine called out of
sequence.
Hi Friends,
When i tried,
query = "insert into ONTTable
(slotId,ponChannelId,onuType,onuId,adminStatus) values (?1,?2,?3,?4,?5);";
then binding each parameter.....
//sqlite3_prepare_v2(db,query,strlen(query)+1, &stmt, NULL);
sqlite3_bind_int(stmt,1,ontTable -> slotId);
sqlite3_step(stmt,DONE);
//sqlite3_prepare_v2(db,query,strlen(query)+1, &stmt, NULL);
sqlite3_bind_int(stmt,1,ontTable -> ponChannelId);
sqlite3_step(stmt,DONE);
//sqlite_prepare_v2(db,query,strlen(query)+1, &stmt, NULL);
sqlite3_bind_int(stmt,1,ontTable -> ontType);
sqlite3_step(stmt,DONE);
//sqlite3_prepare_v2(db,query,strlen(query)+1, &stmt, NULL);
sqlite3_bind_int(stmt,1,ontTable -> onuId);
sqlite3_step(stmt,DONE);
//sqlite3_bind_prepare_v2(db,query,strlen(query)+1, &stmt, NULL);
sqlite3_bind_int(stmt,1,ontTable -> adminStatus);
I am getting the following error.
sqilte3_bind_int(stmt,1,ontTable -> ponChannelId) failed with status 21:
library routine called out of sequence.
Regards,
Bhaskar Reddy.
--
View this message in context:
http://old.nabble.com/sqlite3_bind.-error-as-library-routine-called-out-of-sequence.-tp33147572p33147572.html
Sent from the SQLite mailing list archive at Nabble.com.
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users