mardi 5 novembre 2019

Please help me to store the data on a variable of the individual field from SQLite database using c++ ->> Please help me

My problem is that I can not store the individual database field data into the variable and I used the SQLite database and I used the c++. and I send the code, please see this.

#include <iostream>
#include <string>
#include <cstring>
#include <stdio.h>
#include <windows.h>
#include "sqlite3.h"
using namespace std;

static int callback(void* data, int argc, char** argv, char** azColName)
{
    int i;
    //fprintf(stderr, "%s: \n", (const char*)data);

    for (i = 0; i < argc; i++) {
        //printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
        //cout << argv[i].FirstName << endl;
        // cout << azColName[i] << endl;
        if(argv[i]){
            printf("%s = %s \t", azColName[i],argv[i]);
            Sleep(30);
        }else{
            printf("%20s", " ");
        }
    }
    printf("\n");
    return 0;
}

In this function show the data Row and coloum wise

int main(int argc, char** argv){
    sqlite3* DB;
    char* messagesError;
    int exit = sqlite3_open("chinook.db", &DB);
    if (exit) {
        cerr << "Error open DB " << sqlite3_errmsg(DB) << endl;
        return (-1);
    }
    else
        cout << "Opened Database Successfully!" << endl;
    string query = "SELECT invoicelineid,invoiceid,trackid,unitprice,quantity FROM invoice_items;";
    exit = sqlite3_exec(DB, query.c_str(), callback, NULL, &messagesError);
    sqlite3_close(DB);
    return (0);
}


Aucun commentaire:

Enregistrer un commentaire