Inserting string with special character in database.

30 مرّة مشاهدة
التخطي إلى أول رسالة غير مقروءة

Anubhaw Prakash

غير مقروءة،
23‏/02‏/2009، 12:41:47 ص23‏/2‏/2009
إلى rubyonra...@googlegroups.com
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.
--
Posted via http://www.ruby-forum.com/.

Jeffrey L. Taylor

غير مقروءة،
23‏/02‏/2009، 3:44:22 ص23‏/2‏/2009
إلى rubyonra...@googlegroups.com
Quoting Anubhaw Prakash <rails-mai...@andreas-s.net>:
>
> 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 Prakash

غير مقروءة،
23‏/02‏/2009، 4:17:19 ص23‏/2‏/2009
إلى rubyonra...@googlegroups.com

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

Anubhaw

Priya Buvan

غير مقروءة،
23‏/02‏/2009، 5:15:28 ص23‏/2‏/2009
إلى rubyonra...@googlegroups.com
Anubhaw Prakash 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

غير مقروءة،
23‏/02‏/2009، 10:23:47 ص23‏/2‏/2009
إلى rubyonra...@googlegroups.com

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 Prakash

غير مقروءة،
24‏/02‏/2009، 2:36:33 ص24‏/2‏/2009
إلى rubyonra...@googlegroups.com
Jeffrey L. Taylor wrote:
> Quoting Anubhaw Prakash <rails-mai...@andreas-s.net>:
>> >> 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.

الرد على الكل
رد على الكاتب
إعادة توجيه
0 رسالة جديدة