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 2/3] sqlite: use `BLOB' column type instead of `VARBINARY'
Date: Wed,  4 Dec 2024 19:39:13 +0000	[thread overview]
Message-ID: <20241204193914.3227868-3-e@80x24.org> (raw)
In-Reply-To: <20241204193914.3227868-1-e@80x24.org>

`VARBINARY' isn't actually a documented type for SQLite but
rather the result of MySQL infecting my mind decades ago.
`BLOB' gives it the proper affinity and probably makes it easier
for 3rd-party and one-off scripts to deal with such columns and
should also make things more familiar to existing users.
Surprisingly, this appears to have no functional change with
forward or backwards compatibility since we ->bind_param binary
data with SQL_BLOB on INSERTs anyways to prevent the flexible
typing of SQLite from trying to guess types for us.
---
 lib/PublicInbox/LeiMailSync.pm | 8 ++++----
 lib/PublicInbox/OverIdx.pm     | 4 ++--
 lib/PublicInbox/POP3D.pm       | 4 ++--
 lib/PublicInbox/SharedKV.pm    | 4 ++--
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm
index d23f6b4b..fc7963a1 100644
--- a/lib/PublicInbox/LeiMailSync.pm
+++ b/lib/PublicInbox/LeiMailSync.pm
@@ -61,13 +61,13 @@ sub create_tables {
 	$dbh->do(<<'');
 CREATE TABLE IF NOT EXISTS folders (
 	fid INTEGER PRIMARY KEY,
-	loc VARBINARY NOT NULL, /* URL;UIDVALIDITY=$N or $TYPE:/pathname */
+	loc BLOB NOT NULL, /* URL;UIDVALIDITY=$N or $TYPE:/pathname */
 	UNIQUE (loc)
 )
 
 	$dbh->do(<<'');
 CREATE TABLE IF NOT EXISTS blob2num (
-	oidbin VARBINARY NOT NULL,
+	oidbin BLOB NOT NULL,
 	fid INTEGER NOT NULL, /* folder ID */
 	uid INTEGER NOT NULL, /* NNTP article number, IMAP UID, MH number */
 	/* not UNIQUE(fid, uid), since we may have broken servers */
@@ -80,9 +80,9 @@ CREATE INDEX IF NOT EXISTS idx_fid_uid ON blob2num(fid,uid)
 
 	$dbh->do(<<'');
 CREATE TABLE IF NOT EXISTS blob2name (
-	oidbin VARBINARY NOT NULL,
+	oidbin BLOB NOT NULL,
 	fid INTEGER NOT NULL, /* folder ID */
-	name VARBINARY NOT NULL, /* Maildir basename, JMAP blobId */
+	name BLOB NOT NULL, /* Maildir basename, JMAP blobId */
 	/* not UNIQUE(fid, name), since we may have broken software */
 	UNIQUE (oidbin, fid, name)
 )
diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm
index 10cf8c39..dea6f0fc 100644
--- a/lib/PublicInbox/OverIdx.pm
+++ b/lib/PublicInbox/OverIdx.pm
@@ -389,7 +389,7 @@ CREATE TABLE IF NOT EXISTS over (
 	sid INTEGER, /* Subject ID (IMAP ORDEREDSUBJECT "threading") */
 	ts INTEGER, /* IMAP INTERNALDATE (Received: header, git commit time) */
 	ds INTEGER, /* RFC-2822 sent Date: header, git author time */
-	ddd VARBINARY /* doc-data-deflated (->to_doc_data, ->load_from_data) */
+	ddd BLOB /* doc-data-deflated (->to_doc_data, ->load_from_data) */
 )
 
 	$dbh->do('CREATE INDEX IF NOT EXISTS idx_tid ON over (tid)');
@@ -543,7 +543,7 @@ CREATE TABLE IF NOT EXISTS xref3 (
 	docid INTEGER NOT NULL, /* <=> over.num */
 	ibx_id INTEGER NOT NULL, /* <=> inboxes.ibx_id */
 	xnum INTEGER NOT NULL, /* NNTP article number in ibx */
-	oidbin VARBINARY NOT NULL, /* 20-byte SHA-1 or 32-byte SHA-256 */
+	oidbin BLOB NOT NULL, /* 20-byte SHA-1 or 32-byte SHA-256 */
 	UNIQUE (docid, ibx_id, xnum, oidbin)
 )
 
diff --git a/lib/PublicInbox/POP3D.pm b/lib/PublicInbox/POP3D.pm
index bd440434..1898c89d 100644
--- a/lib/PublicInbox/POP3D.pm
+++ b/lib/PublicInbox/POP3D.pm
@@ -93,7 +93,7 @@ sub create_state_tables ($$) {
 	$dbh->do(<<''); # map publicinbox.<name>.newsgroup to integers
 CREATE TABLE IF NOT EXISTS newsgroups (
 	newsgroup_id INTEGER PRIMARY KEY NOT NULL,
-	newsgroup VARBINARY NOT NULL,
+	newsgroup BLOB NOT NULL,
 	UNIQUE (newsgroup) )
 
 	# the $NEWSGROUP_NAME.$SLICE_INDEX is part of the POP3 username;
@@ -108,7 +108,7 @@ CREATE TABLE IF NOT EXISTS mailboxes (
 	$dbh->do(<<''); # actual users are differentiated by their UUID
 CREATE TABLE IF NOT EXISTS users (
 	user_id INTEGER PRIMARY KEY NOT NULL,
-	uuid VARBINARY NOT NULL,
+	uuid BLOB NOT NULL,
 	last_seen INTEGER NOT NULL, /* to expire idle accounts */
 	UNIQUE (uuid) )
 
diff --git a/lib/PublicInbox/SharedKV.pm b/lib/PublicInbox/SharedKV.pm
index 51ece48d..062d5e3e 100644
--- a/lib/PublicInbox/SharedKV.pm
+++ b/lib/PublicInbox/SharedKV.pm
@@ -32,8 +32,8 @@ sub dbh {
 				($opt->{journal_mode} // 'WAL'));
 		$dbh->do(<<'');
 CREATE TABLE IF NOT EXISTS kv (
-	k VARBINARY PRIMARY KEY NOT NULL,
-	v VARBINARY NOT NULL,
+	k BLOB PRIMARY KEY NOT NULL,
+	v BLOB NOT NULL,
 	UNIQUE (k)
 )
 

  parent reply	other threads:[~2024-12-04 19:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04 19:39 [PATCH 0/3] some SQLite-related things Eric Wong
2024-12-04 19:39 ` [PATCH 1/3] sqlite: avoid incorrect/deprecated `LIKE' use Eric Wong
2024-12-04 19:39 ` Eric Wong [this message]
2024-12-04 19:39 ` [PATCH 3/3] SQLiteUtil: hoist out common create_db code Eric Wong

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=20241204193914.3227868-3-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).