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

#include "PreparedStatement.h"

Inheritance diagram for PreparedStatementTask:
SQLOperation

Public Member Functions

 PreparedStatementTask (PreparedStatementBase *stmt, bool async=false)
 
 ~PreparedStatementTask () override
 
bool Execute () override
 
PreparedQueryResultFuture GetFuture ()
 
- Public Member Functions inherited from SQLOperation
 SQLOperation ()=default
 
virtual ~SQLOperation ()=default
 
virtual int call ()
 
virtual bool Execute ()=0
 
virtual void SetConnection (MySQLConnection *con)
 

Protected Attributes

PreparedStatementBasem_stmt
 
bool m_has_result
 
PreparedQueryResultPromisem_result
 

Additional Inherited Members

- Public Attributes inherited from SQLOperation
MySQLConnectionm_conn {nullptr}
 

Detailed Description

Constructor & Destructor Documentation

◆ PreparedStatementTask()

PreparedStatementTask::PreparedStatementTask ( PreparedStatementBase stmt,
bool  async = false 
)
67 :
68 m_stmt(stmt),
69 m_result(nullptr)
70{
71 m_has_result = async; // If it's async, then there's a result
72
73 if (async)
75}
std::promise< PreparedQueryResult > PreparedQueryResultPromise
Definition: DatabaseEnvFwd.h:48
bool m_has_result
Definition: PreparedStatement.h:181
PreparedQueryResultPromise * m_result
Definition: PreparedStatement.h:182
PreparedStatementBase * m_stmt
Definition: PreparedStatement.h:180

References m_has_result, and m_result.

◆ ~PreparedStatementTask()

PreparedStatementTask::~PreparedStatementTask ( )
override
78{
79 delete m_stmt;
80
82 delete m_result;
83}

References m_has_result, m_result, and m_stmt.

Member Function Documentation

◆ Execute()

bool PreparedStatementTask::Execute ( )
overridevirtual

Implements SQLOperation.

86{
87 if (m_has_result)
88 {
90 if (!result || !result->GetRowCount())
91 {
92 delete result;
93 m_result->set_value(PreparedQueryResult(nullptr));
94 return false;
95 }
96
97 m_result->set_value(PreparedQueryResult(result));
98 return true;
99 }
100
101 return m_conn->Execute(m_stmt);
102}
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:46
ResultSet * Query(std::string_view sql)
Definition: MySQLConnection.cpp:311
bool Execute(std::string_view sql)
Definition: MySQLConnection.cpp:176
Definition: QueryResult.h:99
uint64 GetRowCount() const
Definition: QueryResult.h:105
MySQLConnection * m_conn
Definition: SQLOperation.h:56

References MySQLConnection::Execute(), PreparedResultSet::GetRowCount(), SQLOperation::m_conn, m_has_result, m_result, m_stmt, and MySQLConnection::Query().

◆ GetFuture()

PreparedQueryResultFuture PreparedStatementTask::GetFuture ( )
inline
177{ return m_result->get_future(); }

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

Member Data Documentation

◆ m_has_result

bool PreparedStatementTask::m_has_result
protected

◆ m_result

PreparedQueryResultPromise* PreparedStatementTask::m_result
protected

◆ m_stmt

PreparedStatementBase* PreparedStatementTask::m_stmt
protected

Referenced by Execute(), and ~PreparedStatementTask().