From: Michel Date: 2012-04-29T16:52:04+09:00 Subject: Re: ruby/shoes GUI - sqlite, how to isert a variable key in table? --=-Q8mE8Re4o016TFvYaEde Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Le samedi 28 avril 2012 à 22:20 +0900, Michel a écrit : > > >From what I've read[1], sqlite will coerce values into the declared > > datatype of the column[2]. > > > > 1: http://viewsourcecode.org/why/hacking/aQuickGuideToSQLite.html > > 2: http://www.sqlite.org/different.html#typing > > > > It seems that sqlite doesn't have the same behavior in Linux (fedora) > and windows 7. > With this script : > > require 'sqlite3' > var1 = '1' > var2 = 2 > var3 = '3' > var4 = 4 > > puts "var2 (#{var2.class}) = #{var2} --- var4 (#{var4.class}) = > #{var4}" > db = SQLite3::Database.new "Ttest.db" > db.execute "create table t1 (text TEXT, num INTEGER)" > db.execute "insert into t1 (text, num) values (#{var1}, #{var2})" > db.execute "insert into t1 values ( ?, ?)", var3, var4 > db.execute "insert into t1 (text, num) values (5, 6)" > rows = db.execute "select text, num from t1" > rows.each{|t,n| puts "#{t.class} : #{t}, #{n.class} : #{n}"} > db.close > > With linux, ruby 1.8.6, I got : > var2 (Fixnum) = 2 --- var4 (Fixnum) = 4 > String : 1, String : 2 > String : 3, String : 4 > String : 5, String : 6 > > But with Windows 7, ruby 1.8.7, I got : > var2 (Fixnum) = 2 --- var4 (Fixnum) = 4 > String : 1, Fixnum : 2 > String : 3, Fixnum : 4 > String : 5, Fixnum : 6 > > Somebody knows why ? > > Regards, > Michel > If I add : db.type_translation = true just after openning the data base, I get the same result in Linux as in Windows. Sorry, I forgot that. Michel. --=-Q8mE8Re4o016TFvYaEde Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 7bit Le samedi 28 avril 2012 à 22:20 +0900, Michel a écrit :
>From what I've read[1], sqlite will coerce values into the declared
datatype of the column[2].

1: http://viewsourcecode.org/why/hacking/aQuickGuideToSQLite.html
2: http://www.sqlite.org/different.html#typing

It seems that sqlite doesn't have the same behavior in Linux (fedora) and windows 7.
With this script :

require 'sqlite3'
  var1 = '1'
  var2 = 2
  var3 = '3'
  var4 = 4
 
  puts "var2 (#{var2.class}) = #{var2} --- var4 (#{var4.class}) = #{var4}"
  db = SQLite3::Database.new "Ttest.db"
  db.execute "create table t1 (text TEXT, num INTEGER)"
  db.execute "insert into t1 (text, num) values (#{var1}, #{var2})"
  db.execute "insert into t1 values ( ?, ?)", var3, var4
  db.execute "insert into t1 (text, num) values (5, 6)"
  rows = db.execute "select text, num from t1"
  rows.each{|t,n| puts "#{t.class} : #{t}, #{n.class} : #{n}"}
  db.close

With linux, ruby 1.8.6, I got :
var2 (Fixnum) = 2 --- var4 (Fixnum) = 4
String : 1, String : 2
String : 3, String : 4
String : 5, String : 6

But with Windows 7, ruby 1.8.7, I got :
var2 (Fixnum) = 2 --- var4 (Fixnum) = 4
String : 1, Fixnum : 2
String : 3, Fixnum : 4
String : 5, Fixnum : 6

Somebody knows why ?

Regards,
Michel

If I add : db.type_translation = true just after openning the data base, I get the same result in Linux as in Windows.
Sorry, I forgot that.
Michel.



--=-Q8mE8Re4o016TFvYaEde--