Reverse Engineering a Database (Scripting)

You can connect to a database using the ConnectToDatabase() method, and reverse engineer the schema to a PDM using ReverseDatabase().

To connect to a database via a user or system data source, define a constant in the form "ODBC:datasourcename" . For example:
Const cnxDSN = "ODBC:ASA 9.0 sample"
To use a data source file, define a constant with the full path to the DSN file. For example:
Const cnxDSN = "\\romeo\public\DATABASES\_filedsn\sybase_asa9_sample.dsn"

This script creates a new PDM, connects to a database via a system data source, sets reverse options and reverses all objects to the PDM:

' Define ODBC data source and PDM file
Const cnxDSN = "ODBC:MyDatabase"
Const cnxUSR = "MyUser"
Const cnxPWD = "MyPassword"
Const filename = "C:\temp\MyReversedDB.pdm"

Dim pModel, pOpt
' Create model with appropriate DBMS
Set pModel=CreateModel(PdPDM.cls_Model, "|DBMS=Sybase SQL Anywhere 12")
' Hide dialogs
InteractiveMode = im_Batch

' Connect to the database
 pModel.ConnectToDatabase cnxDSN, cnxUSR, cnxPWD
' Set reverse options to reverse all listed objects via ODBC
 Set pOpt = pModel.GetPackageOptions()
 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
 
' Reverse database to model and then save model
 pModel.ReverseDatabase
 pModel.save(filename)