功能
为所有打开的pdm生成SQL
代码
开箱即用,无需修改
' 批量Pdm转Sql
' This script exports all open PDM files to SQL files
' Author: huangshengsheng
option explicit
dim strOutputFolder
dim objModel
Dim strFileName
dim flag
' Set the output folder where SQL files will be saved
strOutputFolder = InputBox("输出文件夹路径","输入框" ,"C:\Users\13569\Desktop\pdm_output")
call CreateDirectoryIfNotExists()
If strOutputFolder <> "" and flag <> 1 then
For Each objModel in Models
call GenerateDatabaseScripts(objModel)
Next
Else
output "您已取消执行!"
end If
' 生成SQL脚本
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.GenerationCharacterCase = 1
opts.GenerationEncoding = "UTF-8"
opts.CaseSensitivityUsingQuote=False
opts.GenerationPathName = strOutputFolder + "\"
call GetModelFileNameWithoutExtension(m)
opts.GenerationScriptName = strFileName + ".sql"
m.GenerateDatabase
output "文件生成: " & opts.GenerationPathName & opts.GenerationScriptName
end sub
Sub GetModelFileNameWithoutExtension(objModel)
Dim intLastIndex
If Not objModel Is Nothing Then
strFileName = objModel.FileName
intLastIndex = InStrRev(strFileName, "\")
strFileName = Mid(strFileName, intLastIndex + 1)
strFileName = Left(strFileName, InStrRev(strFileName, ".") - 1)
Else
MsgBox "Invalid model object.", vbExclamation, "Error"
End If
End Sub
Sub CreateDirectoryIfNotExists()
Dim folderPath
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
folderPath = strOutputFolder ' 设置目录路径
' 检查目录是否存在
If Not fso.FolderExists(folderPath) Then
MsgBox "路径" + folderPath + "不存在"
flag = 1
End If
End Sub