试图与Emacs一起使用MySQL的问题 [英] Problems trying to use MySQL in conjunction with Emacs

查看:354
本文介绍了试图与Emacs一起使用MySQL的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,试图与Emacs结合使用MySQL。让我先从相关的版本信息开始:​​

 本地操作系统:Windows XP,SP3 
终端模拟器/ SSH客户端:Putty 0.58
远程操作系统(由uname -a报告):Linux 2.6.19.7(也发生在Linux 2.6.18的另一个安装)
Emacs版本(在远程操作系统上运行):21.3。 1(也发生在Emacs为21.4.1的另一个安装)
MySQL版本(在远程操作系统上运行):4.1.22(也发生在MySQL 5.0.91的另一个安装)
  mysql -uuserid -ppassword 

它只是挂起来。当我杀死mysql进程时,它会报告:

  bash:[XXXXX:2] tcsetattr:参数无效
其中XXXXX是作为已被杀死的mysql进程的父级的bash shell的进程ID。

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



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



我可以找到关于如何使用M-x sql-mysql的文档相当不完整。它没有提供有关如何运行查询的任何信息。 http://www.emacswiki.org/emacs/SqlMode 说,

 键入Mx sql-help RET以阅读在线帮助。 

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

  Mx sql-mysql 

调用MySQL,然后说,

 一旦你有SQLi缓冲区,您可以在缓冲区中输入SQL语句,生成的输出将附加到缓冲区,并生成新的提示。 

缓冲区从未显示提示。我不能单击Emacs的菜单栏中的项目,因为我通过ssh(客户端是putty)连接,而putty似乎没有传输鼠标点击。所以我不能得到Emacs菜单中的SQL或In / Out菜单。



我尝试发送一个Cc(通过键入Cc Cc) * SQL *缓冲区,期望它会导致它退出,就像一个shell缓冲区。令我惊讶的是,在报告之前显示了QUERY的输出:

  Ctrl-C  - 退出! 
处理SQL异常退出代码1

然后我注意到Mx sql-help也说:

 如果你有一个非常复杂的SQL语句,或者如果你正在编写一个过程,你可以在一个单独的缓冲区通过调用Mx sql-mode将新缓冲区放在`sql-mode'中,这个缓冲区的名字可以是任何东西,主要模式的名称是SQL。 

在这个SQL缓冲区(SQL模式)中,您可以将区域或整个缓冲区发送到交互式SQL缓冲区(SQLi模式),结果附加到SQLi缓冲区,而不会干扰您的SQL缓冲区。

所以我创建了一个名为my-sql-buffer的第二个缓冲区,并运行Mx sql-模式。当我输入查询时:

  show tables; 

到该缓冲区并用RET终止它,* SQL *缓冲区中没有任何反应。我尝试将光标定位在查询结尾并键入C-c C-c。底部的minibuffer显示:

 将字符串发送到缓冲区* SQL *。 

,但没有出现在* SQL *缓冲区中。我打了几次C-c C-c。每次微型缓冲区重新显示:

 将字符串发送到缓冲区* SQL *。 

多次输入C-c C-c后,突然输出出现在* SQL *缓冲区中。这是以下输出:

  show tables; 

重复5次!除了最后一次停在中间。这个行为表明某些东西正在缓冲输出。我检查了输出了多少个字节(C-x h M-C- | wc -c),并输出了4096个字节!由于4K是一个通用的缓冲区大小,这证明了我怀疑某些东西正在缓冲输出。但是我不知道缓冲是怎么做的,以及如何关闭缓冲区。



任何人都可以帮我解决一个或多个以下问题:


  1. 如何从emacs中的bash提示符运行mysql可执行文件,并且在调用tcsetattr()时不会挂起?


  2. 如何运行Mx sql-mysql,在* SQL *缓冲区中键入一个查询,实际上让它运行而不使SQL进程退出?


  3. 当我将查询输入到sql-mode中的第二个缓冲区中时,如何将输出刷新到* SQL *?


advTHANKSance为您的帮助。

  Mark Rosenthal $ b $你必须添加(setq sql- mysql-options'(-C-t-f-n))到你的_emacs以使sql-mysql正常工作在Windows上。  M-x描述变量  sql-mysql-options 阅读文档。


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 (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)

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: [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.)

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 Emacs' menubar 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 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:

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

解决方案

You got to add (setq sql-mysql-options '("-C" "-t" "-f" "-n")) to your _emacs to make sql-mysql work on Windows properly. M-x describe-variable sql-mysql-options to read the docs.

这篇关于试图与Emacs一起使用MySQL的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆