File tree Expand file tree Collapse file tree 3 files changed +37
-6
lines changed Expand file tree Collapse file tree 3 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -404,7 +404,12 @@ class Stmt_op
404
404
using Row_processor::col_count_t ;
405
405
using Row_processor::row_count_t ;
406
406
407
- Session& m_session;
407
+ /*
408
+ This points at statement's session as long as the statement is active and
409
+ registered with it.
410
+ */
411
+
412
+ Session *m_session = nullptr ;
408
413
409
414
/*
410
415
If several asynchronous statements have been issued, these pointers
@@ -431,21 +436,30 @@ class Stmt_op
431
436
Cursor *m_current_cursor = nullptr ;
432
437
433
438
Stmt_op (Session &s)
434
- : m_session(s)
435
439
{
436
- m_session.register_stmt (this );
440
+ s.register_stmt (this );
441
+ // Note: m_session is set during registration.
442
+ assert (m_session);
437
443
}
438
444
439
445
virtual ~Stmt_op ()
440
446
{
441
447
discard ();
442
448
wait ();
443
- m_session.deregister_stmt (this );
449
+ if (m_session)
450
+ m_session->deregister_stmt (this );
451
+ }
452
+
453
+ Session& get_session ()
454
+ {
455
+ // Note: get_session() should not be called for inactive statement.
456
+ assert (m_session);
457
+ return *m_session;
444
458
}
445
459
446
460
Protocol& get_protocol ()
447
461
{
448
- return m_session .m_protocol ;
462
+ return get_session () .m_protocol ;
449
463
}
450
464
451
465
// Async_op
Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ bool Stmt_op::do_cont()
65
65
66
66
assert (ERROR != m_state);
67
67
assert (DONE != m_state || m_op);
68
+ assert (m_session);
68
69
69
70
try {
70
71
@@ -125,7 +126,7 @@ bool Stmt_op::do_cont()
125
126
will be set to NULL so that we don't enter this branch again.
126
127
*/
127
128
128
- m_session. deregister_stmt (m_prev_stmt);
129
+ m_session-> deregister_stmt (m_prev_stmt);
129
130
assert (nullptr == m_prev_stmt);
130
131
}
131
132
@@ -195,6 +196,12 @@ bool Stmt_op::do_cont()
195
196
196
197
bool Stmt_op::is_completed () const
197
198
{
199
+ if (!m_session)
200
+ {
201
+ assert (DONE == m_state || ERROR == m_state);
202
+ return true ;
203
+ }
204
+
198
205
switch (m_state)
199
206
{
200
207
case ERROR:
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ POP_SYS_WARNINGS_CDK
39
39
40
40
#include " stmt.h"
41
41
42
+
42
43
namespace cdk {
43
44
namespace mysqlx {
44
45
@@ -739,6 +740,9 @@ void Session::close()
739
740
void Session::register_stmt (Stmt_op *stmt)
740
741
{
741
742
assert (stmt);
743
+ assert (!stmt->m_session );
744
+
745
+ stmt->m_session = this ;
742
746
743
747
// Append stmt to the end of the list of active statements.
744
748
@@ -756,6 +760,12 @@ void Session::deregister_stmt(Stmt_op *stmt)
756
760
{
757
761
assert (stmt);
758
762
763
+ if (!stmt->m_session )
764
+ return ;
765
+
766
+ assert (stmt->m_session == this );
767
+ stmt->m_session = nullptr ;
768
+
759
769
// Remove stmt from the list of active statements.
760
770
761
771
if (stmt->m_next_stmt )
You can’t perform that action at this time.
0 commit comments