The world's most popular open source database
#include "mysql_priv.h"#include "sql_cursor.h"#include "sql_select.h"Include dependency graph for sql_cursor.cc:

Go to the source code of this file.
Classes | |
| class | Sensitive_cursor |
| struct | Sensitive_cursor::Engine_info |
| class | Materialized_cursor |
| class | Select_materialize |
Functions | |
| int | mysql_open_cursor (THD *thd, uint flags, select_result *result, Server_side_cursor **pcursor) |
| int mysql_open_cursor | ( | THD * | thd, | |
| uint | flags, | |||
| select_result * | result, | |||
| Server_side_cursor ** | pcursor | |||
| ) |
Definition at line 138 of file sql_cursor.cc.
References ALWAYS_MATERIALIZED_CURSOR, DBUG_ASSERT, free_tmp_table(), Sensitive_cursor::get_lock_id(), Sensitive_cursor::is_open(), st_table::mem_root, mysql_execute_command(), Materialized_cursor::open(), and Sensitive_cursor::post_open().
Referenced by Prepared_statement::execute(), and sp_cursor::open().
00140 { 00141 Sensitive_cursor *sensitive_cursor; 00142 select_result *save_result; 00143 Select_materialize *result_materialize; 00144 LEX *lex= thd->lex; 00145 int rc; 00146 00147 /* 00148 The lifetime of the sensitive cursor is the same or less as the 00149 lifetime of the runtime memory of the statement it's opened for. 00150 */ 00151 if (! (result_materialize= new (thd->mem_root) Select_materialize(result))) 00152 return 1; 00153 00154 if (! (sensitive_cursor= new (thd->mem_root) Sensitive_cursor(thd, result))) 00155 { 00156 delete result; 00157 return 1; 00158 } 00159 00160 save_result= lex->result; 00161 00162 lex->result= result_materialize; 00163 if (! (flags & (uint) ALWAYS_MATERIALIZED_CURSOR)) 00164 { 00165 thd->lock_id= sensitive_cursor->get_lock_id(); 00166 thd->cursor= sensitive_cursor; 00167 } 00168 00169 rc= mysql_execute_command(thd); 00170 00171 lex->result= save_result; 00172 thd->lock_id= &thd->main_lock_id; 00173 thd->cursor= 0; 00174 00175 /* 00176 Possible options here: 00177 - a sensitive cursor is open. In this case rc is 0 and 00178 result_materialize->table is NULL, or 00179 - a materialized cursor is open. In this case rc is 0 and 00180 result_materialize->table is not NULL 00181 - an error occured during materializaton. 00182 result_materialize->table is not NULL, but rc != 0 00183 - successful completion of mysql_execute_command without 00184 a cursor: rc is 0, result_materialize->table is NULL, 00185 sensitive_cursor is not open. 00186 This is possible if some command writes directly to the 00187 network, bypassing select_result mechanism. An example of 00188 such command is SHOW VARIABLES or SHOW STATUS. 00189 */ 00190 if (rc) 00191 goto err_open; 00192 00193 if (sensitive_cursor->is_open()) 00194 { 00195 DBUG_ASSERT(!result_materialize->table); 00196 /* 00197 It's safer if we grab THD state after mysql_execute_command 00198 is finished and not in Sensitive_cursor::open(), because 00199 currently the call to Sensitive_cursor::open is buried deep 00200 in JOIN::exec of the top level join. 00201 */ 00202 sensitive_cursor->post_open(thd); 00203 *pcursor= sensitive_cursor; 00204 goto end; 00205 } 00206 else if (result_materialize->table) 00207 { 00208 Materialized_cursor *materialized_cursor; 00209 TABLE *table= result_materialize->table; 00210 MEM_ROOT *mem_root= &table->mem_root; 00211 00212 if (!(materialized_cursor= new (mem_root) 00213 Materialized_cursor(result, table))) 00214 { 00215 rc= 1; 00216 goto err_open; 00217 } 00218 00219 if ((rc= materialized_cursor->open(0))) 00220 { 00221 delete materialized_cursor; 00222 goto err_open; 00223 } 00224 00225 *pcursor= materialized_cursor; 00226 thd->stmt_arena->cleanup_stmt(); 00227 goto end; 00228 } 00229 00230 err_open: 00231 DBUG_ASSERT(! (sensitive_cursor && sensitive_cursor->is_open())); 00232 delete sensitive_cursor; 00233 if (result_materialize->table) 00234 free_tmp_table(thd, result_materialize->table); 00235 end: 00236 delete result_materialize; 00237 return rc; 00238 }
Here is the call graph for this function:

Here is the caller graph for this function:

1.4.7

