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