简体   繁体   中英

C++ sqlite3 api is not defined (Visual Studio 2015)

so i wanted to mess around a bit, just to learn and stuff, but now i get an error, that "sqlite3_api" is not defined.

#include "stdafx.h"
#include "sqlite3.h"
#include "sqlite3ext.h"

using namespace std;

#define DB "dumpshit.s3db"

bool isOpenDB = false;
sqlite3 *db;

bool ConnectDB();

bool ConnectDB()
{
    if (sqlite3_open(DB, &db) == SQLITE_OK)
    {
        isOpenDB = true;
        return true;
    }

    return false;
}

That is literally everything in that test file right now. I also added the sqlite3.c to my source files and sqlite3.h + sqlite3ext.h to my header files.

Why am i getting that error message?

There is no need to include sqlite3ext.h file. Just include the sqlite3.h file and add the sqlite3.c file in the Source File folder and compile the program, the program will be executed without any error.

Here is the sample code which i have written and it's working:

#include <sqlite3.h>
#include <stdio.h>

int main(void) 
{
sqlite3 *db;    
sqlite3_stmt *res;
int rec;
/* Opening Database. */
int rec = sqlite3_open("test.db", &db);
/* Preparing the query */    
sqlite3_prepare_v2(db, "create table tb1 (col1 text, col2 text, col3 int)", -1, &res, 0);
 /* Evaluating the statement. */
sqlite3_step(res);    
/* Closing Database. */
sqlite3_close(db);

return 0;
}

Hope it helped..!!

I ran into this problem while developing an extension, so simply removing #include "sqlite3ext.h" was not a workable solution for me.

What did work was the following, from "4. Programming Loadable Extensions", of sqlite's Run-Time Loadable Extensions documentation.

  1. Put the macro "SQLITE_EXTENSION_INIT1" on a line by itself right after the "#include <sqlite3ext.h>" line.

So:

#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1

worked to fix the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM