我遇到了一个问题,试图将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连接的特征波特率、奇偶校验等等。显然,对于伪tty来说,大部分属性都是无关的。看起来,“mysql”可执行文件试图执行一些在Emacs缓冲区上下文中不能工作的硬件控制。
当我进一步研究时,我发现Emacs有一个名为sql的Lisp函数,它听起来像是直接运行MySQL查询。对我来说听起来不错。但当我尝试的时候我遇到了不同的问题。
我所能找到的关于如何使用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."缓冲区从未显示提示符。我不能点击Emacs‘menubar中的项目,因为我是通过ssh连接的(客户端是putty),而putty似乎没有发送鼠标单击。因此,我无法获得Emacs‘menubar中的"SQL“或" in /Out”菜单。
我尝试向*SQL*缓冲区发送C-c (输入c C-c),希望这会导致它退出,就像shell缓冲区一样。令我惊讶的是,它显示了我在报告之前输入的查询的输出:
Ctrl-C -- exit!
Process SQL exited abnormally with code 1然后,我注意到M help还说:
"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缓冲区”,并运行my-模式。当我键入查询时:
show tables;进入该缓冲区并使用RET终止它,*SQL*缓冲区中什么都不会发生。我尝试将光标定位在查询的末尾,然后输入c。底部的微型缓冲器显示:
"Sent string to buffer *SQL*."但是*SQL*缓冲区中没有出现任何内容。我又打了几次。每次小型缓冲区重新显示时:
"Sent string to buffer *SQL*."在多次输入c之后,*SQL*缓冲区中突然出现了输出。它的产出来自:
show tables;重复5次!只是上次停在中间。这种行为意味着某种东西正在缓冲输出。我检查了输出了多少字节(C、M C- -c),并输出了4096字节!由于4K是一个常见的缓冲区大小,这证实了我的怀疑,什么东西正在缓冲输出。但我不知道是什么在做缓冲和如何关闭缓冲。
有人能帮我解决以下一个或多个问题吗?
如何从emacs内的bash提示符运行mysql可执行文件,而当它调用tcsetattr()?
。
advTHANKSance感谢您的帮助。
Mark Rosenthal发布于 2011-02-14 02:26:21
您必须将(setq sql-mysql-options '("-C" "-t" "-f" "-n"))添加到_emacs中,以使sql在_emacs上正常工作。M-x describe-variable sql-mysql-options来读取文档。
https://stackoverflow.com/questions/4879206
复制相似问题