How can i fetch data from sqlite3 database using C++? -


i new c++ , how can retrive data sqlite3 db using select query , callback method in sqliteutil class?

i know data can collected using callback method

method scheme readrecords() -> executequery() -> sqlite3_exec(callback)

sqliteutil.cpp

#include "sqliteutil.hpp"  // readrecords method **static int sqliteutil::callback(?char *record?, int argc, char **argv, char **azcolname) {     for(int i=0; < argc; i++){         cout <<     azcolname[i];         cout << "\t";         cout << argv[i] ? argv[i] : "null";         cout << "\n";     }     cout << "\n";**     return 0; }  // thats execute query, dry. void sqliteutil::executequery(string sql) {     sql += ";";     int result = sqlite3_exec(db, sql.c_str(), callback, ?records_s?, &zerrmsg);     printerror(result); }   void sqliteutil::readrecords(vector<string> columns = {}, vector<string> order = {}) {     string sql = "select";     if (columns.size() == 0 ) {         sql += " * ";     } else {         sql += " " + joinstrarray(columns) + " ";     }     sql += "from " + table;      if (order.size() != 0) {         sql += " order " + joinstrarray(order) + " asc";     }      executequery(sql); } 

sqliteutil.hpp

#ifndef sqlite_util_h #define sqlite_util_h  #include <string> #include <vector> #include <iostream> #include "../sqlite/sqlite3.h" using namespace std;  class sqliteutil {     private:         string path; //path database         string table; //current table         sqlite3 *db; //database reference         char *zerrmsg;         const char* data;         //vector<vector<string>> records;         char **records;          string joinstrarray(vector<string> lines, int quoted=0);         !!!!static int callback( ?char *records ?, int argc, char **argv, char **azcolname);         !!!!void executequery(string sql);         void printerror(int code);      public:         sqliteutil(string dbpath, string tablename);         //setters , getters         void setpath(string dbpath);         string getpath();         void settable(string tablename);         string gettable();          //methods work sqlite3         void opendb();         void closedb();         void createtable(vector<string> columns);         void deletetable();         void createrecord(vector<string> values);         !!!!void readrecords(vector<string> columns = {}, vector<string> order = {});         string updaterecord();         void deleterecord(string id = "0"); };  #endif 


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -