2011-02-02 45 views
1

我正在使用MySQL到试图与Emacs的结合使用MySQL的一个问题。让我通过给相关版本信息开始:​​问题试图结合使用Emacs

Local OS: Windows XP, SP3 
Terminal emulator/SSH client: Putty 0.58 
Remote OS (as reported by uname -a): Linux 2.6.19.7 (also happens on another installation whose Linux is 2.6.18) 
Emacs version (running on remote OS): 21.3.1 (also happens on another installation whose Emacs is 21.4.1) 
MySQL version (running on remote OS): 4.1.22 (also happens on another installation whose MySQL is 5.0.91) 

我一直有在Emacs运行shell缓冲,我想运行命令“mysql的”所以我可以运行SQL查询。但如果我输入

mysql -uuserid -ppassword 

它只是挂起。当我杀了MySQL的过程中,它会报告:

bash: [XXXXX: 2] tcsetattr: Invalid argument 
    (where XXXXX is the process id of the bash shell that's the parent of the mysql process that was killed.) 

几年前,我写的C代码调用tcsetattr()设置标志tty设备驱动程序。我记得它是基于一个TTY是通过RS-232连接的想法,和许多您通过tcsetattr()控制的RS-232连接的特性设置属性 - 波特率,奇偶校验等。显然,对于伪ttys,其中大部分是无关紧要的。它看起来像'mysql'可执行文件正在尝试执行一些在Emacs shell缓冲区中不起作用的硬件控制。

正如我进一步调查,我发现,Emacs有一个名为Lisp函数SQL-mysql的这听起来就像是直接运行的MySQL查询。这听起来对我很好。但是当我尝试它时,我遇到了不同的问题。

我能找到的关于如何使用M-X SQL-mysql的什么小的文件是相当不完整的。它没有提供任何有关如何运行查询的信息。 http://www.emacswiki.org/emacs/SqlMode说,

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

所以我做到了。帮助建议运行:

M-x sql-mysql 

调用的MySQL,然后说,

"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." 

缓冲区永远不会显示一个提示。因为我通过SSH连接(客户端是腻子),我不能在Emacs的菜单栏点击物品,腻子似乎并没有传递鼠标点击。所以我无法获取Emacs菜单栏中的“SQL”或“In/Out”菜单。

我试图发送一个C-C(通过键入C-C C-C)到* SQL *缓冲区,预计这将导致其退出,就像一个壳缓冲。出乎我的意料,它表现我输入的查询的输出报告之前:

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

然后我注意到的Mx SQL的帮助也说:

"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." 

所以我创建了一个第二缓冲,将其命名为“my-sql-buffer”并运行Mx sql模式。当我键入查询:

show tables; 

到该缓冲区中,与RET终止它,什么都不会发生在* SQL *缓冲区。我尝试将光标放在查询的末尾并输入C-c C-c。显示底部的小缓冲区:

"Sent string to buffer *SQL*." 

但是没有任何内容出现在* SQL *缓冲区中。我再输入C-c C-c几次。迷你缓冲区重新显示每次:

"Sent string to buffer *SQL*." 

键入C-C C-C几次之后,突然输出出现在* SQL *缓冲区。它是从以下输出:

show tables; 

重复5次!除了最后一次停在中间。这种行为表明有东西在缓冲输出。我检查了输出了多少个字节(C-x h M-C- | wc -c),它输出了4096个字节!由于4K是一个常见的缓冲区大小,这证实了我怀疑某些东西在缓冲输出。但我无法弄清楚什么是缓冲以及如何关闭缓冲。

谁能帮我解决以下一个或多个问题:

  1. 如何运行从bash提示符MySQL的可执行文件内Emacs和当它调用tcsetattr没有它挂()?

  2. 如何运行M-x sql-mysql,将查询键入* SQL *缓冲区并实际让它运行而不使SQL进程退出?

  3. 如何在每次查询后将输出刷新到* SQL *时,我将查询键入到sql模式下的第二个缓冲区中?

advTHANKSance for your help。

Mark Rosenthal 

回答

4

您必须将(setq sql-mysql-options '("-C" "-t" "-f" "-n"))添加到_emacs中才能使sql-mysql在Windows上正常工作。 M-x describe-variablesql-mysql-options阅读文档。