AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
BasicStatementTask Class Reference

#include "AdhocStatement.h"

Inheritance diagram for BasicStatementTask:
SQLOperation

Public Member Functions

 BasicStatementTask (std::string_view sql, bool async=false)
 
 ~BasicStatementTask ()
 
bool Execute () override
 
QueryResultFuture GetFuture () const
 
- Public Member Functions inherited from SQLOperation
 SQLOperation ()=default
 
virtual ~SQLOperation ()=default
 
virtual int call ()
 
virtual bool Execute ()=0
 
virtual void SetConnection (MySQLConnection *con)
 

Private Attributes

std::string m_sql
 
bool m_has_result
 
QueryResultPromisem_result
 

Additional Inherited Members

- Public Attributes inherited from SQLOperation
MySQLConnectionm_conn {nullptr}
 

Detailed Description

Raw, ad-hoc query.

Constructor & Destructor Documentation

◆ BasicStatementTask()

BasicStatementTask::BasicStatementTask ( std::string_view  sql,
bool  async = false 
)

Basic, ad-hoc queries.

23 : m_result(nullptr)
24{
25 m_sql = std::string(sql);
26 m_has_result = async; // If the operation is async, then there's a result
27
28 if (async)
30}
std::promise< QueryResult > QueryResultPromise
Definition: DatabaseEnvFwd.h:29
bool m_has_result
Definition: AdhocStatement.h:37
std::string m_sql
Definition: AdhocStatement.h:36
QueryResultPromise * m_result
Definition: AdhocStatement.h:38

References m_has_result, m_result, and m_sql.

◆ ~BasicStatementTask()

BasicStatementTask::~BasicStatementTask ( )
33{
34 m_sql.clear();
36 delete m_result;
37}

References m_has_result, m_result, and m_sql.

Member Function Documentation

◆ Execute()

bool BasicStatementTask::Execute ( )
overridevirtual

Implements SQLOperation.

40{
41 if (m_has_result)
42 {
43 ResultSet* result = m_conn->Query(m_sql);
44 if (!result || !result->GetRowCount() || !result->NextRow())
45 {
46 delete result;
47 m_result->set_value(QueryResult(nullptr));
48 return false;
49 }
50
51 m_result->set_value(QueryResult(result));
52 return true;
53 }
54
55 return m_conn->Execute(m_sql);
56}
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
ResultSet * Query(std::string_view sql)
Definition: MySQLConnection.cpp:310
bool Execute(std::string_view sql)
Definition: MySQLConnection.cpp:175
Definition: QueryResult.h:49
uint64 GetRowCount() const
Definition: QueryResult.h:55
bool NextRow()
Definition: QueryResult.cpp:188
MySQLConnection * m_conn
Definition: SQLOperation.h:56

References MySQLConnection::Execute(), ResultSet::GetRowCount(), SQLOperation::m_conn, m_has_result, m_result, m_sql, ResultSet::NextRow(), and MySQLConnection::Query().

◆ GetFuture()

QueryResultFuture BasicStatementTask::GetFuture ( ) const
inline
33{ return m_result->get_future(); }

Referenced by DatabaseWorkerPool< T >::AsyncQuery().

Member Data Documentation

◆ m_has_result

bool BasicStatementTask::m_has_result
private

◆ m_result

QueryResultPromise* BasicStatementTask::m_result
private

◆ m_sql

std::string BasicStatementTask::m_sql
private