On Sat, 26 Jun 2004, Meino Christian Cramer wrote:

> Hi,
>
> a problem with "other chars" hits me... :)
>
> I try to read a database of shortwave broadcasters (formatted ascii)
> into a SQLIte-Ruby database.
>
> The initialization is ok, but from time to time the population of the
> db breaks, cause some broadcasters station names include invalid
> chars like
>
> 	   R.N'Djamena
>
> and the "'" kills everything.
>
> Escaping that character in the textfile, which is read to populate
> the db, doesn't work, cause "\'" ist read as "\" + "'", which
> again is one "'" to much.
>
> With mysql there was a method called ".Mysql_escape_string" which
> does this job. In the SQLite and SQLite-Ruby docs I haven't found
> anything similiar...
>
> How can I solve this problem?
>
> Kind regards and thank you very much in advance,
> Meino

fields.map!{|f| f.gsub(%r/'/o, "''")}

~ > sqlite db "create table foo(bar); insert into foo values ('''quoted'''); select * from foo;"
'quoted'



-a
--
===============================================================================
| EMAIL   :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE   :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it. 
|   --Dogen
===============================================================================