[gradsusr] read from grib and insert into mysql

claudiomet claudiomet at gmail.com
Wed Jul 4 16:10:51 EDT 2012


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!




More information about the gradsusr mailing list