fragmenta / fragmenta-cms

A user-friendly CMS written in Go (golang)
http://fragmenta.eu
MIT License
586 stars 70 forks source link

I can't pass DML SQL commands to database #37

Open shahendaeldeeb opened 6 years ago

shahendaeldeeb commented 6 years ago

whenever i try to send custom SQL command to database in q.SQL() it reset q.sql at the end of the function so it send empty q.sql,and also q.sql is being reset in all other function ex.: q.Where(), q.Limit(), q.offSet(), please tell me the difference between q.SQL() and q.Select(). If they both are used to pass sql commands why we don't use q.SQL() for all custom commands?

According to current implementation if we used q.Select() for update/ insert commands it would then need to accept arguments, the same idea of passing arguments to q.Where()

i think we can solve this issue also by creating q.Args() that will append args to q.args that then will be used is q.SQL()/q.Select(). Thanks in advance.

kennygrant commented 6 years ago

Select sets the select sql, rather than the full sql. SQL() was intended for sending arbitrary sql commands. I don't use that much though so will have to try it out to check it is working as intended. Can you give me a test case here that fails to test with (with code?)

shahendaeldeeb commented 6 years ago

First thanks for your reply , In query/query.go , UpdateAll() uses q.Select() for updating resource data , so why here we didn't use q.SQL() ? don't you think that it would be better if we use q.SQL() for update/delete statements. you may try to trace q.SQL() and you will find that you rest q.sql at line 498 before returning.