ygrek / sqlgg

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

bug when inserting one column #7

Closed gdsfh closed 10 years ago

gdsfh commented 10 years ago

I have some.sql:

create table test1 (x integer not null);
-- @ins1
insert into test1 values;
-- @ins2
insert into test1 (x) values;

Then I generate some.ml:

sqlgg -gen caml -name Make some.sql > some.ml

Both functions are wrong:

  let ins1 db ~ =
    let set_params stmt =
      let p = T.start_params stmt 1 in
      T.set_param_Int p 0 ;
      T.finish_params p
    in
    T.execute db "insert into test1 values (@)" set_params 

  let ins2 db ~ =
    let set_params stmt =
      let p = T.start_params stmt 1 in
      T.set_param_Int p 0 ;
      T.finish_params p
    in
    T.execute db "insert into test1 (x) values (@)" set_params 

This bug appears when insert statement has one column, and it doesn't matter how many columns has table actually.