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

  • SEARCH
  • Home
  • 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 8360313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:25:29+00:00 2026-06-09T11:25:29+00:00

I would like to select * from abe_account like this sqlite> select * from

  • 0

I would like to select * from abe_account like this

sqlite> select * from abe_account;
admin|Peter John|admin_account|password

But I wanna do that in C++ and return each element e.g

admin as vector x[0]
Peter John as vector x[1]
admin_account as vector x[2]
password as vector x[4]

and then use it outside when I close sqlite3_close(db)

such as cout << x[0] << endl;

How do i do it, i tried to cout << str << endl;

but it print nothing.

the following code below is what I tried on my own:

#include <iostream>
#include <sqlite3.h>

//g++ -o test test.cpp -lsqlite3
using namespace std;

int main()
{

    sqlite3 *db;
    sqlite3_stmt * stmt;

    if (sqlite3_open("abeserver.db", &db) == SQLITE_OK)
    {
    sqlite3_prepare( db, "SELECT * from abe_account;", -1, &stmt, NULL );//preparing the statement
    sqlite3_step( stmt );//executing the statement
    char * str = (char *) sqlite3_column_text( stmt, 0 );///reading the 1st column of the result
        }
    else
    {
        cout << "Failed to open db\n";
    }

    sqlite3_finalize(stmt);
    sqlite3_close(db);

    cout << str << endl;

    return 0;

}
  • 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-09T11:25:31+00:00Added an answer on June 9, 2026 at 11:25 am

    When you execute a statement, you get a result as a table. You have some columns, the amount of which you do know, and rows, the amount of which you do not know.

    First, make a

    std::vector< std::vector < std:: string > > result;
    

    The string part is the text in a cell.
    The inner vector is a row.
    The outer vector is a column.

    Since you know exactly the numbe rof columns, you can “add the columns”. In your case, you need 4 of them:

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

    Now, your outer vector has 4 elements that represent 4 columns.

    Now, in your code you get the data like this

    while( sqlite3_column_text( stmt, 0 ) )
    {
        for( int i = 0; i < 4; i++ )
            result[i].push_back( std::string( (char *)sqlite3_column_text( stmt, i ) ) );
        sqlite3_step( stmt );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to select a row from 2 different tables that are relational.
I would like do some thing like this: SELECT sum(quantity) FROM orders WHERE order_code
i would like to do this: DECLARE @TmpTable TABLE = select * from someTable
I would like to select a subset of elements from a whole that satisfy
I have written a subquery that goes like this: select top 1 A from
I would like to have an UPDATE statement like this: SELECT * FROM Employee
I would like to run something like: select * from table where field in
I have a simple one-to-many relationship. I would like to select rows from the
I would like to select a row from the database based on two input
I would like to select all matches from a commaseparated column in table2, where

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.