#include "msql_acces.h" #include msql_acces::msql_acces() { driver = get_driver_instance(); con = driver->connect("tcp://127.0.0.1:3306", "root", "1234"); con->setSchema("bin_database"); } std::string msql_acces::get_passwd(std::string username){ sql::PreparedStatement *pstmt = con->prepareStatement("select passwd from users where username=?"); pstmt->setString(1,username); sql::ResultSet *res = pstmt->executeQuery(); std::string ret; while(res->next()) ret = res->getString("passwd"); delete res; return ret; } std::list msql_acces::get_pinfo(){ sql::PreparedStatement *pstmt = con->prepareStatement("select * from packages"); sql::ResultSet *res = pstmt->executeQuery(); std::list ret; std::string aux; while(res->next()){ aux=""; aux += res->getString("name"); if(res->getBoolean("uses")){ aux+=":true"; }else{ aux+=":false"; } aux += ":"+res->getString("created"); } delete res; return ret; } void msql_acces::write_install(std::string package, std::string user){ sql::PreparedStatement *pstmt = con->prepareStatement("insert into packages(name,user) values(?,(select id from users where username=?))"); pstmt->setString(1,package); pstmt->setString(2,user); pstmt->executeUpdate(); } void msql_acces::write_remove(std::string package){ sql::PreparedStatement *pstmt = con->prepareStatement("delete from packages where name=?"); pstmt->setString(1,package); pstmt->executeUpdate(); } bool msql_acces::get_package_exists(std::string package){ sql::PreparedStatement *pstmt = con->prepareStatement("select count(id) from packages where name=?"); pstmt->setString(1,package); sql::ResultSet *res = pstmt->executeQuery(); int ret=0; while(res->next()) ret = res->getInt(1); return ret>0; }