Single Quote Causing Syntax Error in Command Line Osql PERL script.


I'm loading data into a database after doing processing on the values. I'm having an issue with the syntax of the call whenever my data contains a single quote. I have tried substituting out the single quote with an escaped quote but that does not work.

This is the error I get:
Msg 105, Level 15, State 1, Server HOME_DEV, Line 1
Unclosed quotation mark after the character string '

$ProductDescription =~ s/'/\'/i;

system("osql -Q \"insert into Table1 (ProductName, ProductDescription) values ('$ProductName','$ProductDescription')\" -S $LocalDBServer -d $LocalDBName -U $DBUser -P $DBPass");

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I would highly recommend using DBI and DBD::<db> modules rather than doing a system call to do the insert.

At a guess, you could also try:

$ProductDescription =~ s/'/''/g;

Some databases use double-single-quotes to escape a quote rather than \'.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maddhacker24Author Commented:
I made the switch over to DBI::ODBC and used the double single quote.

That did the trick. Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.