Reverse Engineering a Database by Script

You reverse engineer a database using scripts using the ReverseDatabase(ByVal Diagram As BaseObject = Nothing) method.

In the following example, the ODBC database is reversed into a new PDM.

The first lines of the script define the constants used:

Example

option explicit

' To use a user or system datasource, define constant with "ODBC:<datasourcename>"
' -> Const cnxDSN = "ODBC:ASA 9.0 sample"
' To use a datasource file, define constant with the full path to the DSN file
' -> Const cnxDSN = "\\romeo\public\DATABASES\_filedsn\sybase_asa9_sample.dsn"

' use ODBC datasource
Const cnxDSN = "ODBC:ASA 9.0 sample"
Const cnxUSR = "dba"
Const cnxPWD = "sql"
Const GenDir = "C:\temp\"
Const filename = "D:\temp\phys.pdm"

' Call to main function with the newly created PDM
' This sample use an ASA9 database
Start CreateModel(PdPDM.cls_Model, "|DBMS=Sybase AS Anywhere 9")

Sub Start(pModel)

 If (pModel is Nothing) then
  output "Unable to create a physical model for selected DBMS"
  Exit Sub
 End If

 InteractiveMode = im_Batch

' Reverse database phase
' First connect to the database with connection parameters
 pModel.ConnectToDatabase cnxDSN, cnxUSR, cnxPWD
' Get the reverse option of the model
 Dim pOpt
 Set pOpt = pModel.GetPackageOptions()

' Force ODBC Reverse of all listed objects
 pOpt.ReversedScript = False
 pOpt.ReverseAllTables = true
 pOpt.ReverseAllViews = true
 pOpt.ReverseAllStorage = true
 pOpt.ReverseAllTablespace = true
 pOpt.ReverseAllDomain = true
 pOpt.ReverseAllUser = true
 pOpt.ReverseAllProcedures = true
 pOpt.ReverseAllTriggers = true
 pOpt.ReverseAllSystemTables = true
 pOpt.ReverseAllSynonyms = true
' Go !
 pModel.ReverseDatabase
 pModel.save(filename)
' close model at the end
 pModel.Close false
End Sub