|Subject:||[h-e-w] Problems trying to use MySQL in conjunction with Emacs|
|Date:||Mon, 31 Jan 2011 21:56:56 -0500|
|User-agent:||Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:188.8.131.52) Gecko/20101207 Thunderbird/3.1.7|
This question actually
has to do with Emacs running under Linux, but I'm not yet a member
of help-gnu-emacs. I just signed up, but the moderator hasn't yet
approved it. Since I've been a member of help-emacs-windows for a
long time, I'm hoping someone here might be able to help. Besides
which, there's a very good chance I'll want to do the same thing
locally in my Windows environment, so it's not entirely irrelevant
to this group.|
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 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:
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:
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 minibuffer redisplayed:
"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:
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?
|[Prev in Thread]||Current Thread||[Next in Thread]|