InstallShield methods for executing SQL scripts in MySQL and Oracle InstallShield methods for executing SQL scripts in MySQL and Oracle

Source: Internet
Author: User

Briefly

InstallShield has built-in support for MySQL and Oracle. However, this functionality is implemented through ODBC, which is very strict in the format of SQL scripts, so the scripts that have been tested by the official client are often given an error when executed in is.

In general, database scripting is guaranteed only through official client testing, while maintaining a script that is executed by the IS takes time and effort. Therefore, consider the installation program's support for the two database through the official client implementation.

Mysql

functionInstallmysqlcomponent(Szcomponent)Number Nresult;STRINGSzserver,szdb,szuser,szpassword,scmd,sopt,sresult1,sresult2,svline,smsg,spath;    Number Nvfilehandle,nvcount; LIST Liststatus;beginSMSG =' Install '+szcomponent+' ... '; Sdshowmsg(SMSG,TRUE);The //source command does not recognize the backslash in the Windows path, so it replaces the backslash in the srcdir with a slashspath = Srcdir; Strreplace(Spath,'//','/',0);//Fetch database connection InformationSqlrtgetconnectioninfo( ' MySQL ', Szserver, Szdb, Szuser, Szpassword); Scmd = winsysdir^' cmd.exe '; SOPT ='/C '+srcdir^' Mysql.exe-h '+szserver+'-u '+szuser+'-P '+szpassword+'-d '+SZDB; SOPT = sopt+'-e ' source '+spath^szcomponent+'. sql ' > '+srcdir^' Dbstatus.txt 2>&1 ';//Execute The script associated with the given component in databaseNresult=launchappandwait(Scmd, SOPT, WAIT.|Laaw_option_hidden);if (Nresult< 0)  ThenMessageBox(' Failed installing '+szcomponent+'! ', SEVERE);    Abort endif//Close Installation TipsSdshowmsg("',FALSE);//Read dbstatus.txtOpenfilemode(File_mode_normal);if (OpenFile(Nvfilehandle, Srcdir,' Dbstatus.txt ')<0)  ThenMessageBox(' Failed checking the status of installing '+szcomponent+'! ', SEVERE);    Abort    endif Liststatus = Listcreate(Stringlist); whileGetLine(Nvfilehandle, Svline)=0Listaddstring(Liststatus, Svline, after); Endwhile;CloseFile(Nvfilehandle);//Count How many lines fetched from Dbstatus.txtNvcount = ListCount(Liststatus);ifNvcount> 0  ThenSMSG ="Error updating database, point" is "open log file and exit the installation, click" No "to exit the installation directly. /n "; SMSG = smsg+"If errors can be ignored, select the database type" None "to skip database updates and update the program directly,/n"; SMSG = smsg+"Then execute the SQL script manually in the database (saved in the script directory after installation)"; Nresult = AskYesNo(SMSG, YES);if (Nresult = YES)  ThenLaunchapp(winsysdir^' notepad.exe ', srcdir^' Dbstatus.txt '); endif;    Abort endifEnd;
Oracle

functionInstalloraclecomponent(Szcomponent)Number Nresult,nvfilehandle,nindex,nvcount;STRINGSmsg,szserver,szdb,szuser,szpassword,scmd,sopt,sinstance,stmp,svline; LIST Liststatus;beginSMSG =' Install '+szcomponent+' ... '; Sdshowmsg(SMSG,TRUE);//Fetch database connection InformationSqlrtgetconnectioninfo( ' Oracle ', Szserver, Szdb, Szuser, Szpassword); NIndex = Strfind(Szserver,': '); NIndex = Strfindex(Szserver,'/', NIndex); Strsub(Sinstance, Szserver, nindex+1, -); Scmd = winsysdir^' cmd.exe '; SOPT ='/C '+' sqlplus.exe-l-S '+szuser+'/'+szpassword+' @ '+sinstance; SOPT = sopt+' @ '+srcdir^szcomponent+'. sql > '+srcdir^' Dbstatus.txt 2>&1 ';//Execute The script associated with the given component in databaseNresult=launchappandwait(Scmd, SOPT, WAIT.|Laaw_option_hidden);if (Nresult< 0)  ThenMessageBox(' Failed installing '+szcomponent+'! ', SEVERE);    Abort endif//Close Installation TipsSdshowmsg("',FALSE);//query string Holytail in Dbstatus.txt, if present, stating that the script has finished executing    if (Filegrep(srcdir^' Dbstatus.txt ',' Holytail ', Svline, NIndex,RESTART)=0)  Then        //query string ora-in Dbstatus.txt, if present, indicates script execution error        if (Filegrep(srcdir^' Dbstatus.txt ',' ora-', Svline, NIndex,RESTART)=0)  ThenSMSG ="Error updating database, point" is "open log file and exit the installation, click" No "to exit the installation directly. /n "; SMSG = smsg+"If errors can be ignored, select the database type" None "to skip database updates and update the program directly,/n"; SMSG = smsg+"Then execute the SQL script manually in the database (saved in the script directory after installation)"; Nresult = AskYesNo(SMSG, YES);if (Nresult = YES)  ThenLaunchapp(winsysdir^' notepad.exe ', srcdir^' Dbstatus.txt ');                               endif        Abort endifElseSMSG ="Error updating database, point" is "open log file and exit the installation, click" No "to exit the installation directly. /n "; SMSG = smsg+"If errors can be ignored, select the database type" None "to skip database updates and update the program directly,/n"; SMSG = smsg+"Then execute the SQL script manually in the database (saved in the script directory after installation)"; Nresult = AskYesNo(SMSG, YES);if (Nresult = YES)  ThenLaunchapp(winsysdir^' notepad.exe ', srcdir^' Dbstatus.txt ');                           endif    Abort endifEnd;
Summarize
    1. to facilitate the execution of the script in the database, the script is executed through the official client through the notation "; " redirects the client's output information to Dbstatus.txt ; Use " 2>&1 " to redirect the standard error output to a standard output device, which, of course, is further redirected to the Dbstatus.txt file, otherwise the error message cannot be obtained. The
    2. Sqlplus does not automatically exit after executing the SQL script, so the statement " exit; " should be added to the Oracle script. The
    3. overloads the onsqlcomponentinstalled () function, and in which MySQL and Oracle's SQL scripts are disabled, the corresponding component are executed for installation. The database is then updated with the above two functions.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.