0

Is it possible to automatically create (running a script) a physical database model of the (.pdm) by doing a reverse engineer of a Sybase 15.7 server?

I know I can do it manually, but is it possible to do it via script?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
aF.
  • 64,980
  • 43
  • 135
  • 198

2 Answers2

2

I'm using something like this to reverse a database.

   dim path
   path = EvaluateNamedPath("%WORKDIR%\cnctjdbcasa.dcp")
   ReverseModel path, "dbuser", "dbpassword", "Sybase SQL Anywhere 12"

Function ReverseModel(cnxDSN, cnxUSR, cnxPWD, sDBMS)
   Dim mdl
   Set mdl = CreateModel(PdPDM.cls_Model, "|DBMS=" & sDBMS)
   set ReverseModel = mdl
   If mdl is Nothing Then
      MsgBox "Error: Unable to create a physical model for " & sDBMS, 0, "ReverseTest"
      Exit Function
   End If

   ' connect to the database with connection parameters
   If Not(mdl.ConnectToDatabase(cnxDSN, cnxUSR, cnxPWD)) Then
      MsgBox "Error: Unable to connect to " & cnxDSN & " - " & cnxUSR, 0, "ReverseTest"
      set ReverseModel = nothing
      mdl.Close false
      exit Function
   End If

   ' reverse tables from ODBC
   Dim opt
   Set opt = mdl.GetPackageOptions()
   opt.ReversedScript = False
   opt.ReverseAllTables = true
   opt.ReverseAllViews = false
   opt.ReverseAllStorage = false
   opt.ReverseAllTablespace = false
   opt.ReverseAllDomain = false
   opt.ReverseAllUser = false
   opt.ReverseAllProcedures = false
   opt.ReverseAllTriggers = false
   opt.ReverseAllSystemTables = false
   opt.ReverseAllSynonyms = false
   ' not interested in table details
   opt.ReversePrimaryKey = false
   opt.ReverseForeignKey = false
   opt.ReverseAlternateKey = false
   opt.ReverseIndex = false
   opt.ReverseCheck = false
   opt.ReversePhysicalOptions = false
   opt.ReverseStatistics = false
   opt.ReverseTablPermissions = false

   mdl.ReverseDatabase
End Function
pascal
  • 3,287
  • 1
  • 17
  • 35
  • Are you executing this within PowerDesigner? Is it possible to execute outside? Or how can I make a scheduled task (batch file) call that? – aF. Feb 27 '14 at 17:04
  • I'm executing it as a vbscript in the `Tools>Execute Commands>Edit/Run Script`. But it could located in an extension (modified DBMS definition/.xdb, or new extended model definition/.xem), and attached to a menu option. – pascal Feb 28 '14 at 09:01
  • 1
    It's just a demonstration that it is possible to reverse a database. Then the same can be written from any language which supports Automation, for example wscript. – pascal Feb 28 '14 at 09:01
0

You’ve probably figured it a long time ago, but maybe I can still help somebody. So, I created a .sql script file from my DB in Server Management Studio by Tasks->Generate Scripts. Next, in PowerDesigner 12.5 I did Reverse Engineer -> Database (chose Copy the DBMS definition in model) -> OK (chose script files), et voila -> there is my PhysicalDataModel containing a PhysicalDiagram. I was not able to understand what language he spoke but this guy gave me a good idea how to do it. https://www.youtube.com/watch?v=A8I47kLdIXg Happy coding :))

bakke2ooo
  • 1
  • 2