Mysql escape array

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?

On Jan 23, 2008 11:49 AM, JacobC2 [email protected] 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

Heya

On Jan 23, 2008 6:49 PM, JacobC2 [email protected] 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) }

On Jan 23, 3:37 pm, Thomas W. [email protected] wrote:

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs