Discipulus has asked for the wisdom of the Perl Monks concerning the following question:

Hi wise monks,

I had to work with a MS platform.. I need learn how to deal with MSAccess.

I have the idea to code a script very generic and pass to it parameters to view and edit files MDB.

I have stopped on the firs step: how to pass variable to Sql statements ? Many examples I have found does not run on my machine.
use Win32::ODBC(); my($db) = new Win32::ODBC('viniprova'); $a1='nome'; $a2='categoria'; $a3='item'; $a4='bianco'; my $query2= q! INSERT INTO vini ('$a1', '$a2') VALUES ('$a3', '$a4')!; $db->Sql($query2); $db->Close(); print "errore: ".Win32::ODBC::Error()."\n";
It dont wont to run with '$a1', "$a1", ("$a1", \'$a1\'
any idea ?

Replies are listed 'Best First'.
Re: win32::ODBC passing values to Sql statment
by Tanalis (Curate) on Dec 20, 2002 at 13:08 UTC
    Heys,

    q// isn't interpolated - so $a1 (for example) will get passed into the SQL string as (literally) "$a1", not as "nome".

    Try changing q// for qq//, which does interpolate variables, and that should hopefully solve the problem.

    See perldoc for more info about the string quoting operators.

    Hope that helps ..
    -- Foxcub

    Update: Clarified stuff a little.

      OH MY GOD ! when a tree make the forest invisible !!!
      thanks lor*
Re: win32::ODBC passing values to Sql statment
by CountZero (Bishop) on Dec 20, 2002 at 20:30 UTC

    My suggestion would be to drop Win32::ODBC alltogether and start database access coding with DBI and DBD. It is more portable and if you ever have to change the type of database you use, all you do is plug in a new DBD module and perhaps make some very small changes to your scripts.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      Also, there are probably a lot more people familiar with DBI and the various DBD backends than there are with Win32::ODBC so you're likely to get more and better help when you need it.

      --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';