[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Mysql escape array

JacobC2

1/23/2008 5:48:00 PM

I am writing a program that reads a text file and then dumps it into a
mysql database, the problem that I am having is that the array has
illegal characters in it so I need to do an escape_string or something
on it. but how could I do this on an array?
3 Answers

Todd Benson

1/23/2008 6:33:00 PM

0

On Jan 23, 2008 11:49 AM, JacobC2 <jacobc2@gmail.com> wrote:
> I am writing a program that reads a text file and then dumps it into a
> mysql database, the problem that I am having is that the array has
> illegal characters in it so I need to do an escape_string or something
> on it. but how could I do this on an array?
>

You probably should iterate. Look at Array#map!

Todd

Thomas Wieczorek

1/23/2008 8:37:00 PM

0

Heya

On Jan 23, 2008 6:49 PM, JacobC2 <jacobc2@gmail.com> wrote:
> I am writing a program that reads a text file and then dumps it into a
> mysql database, the problem that I am having is that the array has
> illegal characters in it so I need to do an escape_string or something
> on it. but how could I do this on an array?
>

You can use map! or collect! or their non-destructive brothers map and
collect. collect/map apply a method to each element in the array and
return a new array with the results.

# lines is some array
escaped = lines.map { |element| some_mysql_escape(element) }

JacobC2

1/24/2008 8:24:00 PM

0

On Jan 23, 3:37 pm, Thomas Wieczorek <wieczo...@googlemail.com> wrote:
> Heya
>
> On Jan 23, 2008 6:49 PM, JacobC2 <jaco...@gmail.com> wrote:
>
> > I am writing a program that reads a text file and then dumps it into a
> > mysql database, the problem that I am having is that the array has
> > illegal characters in it so I need to do an escape_string or something
> > on it. but how could I do this on an array?
>
> You can use map! or collect! or their non-destructive brothers map and
> collect. collect/map apply a method to each element in the array and
> return a new array with the results.
>
> # lines is some array
> escaped = lines.map { |element| some_mysql_escape(element) }

Thanks that work.