unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: MBR <mbr@arlsoft.com>
To: help-gnu-emacs@gnu.org
Subject: Problems trying to use MySQL in conjunction with Emacs
Date: Tue, 01 Feb 2011 08:32:04 -0500	[thread overview]
Message-ID: <4D480B54.3020807@arlsoft.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 4505 bytes --]

I'm running into a problem trying to use MySQL in conjunction with 
Emacs.  Let me start by giving the relevant version information:

     Local OS: Windows XP, SP3
     Terminal emulator/SSH client: Putty 0.58
     Remote OS: Linux 2.6.18
     Emacs version (running on remote OS): 21.4.1
     MySQL version (running on remote OS): 5.0.91

I always have a shell buffer running inside Emacs, and I'd like to run 
the command 'mysql' so I can run SQL queries.  But if I type

     mysql -uuserid -ppassword

it just hangs.  When I kill the mysql process, it reports:

     bash: [5423: 2] tcsetattr: Invalid argument

Years ago I wrote C code that called tcsetattr() to set flags for the 
tty device driver.  I remember it being based on the idea that a tty was 
connected via RS-232, and many of the attributes you set via tcsetattr() 
controlled characteristics of the RS-232 connection - baud rate, parity, 
etc.  Obviously, for pseudo-ttys, most of that is irrelevant.  It looks 
like the 'mysql' executable is trying to do some hardware control that 
doesn't work in the context of an Emacs shell buffer.

As I investigated further, I discovered that Emacs has a Lisp function 
named sql-mysql which sounds like it runs MySQL queries directly.  That 
sounded good to me.  But when I tried it I ran into different problems.

What little documentation I could find on how to use M-x sql-mysql was 
rather incomplete.  It didn't give any information on how to run a 
query. http://www.emacswiki.org/emacs/SqlMode says,

     "Type M-x sql-help RET to read the online help."

so I did that.  The help suggests running:

     M-x sql-mysql

to invoke MySQL, and then says,

    "Once you have the SQLi buffer, you can enter SQL statements in the
    buffer.  The output generated is appended to the buffer and a new
    prompt is generated."

The buffer never displayed a prompt.  I can't click on the items in the 
menubar at the top because I'm connecting via ssh (client is putty), and 
putty doesn't seem to transmit mouse clicks.  So I can't get at the 
"SQL" or "In/Out" menus in Emacs' menubar.

I tried sending a C-c (by typing C-c C-c) to the *SQL* buffer, expecting 
that would cause it to exit, just like a shell buffer.  Much to my 
surprise, IT DISPLAYED THE OUTPUT OF THE QUERY I'D ENTERED before reporting:

     Ctrl-C -- exit!
     Process SQL exited abnormally with code 1

I then noticed that M-x sql-help also says:

    "If you have a really complex SQL statement or if you are writing a
    procedure, you can do this in a separate buffer. Put the new buffer
    in `sql-mode' by calling M-x sql-mode.  The name of this buffer can
    be anything.  The name of the major mode is SQL."

    "In this SQL buffer (SQL mode), you can send the region or the
    entire buffer to the interactive SQL buffer (SQLi mode).  The
    results are appended to the SQLi buffer without disturbing your SQL
    buffer."

So I created a second buffer, named it "my-sql-buffer" and ran M-x 
sql-mode.  When I type the query:

     show tables;

into that buffer and terminate it with RET, nothing happens in the *SQL* 
buffer.  I tried positioning my cursor at the end of the query and 
typing C-c C-c.  The minibuffer at the bottom displayed:

     "Sent string to buffer *SQL*."

but nothing appeared in the *SQL* buffer.  I typed C-c C-c a few more 
times.  Each time the minibufferredisplayed:

     "Sent string to buffer *SQL*."

After typing C-c C-c several times, suddenly output appeared in the 
*SQL* buffer.  It was the output from:

     show tables;

repeated 5 times!  Except the last time stopped in the middle.  This 
behavior suggests that something is buffering the output.  I checked how 
many bytes had been output (C-x h M-C-| wc -c) and it had output 4096 
bytes!  Since 4K is a common buffer size, this confirms my suspicion 
that something is buffering the output.  But I can't figure out what's 
doing the buffering and how to turn the buffering off.

Can anyone help me solve one or more of the following problems:

1. How to run the mysql executable from a bash prompt inside emacs and 
not have it hang when it calls tcsetattr()?

2. How to run M-x sql-mysql, type a query into the *SQL* buffer and 
actually get it to run without making the SQL process exit?

3. How to flush the output to *SQL* after each query when I type a query 
into a second buffer that's in sql-mode?

advTHANKSance for your help.

    Mark Rosenthal
    mbr@arlsoft.com <mailto:mbr@arlsoft.com>




[-- Attachment #2: Type: text/html, Size: 6787 bytes --]

             reply	other threads:[~2011-02-01 13:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-01 13:32 MBR [this message]
     [not found] <mailman.4.1296574101.31480.help-gnu-emacs@gnu.org>
2011-02-01 15:41 ` Problems trying to use MySQL in conjunction with Emacs rusi
2011-02-02 21:34 ` Tim X

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://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=4D480B54.3020807@arlsoft.com \
    --to=mbr@arlsoft.com \
    --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.
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).