简体   繁体   中英

MySQL Recursive Stored Procedure with Cursor & View Is Not Refreshing

I have a working MySQL 5.5 stored procedure that calls itself recursively.

I needed to execute a dynamic sql query that is unique with every call, then loop through all the values from the query. To do this, I declare a cursor that is based on a view, and I create a view with the dynamic SQL before opening the cursor. I quickly loop through the cursor, capture some information into a pseudo array variable, then close the cursor and drop the view. I then process the information that has been captured in my array, which may include a recursive call to the same stored procedure.

The problem that I'm running into is that even though the view is created and dropped each time the procedure is called, the view definition seems to get stuck after the first recursive call (ie the view is created Ok in the initial call, it is created Ok in the first recursive call, but the view in the second recursive call is identical to what it was in the first recursive call, even though the SQL to create the view is different.)

The name of the view is the same each time it is created (part of the kludge to simulate a dynamic SQL cursor in MySQL), and it seems as if the view definition is cached somewhere and 'resurrected' when it is being created, even though the CREATE VIEW statement is different each time.

I know the view is being created and dropped as expected, because there is code to prevent simultaneous users from inadvertently using the same public view - ie check and delay execution if the view already exists (another MySQL kludge for lack of private views).

I've been able to work around all the other shortcomings of MySQL, but this one has me stumped. Thanks in advance for any insights/assistance!

Mike

似乎这可能与事务隔离有关-您是否在事务内部执行此操作,是否在删除后提交,是否自动提交等等?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM