Created
January 20, 2013 15:18
-
-
Save krofna/4579301 to your computer and use it in GitHub Desktop.
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 "mysql_connection.h" | |
#include <cppconn/driver.h> | |
#include <cppconn/exception.h> | |
#include <cppconn/resultset.h> | |
#include <cppconn/statement.h> | |
#include <cppconn/prepared_statement.h> | |
#include <memory> | |
#include <fstream> | |
#include <vector> | |
#include <cstring> | |
#include <cstdint> | |
typedef uint32_t uint32; | |
typedef int32_t int32; | |
typedef std::unique_ptr<sql::ResultSet> QueryResult; | |
typedef std::unique_ptr<sql::Connection> ConnectionPtr; | |
typedef std::unique_ptr<sql::PreparedStatement> PStatementPtr; | |
class Database | |
{ | |
public: | |
Database(); | |
QueryResult Query(const char* sql); | |
private: | |
sql::Driver* Driver; | |
ConnectionPtr Connection; | |
PStatementPtr PStatement; | |
}; | |
Database::Database() : Driver(nullptr) | |
{ | |
Driver = get_driver_instance(); | |
std::string Username, Password, Schema; | |
std::cout << "Username: "; | |
std::cin >> Username; | |
std::cout << "Password: "; | |
std::cin >> Password; | |
std::cout << "Schema: "; | |
std::cin >> Schema; | |
Connection.reset(Driver->connect("tcp://127.0.0.1:3306", Username, Password)); | |
Connection->setSchema(Schema); | |
} | |
QueryResult Database::Query(const char* sql) | |
{ | |
PStatement.reset(Connection->prepareStatement(sql)); | |
return QueryResult(PStatement->executeQuery()); | |
} | |
int main() | |
{ | |
Database sDatabase; | |
QueryResult Result = sDatabase.Query("SELECT entry, class, subclass, SoundOverrideSubclass, Material, displayid, InventoryType, sheath FROM item_template"); | |
QueryResult R2 = sDatabase.Query("SELECT COUNT(*) FROM item_template"); | |
R2->next(); | |
uint32 Records = R2->getUInt(1), nb = 8, es = 32, ss = 1; | |
std::ofstream DbcFile("Item.dbc", std::ios::binary); | |
DbcFile << "WDBC"; | |
DbcFile.write((const char*)&Records, 4); | |
DbcFile.write((const char*)&nb, 4); | |
DbcFile.write((const char*)&es, 4); | |
DbcFile.write((const char*)&ss, 4); | |
while (Result->next()) | |
{ | |
uint32 utemp; | |
int32 itemp; | |
for (int i = 1; i < 4; ++i) | |
{ | |
utemp = Result->getUInt(i); | |
DbcFile.write((const char*)&utemp, 4); | |
} | |
for (int i = 4; i < 6; ++i) | |
{ | |
itemp = Result->getInt(i); | |
DbcFile.write((const char*)&itemp, 4); | |
} | |
for (int i = 6; i < 9; ++i) | |
{ | |
utemp = Result->getUInt(i); | |
DbcFile.write((const char*)&utemp, 4); | |
} | |
} | |
std::cout << "Done! " << Records << " items written into Item.dbc" << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment