You're not doing the right sequencing...so your cout is only executing when
there is NOT a row.
Change
rc = sqlite3_step(stmt);
if(rc != SQLITE_DONE) { ... }
while ( sqlite3_step(stmt) != SQLITE_ROW) {
sName = (char*)sqlite3_column_text(stmt, 0); //<== Seg fault
std::cout << sName << std::endl;
...
}
To
while ( sqlite3_step(stmt) == SQLITE_ROW) {
sName = (char*)sqlite3_column_text(stmt, 0); //<== Seg fault
std::cout << sName << std::endl;
...
}
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 Arbol One [[email protected]]
Sent: Monday, June 25, 2012 8:27 AM
To: 'General Discussion of SQLite Database'
Subject: EXT :Re: [sqlite] C++ programming - Extracting data
Sorry, I forgot to give you a snip of the test-bench code
getter() {
string sName;
string sAddress;
int age = 0;
string dbdata = "SELECT * FROM friend";
rc = sqlite3_prepare_v2(db, dbdata.c_str(), -1, &stmt, NULL );
....
rc = sqlite3_step(stmt);
if(rc != SQLITE_DONE) { ... }
while ( sqlite3_step(stmt) != SQLITE_ROW) {
sName = (char*)sqlite3_column_text(stmt, 0); //<== Seg fault
std::cout << sName << std::endl;
...
}
sqlite3_finalize(stmt);
}
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Igor Tandetnik
Sent: Monday, June 25, 2012 9:07 AM
To: [email protected]
Subject: Re: [sqlite] C++ programming - creating a table
Arbol One <[email protected]> wrote:
> Q: What are you trying to achieve here? What's the supposed purpose of
> sqlite3_column_type call?
>
> A: What I am trying to do is to display the data in a data table
You run a SELECT statement for that. In any case, what data do you expect
there to be right after CREATE TABLE?
--
Igor Tandetnik
_______________________________________________
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
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users