From: Tim Landscheidt <tim@tim-landscheidt.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Interacting with PostgreSQL
Date: Tue, 24 Nov 2020 23:14:40 +0000 [thread overview]
Message-ID: <87sg8yuz33.fsf@passepartout.tim-landscheidt.de> (raw)
In-Reply-To: X7m/0rcucKx57Wls@protected.rcdrun.com
Jean Louis <bugs@gnu.support> wrote:
> […]
>> | "/usr/bin/psql")))
>> I then add UPDATEs, CREATE FUNCTIONs, test cases, etc.,
>> press [f12] until I am satisfied with the results, remove
>> the test cases, uncomment the COMMIT and then press [f12]
>> for the last time before killing the buffer.
> Sounds complicated to me. If I want direct interactivity then I just
> do {M-x sql-postgres RET} and from inside I use \e or \ev or \ef to
> create some functions or change views, etc.
> emacsclient is opening within Emacs, when I kill it, SQL is
> executed. I do not use any self made functions to interact with
> Emacs.
As a mere mortal :-), when for example I add triggers to
five tables with three test cases (INSERT, UPDATE, DELETE)
each, I will not remember which of the triggers or test
cases have been set/inserted/updated/deleted. Also, my mind
will be focussed on fixing the functions/etc. Worst case is
that I miss that psql has reverted to auto-commit mode and
my not-yet-working trigger/query overwrites good data with
garbage.
So I definitely want to be sure that my changes are (easily)
revertable until they are working properly.
> […]
>> 3. Writing data to the database: These are queries where I
>> want to store data, either single tuples or complex
>> structures. Here again I use an inline Perl script that
>> uses DBI to connect to the database and do all the neces-
>> sary transaction handling, escaping and sanity checks.
> Ha, alright, but not quite. Why use two programming languages when one
> is enough. Somehow complex. Some people like it.
For the same reason why I use PostgreSQL to store data and
not Emacs :-). It is highly unlikely that call-process and
Perl's DBI change in a fundamental way anytime soon, and if
they did, there would probably be millions of users explain-
ing how to migrate to a new system.
> What escaping you need?
> I am using this escaping function:
> (defun sql-escape-string (str)
> "Returnes escaped string for PostgreSQL. If string is `NULL' returns `NULL'"
> (if (null str)
> (setq str "NULL")
> (when (or (string-match "\\\\" str)
> (string-match "'" str))
> (setq str (replace-regexp-in-string "\\\\" "\\\\\\\\" str))
> (setq str (replace-regexp-in-string "'" "''" str))))
> (unless (string= "NULL" str)
> (setq str (format "E'%s'" str)))
> str)
> Maybe I am missing something but so far in last year I did not have
> any incident for using this escaping.
> […]
I prefer to use shell-quote-argument and other prebaked
functions because "did not break yet" means that there is a
chance that I will discover at 3 AM that my data has been
garbled, and now I would have to find the error in my quote
function, fix all the data that has been trashed, and do all
that under time pressure because I have a deadline at 4 AM.
So if I have a working solution with call-process and DBI
that is partially tested every day by millions of users, I
rather not replace just for the sake of replacing it.
Tim
next prev parent reply other threads:[~2020-11-24 23:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-21 23:51 Interacting with PostgreSQL Tim Landscheidt
2020-11-22 1:33 ` Jean Louis
2020-11-24 23:14 ` Tim Landscheidt [this message]
2020-11-25 4:18 ` Jean Louis
2020-11-25 10:37 ` Tim Landscheidt
2020-11-25 14:25 ` Jean Louis
2020-11-25 17:08 ` Tim Landscheidt
2020-11-27 1:40 ` Jean Louis
2020-11-30 3:12 ` Tim Landscheidt
2020-11-30 9:12 ` Jean Louis
2020-11-22 21:33 ` Marcin Borkowski
2020-11-24 20:42 ` Tim Landscheidt
2020-11-27 2:01 ` Jean Louis
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sg8yuz33.fsf@passepartout.tim-landscheidt.de \
--to=tim@tim-landscheidt.de \
--cc=help-gnu-emacs@gnu.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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.