C++ SQLite3 how to know if select return 0 rows

Viewed 6080

C++ SQLite3 how to know if select return 0 rows

I have a select statement for SQLite3, how do I know that if after executing the sql statement, the result is 0 rows , no match found etc..

How can i modify my code so that if 0 rows found, it will not execute the part where it put the result into a vector.

My code below:

sqlstatement = "SELECT * from abe_account where department="+quotesql(department)+" AND name="+quotesql(name)+";";


    std::vector< std::vector < std:: string > > result;
    for( int i = 0; i < 4; i++ )
    result.push_back(std::vector< std::string >());


    sqlite3_prepare( db, sqlstatement.c_str() , -1, &stmt2, NULL );//preparing the statement
    sqlite3_step( stmt2 );//executing the statement

    while( sqlite3_column_text( stmt2, 0 ) )
{
    for( int i = 0; i < 4; i++ )
    result[i].push_back( std::string( (char *)sqlite3_column_text( stmt2, i ) ) );
    sqlite3_step( stmt2 );
    counter ++;
}
2 Answers
Related