perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mathias Hennersdorf" <mathiashennersd...@web.de>
Subject Perl + C + DBI
Date Thu, 15 May 2003 12:33:34 GMT
Hi!

I`ve a big problem:
I `ve written 2 scripts, one in perl (db_connect.pl) and one in c
(connect.c).
The C-Script shoul connect to a DB by the Perlskript.
But i doesn`t get any result.

Greetings

Mathias

Here the scripts, every idea is welcome:

connect.c

#include <EXTERN.h>
#include </usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE/perl.h>
#include </usr/include/stdio.h>

#ifdef __cplusplus
#  define EXTERN_C extern "C"
#else
#  define EXTERN_C extern
#endif

static PerlInterpreter *my_perl;

static void xs_init (pTHX);

EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);

EXTERN_C void
xs_init(pTHX)
{
char *file = __FILE__;
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}

PerlOpenDB(char *db_name)
{
int a;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(db_name,a)));

PUTBACK;
call_pv("db_connect", G_SCALAR);
SPAGAIN;
printf("db open: %d wurde %d geƶffnet!\n",db_name,POPi);
PUTBACK;
FREETMPS;
LEAVE;
}

int main (int argc, char **argv, char **env)
{
char *loader[] = { "", "db_connect.pl" };

my_perl = perl_alloc();
perl_construct( my_perl );

perl_parse(my_perl, xs_init, argc, loader, NULL);
//perl_parse(my_perl, NULL, 2, my_argv, (char **)NULL);
perl_run(my_perl);

PerlOpenDB("testdb");

perl_destruct(my_perl);
perl_free(my_perl);
}


the perl-script:


#!/usr/bin/perl -w

use DBI;

sub db_open_pg
{
$data_source_pgsql="dbi:Pg:dbname=$db_name";

$dbuser="postgres";
$dbpass="";


$dbh_pgsql = DBI -> connect ($data_source_pgsql, $dbuser, $dbpass );

print "Errors: $DBI::err, $DBI::errstr\n" if ($DBI::err || $DBI::errstr);
if (! defined $dbh_pgsql)
{
print "No connection to:$db_name: $DBI::errstr\n";
$opendb=0;

}
else
{
print "Connect to $db_name !\n";
$opendb=1;
}

return $opendb;
}



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Mime
View raw message