You're example should work if you only prepare the statement once.

So assuming mystmt is set to NULL on your object creation.


if (mystmt == NULL) {
  rc = sqlite_prepare_v2.....
}

Then reset it to NULL again when you set apstr="finished".  After 
sqlite3_finalize(mystmt).  That way you're next query will reprepare the 
statement again.

}else{
  if (rc == SQLITE_DONE) {
    apstr = "finished";
    this->finalize();
    mystmt = NULL; // is this being done in your finalize??? It could be put in 
there instead of here.
  }
  else {
    apstr = "error: " + sqlite3_errmsg(db);
    this->finalize();
    mystmt = NULL;
  }
}


Michael D. Black
Senior Scientist
Advanced Analytics Directorate
Advanced GEOINT Solutions Operating Unit
Northrop Grumman Information Systems

________________________________________
From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on 
behalf of Arbol One [arbol...@gmail.com]
Sent: Friday, September 07, 2012 4:07 AM
To: 'General Discussion of SQLite Database'
Subject: EXT :Re: [sqlite] C++ - WHERE clause - 2nd update

Yes, thank?
I gave you the answer you gave me, obviously I was right.
I need you to prove me right again, how about, haaa.... yes! if 2x2 is 4,
what is 2x2? Come on! I know you can get it, just try going slowly this
time.

-----Original Message-----
From: sqlite-users-boun...@sqlite.org
[mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Marcus Grimm
Sent: Friday, September 07, 2012 3:39 AM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] C++ - WHERE clause - 2nd update


On 07.09.2012 08:58, Arbol One wrote:
> I got this code to work, however, I am getting a segmentation fault on
> this code.
>
> I pass to SQLite only one statement [db->setStmt(apstr);], I read the
> first of the 'fname', but I don't know how to get to the second
> 'fname' in the database.
> I am not very sure as to what do to tell the program to read the next
> row until there are no more [ read_str until SQLITE_DONE ] rows to read.

well.. you already answered your question:
You step thru the result list until you reach SQLITE_DONE.

In your example you re prepare the statement all the time and thus you will
always get the first hit in your data.
The sequence should be:

sqlite3_prepare_v2

while( sqlite3_step(mystmt) == SQLITE_ROW ) {
/** read the data .. **/
}

sqlite3_finalize
...


> Help?
>
>      Glib::ustring apstr;
>      Glib::ustring sName;
>      int apint;
>      mySQLite3* db;
>      try {
>          db = new mySQLite3(db_name.c_str());
>      } catch(somexception&  e) {
>          //do something
>      }
>
>      // SQL statement
>      Glib::ustring sName;
>      apstr = "SELECT fname FROM ";
>      apstr += this->db_table_name;
>      apstr += " WHERE title = \'";
>      apstr += token;
>      apstr += "\' ";
>
>      apint = 0;
>      db->setStmt(apstr);
>      do{
>          try {
>              sName = db->read_str(apint);
>          } catch(jme::Exception&  e ) {
>              e.Display();
>          }
>          apex.setException(sName, FILE, METHOD, LINE);
>          apex.Display();
>      }while(sName != "finished");
>
>
> --------------------------------------------
> const Glib::ustring&  mySQLite3::read_str(const int pos)
> throw(somexception) {
>
>      rc = sqlite3_prepare_v2(db, this->SQLStatement.c_str(),
> -1,&mystmt, NULL);
>      if(rc != SQLITE_OK) {
>          // do something
>      }
>      rc = sqlite3_step(mystmt);
>      if(rc == SQLITE_ROW ) {
>          apstr = (const char*)sqlite3_column_text(mystmt,pos);
>      }else{
>          apstr = "finished"; // a small modification
>      }
>      try {
>          this->finalize();
>      } catch(somexception&  e) {
>          throw e;
>      }
>      return apstr;
> }
>
> What am I doing wrong?
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to