MySQL 符合多数据库的在线SQL语法检查器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5015613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Online SQL syntax checker conforming to multiple databases
提问by Phani
Is there any site available online for verifying the syntax which conforms to multiple databases?
是否有任何网站可以在线验证符合多个数据库的语法?
For example: If I have a SQL statement with a 'usage' keyword, then the site should throw me an error saying that 'usage' keyword is reserved in MYSQL?
例如:如果我有一个带有 'usage' 关键字的 SQL 语句,那么该站点应该向我抛出一个错误,说 'usage' 关键字是在 MYSQL 中保留的?
回答by Gary Myers
You could try a formatter like this
你可以尝试像格式化这个
They will always be limited because they don't (and can't) know what user defined functions you may have defined in your database (or which built-in functions you have or don't have access to).
它们将始终受到限制,因为它们不(也不能)知道您可能在数据库中定义了哪些用户定义的函数(或者您可以访问或无法访问哪些内置函数)。
You could also look at ANTLR (but that would be an offline solution)
你也可以看看 ANTLR (但这将是一个离线解决方案)
回答by Infotekka
Have you tried http://www.dpriver.com/pp/sqlformat.htm?
回答by Michael Broughton
I haven't ever seen such a thing, but there is this dev tool that includes a syntax checker for oracle, mysql, db2, and sql server... http://www.sqlparser.com/index.php
我从来没有见过这样的东西,但是有一个开发工具,它包括一个用于 oracle、mysql、db2 和 sql server 的语法检查器... http://www.sqlparser.com/index.php
However this seems to be just the library. You'd need to build an app to leverage the parser to do what you want. And the Enterprise edition that includes all of the databases would cost you $450... ouch!
然而,这似乎只是图书馆。您需要构建一个应用程序来利用解析器来执行您想要的操作。而包含所有数据库的企业版将花费您 450 美元...哎哟!
EDIT: And, after saying that - it looks like someone might already have done what you want using that library: http://www.wangz.net/cgi-bin/pp/gsqlparser/sqlpp/sqlformat.tpl
编辑:而且,说完之后-看起来有人可能已经使用该库完成了您想要的操作:http: //www.wangz.net/cgi-bin/pp/gsqlparser/sqlpp/sqlformat.tpl
The online tool doesn't automatically check against each DB though, you need to run each manually. Nor can I say how good it is at checking the syntax. That you'd need to investigate yourself.
在线工具不会自动检查每个数据库,但您需要手动运行每个数据库。我也不能说它在检查语法方面有多好。你需要自己调查。
回答by RemoteSojourner
Only know about this. Not sure how well does it against MySQL http://developer.mimer.se/validator/
只知道这件事。不知道它对 MySQL 的效果如何 http://developer.mimer.se/validator/
回答by OMG Ponies
I don't know of any such, and my experience is that it doesn't currently exist. Most are side by side comparisons of two databases. That information requires experts in all the databases encountered, which isn't common. Versions depend too, to know what is supported.
我不知道有任何这样的,我的经验是它目前不存在。大多数是两个数据库的并排比较。该信息需要所遇到的所有数据库的专家,这并不常见。版本也取决于,以了解支持的内容。
ANSI functions are making strides to ensure syntax is supported across databases, but it's dependent on vendors implementing the spec. And to date, they aren't implementing the entire ANSI spec at a time.
ANSI 函数在确保跨数据库支持语法方面取得了长足的进步,但这取决于实施规范的供应商。迄今为止,他们并没有一次实现整个 ANSI 规范。
But you can crowd source on sites like this one by asking specific questions and including the databases involved and the versions used.
但是,您可以通过询问特定问题并包括所涉及的数据库和使用的版本来在此类网站上众包源。
回答by Gnudiff
I am willing to bet some of my reputation that there is no such thing.
我愿意打赌我的一些声誉,没有这样的事情。
Partially because if you are worried about cross-platform SQL compatibility, your best bet in turn is to abstract your database code with some API or ORMtool that handles these things for you, and is well supported, so will deal with newer database versions as they come out.
部分是因为如果您担心跨平台 SQL 兼容性,那么最好的选择是使用一些 API 或ORM工具抽象您的数据库代码,这些工具为您处理这些事情,并且得到很好的支持,因此将处理较新的数据库版本他们出来。
Exact kind of API available to you will be dependent on your programming language/platform. For example, PHP has Pear:DB and others, I personally have found quite nice Python's ORM features implemented in Django framework. I presume there should be some of these things available on other platforms as well.
您可以使用的确切类型的 API 将取决于您的编程语言/平台。例如,PHP 有 Pear:DB 等,我个人发现在Django 框架中实现的 Python 的 ORM 特性非常好。我认为其他平台上也应该有一些这样的东西。