[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sql.el MariaDB support

From: Robert Cochran
Subject: Re: sql.el MariaDB support
Date: Thu, 07 Jun 2018 01:48:49 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Michael Mauger <address@hidden> writes:

> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On June 6, 2018 10:53 AM, Eli Zaretskii <address@hidden> wrote:
>> ​​
>> > From: Robert Cochran address@hidden
>> > Date: Tue, 05 Jun 2018 20:07:50 -0700
>> > 
>> > I've decided that I want to spend a little bit of time improving the
>> > MariaDB support in sql.el to make a nicer experience, namely changing
>> > the prompt regexps so that the prompts will actually show up without
>> > having to fiddle with sql-prompt-regexp.
>> > What I'm not so sure about, and thus asking here, is whether or not to
>> > put the MariaDB changes in with the MySQL product? MariaDB is still a
>> > drop-in replacement for MySQL AFAIK, so in my mind it wouldn't be
>> > unreasonable to lump those two together as a single product. But I'm not
>> > well-versed on what doing that may imply.
>> > TBH, I'd rather lump them together, as really all I'm intending to do is
>> > modify the continuation prompt regexps to work for either database, and
>> > making a whole separate MariaDB product would be overkill in my mind.
>> > 
>> > Thoughts?
>> I hope Micheal (CC'ed) will have comments on your proposal.
> Great idea! My recommendation is to create a new sql product/dialect akin 
> to mysql in sql.el and either reuse the mysql settings/variables where 
> appropriate, or create defvaralias's for the mariadb variables pointing back
> to the mysql variables. 
> That is, reuse the font-locking and login setup, but override the prompt 
> string.

Alright, I went that route. I made a copy of the MySQL entry and
modified it to fit MariaDB. I then made most all of the MariaDB
variables defvaralias-es of the MySQL ones. `sql-comint-mariadb' just
calls into `sql-comint-mysql'. MariaDB is almost no different than MySQL
except for the prompt.

> I'd also encourage you to update the shared font-lock settings to get it 
> up-to-date with the latest features. It's been a very long time since I used 
> MySQL so there is some bit-rot there.

I'm probably not your guy on this one. I'm a *very* casual user, so I'd
honestly have no idea where to even start with that. Sorry. :(

So my first attempt is attached below. Doubtless I've done at least a
handful of things wrong, but I can just fix them as we go.

A couple of things I've been thinking about that might be wrong/need

1) Should we try to support a configuration where the MariaDB and MySQL
configuration options differ (aka making MariaDB variables not mere
aliases for the MySQL ones)? Simple-minded me thinks not, that there
wouldn't really be a point in doing that since MariaDB is supposed to be
able to drop-in replace MySQL. But I'm asking anyways.

2) Will it be problematic that the MariaDB entry doesn't have a
:prompt-length? The MariaDB prompt contains the current database, so
there's no real knowing ahead of time how long the prompt will
be. Looking at how it's used, it appears that query text on continuation
lines will be messed up. Maybe it would be close enough to have
:prompt-length be (length "MariaDB []> ") - everything except the
database name?

3) To that end, is it okay that my regexp for matching the database name
is pretty loose? I figured on the first pass that being a little
generous with the match criterion is acceptable, but I wouldn't be
surprised if that wasn't good enough for a final solution.

Well, here goes. Hopefully this won't need tons of rework cycles.

~Robert Cochran

GPG Fingerprint - BD0C 5F8B 381C 64F0 F3CE  E7B9 EC9A 872C 41B2 77C2

>From e56a3658a809e6737c46930c2387817f97ce3d8f Mon Sep 17 00:00:00 2001
From: Robert Cochran <address@hidden>
Date: Thu, 7 Jun 2018 01:13:47 -0700
Subject: [PATCH] Add MariaDB support to lisp/progmodes/sql.el

* lisp/progmodes/sql.el (sql-product-alist): Add MariaDB entry
  (sql-mariadb-program), (sql-mariadb-options),
  (sql-mariadb-login-params), (sql-mode-mariadb-font-lock): New
  variables, aliases of the MySQL equivalents
  (sql-mariadb), (sql-comint-mariadb): New interaction mode
  functions for MariaDB
 lisp/progmodes/sql.el | 68 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index 63428610a5..bc30fc01a6 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -416,6 +416,23 @@ sql-product-alist
      :prompt-regexp "^SQL>"
      :prompt-length 4)
+    (mariadb
+     :name "MariaDB"
+     :free-software t
+     :font-lock sql-mode-mariadb-font-lock-keywords
+     :sqli-program sql-mariadb-program
+     :sqli-options sql-mariadb-options
+     :sqli-login sql-mariadb-login-params
+     :sqli-comint-func sql-comint-mariadb
+     :list-all "SHOW TABLES;"
+     :list-table "DESCRIBE %s;"
+     ;; FIXME: I really don't know what the proper regexp for valid
+     ;; database names is, so just match anything
+     :prompt-regexp "^MariaDB \\[.*]> "
+     :prompt-cont-regexp "^    [\"'`-]> "
+     :syntax-alist ((?# . "< b"))
+     :input-filter sql-remove-tabs-filter)
      :name "Microsoft"
      :font-lock sql-mode-ms-font-lock-keywords
@@ -982,6 +999,17 @@ sql-mysql-login-params
   :version "24.1"
   :group 'SQL)
+;; Customization for MariaDB
+;; MariaDB is a drop-in replacement for MySQL, so just make the
+;; MariaDB variables aliases of the MySQL ones.
+(defvaralias 'sql-mariadb-program 'sql-mysql-program)
+(defvaralias 'sql-mariadb-options 'sql-mysql-options)
+(defvaralias 'sql-mariadb-login-params 'sql-mysql-login-params)
 ;; Customization for Solid
 (defcustom sql-solid-program "solsql"
@@ -2399,6 +2427,8 @@ sql-mode-mysql-font-lock-keywords
 function `regexp-opt'.  Therefore, take a look at the source before
 you define your own `sql-mode-mysql-font-lock-keywords'.")
+(defvaralias 'sql-mode-mariadb-font-lock-keywords 
 (defvar sql-mode-sqlite-font-lock-keywords
@@ -4875,6 +4905,44 @@ sql-comint-mysql
               (list sql-database)))))
     (sql-comint product params buf-name)))
+(defun sql-mariadb (&optional buffer)
+    "Run mariadb by TcX as an inferior process.
+MariaDB is free software.
+If buffer `*SQL*' exists but no process is running, make a new process.
+If buffer exists and a process is running, just switch to buffer
+Interpreter used comes from variable `sql-mariadb-program'.  Login uses
+the variables `sql-user', `sql-password', `sql-database', and
+`sql-server' as defaults, if set.  Additional command line parameters
+can be stored in the list `sql-mariadb-options'.
+The buffer is put in SQL interactive mode, giving commands for sending
+input.  See `sql-interactive-mode'.
+To set the buffer name directly, use \\[universal-argument]
+before \\[sql-mariadb].  Once session has started,
+\\[sql-rename-buffer] can be called separately to rename the
+To specify a coding system for converting non-ASCII characters
+in the input and output to the process, use 
+before \\[sql-mariadb].  You can also specify this with 
+in the SQL buffer, after you start the process.
+The default comes from `process-coding-system-alist' and
+\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
+  (interactive "P")
+  (sql-product-interactive 'mariadb buffer))
+(defun sql-comint-mariadb (product options &optional buf-name)
+  "Create comint buffer and connect to MariaDB."
+  (sql-comint-mysql proudct options buf-name))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]