1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
//=============================================================================
#include "CDBMGR.h"
#include <string> // std::string
#include <sqlite3.h>
#include <iostream>
#include <sstream>
#include <cstring>
//=============================================================================
CDBMGR::CDBMGR() {
}
//=============================================================================
bool CDBMGR::open( char dbname[256])
{
rc = sqlite3_open("rpg.db", &db);
}
int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
//returnvalue = (int)argv[i];
printf("\n");
return 0;
}
void CDBMGR::SetHP(char username[256], int value)
{
std::ostringstream ss;
ss<<"UPDATE USERS SET HP = ";
ss<<value;
ss<<" WHERE username = '";
ss<<username;
ss<<"'";
strcpy(sql, ss.str().c_str());
rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
if( rc != SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
fprintf(stdout, "Operation done successfully\n");
}
}
int CDBMGR::GetHP( char username[256])
{
std::ostringstream ss;
ss<<"select HP from USERS where username = '";
ss<<username;
ss<<"'";
strcpy(sql, ss.str().c_str());
rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
}
|