1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-06 10:47:45 +00:00
sapphire/deps/mysqlConnector/Statement.cpp
Reyli 9435e6e66a General warning cleanup 1
* A lot of hit has to do with size_t being unsigned long long in 64 bit.
  - Just explicitly casting for a lot of cases removes the warning
* Good bit are also the differences in struct definitions to match packets and function definitions
  - Also just cast to fix
* Used a lot of #pragma warning( disable : 4244/4267 ) for template warnings
* InviteHandlers.cpp line 118 was definitely a typo bug. Needed assignment "=" instead of "=="
2024-06-21 03:01:16 -05:00

67 lines
1.7 KiB
C++

#include "Statement.h"
#include "Connection.h"
#include "ResultSet.h"
#include "mysql_util.h"
#include <mysql.h>
std::shared_ptr< Mysql::Connection > Mysql::Statement::getConnection()
{
return m_pConnection;
}
Mysql::Statement::Statement( std::shared_ptr< Mysql::Connection > conn ) :
m_pConnection( conn )
{
}
void Mysql::Statement::doQuery( const std::string &q )
{
mysql_real_query( m_pConnection->getRawCon(), q.c_str(), (unsigned long)q.length() );
if( errNo() )
throw std::runtime_error( m_pConnection->getError() );
m_warningsCount = getWarningCount();
}
bool Mysql::Statement::execute( const std::string &sql )
{
doQuery( sql );
bool ret = mysql_field_count( m_pConnection->getRawCon() ) == 0;
m_lastUpdateCount = mysql_affected_rows( m_pConnection->getRawCon() );
return ret;
}
uint64_t Mysql::Statement::getUpdateCount()
{
return m_lastUpdateCount;
}
uint32_t Mysql::Statement::getWarningCount()
{
return mysql_warning_count( m_pConnection->getRawCon() );
}
uint32_t Mysql::Statement::errNo()
{
return mysql_errno( m_pConnection->getRawCon() );
}
std::shared_ptr< Mysql::ResultSet > Mysql::Statement::executeQuery( const std::string &sql )
{
m_lastUpdateCount = UL64(~0);
doQuery( sql );
return std::make_shared< ResultSet >( mysql_store_result( m_pConnection->getRawCon() ), shared_from_this() );
}
std::shared_ptr< Mysql::ResultSet > Mysql::Statement::getResultSet()
{
if( errNo() != 0 )
throw std::runtime_error( "Error during getResultSet() : " + std::to_string( errNo() ) + ": " +
m_pConnection->getError() );
return std::make_shared< ResultSet >( mysql_store_result( m_pConnection->getRawCon() ), shared_from_this() );
}