简体   繁体   English

如何使用Emacs连接到SQL Server?

[英]How do I connect to SQL Server using Emacs?

What steps do I take? 我该采取什么措施? Any gotchas to be aware of or tips to enhance the IDE experience that are specific to SQL Server when using Emacs? 在使用Emacs时,是否有任何需要注意或提示增强SQL Server特有的IDE体验?

Connecting

To connect to a SQL Server database instance from Emacs: 要从Emacs连接到SQL Server数据库实例:

M-x sql-ms RET
M-x sql-mode     

You will be prompted for standard connection information specifically the following: 系统将提示您输入标准连接信息,具体如下:

  • User 用户
  • Password 密码
  • Server 服务器
  • Database 数据库

For SQL Server Authentication, type in the necessary user and password info. 对于SQL Server身份验证,请键入必要的用户和密码信息。 However, if connecting via Windows Authentication, then press RETURN for both user and password leaving them blank. 但是,如果通过Windows身份验证进行连接,则按RETURN键同时输入用户名和密码,将其留空。

Viewing Output Results 查看输出结果

Note that to see the text of any output results in the *SQL* buffer, the 'go' statement should be called at some point. 请注意,要查看任何输出的文本结果是* SQL *缓冲区,应该在某个时候调用'go'语句。 A couple of ways of doing this. 有两种方法可以做到这一点。

For example, this sql statement will execute but it will not show any result text in the *SQL* buffer in its current format: 例如,此sql语句将执行,但它不会以*当前格式在* SQL *缓冲区中显示任何结果文本:

select 'foo' as bar

However, if a 'go' is appended to the end: 但是,如果在末尾附加'go':

select 'foo' as bar
go

the following will be displayed in the *SQL* buffer: 以下内容将显示在* SQL *缓冲区中:

 bar   
 ----- 
 foo

(1 row affected)

Alternatively, if you do not want to have 'go' statements littering the text of your SQL script then call 'go' on the fly to see all output results since the last time that the previous 'go' statement was sent to the sql process: 或者,如果你不想让'go'语句乱丢你的SQL脚本文本,那么随时调用'go'来查看自上次将'go'语句发送到sql进程以来的所有输出结果:

C-c C-s go RET

This is helpful if you need to view any error messages that might not initially show in the *SQL* buffer. 如果您需要查看最初可能未在* SQL *缓冲区中显示的任何错误消息,这将非常有用。

首先,看一下SQL模式

sometimes the display of emacs's sql-ms sucks because that some columns displayed are too wide for reading. 有时emacs的sql-ms的显示很糟糕,因为显示的某些列太宽而无法读取。

here are some skills for bad output experience. 这里有一些糟糕的输出体验技巧。

1. 1。

M-x toggle-truncate-lines

toggle truncate-lines can improve some readable. 切换截断线可以提高一些可读性。

2. 2。

select left(columnName, 25) from table

this truncates the column width to 25 characters. 这会将列宽限制为25个字符。 This works perfect for me. 这对我来说很完美。

source is here: http://bloggingmath.wordpress.com/2011/02/03/using-emacs-as-your-sql-interface/ 来源在这里: http//bloggingmath.wordpress.com/2011/02/03/using-emacs-as-your-sql-interface/

Also, see here: 另外,请看这里:

https://github.com/kiwanami/emacs-edbi https://github.com/kiwanami/emacs-edbi

This way i just use odbc to connect to everything through DBD::ODBC. 这样我只需使用odbc通过DBD :: ODBC连接到所有内容。

The author mentions "gotchas" when trying to connect to an SQL server. 作者在尝试连接SQL服务器时提到了“陷阱”。

When trying to connect to a mysql server, which as the top-voted answer suggests is done via Mx sql-mysql , I found that I continually got 当试图连接到一个mysql服务器时,我通过Mx sql-mysql完成了最高投票的答案,我发现我不断得到

Unable to locate SQL program 'mysql' 无法找到SQL程序'mysql'

Following the suggestion at this SO question concerning emacs, sql and Macs , I set the following value: 根据有关emacs,sql和Macs的SO问题的建议,我设置了以下值:

(setq sql-mysql-program "/usr/local/mysql/bin/mysql")

which was the location/path to my local mysql binary. 这是我本地mysql二进制文件的位置/路径。

Don't know why this variable is not mentioned in any other tutorials I've seen, so I post this here, as an aforementioned "gotcha" when connecting to a mysql server. 不知道为什么在我见过的任何其他教程中都没有提到这个变量,所以我在这里发布,作为前面提到的“gotcha”连接到mysql服务器时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM