You can generate a PDM as a SQL script or directly to a live database connection using the GenerateDatabase() method. You can generate test data with the GenerateTestData() method.
Dim GenDir, MyModel GenDir = "C:\temp\" Set MyModel=OpenModel(EvaluateNamedPath("%_EXAMPLES%\" & "project.pdm")) GenerateDatabaseScripts MyModel 'Generate a SQL script to create the database ModifyModel MyModel 'Modify each table in the model GenerateAlterScripts MyModel - Generate alter scripts to modify the database GenerateTestDataScript MyModel - generate test data to load into the database
Sub GenerateDatabaseScripts(m) Dim opts Set opts = m.GetPackageOptions() InteractiveMode = im_Batch ' Avoid displaying generation window opts.GenerateODBC = False ' Force sql script generation rather than ODBC opts.GenerationPathName = GenDir opts.GenerationScriptName = "MyScript.sql" m.GenerateDatabase ' Launch the Generate Database feature End SubTo generate to a live database connection, you would connect to the database (using the ConnectToDatabase() method) and then set the GenerateODBC property to true.
Sub ModifyModel(m) dim pTable, pCol For each pTable in m.Tables Set pCol = pTable.Columns.CreateNew() pCol.SetNameAndCode "az" & pTable.Name, "AZ" & pTable.Code pCol.Mandatory = False Next End Sub
Sub GenerateAlterScripts(m) Dim pOpts Set pOpts = m.GetPackageOptions() InteractiveMode = im_Batch ' Avoid displaying generate window ' set generation options using model package options pOpts.GenerateODBC = False ' Force sql script generation rather than ODBC pOpts.GenerationPathName = GenDir pOpts.DatabaseSynchronizationChoice = 0 'force already saved apm as source pOpts.DatabaseSynchronizationArchive = GenDir & "model.apm" pOpts.GenerationScriptName = "MyAlterScript.sql" m.ModifyDatabase ' Launch the Modify Database feature End Sub
Sub GenerateTestDataScript(m) Dim pOpts Set pOpts = m.GetPackageOptions() InteractiveMode = im_Batch ' Avoid displaying generate window ' set generation options using model package options pOpts.TestDataGenerationByODBC = False ' Force sql script generation rather than ODBC pOpts.TestDataGenerationDeleteOldData = False pOpts.TestDataGenerationPathName = GenDir pOpts.TestDataGenerationScriptName = "MyTestData.sql" m.GenerateTestData ' Launch the Generate Test Data feature End Sub