unit1.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. // Please define at project level (Project Options/Other, defines) either
  4. // -dQBEZEOS: Use Zeos in Visual Query Builder
  5. // Please add a project requirement to Zeos zcomponent
  6. // The example uses a Firebird connection (see code below).
  7. // You can of course change this
  8. // or
  9. // -dQBESQLDB: Use SQLDB in Visual Query Builder
  10. // This example uses a Firebird ibconnection.
  11. // You can of course change this.
  12. // or
  13. // -dQBEIBX: Use IBX objects in Visual Query Builder
  14. // to do: needs to be tested/implemented in this demo form
  15. { todo:
  16. - rework as lpk package
  17. - doubleclick in sort cell sorts asc/desc/none not only rightclick
  18. - reinstate registering engines such as sqldb, zeos, ibx so package requirements
  19. can be easily specified
  20. - extract icons rework them as png or whatever so we have source
  21. - test on Linux, OSX
  22. }
  23. interface
  24. uses
  25. SysUtils, Forms, StdCtrls, QBuilder
  26. {$IFDEF QBEIBX}
  27. , {IBDatabase? ,} QBEIBX
  28. {$ENDIF}
  29. {$IFDEF QBESQLDB}
  30. , sqldb, QBESqlDb
  31. , IBConnection {change this if you want another db}
  32. {$ENDIF}
  33. {$IFDEF QBEZEOS}
  34. , ZConnection, QBEZEOS
  35. {$ENDIF}
  36. , Classes;
  37. type
  38. { TForm1 }
  39. TForm1 = class(TForm)
  40. Button1: TButton;
  41. Memo1: TMemo;
  42. {$IFDEF QBESQLDB}
  43. FDbConnection: TIBConnection;
  44. FDBTrans: TSQLTransaction;
  45. {$ENDIF}
  46. {$IFDEF QBEZEOS}
  47. FDbConnection: TZConnection;
  48. {$ENDIF}
  49. //todo: add support for QBEIBX
  50. procedure Button1Click(Sender: TObject);
  51. procedure FormCreate(Sender: TObject);
  52. procedure FormDestroy(Sender: TObject);
  53. private
  54. { private declarations }
  55. public
  56. { public declarations }
  57. end;
  58. var
  59. Form1: TForm1;
  60. implementation
  61. { TForm1 }
  62. procedure TForm1.Button1Click(Sender: TObject);
  63. var
  64. meuqb: TOQBuilderDialog;
  65. {$IFDEF QBEIBX}
  66. VisualQueryEngine: TOQBEngineIBX;
  67. {$ENDIF}
  68. {$IFDEF QBESQLDB}
  69. VisualQueryEngine: TOQBEngineSQLDB;
  70. {$ENDIF}
  71. {$IFDEF QBEZEOS}
  72. VisualQueryEngine: TOQBEngineZEOS;
  73. {$ENDIF}
  74. begin
  75. try
  76. //todo: add ibx code
  77. {$IFDEF QBESQLDB}
  78. FDbConnection.DatabaseName := ExtractFilePath(Application.ExeName)+'EMPLOYEE.FDB';
  79. {$ENDIF}
  80. {$IFDEF QBEZEOS}
  81. DbConnection.Database := ExtractFilePath(Application.ExeName)+'EMPLOYEE.FDB';
  82. {$ENDIF}
  83. meuqb := TOQBuilderDialog.Create(nil);
  84. {$IFDEF QBESQLDB}
  85. VisualQueryEngine := TOQBEngineSQLDB.Create(nil);
  86. {$ENDIF}
  87. {$IFDEF QBEZEOS}
  88. VisualQueryEngine := TOQBEngineZEOS.Create(nil);
  89. {$ENDIF}
  90. VisualQueryEngine.Connection := FDbConnection;
  91. meuqb.OQBEngine := VisualQueryEngine;
  92. {$IFDEF QBESQLDB}
  93. meuqb.OQBEngine.DatabaseName := FDbConnection.DatabaseName;
  94. {$ENDIF}
  95. {$IFDEF QBEZEOS}
  96. meuqb.OQBEngine.DatabaseName := DbConnection.Database;
  97. // If using OQBEngineZEOS: to specify a PostgreSQL schema, set
  98. // VisualQueryEngine.SchemaPostgreSQL := 'my_schema';
  99. VisualQueryEngine.ShowSystemTables := False;
  100. {$ENDIF}
  101. {$IFDEF QBESQLDB}
  102. FDbConnection.Open;
  103. {$ENDIF}
  104. {$IFDEF QBEZEOS}
  105. DbConnection.Connect;
  106. {$ENDIF}
  107. if meuqb.Execute then Memo1.Text := meuqb.SQL.Text;
  108. finally
  109. meuqb.Free;
  110. VisualQueryEngine.Free;
  111. end;
  112. end;
  113. procedure TForm1.FormCreate(Sender: TObject);
  114. begin
  115. // Example using Firebird embedded for both QBESQLDB and QBEZEOS
  116. //todo: add ibx code
  117. {$IFDEF QBESQLDB}
  118. FDbConnection := TIBConnection.Create(nil);
  119. FDbConnection.HostName := '';
  120. FDbConnection.UserName := 'SYSDBA';
  121. FDBTrans := TSQLTransaction.Create(nil);
  122. FDbConnection.Transaction := FDBTrans;
  123. {$ENDIF}
  124. {$IFDEF QBEZEOS}
  125. DbConnection:=ZConnection.Create(nil);
  126. DbConnection.Protocol := 'firebird-2.5';
  127. DbConnection.ControlsCodePage := cCP_UTF8;
  128. DbConnection.User := 'SYSDBA';
  129. {$ENDIF}
  130. FDbConnection.Password := ''; //leave empty to avoid lookup in FB security db
  131. end;
  132. procedure TForm1.FormDestroy(Sender: TObject);
  133. begin
  134. {$IFDEF QBESQLDB}
  135. FDBTrans.Free;
  136. {$ENDIF}
  137. FDbConnection.Free;
  138. end;
  139. {$R *.lfm}
  140. end.