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 8024637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:55:06+00:00 2026-06-04T22:55:06+00:00

I am trying to create a database in c++ using sqlite3 lib.. I am

  • 0

I am trying to create a database in c++ using sqlite3 lib.. I am getting error sqlite3_prepare_v2′
was not declared in this scope
as shown in logcat.

log file

..\src\Test.cpp: In function 'int main(int, const char**)':
..\src\Test.cpp:21:85: error: 'sqlite3_prepare_v2' was not declared in this scope
..\src\Test.cpp:30:13: error: variable 'sqlite3 in' has initializer but incomplete type
..\src\Test.cpp:30:30: error: invalid use of incomplete type 'sqlite3 {aka struct sqlite3}'
..\src\/sqlite3.h:73:16: error: forward declaration of 'sqlite3 {aka struct sqlite3}'

Here is my code

#include <iostream>
using namespace std;
 #include "sqlite3.h"

 int main (int argc, const char * argv[]) {

sqlite3 *db;
sqlite3_open("test.db", & db);

   string createQuery = "CREATE TABLE IF NOT EXISTS items (busid INTEGER PRIMARY KEY, ipaddr TEXT,    time TEXT NOT NULL DEFAULT (NOW()));";
   sqlite3_stmt *createStmt;
  cout << "Creating Table Statement" << endl;
  sqlite3_prepare_v2(db, createQuery.c_str(), createQuery.size(), &createStmt, NULL);
   cout << "Stepping Table Statement" << endl;
   if (sqlite3_step(createStmt) != SQLITE_DONE) cout << "Didn't Create Table!" << endl;

   string insertQuery = "INSERT INTO items (time, ipaddr) VALUES ('test', '192.168.1.1');"; // WORKS!


   sqlite3_stmt *insertStmt;
   cout << "Creating Insert Statement" << endl;
   sqlite3_prepare(db, insertQuery.c_str(), insertQuery.size(), &insertStmt, NULL);
   cout << "Stepping Insert Statement" << endl;
   if (sqlite3_step(insertStmt) != SQLITE_DONE) cout << "Didn't Insert Item!" << endl;

cout << "Success!" << endl;

 return 0;
}

please help me out. thanks…..

  • 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-04T22:55:07+00:00Added an answer on June 4, 2026 at 10:55 pm
     #include <sqlite3.h>
    

    should contain sqlite3_prepare_v2 and struct sqlite3. Make sure you’re including the right sqlite3.h file.

    Also in sqlite3_prepare_v2 the 3rd arg can be (and should be in your case) -1 so the sql is read to the first null terminator.

    Working bare-metal sample using sqlite 3.7.11:

    #include <sqlite3.h>
    int test()
    {
        sqlite3* pDb = NULL;
        sqlite3_stmt* query = NULL;
        int ret = 0;
        do // avoid nested if's
        {
            // initialize engine
            if (SQLITE_OK != (ret = sqlite3_initialize()))
            {
                printf("Failed to initialize library: %d\n", ret);
                break;
            }
            // open connection to a DB
            if (SQLITE_OK != (ret = sqlite3_open_v2("test.db", &pDb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)))
            {
                printf("Failed to open conn: %d\n", ret);
                break;
            }
            // prepare the statement
            if (SQLITE_OK != (ret = sqlite3_prepare_v2(pDb, "SELECT 2012", -1, &query, NULL)))
            {
                printf("Failed to prepare insert: %d, %s\n", ret, sqlite3_errmsg(pDb));
                break;
            }
            // step to 1st row of data
            if (SQLITE_ROW != (ret = sqlite3_step(query))) // see documentation, this can return more values as success
            {
                printf("Failed to step: %d, %s\n", ret, sqlite3_errmsg(pDb));
                break;
            }
            // ... and print the value of column 0 (expect 2012 here)
            printf("Value from sqlite: %s", sqlite3_column_text(query, 0));     
    
        } while (false);
        // cleanup
        if (NULL != query) sqlite3_finalize(query);
        if (NULL != pDb) sqlite3_close(pDb);
        sqlite3_shutdown();
        return ret;
    }
    

    Hope this helps

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

Sidebar

Related Questions

So I'm very new to this and I'm trying to create a database using
I am trying to create dynamic menus from the database using the following example
I'm trying to create a connection to a MySQL database using Mysqli in PHP.
I am trying to create a database deadlock and I am using JUnit. I
I am using SQLserver 2008 R2 edition. I am trying to create a database
I'm trying to create a billing database with Entity Framework 4.3 using Code First
I'm trying to create a table in my database through C# using the following
I'm trying to create some jQuery UI Tabs using data fetched from a database.
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
I'm trying to create a custom function for a SQLite database I'm using with

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.