Saving gzipped string into Sqlite3 via Rails throws unrecognized token error

Not sure if this belongs in the rails forum or here (it's a little of
both)...

I'm using rails 2.3 and I'm trying to compress (gzip) text that I'd
like to save using ActiveRecord into a sqlite database.

However, the compressed text isn't being saved b/c I get this type of
error: SQLite3::SQLException: unrecognized token: "'x##Uˎ#7

Any thoughts on what I can do to avoid this error?

should I compress the text in some other fashion?
should I save the data using some other method(s)?
TIA!!!
Relevant code is below.

···

###########################################
# compress my text
require 'zlib'
defl = Zlib::Deflate
test_string = "<h3>some text</h3>some additional text<p>here's some
more text</p>"
compressed_string = defl.deflate(test_string)
=> "x\234\263\3110\266+\316\317MU(I
\255(\261\321\207\361\022SR2K2\363\363\022s \022\005v\031\251E
\251\352\305\n`\331\334\374\"\230\206\002;\000\0225\027\222"

ModelClass.new(:attribute1 => compressed_string).save
ActiveRecord::StatementInvalid: SQLite3::SQLException: unrecognized
token: "'x#####+##MU(I#(#ч####2K2#### v#E####
################################################

I have no idea if this is what is going on because I haven't worked
much with SQLite, but are you saving to a TEXT field or a BLOB field?
If the field is TEXT, try making it a BLOB and see if that works.

-Jonathan Nielsen

···

On Thu, Mar 25, 2010 at 11:30 PM, pablitoman <thebusyant@gmail.com> wrote:

Not sure if this belongs in the rails forum or here (it's a little of
both)...

I'm using rails 2.3 and I'm trying to compress (gzip) text that I'd
like to save using ActiveRecord into a sqlite database.

However, the compressed text isn't being saved b/c I get this type of
error: SQLite3::SQLException: unrecognized token: "'x##Uˎ#7

Any thoughts on what I can do to avoid this error?

should I compress the text in some other fashion?
should I save the data using some other method(s)?
TIA!!!

Nope. didn't work (thank you, though for the suggestion), but I just
figured out a "workaround"

if you call "dump" on the zipped string, dump will escape everything
problematic.

eval will "unescape" and give you back your zipped string

···

On Mar 26, 1:51 am, Jonathan Nielsen <jonat...@jmnet.us> wrote:

On Thu, Mar 25, 2010 at 11:30 PM, pablitoman <thebusy...@gmail.com> wrote:
> Not sure if this belongs in the rails forum or here (it's a little of
> both)...

> I'm using rails 2.3 and I'm trying to compress (gzip) text that I'd
> like to save using ActiveRecord into a sqlite database.

> However, the compressed text isn't being saved b/c I get this type of
> error: SQLite3::SQLException: unrecognized token: "'x##Uˎ#7

> Any thoughts on what I can do to avoid this error?

> should I compress the text in some other fashion?
> should I save the data using some other method(s)?
> TIA!!!

I have no idea if this is what is going on because I haven't worked
much with SQLite, but are you saving to a TEXT field or a BLOB field?
If the field is TEXT, try making it a BLOB and see if that works.

-Jonathan Nielsen

Sorry, you were right. I had a bug in my code when I was testing your
suggestion. converting the columns to blob worked perfectly.

TKS!

···

On Mar 26, 1:51 am, Jonathan Nielsen <jonat...@jmnet.us> wrote:

On Thu, Mar 25, 2010 at 11:30 PM, pablitoman <thebusy...@gmail.com> wrote:
> Not sure if this belongs in the rails forum or here (it's a little of
> both)...

> I'm using rails 2.3 and I'm trying to compress (gzip) text that I'd
> like to save using ActiveRecord into a sqlite database.

> However, the compressed text isn't being saved b/c I get this type of
> error: SQLite3::SQLException: unrecognized token: "'x##Uˎ#7

> Any thoughts on what I can do to avoid this error?

> should I compress the text in some other fashion?
> should I save the data using some other method(s)?
> TIA!!!

I have no idea if this is what is going on because I haven't worked
much with SQLite, but are you saving to a TEXT field or a BLOB field?
If the field is TEXT, try making it a BLOB and see if that works.

-Jonathan Nielsen