ruby sqlite3 insert with autoincrement -
i have trouble inserting data sqlite3 database id autoincrement. here have tried far:
begin db = sqlite3::database.open db_name db.execute "create table if not exists audit( id integer primary key autoincrement, module text, hostname text, criticity text, raw_data text );" rescue sqlite3::exception => e puts e.backtrace ensure db.close if db end
and insert data this:
db.execute("insert audit values (module,hostname,criticity,raw_data)", check, hostname, raw_data, criticity )
here error:
#<sqlite3::sqlexception: table audit has 5 columns 4 values supplied>
i don't know how supply id
values should auto-incremented
that's odd error sqlite3::sqlexception: no such column: module
think have wrong format format try,
db.execute("insert audit (module,hostname,criticity,raw_data) values (?,?,?,?) ", 'module', 'host', 'criticity', "\x01\x00\x00\x00\x01")
results:
sqlite> select * audit; 1|module|host|criticity|☺
Comments
Post a Comment