Re: last_insert_id failing for table name with double quotes

Joseph Boakye <[email protected]> Thu, 11 Nov 2021 02:49:40 +0000
Newsgroups gmane.comp.db.postgresql.dbdpg
Message-ID <DM6PR04MB7097F438F6832DD025CF96BFBE949@DM6PR04MB7097.namprd04.prod.outlook.com>
--_000_DM6PR04MB7097F438F6832DD025CF96BFBE949DM6PR04MB7097namp_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I have a fix ready to go if I am able to open a pull request, I appreciate =
all of your work and I know you are busy. If I could get some sort of respo=
nse that would be great as my current project is stalled. Thank you all so =
much.

diff --git a/Pg.pm b/Pg.pm
index 2839aab..80ae1c1 100644
--- a/Pg.pm
+++ b/Pg.pm
@@ -351,7 +351,10 @@ use 5.008001;
                 $dbh->set_err(1, 'last_insert_id needs at least a sequence=
 or table name');
                 return undef;
             }
-            my @args =3D ($table);
+            #if table includes double quotes, it would be paired up at thi=
s point. we want to unpair it.
+            my $table_for_query =3D $table;
+            $table_for_query =3D~  s/["]{2}/"/g;
+            my @args =3D ($table_for_query);
             my $schemawhere;
             if (length $schema) {
                 # if given a schema, use that

--_000_DM6PR04MB7097F438F6832DD025CF96BFBE949DM6PR04MB7097namp_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div>I have a fix ready to go if I am able to open a pull request, I apprec=
iate all of your work and I know you are busy. If I could get some sort of =
response that would be great as my current project is stalled. Thank you al=
l so much.</div>
<div><br>
</div>
<div>diff --git a/Pg.pm b/Pg.pm
<div>index 2839aab..80ae1c1 100644</div>
<div>--- a/Pg.pm</div>
<div>+++ b/Pg.pm</div>
<div>@@ -351,7 +351,10 @@ use 5.008001;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$dbh-&gt=
;set_err(1, 'last_insert_id needs at least a sequence or table name');</div=
>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return u=
ndef;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div>
<div>- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;my @args =3D ($table);</div=
>
<div>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#if table includes double q=
uotes, it would be paired up at this point. we want to unpair it.</div>
<div>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;my $table_for_query =3D $ta=
ble;</div>
<div>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$table_for_query =3D~ &nbsp=
;s/[&quot;]{2}/&quot;/g;</div>
<div>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;my @args =3D ($table_for_qu=
ery);</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;my $schemawhere;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (length $schema) {<=
/div>
<span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# if gi=
ven a schema, use that</span><br>
</div>
</body>
</html>

--_000_DM6PR04MB7097F438F6832DD025CF96BFBE949DM6PR04MB7097namp_--