By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,247 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,247 IT Pros & Developers. It's quick & easy.

Need help with string variable insert in MySql

P: n/a
I have a problem with string insert that I hope someone can help me
with.

I'm doint a one-line insert into my database from an other program and
it works perfect (thanks to Bill Karwin):

postupdate mysql -u[user] -p[password] vader -e "INSERT INTO station
(datum,tid,temp1,wspeed,wdeg,wdrpoint,wchill,press ,hum,temp2,temp3,heatindex,tdew1)
VALUES (NOW(),NOW(),$t1$,$wspkph$,$wdrdeg$,$wdrpoint$,$wc hillc$,$barmbar1$,$rh1$,$trhc1$,$tb1$,$heatindexc$ ,$dpc1$)"

My problem is that I want to add a variable that is a string (<10
char) and if I just add it it will return "No column....".

I guess that the string need to be inside ''

How can that be done in this line?

Thanks for any suggestions.

/Micke
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Micke wrote:
I guess that the string need to be inside ''
How can that be done in this line?


It probably depends on the shell environment you're using.
You might have to escape the single-quotes within the double-quotes:

mysql -e "INSERT ... VALUES ( ... \'$stringvalue$\' ... )"

Some shells might permit you to use literal single quotes within your
double-quoted string without escaping:

mysql -e "INSERT ... VALUES ( ... '$stringvalue$' ... )"

The best plan is to read the documentation for the shell you use, or
else do some empirical tests in your shell until you understand the
quoting rules. For example:

echo "one 'two' three"
echo "one \'two\' three"
echo 'one "two" three'
echo 'one \"two\" three'

Regards,
Bill K.
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.