<< ibec_ExecScript | IBEBlock | ibec_ExportReport >>

ibec_ExecSQLScript

Executes an SQL script from a variable or a file.

Syntax

    function ibec_ExecSQLScript(Connection : variant; SQLScript : string; Options : string; ProgressBlock : variant) : variant;
SQLScriptscript text or name of script file.
Optionsadditional options. There are two additional options currently available: ServerVersion and StopOnError.
ProgressBlockan IBEBlock which will be executed for every progress message generated during script execution.

Description

ibec_ExecSQLScript executes an SQL script from a variable or a file.

Connection is an active connection created with the ibec_CreateConnection function which will be used while executing a script. If Connection is not specified (NULL) the script must contain the CREATE DATABASE or the CONNECT statement, otherwise an exception will be raised.

ibec_ExecSQLScript returns NULL if there were no errors while executing a script. Otherwise it returns an error(s) message.

Example

    execute ibeblock
    as
    begin
      cbb = 'execute ibeblock (BlockData variant)
             as
             begin
               sMessage = BlockData;
               if (sMessage is not null) then
                 ibec_Progress('SQL Script: ' + sMessage);
             end';

      db = ibec_CreateConnection(__ctFirebird, ...);
      try
        Scr = 'INSERT INTO MYTABLE (ID, DATA) VALUES (1, 'Bla-bla'); ' + 'INSERT INTO MYTABLE (ID, DATA) VALUES 
       (2, 'Bla-bla'); '  + 'COMMIT;';
        ibec_ExecSQLScript(db, Scr, 'ServerVersion=FB21; StopOnError=FALSE', cbb); ...
        ibec_ExecSQLScript(db, 'D:\Scripts\CheckData.sql', 'ServerVersion=FB21', null); finally
        ibec_CloseConnection(db);
      end
    end    

back to top of page
<< ibec_ExecScript | IBEBlock | ibec_ExportReport >>