[gradsusr] read from grib and insert into mysql
claudiomet
claudiomet at gmail.com
Wed Jul 4 16:43:20 EDT 2012
I answer to myself, problem solved using escape sequences to write the
doublequotes
'!mysql --user=user --password=password database -e "INSERT INTO
station (date,temp,hum) VALUES(\"'date'\",'temperature','humidity');"'
2012/7/4 claudiomet <claudiomet at gmail.com>:
> Hi users !
>
> I'm trying to create a script who reads variables from a point of grib
> file and insert the content into a mysql database but I'dont have any
> success.
> the simplifies script is like this
>
> -------------------------------
> 'open file.ctl'
> 'set lon -70
> 'set lat -30
> t = 1
> while ( t < 49 )
> 'q time'; date=subwrd(result,3)
> 'd t2'; temperature = subwrd(result,4)
> 'd rh2'; humidity = subwrd(result,4)
> '!mysql --user=user --password=password database -e "INSERT INTO
> station (date,temp,hum) VALUES('date','temperature','humidity');"'
> t=t+1
> endwhile
>
> The main problem in the date, is a string that must be enclosed by
> doublequotes in the insert statement, buy when I put doublequotes the
> script fails, putting the doublaquotes enclosing the word date like
> this:
> '!mysql --user=user --password=password database -e "INSERT INTO
> station (date,temp,hum) VALUES('"date"','temperature','humidity');"'
>
> the insert fails, nothing is inserted in the database because the
> script tries to insert the word date (and without quotes) instead the
> value of the variable date with doublequotes
>
> When I put the doublequotes enclosing 'date' like this:
> '!mysql --user=user --password=password database -e "INSERT INTO
> station (date,temp,hum) VALUES("'date'",'temperature','humidity');"'
> the insert fails and date is empty.
>
> The text is very big and dump into a csv file for apply mysqlimport is
> very very slow, I need to avoid the usage of temporal txt files.
>
> ¿how to put strings (variable) in enclosed by quotes and doublequotes
> in a grads script like a mysql intert?
>
> Best regards!
--
Claudio Cortes
Meteorologo, Ingeniero de proyectos
Micomo S.A. Filial Codelco
Unidad de Negocios Ambientales
www.micomo.cl
---
Claudio Cortes
Meteorologist, Project Engineer
Micomo S.A. Codelco Subsidiary
Environmental Business Unit
www.micomo.cl
More information about the gradsusr
mailing list