# Sqlite3, inserting values in database

**URL:** <https://www.ruby-forum.com/t/sqlite3-inserting-values-in-database/136580>\
**Category:** wxRuby\
**Created:** [May 3, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/sqlite3-inserting-values-in-database/136580 "2008-05-03T22:13:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerapcik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/edb3f5/32.png) [@gerapcik](https://www.ruby-forum.com/u/gerapcik)\
**Post date:** [May 3, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/sqlite3-inserting-values-in-database/136580/1 "2008-05-03T22:13:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![gerapcik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/edb3f5/32.png) [@gerapcik](https://www.ruby-forum.com/u/gerapcik)\
**Post date:** [May 3, 2008, 11:21pm UTC](https://www.ruby-forum.com/t/sqlite3-inserting-values-in-database/136580/2 "2008-05-03T23:21:11Z")

</div>

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.”

---

<div class="post-metadata">

**Author:** ![gerapcik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/edb3f5/32.png) [@gerapcik](https://www.ruby-forum.com/u/gerapcik)\
**Post date:** [May 3, 2008, 11:37pm UTC](https://www.ruby-forum.com/t/sqlite3-inserting-values-in-database/136580/3 "2008-05-03T23:37:41Z")

</div>

thanks a lot mario. so much.
