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.

24 : m_result(nullptr)
25{
26 m_sql = std::string(sql);
27 m_has_result = async; // If the operation is async, then there's a result
28
29 if (async)
31}
std::promise< QueryResult > QueryResultPromise
Definition: DatabaseEnvFwd.h:30
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 ( )
34{
35 m_sql.clear();
37 delete m_result;
38}

References m_has_result, m_result, and m_sql.

Member Function Documentation

◆ Execute()

bool BasicStatementTask::Execute ( )
overridevirtual

Implements SQLOperation.

41{
42 if (m_has_result)
43 {
44 ResultSet* result = m_conn->Query(m_sql);
45 if (!result || !result->GetRowCount() || !result->NextRow())
46 {
47 delete result;
48 m_result->set_value(QueryResult(nullptr));
49 return false;
50 }
51
52 m_result->set_value(QueryResult(result));
53 return true;
54 }
55
56 return m_conn->Execute(m_sql);
57}
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
ResultSet * Query(std::string_view sql)
Definition: MySQLConnection.cpp:311
bool Execute(std::string_view sql)
Definition: MySQLConnection.cpp:176
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