[转]用Installshield制作软件包常用的InstallScript--3
prototype BOOL ExecuteSQLScript(STRING);
prototype BOOL ExecuteScript(OBJECT,OBJECT,STRING);
//参数ConnectionString = Provider=SQLOLEDB.1;Data Source=servername;Initial Catalog=MyProject;Integrated Security=SSPI;
function BOOL ExecuteSQLScript(ConnectionString)
OBJECT pADOObj, pADOCommObj,objRecordSet;
STRING szADOObjID, szADOCommObjID;
STRING svLine, szConnString, szSQL, svString;
BOOL nResult;
LIST listID;
begin
try
// Create ADO Connection Object to connect to the SQL server
szADOObjID = "ADODB.Connection";
set pADOObj = CreateObject(szADOObjID);
// Create the SQL string to complete the connection
szConnString = ConnectionString
// Open the ADO Connection
pADOObj.Open(szConnString);
// Create the ADO Command object to execute the script
szADOCommObjID = "ADODB.Command";
set pADOCommObj = CreateObject(szADOCommObjID);
pADOCommObj.ActiveConnection = pADOObj;
nResult = ExecuteScript(pADOObj,pADOCommObj,"Structure.sql");//Structure.sql文件在存放在SRCDIR下名为DBScript的文件夹下
if (nResult = TRUE) then
nResult = ExecuteScript(pADOObj,pADOCommObj,"Trg&Func.sql");");//Trg&Func.sql文件在存放在SRCDIR下名为DBScript的文件夹下
if nResult = TRUE then
nResult = ExecuteScript(pADOObj,pADOCommObj,"Views.sql");//Views.sql文件在存放在SRCDIR下名为DBScript的文件夹下
if(nResult = TRUE)then
nResult = ExecuteScript(pADOObj,pADOCommObj,"InitialData.sql");//InitialData.sql文件在存放在SRCDIR下名为DBScript的文件夹下
endif;
endif;
endif;
catch
set pADOObj = NOTHING;
set pADOCommObj = NOTHING;
nResult = FALSE;
endcatch;
set pADOObj = NOTHING;
set pADOCommObj = NOTHING;
return nResult;
end;
function BOOL ExecuteScript(objConn,objCom,tsFileName)
LIST list;
STRING sSql,sLine;
NUMBER nResult;
BOOL nReturn;
begin
// Create an empty string list.
list = ListCreate (STRINGLIST);
// Read the SQL script file into the list
if (ListReadFromFile(list, SRCDIR^"DBScript"^tsFileName) < 0) then // read list from file
//MessageBox ("ERROR: Unable to open "+tsFileName, SEVERE);
return FALSE;
endif;
// Go through each list item and add it to a string (which will then hold the script)
sSql = "";
try
nResult = ListGetFirstString (list, sLine);
if tsFileName = "InitialData.sql" then
while (nResult = 0)
if sLine != "" then
sSql = sSql + ";" + sLine;
sLine = "";
endif;
nResult = ListGetNextString (list, sLine);
endwhile;
// Execute the call to run the script
objCom.CommandText = sSql;
objCom.Execute();
else
while (nResult = 0)
if sLine != "" then
if(sLine != "go") then
sSql = sSql + " " + sLine;
else
// Execute the call to run the script
objCom.CommandText = sSql;
objCom.Execute();
sSql = "";
endif;
endif;
nResult = ListGetNextString (list, sLine);
endwhile;
endif;
// Be good and clean up your trash
ListDestroy(list);
nReturn = TRUE;
catch
nReturn = FALSE;
endcatch;
return nReturn;
end;