[MDEV-18292] CONNECT Engine JDBC not able to issue simple UPDATE statement from trigger or stored procedure Created: 2019-01-17 Updated: 2019-04-26 Resolved: 2019-03-03 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - Connect |
| Affects Version/s: | 10.3.12 |
| Fix Version/s: | 10.2.23, 10.3.14, 10.4.4 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Robert Dyas | Assignee: | Olivier Bertrand |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
centOS7 |
||
| Attachments: |
|
| Description |
|
Assume we have a CONNECT JDBC table called ProductVariants. I can successfully issue the following command:
The above works with hard coded values when issued direct, works when issued via a stored procedure, but does NOT work when issued via a trigger (on another table). With the trigger you get the following error:
Of course hard coded values are useless, what I was originally trying to do via a trigger was the following:
where v_new_qty and v_ProductVariantId are declared as BIGINT and so are the corresponding connect columns. This command produces different errors depending on if issued via a trigger or stored procedure. When issued via a trigger the error is:
When I call a stored procedure and pass in the values the error is:
In the stored procedure scenario it looks like it is somehow not seeing the variables. In the trigger case I have no idea. This is in a critical code path for a client deployment unfortunately, and we can't find a work around so a bug fix is critical for us. Thank you! |
| Comments |
| Comment by Olivier Bertrand [ 2019-01-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
UPDATE is handled the same way for JDBC and ODBC. The ODBC documentation clearly says that "Unlike the INSERT command, UPDATE and DELETE are supported in a simplified way" and explains that these commands are only achieved by sending to the external source a rephrased original command. Therefore the "original command" must be the UPDATE command and cannot be an implied triggert update or issued in an EXEC procedure command. Sorry about that. The only thing I can do is to specify these restrictions in the documentation. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I didn't realize that simple didn't include a simple update with variables in set and where clause. Given this isn't a bug but a known limitation should I resubmit as a feature request? How difficult would it be to implement? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I may reconsider this issue. The problem with procedure might be handled. For instance:
Here the issue is that in this case the received command to be rephrased is:
instead of
Here connect just change the table name t2 to t1 and send the command to the remote source. Note that if the remote source is a MariaDB server this still work because it understands the NAME_CONST function, but another source will generally fail. Here what to do is to eliminate the extra NAME_CONST functions when rephrasing the command, which is not so easy, or having MariaDB not adding these functions that are only useful when copying procedures. About triggers, could you give me a complete example of table definitions so I can test what happen in this case? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I just realized that variable substitution doesn't work with SELECT statement WHERE clauses either ... I thought it worked because I tested manually issuing a command but as soon as I did real code (with variables called in a loop) it fails.... hopefully related.... For example, if I have a simple stored function that takes a pv_id as a bigint and I call it from the console with values it gives the right answer, but if I call the same function in a loop with various pv_id values it appears to return the correct answer on the first call and null for all subsequent calls: BEGIN I'll post some real functions soon - of if you prefer can I can provide a dump of the database or access to it - it has only test data so far. I don't need complex statement support, just variable substitution in WHERE clause of SELECT, and variable substitution in SET and WHERE clause of UPDATE. The first thing to get working would be from a stored function so long as I can call that from a trigger or scheduled event... ideally the variable substitution works for store proc, stored func, schedule event, and trigger.... but getting it working first with stored function will work so long as I can call it in a loop and pass params and get back results. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Olivier, Code below... the 4 base tables I grabbed from SHOW table, the CONNECT I captured the actual command issued to create it... same with the trigger... let me know if it would be better for me to work up the simplest test case rather than this real use case... the issue is just with the last couple of statements in the trigger that use a SELECT with a variable in the WHERE clause and the UPDATE statement with variables of course. For some reason, the SELECT with variables does not return an error, and does appear to produce the right value on the first time through the loop but null on subsequent passes. Let me know if I can generate any log files to help, or if you would like direct access to this database.... or anything else I can do to help. Thank you!
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
CSVs attached with sample data. ROG.csv | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dump file attached of entire database if that is easier... it is small and only contains test data. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
To test, first issue this to set it back to New:
then issue this to try and mark it Completed - it will fail:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Not yet tried your samples (note that triggers cannot be created on CONNECT tables) but I made a simple one:
Here the received command to rephrase is:
correctly rephrased as:
and all works alright when it is sent to the remote source. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I'm working up a very simplified test case without triggers (just stored procedure/function) to start. I'll post it shortly. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
FYI to clarify, I would never expect to put a trigger ON a connect table... that would not make sense to me at all since it is managed by the remote system. However a trigger on a innodb table that SELECTs from a connect table (with variables in its where clause) or updates values in a connect table (with variables in the SET and WHERE clauses) makes perfect sense to me. In this context (with my zero knowledge of mariadb internals) it would seem that whether the variables are in a stored procedure or trigger or scheduled event would not matter. Test case coming in few minutes. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Simplified test case #1: no trigger, just attempt to update a connect table with variables in SET and WHERE clause.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Test scenario #2: trigger with similar SELECT on connect_testme returns the first record correctly and null for subsequent records
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hums, even for triggers, things fail when the commands use the NEW keyword because it is not replaced by the actual value in the query text. By the way, you can see how the commands are sent to the external source by setting:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have the following in my.cnf general_log=1 But I don't see any CONNECT queries in general.log | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
FYI the following stored proc DOES work correctly when called - even though it is very similar to the trigger one that gives wrong data (both are making multiple SELECTs to connect_testme with a different variable in where clause each time - but in the procedure it produces the right result.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
FYI the following also works correctly as a stored proc (did not test in trigger). So I think hopefully there are just two problems:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Olivier, Any idea if it will be possible to fix the NAME_CONST issue in the SET clause? Also, my earlier post about the variables being handled correctly in a stored procedure was unfortunately wrong. The following code produces the correct value on the FIRST call in a loop, but NULL (for v_old_qty) on all subsequent calls:
I have tried with parameters being passed to procedure and even declaring local variables and assigning and then using those to see if that would help (it doesn't). I would be happy to provide the output of my log file, but I'm not seeing any connect info in it. Robert | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I'll work on this. Not so easy but feasible. About triggers, following serg's suggestion, the following turnaround can be made. Instead of:
the following can be done:
This works because queries are rewitten in procedures (with eventual NAME_CONST functions) but they are not rewritten at all for triggers. Note that perhaps my triggers was not properly written because it worked fine when I did:
but not when doing:
Looking further, this seems CONNECT not doing properly the sending of commands when they come from one statement and it probably what explains the issues you have with loops. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I found why loops are not handled correctly by CONNECT, at least in my case. I did not try your example yet. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Awesome! To summarize my use cases were: Within a trigger on some base table (innodb) calling the following in a LOOP (often a CURSOR FOR LOOP): In the above cases [VAR_REF] changes on each loop pass, and could be an int or string, and could be a DECLARED variable, a rec.col1 reference (i.e. a reference to a record in a CURSOR FOR LOOP), or a NEW.colX or OLD.colX reference. Note someConnectTable and anotherConnectTable could be the SAME connect table in certain instances (e.g. changing an inventory quantity) but not in others. Further, the same type of looping with variables WITHIN the stored procedure and/or by CALLing the stored procedure within a loop. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I did successfully test inserts done from a procedure:
Where names is a JDBC table. However, testing in DEBUG mode, the modifications I made are not used. So it should also work for you (unless your procedure is called from a trigger). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Yes, inserts are needed but not part of what I am currently working on so haven't tested insert with variables. Do I understand that variables are handled differently in triggers vs stored procedures? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Olivier, Any luck fixing RE "I found why loops are not handled correctly by CONNECT, at least in my case. I did not try your example yet." Thank you again! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-25 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
RE "I found why loops are not handled correctly by CONNECT, at least in my case. I did not try your example yet." | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-25 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I will push shortly the fix for both the NAME_CONST problem and the loop problem. For triggers, this cannot be directly fixed. Therefore, triggers must not directly issue the commands but call a procedure that execute them. For example:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-25 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thank you. Regarding "For triggers, this cannot be directly fixed." Does that mean it can't be fixed for the next push but it can be fixed eventually somehow? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
It means that because MariaDB does not rewrite the statements used in triggers, CONNECT cannot use them as they contains variable names, such as NEW.race, whose value is unknown. It could only be fixed by MariaDB team forcing these statements to be rewritten replacing variables by their value. By the way, I am also working on allowing triggers for CONNECT table. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Would someone know if there is a function call that could rewrite the statement? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The statement not being rewritten would still contain "myvar" whose value would be unknown. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
In addition, triggers are now allowed for CONNECT tables. (not documented yet) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Because we've covered so much here, I want to clarify what is and is not currently working: FIXED and/or WORKING CURRENTLY NOT FIXED and/or NOT WORKING CURRENTLY Please confirm or correct my understanding - thanks! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The only point I didn't test yet is SELECT in a loop. The rest is Ok. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
SELECT in a loop is super important as we can get values one by one in a loop from the remote system, do something to them, then write them back. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-29 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ok, I tested it on one of your previous example with two mariadb servers:
Is that ok for you or should I make more elaborate tests? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-29 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
It's going to need a little more elaborate test... I'll try to write it below as best I can [hopefully no typos]:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-01-29 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I successfully tested the three syntax procedures. I thought it were alright because unlike UPDATE or DELETE, the SELECT and INSERT commands do not depend on the sent rewritten command. This means BTW that triggers only doing INSERT, even based on SELECT, probably don't need to call a procedure to work. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-01-31 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Have these changes been pushed so they will make the 10.3.13 release? I know that is coming up soon. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-02-11 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Olivier, I just noticed that 10.2.22 does not have this mdev in its changelog Does this mean that 10.3.13 won't have it either? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-02-11 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Yes it does but I mistyped the MDEV number in my message (18192 instead of 18292) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-02-11 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Is there any way to rush it into 10.3.13? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-02-11 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
It will go into 10.3.13 when released. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-02-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I just looked at the change log for 10.3.13 and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-02-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Any advice on what I would need to do build a correct ha_connect.so lib (if that is the correct one) for | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-02-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Don't know why the change log doesn't mention it but I downloaded and installed version 10.3.13 and it works alright concerning procedures and triggers. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-02-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hummm. When I call my original use case posted here (as a stored procedure) I get the same error as before:
ProductVariants is my most important CONNECT table | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-02-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The following, on centOS7, in a stored procedure produces the error:
Guessing the patch wasn't included in all OS releases??? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-02-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I tried to test your case in test_db11615.sql on the new downloaded version 10.3.13 but could not achieve it. Some tables could not be created, for example:
All CREATE PROCEDURE failed with syntax error such as:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-02-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
OK, so your patch IS in 10.3.13 but it does not work for my use case Below is the "reference procedure" that is called from a trigger because the code cannot be within the trigger itself due to a CONNECT limitation:
If I call ProductVariants_AdjustQty manually like the following it DOES work and produces the right result:
Also, if I call ProductVariants_AdjustQty from ANOTHER stored procedure in a loop as shown below, it also works and produces the right result:
However when when I take that exact same code from the testmain procedure and make it a trigger it generates the crashed table error message below:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-02-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
If I want to debug this in order to see what is wrong, I need a complete test case that includes all the tables to create, the triggers, the procedures etc. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-02-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
When trying to execute ProductVariants_AdjustQty I get this error:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-02-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
OK, I'll work on that Monday. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-02-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Regarding the dump example with ProductVariants_AdjustQty ... that will be too hard to set up... it uses a special driver that requires complex licensing.... better to test with a simple remote db and simple table for the connect part. If you take one of your existing stored procedures that does an update on a connect table (one that works), and simply call that procedure from a trigger on a local table I'm guessing you'll see the error right away. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-02-25 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have uploaded the file triggers.sql I was using to test my fix. It does call procedures from triggers and work alright. Can you test it on your system? If so, just make a complete case that fails and I'll work with it. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-02-25 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have uploaded the file trigger_test_3.sql that is a complete and simple test case for this. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-02-25 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Indeed it failed. And just before it said "Column qty not found". I think I know why; when working on the fix I had met this and knew it was a potential error but unfortunately, after having successfully tested my first fix with the case I sent you, I forgot to look at this one. It may be regarded at a CONNECT or MariaDB bug and comes from the fact that when called from a trigger the bitmap indicating what columns are used in a query does not include columns only used by the trigger. I'll look at what I can do to avoid this. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-02-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Were you able to find a fix? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-02-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I am working on it. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-02-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Fixing it and being sure it will work on all cases seems very difficult because MariaDB does not call CONNECT the same way depending on the procedure being directly called or executed from a trigger. I think this is a MariaDB issue rather than a CONNECT one, and trying to overcome this in all cases does not look feasible. The problem comes from the target table being called several times, for instance in the a_test procedure the table MS_t1 is called twice per loop, once for reading and once for updating, this not being properly indicated to CONNECT in the case of trigger. I will discuss this with the MariaDB developers trying to find a solution but I am afraid this can take time. Meanwhile a turnaround can sometimes be to rewrite the procedure to avoid these multiple table calls. For instance, a_test can be rewritten as:
This one works and, besides, is probably faster, the table MS_t1 being updated only once. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-03-03 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This fix works with all the existing test cases; hoping it will always work. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-03-04 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Olivier, I am unclear on your previous message: does this mean you were able to fix the issue? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-03-04 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Yes I was. I just said that there might still be some cases where it might fail. Is is impossible to imagine all the procedures people can write. But it does fix all the cases that I tested. However, you will have to test the ProductVariants_AdjustQty one. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Dyas [ 2019-03-04 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Great! So this doesn't solve the trigger re-write issue I assume.... meaning I still can't issue a simple UPDATE on a connect table from within a trigger, but I can, in theory, call a stored procedure that does. Right? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Olivier Bertrand [ 2019-03-04 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Of course you can. This fixes all issues including calling procedures from triggers. |