Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to connect to sqlite db using schemacrawler using OSX - why is it asking for a user?

See bottom for conclusion:

I'm trying to use schemacrawler to diagram a sqlite database. My setup:

  • OSX 10.8
  • SchemaCrawler 10.5 downloaded from Here
  • Java version 1.7.0_45 downloaded from Oracle
  • sqlite version: 3.7.12 2012-04-03 19:43:07 86b8481be7e76cccc92d14ce762d21bfb69504af

I'm in the directory where I installed schemacrawler, and using this command line:

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

If I specify -password, I get the same error, and specifying various values for -user does the same. Sqlite requires no user/password - why is the jdbc or schemacrawler asking me for one?

Addendum:

Here is a specific series of commands that creates a simple database then attempts to diagram it with 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

Final conclusion: The problem lay in the fact that the path to my db had a space in it; no combination of backslashing, double or single quotes, or both resolved the issue. Running the command from the same directory as my db file did the trick. The space issue may be due to my not understanding the right escape sequences to use in bash - I may have to double-escape the spaces if schemacrawler is spawning other processes using my name as part of the command line.

However, the app did continue to ask for my password, but just pressing enter allowed it to continue successfully.

like image 605
Steve Broberg Avatar asked Nov 01 '22 11:11

Steve Broberg


1 Answers

Steve,

You need to specify the database like this:

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

Notice the double-quotes to allow for the space in the path to the database file, and the -database command-line switch. I also removed the back-slash, since the whole switch in enclosed in double-quotes.

For help on the command-line, simply run:

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

Sualeh Fatehi, SchemaCrawler

like image 104
Sualeh Fatehi Avatar answered Nov 10 '22 05:11

Sualeh Fatehi