SQLite/ActiveRecord and Backslashes

D

David Naseby

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/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[Q] ActiveRecord - Sqlite 1
Using Sqlite for processing 4
Packaging dillema 8

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top