unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] lei_mail_sync: explicit bind for old SQL_VARCHAR compat
Date: Mon, 18 Apr 2022 09:44:01 +0000	[thread overview]
Message-ID: <20220418094401.1771588-1-e@80x24.org> (raw)

This avoids repeated work for incremental "lei import" runs when
users upgrade from 1.7 to current public-inbox.git (and eventually
1.8).

We need the explicit bind_param for fallback calls because
previous bind_param calls are "sticky" for a given statement
handle.  The DBI(3pm) manpage states:

  The data type is 'sticky' in that bind values passed to execute()
  are bound with the data type specified by earlier bind_param()
  calls, if any.  Portable applications should not rely on being
  able to change the data type after the first "bind_param" call.
---
 I feel like a complete fscking moron for taking all this time to
 notice and figure this out :<

 lib/PublicInbox/LeiMailSync.pm | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm
index 85480599..665206a8 100644
--- a/lib/PublicInbox/LeiMailSync.pm
+++ b/lib/PublicInbox/LeiMailSync.pm
@@ -106,12 +106,15 @@ sub get_fid ($$$) {
 	$sth->execute;
 	my ($fid) = $sth->fetchrow_array;
 	if (defined $fid) { # for downgrade+upgrade (1.8 -> 1.7 -> 1.8)
-		$dbh->do('DELETE FROM folders WHERE loc = ? AND fid != ?',
-			undef, $folder, $fid) if defined($dbh);
+		my $del = $dbh->prepare_cached(<<'');
+DELETE FROM folders WHERE loc = ? AND fid != ?
+
+		$del->execute($folder, $fid);
 	} else {
-		$sth->execute($folder); # fixup old stuff
+		$sth->bind_param(1, $folder, SQL_VARCHAR);
+		$sth->execute; # fixup old stuff
 		($fid) = $sth->fetchrow_array;
-		update_fid($dbh, $fid, $folder) if defined($fid) && $dbh;
+		update_fid($dbh, $fid, $folder) if defined($fid);
 	}
 	$fid;
 }
@@ -350,7 +353,8 @@ sub locations_for {
 	}
 
 	# deal with 1.7.0 DBs :<
-	$sth->execute($oidbin);
+	$sth->bind_param(1, $oidbin, SQL_VARCHAR);
+	$sth->execute;
 	while (my ($fid, $uid) = $sth->fetchrow_array) {
 		next if $seen{"$uid.$fid"};
 		push @{$fid2id{$fid}}, $uid;
@@ -366,7 +370,8 @@ sub locations_for {
 	}
 
 	# deal with 1.7.0 DBs :<
-	$sth->execute($oidbin);
+	$sth->bind_param(1, $oidbin, SQL_VARCHAR);
+	$sth->execute;
 	while (my ($fid, $name) = $sth->fetchrow_array) {
 		next if $seen{"$fid.$name"};
 		push @{$fid2id{$fid}}, $name;
@@ -646,7 +651,9 @@ EOM
 	$sth->bind_param(2, $nm, SQL_BLOB);
 	$sth->execute;
 	my @bin = map { $_->[0] } @{$sth->fetchall_arrayref};
-	$sth->execute($fid, $nm);
+	$sth->bind_param(1, $fid);
+	$sth->bind_param(2, $nm, SQL_VARCHAR);
+	$sth->execute;
 	my @old = map { $_->[0] } @{$sth->fetchall_arrayref};
 	my %uniq; # for public-inbox <= 1.7.0
 	grep { !$uniq{$_}++ } (@bin, @old);

                 reply	other threads:[~2022-04-18  9:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220418094401.1771588-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).