Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
TxtAdv/Sql_Qu.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
36 lines (31 sloc)
869 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sqlite3.h> | |
#include <iostream> | |
#include "Sql_Qu.h" | |
using namespace std; | |
/////////////////BASED ON CODE FROM: https://www.tutorialspoint.com/sqlite/sqlite_c_cpp.htm ////////////// | |
static int callback(void *data, int argc, char **argv, char **azColName){ | |
int i; | |
for(i = 0; i<argc; i++){ | |
Data[x] = ("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); ///Modified to store data in an array not just print it | |
x = x+1; | |
} | |
return 0; | |
} | |
int Sql_Qu(int argc, char* argv[], char *sql) | |
{ | |
sqlite3 *db; | |
char *zErrMsg = 0; | |
int rc; | |
int i; | |
const char* data = ""; | |
/* Open database */ | |
rc = sqlite3_open("MonsterDB", &db); | |
/* Execute SQL statement */ | |
rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg); | |
sqlite3_close(db); | |
return 0; | |
} | |
//Made by Ben |