SQLite/ActiveRecord and Backslashes

Discussion in 'Ruby' started by David Naseby, Oct 5, 2004.

  1. David Naseby

    David Naseby Guest

    I've got a problem with some combination of SQLite, ActiveRecord, and my
    brain. Backslashed strings don't load properly from ActiveRecord, as shown
    by the following script:

    require 'rubygems'
    require 'sqlite'
    require_gem 'activerecord'
    require 'test/unit'

    File.delete( "test.db" ) if File.exist?( "test.db" )
    db = SQLite::Database.new( "test.db", 0644 )
    db.execute <<EOE
    CREATE TABLE samples (
    id INTEGER PRIMARY KEY,
    name VARCHAR( 255 )
    )
    EOE
    db.close

    class Sample < ActiveRecord::Base; end

    ActiveRecord::Base.establish_connection(
    :adapter => "sqlite",
    :dbfile => "test.db"
    )

    class TC_ActiveRecordSqliteError < Test::Unit::TestCase

    def test_backslash
    sample = Sample.new 'name' => '\\'
    assert sample.save
    assert_equal '\\', sample.name ## this works
    sample_copy = Sample.find sample.id
    assert_equal '\\', sample_copy.name ## this fails
    end

    end


    This produces:
    1) Failure:
    test_backslash(TC_ActiveRecordSqliteError)
    [C:/Clients/newlite/spike/error.rb:30]:
    <"\\"> expected but was
    <"\\\\">.

    Anyone have any idea whats wrong, or how to fix it?

    David
    http://homepages.ihug.com.au/~naseby/
     
    David Naseby, Oct 5, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWF0dCBIYW1pbHRvbg==?=

    GridView and Backslashes

    =?Utf-8?B?TWF0dCBIYW1pbHRvbg==?=, May 2, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    376
    =?Utf-8?B?TWF0dCBIYW1pbHRvbg==?=
    May 2, 2006
  2. Iki
    Replies:
    1
    Views:
    110
    Gavin Sinclair
    Aug 12, 2004
  3. Carl Youngblood
    Replies:
    1
    Views:
    262
    Carl Youngblood
    Apr 9, 2005
  4. Phil Rhoades
    Replies:
    3
    Views:
    182
    Logan Capaldo
    Dec 20, 2005
  5. Replies:
    4
    Views:
    375
Loading...

Share This Page