5

结论见底部:

我正在尝试使用 schemacrawler 来绘制一个 sqlite 数据库。我的设置:

  • 操作系统 10.8
  • SchemaCrawler 10.5 从这里下载
  • 从 Oracle 下载的 Java 版本 1.7.0_45
  • sqlite 版本:3.7.12 2012-04-03 19:43:07 86b8481be7e76cccc92d14ce762d21bfb69504af

我在安装 schemacrawler 的目录中,并使用以下命令行:

stebro$ java -classpath lib/*:. schemacrawler.tools.sqlite.Main /Library/Application\ Support/MyApp/Data/MyApp.db -command="select count(*) from myTable" -infolevel=maximum
SchemaCrawler 10.5
Copyright (c) 2000-2013, Sualeh Fatehi.

SchemaCrawler is a database schema discovery and comprehension tool. 
You can search for database schema objects using regular expressions, 
and output the schema and data in a readable text format. You can find 
potential schema design issues with lint. The output serves for 
database documentation is designed to be diff-ed against other database 
schemas. SchemaCrawler also generates schema diagrams.
password: 
java.sql.SQLException: Could not connect to database, for user null
    at schemacrawler.schemacrawler.BaseDatabaseConnectionOptions.getConnection(BaseDatabaseConnectionOptions.java:93)
    at schemacrawler.schemacrawler.BaseDatabaseConnectionOptions.getConnection(BaseDatabaseConnectionOptions.java:70)
    at schemacrawler.tools.commandline.SchemaCrawlerCommandLine.execute(SchemaCrawlerCommandLine.java:173)
    at schemacrawler.tools.commandline.SchemaCrawlerMain.main(SchemaCrawlerMain.java:93)
    at schemacrawler.tools.commandline.SchemaCrawlerMain.main(SchemaCrawlerMain.java:52)
    at schemacrawler.tools.sqlite.Main.main(Main.java:43)
Caused by: java.lang.IllegalArgumentException: Insufficient parameters for database connection URL: missing [database]
    at schemacrawler.schemacrawler.DatabaseConfigConnectionOptions.getConnectionUrl(DatabaseConfigConnectionOptions.java:73)
    at schemacrawler.schemacrawler.BaseDatabaseConnectionOptions.getConnection(BaseDatabaseConnectionOptions.java:89)
    ... 5 more

如果我指定 -password,我会得到同样的错误,并且为 -user 指定不同的值也是如此。Sqlite 不需要用户/密码 - 为什么 jdbc 或 schemacrawler 要求我提供一个?

附录:

下面是一系列特定的命令,它们创建一个简单的数据库,然后尝试使用 schemacrawler 绘制它:

bash-3.2$ sqlite3 MyApp.db
sqlite3 MyApp.db
SQLite version 3.7.12 2012-04-03 19:43:07
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table smbtest(col1 integer, col2 integer);
create table smbtest(col1 integer, col2 integer);
sqlite> ^D 
bash-3.2$ ~/bin/sunjava -classpath lib/*:. schemacrawler.tools.sqlite.Main -database=MyApp.db -infolevel=maximum -command=graph -outputformat=pdf -outputfile=myapp.pdf
SchemaCrawler 10.5
Copyright (c) 2000-2013, Sualeh Fatehi.

SchemaCrawler is a database schema discovery and comprehension tool. 
You can search for database schema objects using regular expressions, 
and output the schema and data in a readable text format. You can find 
potential schema design issues with lint. The output serves for 
database documentation is designed to be diff-ed against other database 
schemas. SchemaCrawler also generates schema diagrams.
password: 

Graphviz was not available to create the requested graph. Please reinstall 
Graphviz, and make it available on the system PATH. Meanwhile, a .dot text file 
has been created instead. This .dot file can be opened in any Graphviz file 
viewer.
java.io.IOException: Cannot run program "dot": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at schemacrawler.tools.integration.graph.ProcessExecutor.execute(ProcessExecutor.java:124)
at schemacrawler.tools.integration.graph.GraphGenerator.generateDiagram(GraphGenerator.java:87)
at schemacrawler.tools.integration.graph.GraphExecutable.executeOn(GraphExecutable.java:123)
at schemacrawler.tools.executable.SchemaCrawlerExecutable.executeOn(SchemaCrawlerExecutable.java:87)
at schemacrawler.tools.executable.BaseExecutable.execute(BaseExecutable.java:77)
at schemacrawler.tools.commandline.SchemaCrawlerCommandLine.execute(SchemaCrawlerCommandLine.java:176)
at schemacrawler.tools.commandline.SchemaCrawlerMain.main(SchemaCrawlerMain.java:93)
at schemacrawler.tools.commandline.SchemaCrawlerMain.main(SchemaCrawlerMain.java:52)
at schemacrawler.tools.sqlite.Main.main(Main.java:43)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:135)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 9 more

最终结论:问题在于我的数据库的路径中有一个空间;反斜杠、双引号或单引号或两者的组合都无法解决问题。从与我的 db 文件相同的目录运行命令就可以了。空间问题可能是由于我不了解在 bash 中使用的正确转义序列 - 如果 schemacrawler 使用我的名字作为命令行的一部分生成其他进程,我可能必须双重转义空格。

但是,该应用程序确实继续询问我的密码,但只需按 Enter 即可成功继续。

4

3 回答 3

1

史蒂夫,

您需要像这样指定数据库:

"-database=/Library/Application Support/MyApp/Data/MyApp.db"

请注意双引号以允许数据库文件路径中的空间,以及 -database 命令行开关。我还删除了反斜杠,因为整个开关都用双引号括起来。

如需命令行帮助,只需运行:

java -classpath lib/*:. schemacrawler.tools.sqlite.Main

Sualeh Fatehi,SchemaCrawler

于 2013-11-01T23:53:19.607 回答
1

使用 SchemaCrawler 生成 DB Schema ER 图 我们可以使用 SchemaCrawler 可视化我们的 DB 模式 从这里下载最新的包: https ://github.com/sualeh/SchemaCrawler/releases/

复制 _schemacrawler 文件夹并将其重命名为 schemacrawler 到另一个位置并将相同的目录路径添加到 PATH 使用 GraphViz 创建模式图http://sualeh.github.io/SchemaCrawler/diagramming.html

cd 进入 schemacrawler 目录并运行 ./schemacrawler.sh(在 mac 和 ubuntu env 上),选项如下所述。

您可以运行示例命令以获取 postgre db 的 png 图像形式的架构图:

./schemacrawler.sh -command graph -outputformat png -outputfile=dh_er.png -loglevel=CONFIG -server=postgresql -host=localhost -port=5432 -database=testdb -user=testuser -password=testpass -infolevel=standard 

要包含/排除某些表,您需要在 schemacrawler.config.properties 中定义配置,例如:

schemacrawler.table.pattern.include=.*askbot_activityauditstatus |.*askbot_anonymousanswer|.*askbot_anonymousquestion |.*askbot_askwidget|.*askbot_badgedata|.*askbot_bulktagsubscription |.*askbot_bulktagsubscription_groups|.*askbot_bulktagsubscription_tags 

schemacrawler.table.pattern.exclude 是关键。相同的值是 JAVA 正则表达式模式

注意:如果您遇到“服务:无法运行程序“点”:错误=2,没有这样的文件或目录”问题...

 Please install below(for mac only):
 Install the app : brew install graphviz
于 2017-02-14T12:17:44.860 回答
0

我认为您没有-classpath正确指定。我认为您需要一个围绕该命令的包装外壳脚本来扩展每个命令.jarlib以便用:字符分隔:

#!/bin/sh

classpath="."

for j in lib/*.jar
do
    classpath=$classpath:$j
done

java -classpath $classpath schemacrawler.tools.sqlite.Main /Library/Application\ Support/MyApp/Data/MyApp.db -command="select count(*) from myTable" -infolevel=maximum

只是在黑暗中刺伤,但这是我一直这样做的方式。jar显然,如果还必须包含非类路径,这会更加复杂......

于 2013-10-29T14:30:23.023 回答