Re: Calling a PostgreSQL function via DBI




Christian,
As an example, I'd do the following:

$arg1 = "$cookieValue" . "::numeric";
...

$result = $dbh->prepare ( "insert into kunden ( kid, nachname, ..., )
values ( ?, ?, ... )" );

$sqls->bind_param(1, $user_nummer);
$sqls->bind_param(2, $nachname);
...

$sqls->execute();
$sqls->finish();

That will take care of your inserting issues. the "bind_param()" function
takes care of the variables and puts them in a 'proper' form.


As for your select statement with the $arg1, ..., $argN, the bind_param()
function will work on those arguments too, I'd just suggest to use the
process of double quoting your string concatenation assignments upfront:

$arg1 = "$someVariable" . "::someText";

Hope this helps.

No, the question here is to call a self-defined PLpgsql-function.
This is the function:
CREATE OR REPLACE FUNCTION neue_auktion ( numeric, text, text, TIMESTAMP,
TIMESTAMP, numeric, numeric, numeric ) RETURNS text AS $$
DECLARE
my_kunden_id ALIAS FOR $1;
my_name ALIAS FOR $2;
my_beschreibung ALIAS FOR $3;
my_startzeit ALIAS FOR $4;
my_endzeit ALIAS FOR $5;
my_startpreis ALIAS FOR $6;
my_preis ALIAS FOR $7;
my_kategorie ALIAS FOR $8;

BEGIN

INSERT INTO auktionen ( kid, name, beschreibung, startzeit, endzeit,
startpreis, preis, katid ) VALUES ( my_kunden_id, my_name, my_beschreibung,
my_startzeit, my_endzeit, my_startpreis, my_startpreis, my_kategorie );

RETURN 'OK';
END;
$$
LANGUAGE plpgsql;

if a call it on the psql-shell, I do it with this syntax:
SELECT neue_auktion ( 1::numeric, 'robot'::text, 'robot'::text, '1999-01-08
04:05:06'::timestamp, '1999-01-08 04:05:06'::timestamp, 10::numeric,
10::numeric, 1::numeric);

this works.

But in perl there is something that doesn't fit. I try it now this way:
$arg1 = $cookieValue . "::numeric";
$arg2 = "$ueberschrift" . "::text";
$arg3 = "$beschreibung" . "::text";
$arg4 = "$system_zeit" . "::timestamp";
$arg5 = "2001-11-11 11:11:11" . "::timestamp";
$arg6 = "$startpreis" . "::numeric";
$arg7 = "$startpreis" . "::numeric";
$arg8 = "$kategorie_nummer" . "::numeric";


$result = $dbh->prepare ( "SELECT neue_auktion ( $arg1, '$arg2', '$arg3',
'$arg4', '$arg5', $arg6, $arg7, $arg8 ) " ) or die "Vorbereitung nicht
durchfuehrbar!\n";
$result->execute() or die "Abfrage nicht ausfuehrbar -suchprofil!
$DBI::errstr\n";
$result->finish();

But there is still a error-dump which "invalid syntax for Typ timestamp:
»2000-01-01 08:08:23::timestamp«

I tried it also without brackets for the time-values:
$arg4 = $system_zeit . "::timestamp";
$arg5 = 2001-11-11 11:11:11 . "::timestamp";

But this has the same effect.

Gruss Christian

--
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner
.



Relevant Pages

  • Re: MII/GRS Resource Names
    ... Define an alias for the name on each system. ... We don't have to care, ... For IBM-MAIN subscribe / signoff / archive access instructions, ... send email to listserv@xxxxxxxxxxx with the message: GET IBM-MAIN INFO ...
    (bit.listserv.ibm-main)
  • Re: IMS shuts down
    ... the 5.5 Information Store and the IMC. ... This should take care of the problem. ... Please do not send mail directly to this alias. ... > Please let me know an alternative solution, ...
    (microsoft.public.exchange.admin)
  • Re: Unpatched Windows PCs fall to hackers in under 5 minutes
    ... Dan Silly, you can kiss my a$$, and you keep your dime a dozen Lone ... You're a strange little Lone Ranger, ... yourself have tangled with Alias when you first hit the NG, ... Do you think I care about it? ...
    (microsoft.public.windows.vista.general)
  • Re: Pirated XP, means-test everyone and every product with "income
    ... See my earlier posts if you require explanation. ... don't care. ... >> Alias, you are needlessly confrontational, but you have a good ...
    (microsoft.public.windowsxp.general)
  • Re: [OT] New Firefox/Mozilla Critical Update
    ... HeyBub wrote: ... > Alias wrote: ... >> updates. ... > And we care about this exactly why? ...
    (microsoft.public.windowsxp.general)