Forum: Ruby on Rails Inserting string with special character in database.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Anubhaw P. (Guest)
on 2009-02-23 07:41
Hi all.
I am having trouble in reading string containing special characters from
file and storing them in database. For example, for string like
'\x89\xA5\xCFI w...'
it throws error "Incorrect string value". The string should be wrappped
in duoble quotes, but i didn't find any method to do so. If any one has
solution please help. I need it very badly.
Thanks.
Jeffrey L. Taylor (Guest)
on 2009-02-23 10:45
(Received via mailing list)
Quoting Anubhaw P. <removed_email_address@domain.invalid>:
>
> Hi all.
> I am having trouble in reading string containing special characters from
> file and storing them in database. For example, for string like
> '\x89\xA5\xCFI w...'
> it throws error "Incorrect string value". The string should be wrappped
> in duoble quotes, but i didn't find any method to do so. If any one has
> solution please help. I need it very badly.

Which database and what character set, e.g. UTF-8, Latin1, ASCII?  Rails
now
defaults to UTF-8, but most databases default to Latin1.

Jeffrey
Anubhaw P. (Guest)
on 2009-02-23 11:17
Jeffrey L. Taylor wrote:
> Quoting Anubhaw P. <removed_email_address@domain.invalid>:
>>
>> Hi all.
>> I am having trouble in reading string containing special characters from
>> file and storing them in database. For example, for string like
>> '\x89\xA5\xCFI w...'
>> it throws error "Incorrect string value". The string should be wrappped
>> in duoble quotes, but i didn't find any method to do so. If any one has
>> solution please help. I need it very badly.
>
> Which database and what character set, e.g. UTF-8, Latin1, ASCII?  Rails
> now
> defaults to UTF-8, but most databases default to Latin1.
>
> Jeffrey

Database is MySql and character set is UTF-8 default.

Anubhaw
Thanks.
Priya B. (Guest)
on 2009-02-23 12:15
Anubhaw P. wrote:
> Hi all.
> I am having trouble in reading string containing special characters from
> file and storing them in database. For example, for string like
> '\x89\xA5\xCFI w...'
> it throws error "Incorrect string value". The string should be wrappped
> in duoble quotes, but i didn't find any method to do so. If any one has
> solution please help. I need it very badly.
> Thanks.

you can give .to_s to convert into string.

a= 123
eg: a.to_s
Jeffrey L. Taylor (Guest)
on 2009-02-23 17:24
(Received via mailing list)
Quoting Anubhaw P. <removed_email_address@domain.invalid>:
> >> solution please help. I need it very badly.
> Thanks.
The first character is a control code in UTF-8, HTJ.  I've tried
assigning and
saving the above character strings in the Rails console.  The saved and
retrieved string is empty, but I'm not seeing the error "Incorrect
string
value".  What is throwing this error?  I also don't understand the part
about
wrapping in double quotes.  Why can't you modify your program to change
single
to double quotes?

Jeffrey
Anubhaw P. (Guest)
on 2009-02-24 09:36
Jeffrey L. Taylor wrote:
> Quoting Anubhaw P. <removed_email_address@domain.invalid>:
>> >> solution please help. I need it very badly.
>> Thanks.
> The first character is a control code in UTF-8, HTJ.  I've tried
> assigning and
> saving the above character strings in the Rails console.  The saved and
> retrieved string is empty, but I'm not seeing the error "Incorrect
> string
> value".  What is throwing this error?  I also don't understand the part
> about
> wrapping in double quotes.  Why can't you modify your program to change
> single
> to double quotes?
>
> Jeffrey

Hi Jeffrey,
Your question solved my trouble. I set the database character set to
Latin1 and it worked. It took the string with special character in DB.

Thanks.
This topic is locked and can not be replied to.