ibec_psql_Format

This functions performs code formatting of an PSQL statement.

Syntax

 ibec_psql_Format(PSQLObject : variant; FormatOptions : string) : string;
 
  • PSQLObject - PSQL object created with ibec_psql_Parse function
  • FormatOptions - string with set of formatting options. It can be loaded from an ini-file (Options | Code formatting options | Save formatting options to file).

ibec_psql_Format returns string value containing formatted PSQL code.

Example

The following example retrieves all procedure DDL's from a database, formats them and saves formatted code in separate files:

 execute ibeblock
 as
 begin
   sFormatOptions = '';

   -- Try to get format options from the IBExpert User Database
   userdb = ibec_GetUserDBConnection();
   if (userdb is not null) then
   begin
     ibec_UseConnection(userdb);
     select data from config where ident = 'CodeFormatOptions' into :sFormatOptions;
   end

   db = ibec_GetDefaultConnection();
   ibec_UseConnection(db);

   -- Directory to save formatted sources of procedures
   sDir = 'D:\Temp\Procs';
   ibec_ForceDirectories(sDir);

   for select rdb$procedure_name
       from RDB$PROCEDURES
       -- Comment the next line if your server doesn't support packages
       where rdb$package_name is null
       order by 1
       into :ProcName
    do
    begin
      ProcName = ibec_Trim(:ProcName);

      -- Pass an empty string as an option string to get pure single CREATE statement without SET TERM etc.
      sPSQL = ibec_GetObjectScript(db, :ProcName, __dboProcedure, '');

      -- Just for example we will replace CREATE PROCEDURE with CREATE OR ALTER PROCEDURE
      sPSQL = ibec_Trim(sPSQL);
      sPSQL = ibec_preg_Replace('^(?i)CREATE[\x01-\x20]+PROCEDURE', 'CREATE OR ALTER PROCEDURE', sPSQL);

      ObjPSQL = ibec_psql_Parse(sPSQL, 3, __svFB30);
      try
        sPSQLSource = ibec_psql_Format(ObjPSQL, sFormatOptions);
        sFileName = sDir || '\' || ProcName || '.sp';
        ibec_SaveToFile(sFileName, sPSQLSource, __stfOverwrite);
      finally
        ibec_psql_Free(ObjPSQL);
      end
    end;
 end;

back to top of page
<< ibec_cr_OpenCursor | IBEBlock | ibec_psql_Analyze >>