From: Michel Date: 2012-04-27T15:52:28+09:00 Subject: Re: ruby/shoes GUI - sqlite, how to isert a variable key in table? --=-zdJxv0uvmgGXnyqqWz9a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Le vendredi 27 avril 2012 à 15:35 +0900, Zachary Scott a écrit : > Hi Danilo, How are you enjoying shoooes? > > Make sure to interpolate those instance variables! > > db.execute "insert into db.table (column-name) values (#{@ivar})" > Yes, you can do like that. But I think that works only with VARCHAR types, because #{var} calls the to_s method on var. Regards, Michel. > > On Thu, Apr 26, 2012 at 10:47 PM, Danilo L. wrote: > > Hello, I am struggling to insert a variable into a table, for example: > > > > > > @name = edit_line > > > > db = SQLite3::Database.new "test.db" > > db.execute "create table teste (teste VARCHAR(25))" > > db.execute "insert into teste (teste) values (@name)" > > > > > > How can I add what has been written in edit line in table? > > > > -- > > Posted via http://www.ruby-forum.com/. > > > --=-zdJxv0uvmgGXnyqqWz9a Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 7bit Le vendredi 27 avril 2012 à 15:35 +0900, Zachary Scott a écrit :
Hi Danilo, How are you enjoying shoooes?

Make sure to interpolate those instance variables!

db.execute "insert into db.table (column-name) values (#{@ivar})"

Yes, you can do like that. But I think that works only with VARCHAR types, because #{var} calls the to_s method on var.
Regards,
Michel.

On Thu, Apr 26, 2012 at 10:47 PM, Danilo L. <lists@ruby-forum.com> wrote:
> Hello, I am struggling to insert a variable into a table, for example:
>
>
> @name = edit_line
>
> db = SQLite3::Database.new "test.db"
> db.execute "create table teste (teste VARCHAR(25))"
> db.execute "insert into teste (teste) values (@name)"
>
>
> How can I add what has been written in edit line in table?
>
> --
> Posted via http://www.ruby-forum.com/.
>


--=-zdJxv0uvmgGXnyqqWz9a--