Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8386781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:02:03+00:00 2026-06-09T18:02:03+00:00

C++ SQLite3 how to know if select return 0 rows I have a select

  • 0

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 ++;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:02:05+00:00Added an answer on June 9, 2026 at 6:02 pm

    sqlite3_step returns SQLITE_DONE when there are no (more) rows to process:

    int stat = sqlite3_step(stmt2);
    if (stat == SQLITE_DONE) {
        // no rows to process
    }
    

    Remember to check for errors as well, e.g.:

    if (stat != SQLITE_DONE && stat != SQLITE_ROW) {
        // there's probably a problem
    }
    

    You can find the complete list of result codes in the manual.

    Lastly, you should use the “v2” interface when using SQLite3. From the manual:

    The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are recommended for all new programs. The two older interfaces are retained for backwards compatibility, but their use is discouraged.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that in oracle/mysql/sqlserver select statement you are not able to reference a
Using sqlite3, I have two tables: products, orders. I want to know how many
I know that in iOS, if the .sqlite is updated / read by SQL
I'm trying to query my SQLite DB for all rows that have a particular
I'm new to SQLite3 with iOS I'm trying to create an SQL Query that
I use SQLite3 and have a table called blobs that stores content and *hash_value*.
Does someone know of a Sqlite manager that I can put on my site,
Please let me know how to delete n-rows in android sqlite database. I used
I know this is simple but I can't get it working! I have no
I have a table of events (in a sqlite3 database for what it's worth)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.