使用 Java schemacrawler,为什么它要扫描我数据库中的每个表?

发布于 2024-12-12 11:09:39 字数 547 浏览 2 评论 0原文

使用 Java schemacrawler,为什么它要扫描我数据库中的每个表?难道不应该只是扫描我在命令行指定的数据库:-database=openfire???

:: schemacrawler batch launcher
@echo off
C:\JDK\bin\java.exe -classpath jtds-1.2.4.jar;schemacrawler-8.8.jar; \
schemacrawler-sqlserver-8.8.jar schemacrawler.tools.sqlserver.Main \
-user=sa -password=password -database=openfire -port=1433 -host=localhost \
-table_types=TABLE -command=schema -schemas=.*\.dbo.* -infolevel=standard \
-loglevel=FINE

Using Java schemacrawler, why is it scanning every table in my database? Shouldn't it just be scanning the database I specified on the command line: -database=openfire ???

:: schemacrawler batch launcher
@echo off
C:\JDK\bin\java.exe -classpath jtds-1.2.4.jar;schemacrawler-8.8.jar; \
schemacrawler-sqlserver-8.8.jar schemacrawler.tools.sqlserver.Main \
-user=sa -password=password -database=openfire -port=1433 -host=localhost \
-table_types=TABLE -command=schema -schemas=.*\.dbo.* -infolevel=standard \
-loglevel=FINE

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太傻旳人生 2024-12-19 11:09:39

好吧,我明白了。 -database 标志只为 sql 驱动程序提供连接路径,它不会影响数据库名称的过滤器。换句话说:

-database=openfire  DOES NOT EQUAL  -schemas=openfire.dbo.*

所以,答案是:

:: schemacrawler batch launcher
@echo off
C:\JDK\bin\java.exe -classpath jtds-1.2.4.jar;schemacrawler-8.8.jar; \
schemacrawler-sqlserver-8.8.jar schemacrawler.tools.sqlserver.Main \
-user=sa -password=password -database=openfire -schemas=openfire.dbo.* \
-port=1433 -host=localhost -table_types=TABLE -command=schema \
-infolevel=standard -loglevel=FINE

我完成的批处理脚本:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
:: first get timestamp of this script
SETLOCAL
FOR /F "skip=1 tokens=2-4 delims=(-)" %%a IN ('"echo.|date"') DO (
    FOR /F "tokens=1-3 delims=/.- " %%A IN ("%DATE:* =%") DO (
        SET %%a=%%A&SET %%b=%%B&SET %%c=%%C))
SET /A "yy=10000%yy% %%10000,mm=100%mm% %% 100,dd=100%dd% %% 100"
FOR /F "tokens=1-4 delims=:. " %%A IN ("%time: =0%") DO @SET \
UNIQUE=%yy%%mm%%dd%-%%A%%B

SET TITLE=Schema Crawler
TITLE=%TITLE%
:: supports DBNAME as argument
IF NOT "%1"=="" (
  SET DBNAME=%1
  C:\JDK\bin\java.exe -classpath jtds-1.2.4.jar;schemacrawler-8.8.jar; \
  schemacrawler-sqlserver-8.8.jar schemacrawler.tools.sqlserver.Main -user=sa \
  -password=password -database=!DBNAME! -schemas=!DBNAME!.dbo.* -port=1433 \
  -host=localhost -table_types=TABLE -command=schema -procedures= \
  -infolevel=lint -loglevel=OFF > !DBNAME!_schema_!UNIQUE!.txt
  GOTO :END
)

:: run minimized
::IF NOT DEFINED PIL (
::    SET PIL=1
 ::   START /MIN "" %~0 %1
 ::   EXIT /B
::)

:: script start
ECHO Working...
OSQL.exe -E -Slocalhost -h-1 -Q"SET NOCOUNT ON;SELECT LTRIM(RTRIM(name)) \
FROM sysdatabases WHERE name NOT IN ('master','tempdb','model','msdb');" \
>dblist.txt
FOR /F "tokens=* delims= " %%I IN (dblist.txt) DO (
  IF NOT "%%I"=="                                                      " (
    SET DBNAME=%%I
    SET DBNAME=!DBNAME: =!
    ECHO !DBNAME!
    C:\JDK\bin\java.exe -classpath jtds-1.2.4.jar;schemacrawler-8.8.jar; \
  schemacrawler-sqlserver-8.8.jar schemacrawler.tools.sqlserver.Main -user=sa \
  -password=password -database=!DBNAME! -schemas=!DBNAME!.dbo.* -port=1433 \
  -host=localhost -table_types=TABLE -command=schema -procedures= \
  -infolevel=lint -loglevel=OFF > !DBNAME!_schema_!UNIQUE!.txt
  )
)
DEL /Q dblist.txt
GOTO :EXIT

:END
ECHO Finished processing %1 .  Closing in 20 seconds...
ECHO.
FOR /l %%a in (20,-1,1) do (TITLE %TITLE% -- closing in %%as&ping \
-n 2 -w 1 127.0.0.1>NUL)

:EXIT
EXIT

Ok, I figured it out. The -database flag only gives the sql driver a connect path, it doesn't affect the filter for the database name. In other words:

-database=openfire  DOES NOT EQUAL  -schemas=openfire.dbo.*

So, the answer is:

:: schemacrawler batch launcher
@echo off
C:\JDK\bin\java.exe -classpath jtds-1.2.4.jar;schemacrawler-8.8.jar; \
schemacrawler-sqlserver-8.8.jar schemacrawler.tools.sqlserver.Main \
-user=sa -password=password -database=openfire -schemas=openfire.dbo.* \
-port=1433 -host=localhost -table_types=TABLE -command=schema \
-infolevel=standard -loglevel=FINE

My finished batch script:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
:: first get timestamp of this script
SETLOCAL
FOR /F "skip=1 tokens=2-4 delims=(-)" %%a IN ('"echo.|date"') DO (
    FOR /F "tokens=1-3 delims=/.- " %%A IN ("%DATE:* =%") DO (
        SET %%a=%%A&SET %%b=%%B&SET %%c=%%C))
SET /A "yy=10000%yy% %%10000,mm=100%mm% %% 100,dd=100%dd% %% 100"
FOR /F "tokens=1-4 delims=:. " %%A IN ("%time: =0%") DO @SET \
UNIQUE=%yy%%mm%%dd%-%%A%%B

SET TITLE=Schema Crawler
TITLE=%TITLE%
:: supports DBNAME as argument
IF NOT "%1"=="" (
  SET DBNAME=%1
  C:\JDK\bin\java.exe -classpath jtds-1.2.4.jar;schemacrawler-8.8.jar; \
  schemacrawler-sqlserver-8.8.jar schemacrawler.tools.sqlserver.Main -user=sa \
  -password=password -database=!DBNAME! -schemas=!DBNAME!.dbo.* -port=1433 \
  -host=localhost -table_types=TABLE -command=schema -procedures= \
  -infolevel=lint -loglevel=OFF > !DBNAME!_schema_!UNIQUE!.txt
  GOTO :END
)

:: run minimized
::IF NOT DEFINED PIL (
::    SET PIL=1
 ::   START /MIN "" %~0 %1
 ::   EXIT /B
::)

:: script start
ECHO Working...
OSQL.exe -E -Slocalhost -h-1 -Q"SET NOCOUNT ON;SELECT LTRIM(RTRIM(name)) \
FROM sysdatabases WHERE name NOT IN ('master','tempdb','model','msdb');" \
>dblist.txt
FOR /F "tokens=* delims= " %%I IN (dblist.txt) DO (
  IF NOT "%%I"=="                                                      " (
    SET DBNAME=%%I
    SET DBNAME=!DBNAME: =!
    ECHO !DBNAME!
    C:\JDK\bin\java.exe -classpath jtds-1.2.4.jar;schemacrawler-8.8.jar; \
  schemacrawler-sqlserver-8.8.jar schemacrawler.tools.sqlserver.Main -user=sa \
  -password=password -database=!DBNAME! -schemas=!DBNAME!.dbo.* -port=1433 \
  -host=localhost -table_types=TABLE -command=schema -procedures= \
  -infolevel=lint -loglevel=OFF > !DBNAME!_schema_!UNIQUE!.txt
  )
)
DEL /Q dblist.txt
GOTO :EXIT

:END
ECHO Finished processing %1 .  Closing in 20 seconds...
ECHO.
FOR /l %%a in (20,-1,1) do (TITLE %TITLE% -- closing in %%as&ping \
-n 2 -w 1 127.0.0.1>NUL)

:EXIT
EXIT
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文