自定义回调sqlite3_exec()麻烦

时间:2015-07-16 16:45:48

标签: c++ sqlite callback

我正在编写一个与SQLite数据库连接的c ++类。

目前我正在尝试从数据库中获取值。到目前为止,我有:(只显示问题所需的内容)

#include "sqlite3.h"
#include <sstream>

using namespace std;

class ClDBTransporter
{
public:

    //Takes in a custom sql statement
    //Returns true/false based on if the statement completed sucessfully
    bool Custom(string in)
    {
        //check = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);

        char *sql = toSql(in);
        check = sqlite3_exec(db, sql, callback, NULL, &zErrMsg);
        if (check != SQLITE_OK)
        {
            fprintf(stderr, "SQL error: %s\n", zErrMsg);
            sqlite3_free(zErrMsg);
            return false;
        }
        return true;
    }

private:
    static char *returnedValue;

protected:

    static int callback(void *passed, int count, char **data, char **columns)
    {
        returnedValue = data[0];
        return 0;
    }

    //Used to convert string to char* necessary for sqlite3_exec()
    char* toSql(string in)
    {
        char *y = new char[in.length() + 1];
        strcpy(y, in.c_str());
        return y;
    }

};

这是我之前使用的回调函数:

//callback used to print multiple rows of a SELECT statement
static int callback(void *passed, int count, char **data, char **columns)
{
    for (int i = 0; i<count; i++)
    {
        printf("%s = %s\n", columns[i], data[i] ? data[i] : "NULL");
    }
    printf("\n");
    return 0;
}

我试图在其他类的其他函数中访问returnedValue以获取其他函数。我稍后会设置另一个变量来将returnedValue的值转换为int,float或string。

我无法编译获取错误:

Error   3   error LNK2001: unresolved external symbol "private: static char * ClDBTransporter::returnedValue" (?returnedValue@ClDBTransporter@@0PADA)   H:\CodeLab\SQLite\SQLite\Start.obj  SQLite
Error   4   error LNK1120: 1 unresolved externals   H:\CodeLab\SQLite\Debug\SQLite.exe  1   1   SQLite

0 个答案:

没有答案