Sqlite3, inserting values in database

hi,
i have a small form of textfields and i need to add these informations
to a table in sqlite3 database. but i dont know how to do it. i mean
that its small address book program. and ‘id’ from ‘clients’ table has
to increments. i open database with : db = Database.open(“data.db”), but
then i dont know what to do…

anyone can help?

Well, if you create your table with the id set as an INTEGER PRIMARY
KEY,
then it will auto-increment for you. You won’t need to do it yourself.
All
you have to do is insert the data. An example would be:

db.execute(“INSERT INTO clients (name,address,phone,email,website)
VALUES(?,?,?,?,?);”,@name.get_value(),@address.get_value(),@phone.get_value(),@email.get_value,@website.get_value())

@name, @address, @phone, @email and @website would be TextCtrl’s that
hold
the data that the user inputed. Then to get them back, you simply do:
db.execute(“SELECT * FROM clients;”) Which returns all rows in the
table.
Or you can narrow down the entries, by doing db.execute(“SELECT * FROM
clients WHERE name=‘Mario S.’;”) Which will return any matches
where
the name column of the row has “Mario S.”

thanks a lot mario. so much.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs