开发者

The request is not determined by the text

Where is the mistake?

If a request for hard-coded 'test' instead @edit.text then a success, but if using a variable then the request fails.

require 'sqlite3'

Shoes.app do

  db = SQLite3::Database.new("test.db")
  db.execute("create table t1 ( one VARCHAR(30), two INTEGER )")
  db.execute("insert into t1 ( one, two ) values ('test', 55)")

  @edit = edit_line

  button 'Search' do
    db.execute("select * from t1 where one = ?", @edit.text) do |rows|
      @test_out.text = rows
    end
  end

  @test_out = para ''

end
开发者_Python百科

PS After some experimentation, I decided that question this way:

button 'Search' do
  text = @edit.text.force_encoding("UTF-8")
  db.execute("select * from t1 where one = ?", text) do |rows|
  @test_out.text = rows
  end
end

but my file encoding UTF-8

or as follows:

button 'Search' do
  text = ''
  @edit.text.each_char { |ch| text << ch }
  db.execute("select * from t1 where one = ?", text) do |rows|
  @test_out.text = rows
  end
end

why this strange behavior?


It works

db.execute("select * from t1 where one = ?", "#{@edit.text}") do |rows|
  @test_out.text = rows
end

but it's really, really odd. I'll try to figure it out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜