5

我正在尝试编写一个工具,可以将数据库的架构与安装脚本中的 SQL 进行比较。从数据库中获取信息非常简单,但我在解析安装脚本时遇到了一些麻烦。

我使用了一些出现在 Google 上的解析器,但它们似乎有些不完整。理想情况下,我想找到一个相当稳定并且有一半像样文档的开源解析器。

此外,我并不真正关心特定于某些数据库的类型和语法。需要检查的数据库非常简单。

4

6 回答 6

1

I've used SQL Compare and it's excellent.

You could run the install script to create a new db and then compare the existing db to the new db.

于 2008-11-06T16:32:59.530 回答
1

通用 SQL 解析器是不错的。您可能已经找到了它,但是既然您说 SQL 非常简单,它对您没有什么用?

于 2008-11-06T16:03:38.577 回答
1

一些数据库,比如 postgresql,可以让你查询当前的模式。所以你可以换个方向:你可以创建 SQL 语句来查询你需要的字段和表,以查看它们是否在数据库的模式中,而不是尝试获取模式和解析 SQL。

这是一个示例:postgresql 模式元数据

于 2008-11-06T16:04:40.557 回答
0

Seriously, especially for simple databases, your SQL Server has a great SQL parser built in.

Create a schema and load it up. Compare the data, then drop the schema when you're done.

If you're afraid of running the DDL, then perhaps using one of the several, lightweight, embedded servers will do the job for you (like Derby if you run Java).

Then you get the parsed SQL and access to the tables just like you do now.

You have the database, you may as well leverage it if you can.

于 2008-11-06T16:44:36.060 回答
0

如果您有 DDL 来创建表,请解析表名并为此添加一些生成的表名。根据您使用的 SQL 引擎,您有不同的方式来查询架构:

使用 SQLite:

PRAGMA table_info(my_table)
PRAGMA table_info(temporary_my_table)

或在 MySQL 上:

 SELECT table_name, column_name, data_type
FROM information_schema.columns
WHERE table_schema = 'my_schema'
AND (table_name LIKE '%my_table';
于 2009-05-26T08:12:34.550 回答
0

SQL Server 可能能够为您完成其中的一些工作。它提供了一个非常好的依赖关系树,可以通过 SDK 访问。

于 2008-11-06T16:08:34.277 回答