ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/nongui/IBExtract.pas
(Generate patch)

Comparing ibx/trunk/runtime/nongui/IBExtract.pas (file contents):
Revision 348 by tony, Wed Oct 6 09:38:14 2021 UTC vs.
Revision 349 by tony, Mon Oct 18 08:39:40 2021 UTC

# Line 755 | Line 755 | begin
755        CreateTable := 'CREATE TABLE';
756  
757      if NewName <> '' then
758 <      ExtractOut(Format('%s %s ', [CreateTable,QuoteIdentifier(NewName)]))
758 >      ExtractOut(Format('%s %s', [CreateTable,QuoteIdentifier(NewName)]))
759      else
760 <      ExtractOut(Format('%s %s ', [CreateTable,QuoteIdentifier(RelationName)]));
760 >      ExtractOut(Format('%s %s', [CreateTable,QuoteIdentifier(RelationName)]));
761      if not qryTables.FieldByName('RDB$EXTERNAL_FILE').IsNull then
762        ExtractOut(Format('EXTERNAL FILE %s ',
763          [QuotedStr(qryTables.FieldByName('RDB$EXTERNAL_FILE').AsString)]));
# Line 1518 | Line 1518 | procedure TIBExtract.ListPackages(Packag
1518   const
1519    PackageSQL = 'Select * From RDB$PACKAGES Where RDB$SYSTEM_FLAG = 0 order by RDB$PACKAGE_NAME';
1520    PackageNameSQL = 'Select * From RDB$PACKAGES Where RDB$PACKAGE_NAME = :PackageName order by RDB$PACKAGE_NAME';
1521 <  PackageHeaderSQL = 'CREATE PACKAGE %s%s%sAS%s';
1522 <  PackageBodySQL = 'CREATE PACKAGE BODY %s%sAS%s';
1521 >  PackageHeaderSQL = 'CREATE PACKAGE %s%s%sAS';
1522 >  PackageBodySQL = 'CREATE PACKAGE BODY %s%sAS';
1523   var
1524    qryPackages : TIBSQL;
1525    Header : Boolean;
# Line 1548 | Line 1548 | begin
1548        begin
1549          ExtractOut('COMMIT WORK;');
1550          ExtractOut('SET AUTODDL OFF;');
1551 <        ExtractOut(Format('SET TERM %s %s', [ProcTerm, Term]));
1551 >        ExtractOut(Format('SET TERM %s%s', [ProcTerm, Term]));
1552          ExtractOut(Format('%s/* Package Definitions */%s', [LineEnding, LineEnding]));
1553          Header := false;
1554        end;
1555  
1556        AddComment(qryPackages,ctPackage,Comments);
1557 <      aPackageName := qryPackages.FieldByName('RDB$PACKAGE_NAME').AsString;
1557 >      aPackageName := Trim(qryPackages.FieldByName('RDB$PACKAGE_NAME').AsString);
1558        if PackageDDLType in [paHeader,paBoth] then
1559        begin
1560           {SQL Security added in Firebird 4}
# Line 1564 | Line 1564 | begin
1564            SQLSecurity := '';
1565  
1566         ExtractOut(Format(PackageHeaderSQL,[aPackageName,SQLSecurity,
1567 <                                               LineEnding,LineEnding]));
1567 >                                               LineEnding]));
1568          SList.Text :=  qryPackages.FieldByName('RDB$PACKAGE_HEADER_SOURCE').AsString;
1569 <        SList.Add(Format(' %s%s', [ProcTerm, LineEnding]));
1569 >        SList.Add(Format('%s%s', [ProcTerm, LineEnding]));
1570          ExtractOut(SList);
1571        end;
1572  
1573        if PackageDDLType in [paBody,paBoth] then
1574        begin
1575 <        ExtractOut(Format(PackageBodySQL,[aPackageName,
1576 <                                               LineEnding,LineEnding]));
1575 >        ExtractOut(Format(PackageBodySQL,[aPackageName,LineEnding]));
1576          SList.Text :=  qryPackages.FieldByName('RDB$PACKAGE_BODY_SOURCE').AsString;
1577 <        SList.Add(Format(' %s%s', [ProcTerm, LineEnding]));
1577 >        SList.Add(Format('%s%s', [ProcTerm, LineEnding]));
1578          ExtractOut(SList);
1579        end;
1580  
# Line 1587 | Line 1586 | begin
1586  
1587      if not Header then
1588      begin
1589 <      ExtractOut(Format('SET TERM %s %s', [Term, ProcTerm]));
1589 >      ExtractOut(Format('SET TERM %s%s', [Term, ProcTerm]));
1590        ExtractOut('COMMIT WORK;');
1591        ExtractOut('SET AUTODDL ON;');
1592      end;
# Line 1687 | Line 1686 | begin
1686        begin
1687          ExtractOut('COMMIT WORK;');
1688          ExtractOut('SET AUTODDL OFF;');
1689 <        ExtractOut(Format('SET TERM %s %s', [ProcTerm, Term]));
1689 >        ExtractOut(Format('SET TERM %s%s', [ProcTerm, Term]));
1690          ExtractOut('');
1691          if ProcDDLType in [pdCreateStub,pdCreateProc] then
1692            ExtractOut('/* Stored procedures Definitions*/')
# Line 1716 | Line 1715 | begin
1715              qryProcSecurity.SQL.Text := ProcedureSecuritySQL;
1716              qryProcSecurity.Params.ByName('ProcedureName').AsString := ProcName;
1717              qryProcSecurity.ExecQuery;
1718 <            ExtractOut(AddSQLSecurity(qryProcSecurity.FieldByName('RDB$SQL_SECURITY')));
1718 >            if not qryProcSecurity.FieldByName('RDB$SQL_SECURITY').IsNull then
1719 >              ExtractOut(AddSQLSecurity(qryProcSecurity.FieldByName('RDB$SQL_SECURITY')));
1720            end;
1721            ExtractOut(ProcTerm);
1722          end;
# Line 1743 | Line 1743 | begin
1743            qryProcSecurity.SQL.Text := ProcedureSecuritySQL;
1744            qryProcSecurity.Params.ByName('ProcedureName').AsString := ProcName;
1745            qryProcSecurity.ExecQuery;
1746 <          ExtractOut(AddSQLSecurity(qryProcSecurity.FieldByName('RDB$SQL_SECURITY')));
1746 >          if not qryProcSecurity.FieldByName('RDB$SQL_SECURITY').IsNull then
1747 >            ExtractOut(AddSQLSecurity(qryProcSecurity.FieldByName('RDB$SQL_SECURITY')));
1748          end;
1749  
1750          ExtractOut(ProcTerm);
# Line 1752 | Line 1753 | begin
1753  
1754        pdAlterProc:
1755         begin
1756 <         ExtractOut(Format('%sALTER PROCEDURE %s', [LineEnding,
1756 <            QuoteIdentifier( ProcName)]));
1756 >         ExtractOut(Format('ALTER PROCEDURE %s', [QuoteIdentifier( ProcName)]));
1757           GetProcedureArgs(ProcName);
1758  
1759           if not qryProcedures.FieldByName('RDB$PROCEDURE_SOURCE').IsNull then
1760           begin
1761             SList.Text := qryProcedures.FieldByName('RDB$PROCEDURE_SOURCE').AsString;
1762 <           SList.Add(Format('%s', [ProcTerm]));
1762 >           SList.Add(ProcTerm);
1763             ExtractOut(SList);
1764           end
1765           else
1766             ExtractOut(CreateProcedureStr2 + ProcTerm);
1767         end;
1768        end;
1769 +      ExtractOut('');
1770        if IncludeGrants then
1771          ShowGrantsTo(ProcName,obj_procedure,ProcTerm);
1772        qryProcedures.Next;
# Line 1774 | Line 1775 | begin
1775  
1776      if not Header then
1777      begin
1778 <      ExtractOut(Format('SET TERM %s %s', [Term, ProcTerm]));
1778 >      ExtractOut(Format('SET TERM %s%s', [Term, ProcTerm]));
1779        ExtractOut('COMMIT WORK;');
1780        ExtractOut('SET AUTODDL ON;');
1781      end;
# Line 1913 | Line 1914 | begin
1914        SList.Clear;
1915        if Header then
1916        begin
1917 <        ExtractOut(Format('SET TERM %s %s%s', [Procterm, Term, LineEnding]));
1917 >        ExtractOut(Format('SET TERM %s%s%s', [Procterm, Term, LineEnding]));
1918          ExtractOut(Format('%s/* Triggers only will work for SQL triggers */%s',
1919                         [LineEnding, LineEnding]));
1920          Header := false;
# Line 1964 | Line 1965 | begin
1965            SList.Add(qryTriggers.FieldByName('RDB$TRIGGER_SOURCE').AsString)
1966          else
1967            SList.Add('AS BEGIN EXIT; END');
1968 <        SList.Add(' ' + ProcTerm);
1968 >        SList.Add(ProcTerm);
1969 >        SList.Add('');
1970          if qryTriggers.FieldByName('RDB$FLAGS').AsInteger <> 1 then
1971            SList.Add(' */');
1972          ExtractOut(SList);
# Line 1975 | Line 1977 | begin
1977      end;
1978      if not Header then
1979      begin
1980 <      ExtractOut('COMMIT WORK ' + ProcTerm);
1980 >      ExtractOut('COMMIT WORK' + ProcTerm);
1981        ExtractOut('SET TERM ' + Term + ProcTerm);
1982      end;
1983      ExtractOut(Comments);
# Line 2899 | Line 2901 | begin
2901             TrimRight(qryFunctions.FieldByName('RDB$MODULE_NAME').AsString)]));
2902  
2903         {SQL Security added in Firebird 4}
2904 <       if FDatabaseInfo.ODSMajorVersion >= ODS_VERSION13 then
2904 >       if (FDatabaseInfo.ODSMajorVersion >= ODS_VERSION13) and
2905 >          not qryFunctions.FieldByName('RDB$SQL_SECURITY').IsNull then
2906           ExtractOut(AddSQLSecurity(qryFunctions.FieldByName('RDB$SQL_SECURITY')));
2907  
2908        ExtractOut(TERM + LineEnding + LineEnding);
# Line 2961 | Line 2964 | begin
2964         begin
2965           ExtractOut('COMMIT WORK;');
2966           ExtractOut('SET AUTODDL OFF;');
2967 <         ExtractOut(Format('SET TERM %s %s', [ProcTerm, Term]));
2967 >         ExtractOut(Format('SET TERM %s%s', [ProcTerm, Term]));
2968           ExtractOut('');
2969           if ProcDDLType in [pdCreateStub,pdCreateProc] then
2970             ExtractOut('/* Stored Function declarations */')
# Line 3026 | Line 3029 | begin
3029             ExtractOut(' AS BEGIN END');
3030  
3031             {SQL Security added in Firebird 4}
3032 <           if FDatabaseInfo.ODSMajorVersion >= ODS_VERSION13 then
3032 >           if (FDatabaseInfo.ODSMajorVersion >= ODS_VERSION13) and
3033 >               not qryFunctions.FieldByName('RDB$SQL_SECURITY').IsNull then
3034               ExtractOut(AddSQLSecurity(qryFunctions.FieldByName('RDB$SQL_SECURITY')));
3035          end;
3036  
# Line 3039 | Line 3043 | begin
3043               ExtractOut(Format('CREATE FUNCTION %s',[TrimRight(qryFunctions.FieldByName('RDB$FUNCTION_NAME').AsString)]));
3044             ExtractOut(ReturnBuffer);
3045             if not qryFunctions.FieldByName('RDB$FUNCTION_SOURCE').IsNull then
3046 <             ExtractOut(' AS ' + LineEnding + qryFunctions.FieldByName('RDB$FUNCTION_SOURCE').AsString)
3046 >             ExtractOut('AS' + LineEnding + qryFunctions.FieldByName('RDB$FUNCTION_SOURCE').AsString)
3047             else
3048 <             ExtractOut(' AS BEGIN END');
3048 >             ExtractOut('AS BEGIN END');
3049  
3050             {SQL Security added in Firebird 4}
3051 <           if FDatabaseInfo.ODSMajorVersion >= ODS_VERSION13 then
3051 >           if (FDatabaseInfo.ODSMajorVersion >= ODS_VERSION13) and
3052 >               not qryFunctions.FieldByName('RDB$SQL_SECURITY').IsNull then
3053               ExtractOut(AddSQLSecurity(qryFunctions.FieldByName('RDB$SQL_SECURITY')));
3054           end;
3055  
# Line 3058 | Line 3063 | begin
3063                 [TrimRight(qryFunctions.FieldByName('RDB$FUNCTION_NAME').AsString)]));
3064             ExtractOut(ReturnBuffer);
3065             if not qryFunctions.FieldByName('RDB$FUNCTION_SOURCE').IsNull then
3066 <             ExtractOut(' AS ' + LineEnding + qryFunctions.FieldByName('RDB$FUNCTION_SOURCE').AsString)
3066 >             ExtractOut('AS' + LineEnding + qryFunctions.FieldByName('RDB$FUNCTION_SOURCE').AsString)
3067             else
3068 <             ExtractOut(' AS BEGIN END');
3068 >             ExtractOut('AS BEGIN END');
3069           end;
3070         end;
3071 <       ExtractOut(ProcTerm + LineEnding + LineEnding);
3071 >       ExtractOut(ProcTerm + LineEnding);
3072         if IncludeGrants then
3073           ShowGrantsTo(qryFunctions.FieldByName('RDB$FUNCTION_NAME').AsString,obj_Function,ProcTerm);
3074  
# Line 3072 | Line 3077 | begin
3077  
3078        if not First then
3079        begin
3080 <        ExtractOut(Format('SET TERM %s %s', [Term, ProcTerm]));
3080 >        ExtractOut(Format('SET TERM %s%s', [Term, ProcTerm]));
3081          ExtractOut('COMMIT WORK;');
3082          ExtractOut('SET AUTODDL ON;');
3083        end;
# Line 3112 | Line 3117 | var
3117    qryGenerator : TIBSQL;
3118    qryValue: TIBSQL;
3119    GenName : String;
3120 +  NextSeq: int64;
3121   begin
3122    qryGenerator := TIBSQL.Create(FDatabase);
3123    qryValue := TIBSQL.Create(FDatabase);
# Line 3145 | Line 3151 | begin
3151          qryValue.ExecQuery;
3152          try
3153            if not qryValue.EOF then
3154 +          begin
3155 +            if FDatabaseInfo.ODSMajorVersion >= ODS_VERSION13 then
3156 +              NextSeq := qryValue.FieldByName('GENERATORVALUE').AsInt64 + 1
3157 +            else
3158 +              NextSeq := qryValue.FieldByName('GENERATORVALUE').AsInt64;
3159              ExtractOut(Format('ALTER SEQUENCE %s RESTART WITH %d;',
3160 <                 [QuoteIdentifier( GenName),
3161 <                  qryValue.FieldByName('GENERATORVALUE').AsInt64]));
3160 >                 [QuoteIdentifier( GenName),NextSeq]));
3161 >          end;
3162          finally
3163            qryValue.Close;
3164          end;
# Line 3350 | Line 3361 | begin
3361             qryColumns.FieldByName('RDB$FIELD_NAME').AsString));
3362          qryColumns.Next;
3363          if not qryColumns.Eof then
3364 <          SList.Strings[SList.Count - 1] := SList.Strings[SList.Count - 1] + ', ';
3364 >          SList.Strings[SList.Count - 1] := SList.Strings[SList.Count - 1] + ',';
3365        end;
3366        qryColumns.Close;
3367 <      SList.Text := SList.Text + Format(') AS%s', [LineEnding]);
3367 >      SList.Text := SList.Text + ') AS';
3368        if not qryView.FieldByName('RDB$VIEW_SOURCE').IsNull then
3369          SList.Text := SList.Text + qryView.FieldByName('RDB$VIEW_SOURCE').AsString;
3370        SList.Text := SList.Text + Format('%s%s', [Term, LineEnding]);
# Line 3725 | Line 3736 | begin
3736                  { We are Dialect >=3 since FIELD_PRECISION is non-NULL }
3737                  if (FieldSubType > 0) and (FieldSubType <= MAX_INTSUBTYPES) then
3738                  begin
3739 <                  Result := Format('%s(%d, %d)',
3739 >                  Result := Format('%s(%d,%d)',
3740                                           [IntegralSubtypes[FieldSubType],
3741                                            FieldPrecision,
3742                                            -FieldScale]);
# Line 3736 | Line 3747 | begin
3747  
3748              { Take a stab at numerics and decimals }
3749              if (FieldType = blr_short) and (FieldScale < 0) then
3750 <              Result :=  Format('NUMERIC(4, %d)', [-FieldScale])
3750 >              Result :=  Format('NUMERIC(4,%d)', [-FieldScale])
3751              else
3752              if (FieldType = blr_long) and (FieldScale < 0) then
3753 <                Result := Format('NUMERIC(9, %d)', [-FieldScale])
3753 >                Result := Format('NUMERIC(9,%d)', [-FieldScale])
3754              else
3755              if (FieldType = blr_double) and (FieldScale < 0) then
3756 <               Result :=  Format('NUMERIC(15, %d)', [-FieldScale])
3756 >               Result :=  Format('NUMERIC(15,%d)', [-FieldScale])
3757              else
3758              if (FieldType = blr_int64) and (FieldScale < 0) then
3759 <               Result :=  Format('NUMERIC(18, %d)', [-FieldScale])
3759 >               Result :=  Format('NUMERIC(18,%d)', [-FieldScale])
3760              else
3761              if (FieldType = blr_int128) and (FieldScale < 0) then
3762 <               Result :=  Format('NUMERIC(38, %d)', [-FieldScale])
3762 >               Result :=  Format('NUMERIC(38,%d)', [-FieldScale])
3763              else
3764                  Result :=  TypeName;
3765            end;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines