Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113526 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 79858 invoked from network); 14 Mar 2021 23:10:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Mar 2021 23:10:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 87A051804C0 for ; Sun, 14 Mar 2021 16:03:23 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RAZOR2_CF_RANGE_51_100,RAZOR2_CHECK,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 14 Mar 2021 16:03:23 -0700 (PDT) Received: by mail-oi1-f178.google.com with SMTP id v192so25206669oia.5 for ; Sun, 14 Mar 2021 16:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=noMsOBBHbcUrrt5KChTXJD0K45ay0++jLD2t6J57E6Y=; b=STjht8HaQB4b6idp1g3fREexf1fUxuXGHnLCHqdfwTjBfmZrHebG35gitk/XkVk+Ol BwPC6aP6m8jjRHZ0tW8CffLlPXQGsmRvbf2qE5r5tD6sSSSXAU4lHNFViXXlvJcR2IEP C65gJFDlKwhZzGR0tNaWIq7WJf/kNOZNuhkpn08DrHBQK4XJRZ2Bc1iyz0+NCVe6Sx6m sawWPYEr59YrXFlkjcKpRcEDBck8AKw0H3enJDsjPYKE8FvKTXSroW81Y+r2zm6/9sW5 aR/dwmXUw6NLvIVVVtxeqnv5LyY5v/f0xjX5O1I6+gWRBsasd+QOG4/KLH3uDdZRQkdQ OmNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=noMsOBBHbcUrrt5KChTXJD0K45ay0++jLD2t6J57E6Y=; b=Ru/Ghw+rXhk/F2VSFkz13FkT7QPISZvRaZArjENRXtwkew4CWMcb/YCVuq4Utfa1bz c/fZbTlWXApk0meVzHhADNzq6tbgT2klStE8ZM9n/272gHqvufMGLq1FgdXHdkTUon23 x1T3kksRdF8zDu/ve3NfWetqlPHkdsg9x09NZaBNV4JqbZIpIapLtoaTL4v5lfzCAZs1 nSw6bMKQEtvOJCtBMtKKY+ZCtjCQyPTu3r4/Gh3OUxVI76Kddr1NBoZAFCYgWGrNz2S4 2cktYdUlG3cVghwze785MVojFx/4VUTVi760GeLOpUetlixiwIR6kiBMGSs8GT8S8FlD obYg== X-Gm-Message-State: AOAM5329jEsBlvdDVacOWZ7vUh3j6wmgvIcxDHNUP1DgjMUs5y6oRN3L O3S5YCKlHuGlVjD1HkskHSceASpfjKozpo5XqtCs0jq4dWyt2w== X-Google-Smtp-Source: ABdhPJxh2UVPaxZLunip5iVgXb8ET6UuyQGo1xqcoRuBas+VhHY/ykqdF/p0Sp920DwHPMFs/BL2FrDQCQvhSqa8YNI= X-Received: by 2002:a05:6808:2d2:: with SMTP id a18mr17323038oid.152.1615762999828; Sun, 14 Mar 2021 16:03:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 14 Mar 2021 23:03:09 +0000 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="000000000000a563f005bd872314" Subject: Re: [PHP-DEV] PDO::PARAM_INT and pgsql driver From: davidgebler@gmail.com (David Gebler) --000000000000a563f005bd872314 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable The information you were given on StackOverflow is somewhat misleading, since it is referring to the behaviour of PDO::quote(), not anything to do with binding parameters. The referenced bug report is indeed not a bug. Still, I don't really use Postgres but a quick smoke test indicates you're not wrong about the behaviour of bindValue/bindParam on the PG driver when emulation mode is switched off. $pdb->exec('CREATE OR REPLACE FUNCTION baz(in int, out f1 text) AS $$ SELECT CAST($1 AS text) || \' as int\' $$ LANGUAGE SQL;'); $pdb->exec('CREATE OR REPLACE FUNCTION baz(in text, out f1 text) AS $$ SELECT $1 || \' as string\' $$ LANGUAGE SQL;'); var_dump( $pdb->query('SELECT baz(23);')->fetchAll() ); ["baz"]=3D> string(9) "23 as int" var_dump( $pdb->query('SELECT baz(\'23\');')->fetchAll() ); ["baz"]=3D>string(12) "23 as string" $st=3D$pdb->prepare('SELECT baz(?)'); $st->bindValue(1,3,PDO::PARAM_INT); $st->execute(); var_dump($st->fetchAll()); ["baz"]=3D>string(11) "3 as string" Looks like your only option is: $st=3D$pdb->prepare('SELECT baz(CAST(? AS int))'); $st->bindValue(1,3,PDO::PARAM_INT); $st->execute(); var_dump($st->fetchAll()); which gives the expected ["baz"]=3D>string(8) "3 as int" Whether this is a *bug* I can't really say, there might be a reason Postgres is implemented this way on PDO, I don't know, I'm not a Postgres guy. But the funny thing is it works exactly as expected when emulation is switched ON: $pdb->setAttribute(PDO::ATTR_EMULATE_PREPARES,true); $st =3D $pdb->prepare('SELECT baz(?)'); $st->bindValue(1,3,PDO::PARAM_INT); $st->execute(); var_dump($st->fetchAll()); ["baz"]=3D>string(8) "3 as int" Regards, David On Sun, Mar 14, 2021 at 8:19 PM Benjamin Morel wrote: > Hi internals, > > I just stumbled upon what I consider to be a bug with the PDO pgsql drive= r. > *TL;DR: the driver treats parameters bound with PARAM_INT the same as > PARAM_STR.* > > Take the following example: > > ``` > $pdo =3D new PDO('pgsql:host=3Dlocalhost;port=3D5432', 'postgres', 'postg= res'); > > $statement =3D $pdo->prepare(" > SELECT ST_AsText( > ST_Transform( > ST_GeomFromText('POINT(0 0)', 2154), > ? > ) > ) > "); > > $statement->bindValue(1, 4326, PDO::PARAM_INT); > $statement->execute(); > ``` > > This fails with the following message: > > PDOException: SQLSTATE[XX000]: Internal error: 7 ERROR: could not parse > > proj string '4326' > > > This is because the pgsql driver seems to treat everything as PARAM_STR, > despite being explicitly requested to bind the value as PARAM_INT; the > placeholder is therefore replaced with the string '4326' instead of the > integer 4326. > > The problem is, in PostGIS, the ST_Transform() > function has different > signatures with different behaviours depending on whether the second > parameter is an integer or a string. > > As far as I can see, because of this issue, *there is no way to pass an > actual integer to ST_Transform()*, which forces me to use > PostgreSQL-specific cast syntax to get the behaviour I need, in a library > I maintain that's supposed to work with an= y > GIS-enabled database. > > Is there any reason why the pgsql driver doesn't respect PDO::PARAM_STR? > > I asked this question on StackOverflow > , and was pointed to the > following bug, which I'm not sure is directly related, but was closed as > "not a bug": > > https://bugs.php.net/bug.php?id=3D50206 > > *Should this be requalified as a bug and be fixed?* > > Thanks in advance for your consideration, > > =E2=80=94 Benjamin > --000000000000a563f005bd872314--