ygrek / sqlgg

SQL Guided (code) Generator
https://ygrek.org/p/sqlgg/
GNU General Public License v2.0
62 stars 20 forks source link

"-params none" + insert .. values #6

Closed gdsfh closed 6 years ago

gdsfh commented 10 years ago

I don't use -params option (so sqlgg assumes -params none as default), but sqlgg generates following code for insert:

let set_params stmt =
  let p = T.start_params stmt 2 in
  T.set_param_Text p 0 name;
  T.set_param_Text p 1 cmdline;
  T.finish_params p
in
T.execute db "insert into worker_profile (name, cmdline) values (@name,@cmdline)" set_params

Here parameters are named, and error passes through compile-time to run-time (since my current rdbms cannot into named parameters), which is not in the spirit of sqlgg:

Fatal error: exception Mysql.Error("Prepared.execute : Got 2 parameters, but expected 0")
ygrek commented 10 years ago

This appears to be an unfortunate feature conflict, but it is easily overridable with explicit -params unnamed. There is a difference between none and unnamed. none means do not change anything in the query. But values list is generated by sqlgg and it is generated with named parameters. I think it would be best to remove -params none altogether and make -params unnamed the default..

gdsfh commented 10 years ago

Both @param and ? in query works with none (sqlgg treat them as parameters). Also none is an useful mode. So maybe it's better to fail with error when -params none is set and sqlgg needs to generate (@col1, @col2, ...)? So that user could either set -params <not-none> or supply (@col1, @col2 ...) or (?, ? ...) manually, depending on whether he really needs none.

ygrek commented 10 years ago

Thanks, agree with your analysis. The only question is whether none is really needed. Reducing complexity is always a win.