extern "C"
{
#include "sqlite3.h"
}
#include "stdlib.h"
#include "stdio.h"
#include <iostream>
#include <fstream>
using namespace std;
fstream file;
string db_file = "game.db";
string file_name = "goods.lua";
/*
string sql = "select goods_id,name,descrip,sicon,sort_type from goods where type=0";
int callback(void *p, int count, char** data, char** Colname)
{
string str;
str = "['";
str += data[0];//id
str += "']={";
str += "\n\t['name']='";
str += data[1]; // name
str += "',";
str += "\n\t['brief']='";
str += data[2]; // brief
str += "',";
str += "\n\t['sicon']='icon/goods/";
str += data[3]; // sicon
str += ".png',";
str += "\n\t['sort']='";
str += data[4]; // sort
str += "'},\n";
file.write(str.c_str(), str.length());
return 0;
}
*/
/*
//hero
string sql = "select child_id , name ,descrip ,quality,skill_id,hp,atk,atk,sicon,bicon,camp from child";
int callback(void *p, int count, char** data, char** Colname)
{
string str;
str = "['";
str += data[0];//id
str += "']={";
str += "\n\t['name']='";
str += data[1]; // name
str += "',";
str += "\n\t['brief']='";
str += data[2]; // brief
str += "',";
str += "\n\t['quality']='";
str += data[3]; // quality
str += "',";
str += "\n\t['skill_id']='";
str += data[4]; // skill_id
str += "',";
str += "\n\t['base_hp']='";
str += data[5]; // hp
str += "',";
str += "\n\t['base_attack']='";
str += data[6]; // attack
str += "',";
str += "\n\t['base_speed']='";
str += data[7]; // speed
str += "',";
str += "\n\t['sicon']='icon/hero/";
str += data[8]; // sicon
str += ".png',";
str += "\n\t['bicon']='icon/hero/";
str += data[9]; // bicon
str += ".png',";
str += "\n\t['camp']='";
str += data[10]; // camp
str += "'";
str += "},\n";
file.write(str.c_str(), str.length());
return 0;
}
*/
// equip
string sql = "select equipment_id , name ,descrip ,quality,type,atk,sicon,bicon,hp,hp from equipment";
int callback(void *p, int count, char** data, char** Colname)
{
string str;
str = "['";
str += data[0];//id
str += "']={";
str += "\n\t['name']='";
str += data[1]; // name
str += "',";
str += "\n\t['brief']='";
str += data[2]; // brief
str += "',";
str += "\n\t['quality']='";
str += data[3]; // quality
str += "',";
str += "\n\t['type']='";
str += data[4]; // type
str += "',";
str += "\n\t['attack']='";
str += data[5]; // attack
str += "',";
str += "\n\t['sicon']='icon/equip/";
str += data[6]; // sicon
str += ".png',";
str += "\n\t['bicon']='icon/equip/";
str += data[7]; // bicon
str += ".png',";
str += "\n\t['hp']='";
str += data[8]; // hp
str += "',";
str += "\n\t['speed']='";
str += data[9]; // speed
str += "'";
str += "},\n";
file.write(str.c_str(), str.length());
return 0;
}
/* skill
string sql = "select skill_id,name,descrip,quality,type,atk,sicon,bicon from skill";
int callback(void *p, int count, char** data, char** Colname)
{
string str;
str = "['";
str += data[0];//id
str += "']={";
str += "\n\t['name']='";
str += data[1]; // name
str += "',";
str += "\n\t['brief']='";
str += data[2]; // brief
str += "',";
str += "\n\t['quality']='";
str += data[3]; // quality
str += "',";
str += "\n\t['type']='";
str += data[4]; // type
str += "',";
str += "\n\t['attack']='";
str += data[5]; // attack
str += "',";
str += "\n\t['sicon']='icon/skill/";
str += data[6]; // sicon
str += ".png',";
str += "\n\t['bicon']='icon/skill/";
str += data[7]; // bicon
str += ".png";
str += "'},\n";
file.write(str.c_str(), str.length());
return 0;
}
*/
int main()
{
sqlite3 *db;
int res = sqlite3_open(db_file.c_str(), &db);
if (res)
{
sqlite3_close(db);
return 0;
}
file.open(file_name, ios::out);
char*errorMsg;
string str;
str = "local t={\n";
file.write(str.c_str(), str.length());
sqlite3_exec(db, sql.c_str(), callback, 0, &errorMsg);
str = "}\nreturn t";
file.write(str.c_str(), str.length());
file.flush();
file.close();
//cout << errorMsg << endl;
// system("pause");
return 0;
}