From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Robert Cochran Newsgroups: gmane.emacs.devel Subject: Re: sql.el MariaDB support Date: Thu, 07 Jun 2018 01:48:49 -0700 Message-ID: <874lifm172.fsf@cochranmail.com> References: <874ligy5mh.fsf@cochranmail.com> <83y3fsvudp.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1528361350 25972 195.159.176.226 (7 Jun 2018 08:49:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 7 Jun 2018 08:49:10 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Eli Zaretskii , Robert Cochran , "emacs-devel@gnu.org" To: Michael Mauger Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 07 10:49:06 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fQqbO-0006Yu-Ff for ged-emacs-devel@m.gmane.org; Thu, 07 Jun 2018 10:49:04 +0200 Original-Received: from localhost ([::1]:56392 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQqdV-0007wf-GO for ged-emacs-devel@m.gmane.org; Thu, 07 Jun 2018 04:51:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQqc6-0007u6-OV for emacs-devel@gnu.org; Thu, 07 Jun 2018 04:49:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQqc3-0002mC-94 for emacs-devel@gnu.org; Thu, 07 Jun 2018 04:49:46 -0400 Original-Received: from vps28183.inmotionhosting.com ([23.235.221.66]:57949) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fQqc2-0002If-K2; Thu, 07 Jun 2018 04:49:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cochranmail.com; s=default; h=Content-Type:MIME-Version:Message-ID: In-Reply-To:Date:References:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=DnriPa5dIeP2lpyJ2EKGmH/D2FY/yIsNafampW/D8NI=; b=QVmqpC61wlal3a/4dr2ULIyKD hLtwBINMd88chgnZUavSOktsFBEPIjuc2yRxbuVogTiom99WabnowNk+Ii+iao7wVAYHM1IbkXgLa JPyYjs+AEqJNdMGxk4vli+DCdqdj8jKaxGyNnj5Wv878hGIIfaiqgNAElvB16h0mMc14qVMTV8/tW Uo87pWLLJtQUqOAg7WBbYnrr0XOSqlc1FtRP2X9L8g8gi5ubF6qNs0L6ieRhimG/m/0/wpHWXj9+/ dgyheLCcHSHPe66kjpewWotvUE8kDkH9S5NEDD5ZTZk1a2+hS/ysnR91dte7qN+BUYxv9NmYM1r8i qe9JJitGA==; Original-Received: from 131-191-86-130.as.clicknet.org ([131.191.86.130]:53960 helo=SoraLaptop) by vps28183.inmotionhosting.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fQqbK-00035V-0C; Thu, 07 Jun 2018 01:48:58 -0700 In-Reply-To: (Michael Mauger's message of "Wed, 06 Jun 2018 13:16:20 -0400") X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vps28183.inmotionhosting.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - cochranmail.com X-Get-Message-Sender-Via: vps28183.inmotionhosting.com: authenticated_id: robert@cochranmail.com X-Authenticated-Sender: vps28183.inmotionhosting.com: robert@cochranmail.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 23.235.221.66 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:226090 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Michael Mauger writes: > =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Original = Message =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 > On June 6, 2018 10:53 AM, Eli Zaretskii wrote: >> =E2=80=8B=E2=80=8B >> > From: Robert Cochran robert-emacs@cochranmail.com >> > Date: Tue, 05 Jun 2018 20:07:50 -0700 >> >=20 >> > 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 n= ot >> > 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. >> >=20 >> > Thoughts? >>=20 >> I hope Micheal (CC'ed) will have comments on your proposal. > > Great idea! My recommendation is to create a new sql product/dialect akin= =20 > to mysql in sql.el and either reuse the mysql settings/variables where=20 > appropriate, or create defvaralias's for the mariadb variables pointing b= ack > to the mysql variables.=20 > > 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= =20 > up-to-date with the latest features. It's been a very long time since I u= sed=20 > 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 changing: 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. HTH, --=20 ~Robert Cochran GPG Fingerprint - BD0C 5F8B 381C 64F0 F3CE E7B9 EC9A 872C 41B2 77C2 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-MariaDB-support-to-lisp-progmodes-sql.el.patch Content-Description: Add MariaDB support to sql.el >From e56a3658a809e6737c46930c2387817f97ce3d8f Mon Sep 17 00:00:00 2001 From: Robert Cochran 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) + (ms :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 'sql-mode-mysql-font-lock-keywords) + (defvar sql-mode-sqlite-font-lock-keywords (eval-when-compile (list @@ -4875,6 +4905,44 @@ sql-comint-mysql (list sql-database))))) (sql-comint product params buf-name))) +;;;###autoload +(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 +`*SQL*'. + +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 +buffer. + +To specify a coding system for converting non-ASCII characters +in the input and output to the process, use \\[universal-coding-system-argument] +before \\[sql-mariadb]. You can also specify this with \\[set-buffer-process-coding-system] +in the SQL buffer, after you start the process. +The default comes from `process-coding-system-alist' and +`default-process-coding-system'. + +\(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)) + ;;;###autoload -- 2.17.1 --=-=-=--