rexshijaku/sql-to-laravel-builder

Bad conversion.

Closed this issue · 2 comments

I just found this package and found it very interesting. I have tested it with a query, it worked quite well, however it had an error.

SQL Query:

UPDATE ps_feature_value_lang a 
JOIN ps_feature_value_lang b ON a.id_feature_value = b.id_feature_value and CHAR_LENGTH(b.value) > 0
SET a.value = b.value
WHERE a.value = ''

Result:

DB::table('ps_feature_value_lang a')
->where('a.value','=','')
->join('ps_feature_value_lang b','a.id_feature_value','=and>','b.id_feature_value')
->update(['a.value'=>DB::raw('b.value')]);

The problem is in '=and>'
CHAR_LENGTH(b.value) > 0 is also ignored.

Hi @mreduar and thanks for the feedback

I added the 'Advanced Join Clauses' functionality which should solve the problem. You can try again and see if everything is working properly (I mean for this case, because as I mentioned in documentation, it is not a faultless converter).
See also an example of 'Advanced Join Clauses' at the end of this file.

A small tip/warning for you : Try to use 'AS' when you make aliases on tables because as far as I am informed Laravel escapes the entire 'ps_feature_value_lang a' expression, which will be considered as table and as a result it will throw an exception. So, I would suggest you to use it like 'ps_feature_value_lang AS a'. In this package/app both cases work, but if you want to take the advantage of escaping fields then consider my suggestion.

Thank you! It works perfect.