Posted by funwithdolphin on 2007-05-09 04:47
Forums: ActivePerl discussion | OS: Windows

I have a perl script file fetch1.pl containing following code:


start_reading();
sub start_reading
{
print "Testtable usernames...\n";
use Win32::ODBC;
#$db = new Win32::ODBC( "MyDsn" ) || die "Error: " . Win32::ODBC::Error(); my($db) = new Win32::ODBC("dsn=MyDsn; uid=system; pwd=meta"); $db->Sql("SELECT * FROM test_perl");
while( $db->FetchRow() )
{
my( %Data )= $db->DataHash();
print "User: $Data{USERNAME}\n";
}
$db->Close();
}

When I run this code by doing
perl fetch1.pl

It prints following lines:
Testtable usernames...
User: User1
User: User2

But when I am calling the start_reading function from my C++ code, it is crashing.

In my C++ code, I have written something like this


PERL_SET_CONTEXT(my_perl);
SPAGAIN;
ENTER;
SAVETMPS;
PUSHMARK(sp);

It seems that the crash happened because my application was not able to find the information related to Win32:dbc from parsed Perl Script during calling of subroutine of perl script. So I have made the following changes which parse the perl script and will run the perl interpreter.


PERL_SET_CONTEXT(my_perl);
perl_parse(my_perl, xs_init, m_perl_argc, m_perl_argv, NULL); perl_run(my_perl);
SPAGAIN;
ENTER;
SAVETMPS;
PUSHMARK(sp);

Now it doesn’t crash.

But my questions are
Is this problem related to ODBC or PERL?
Apart from running the perl interpreter, is there any other efficient solution to this problem?

Please reply.