Recent

Author Topic: How I can validate if conntection to server is Mysql, sqlserver or firebird  (Read 1543 times)

eldonfsr

  • Hero Member
  • *****
  • Posts: 526
if possible by using a command 
 {$DEFINE SLQDB}
  {$IFDEF TMySQl57Connection}
  {
    SQLDBLLib.LibraryName:= WideString(ExtractFilePath(ParamStr(0)) + 'libmysql.dll');
    SQLDBLLib.LoadLibrary;
    if(SQLDBLLib.Enabled = True) then begin
     if mysql57c.Connected = true then begin ;
       SQLQuery1.Open;
     end else begin
       mysql57c.Connected:=true;
       SQLQuery1.Open;
     end;
    end;

  } 
{$ENDIF}
or how i can validate what king of server is database connected...

Thanks...

MarkMLl

  • Hero Member
  • *****
  • Posts: 8044
Somewhere in your code you've made the decision to use (i.e. import) certain units, and to associate a TQuery with server-specific units. Apart from that, look at the class of your connection object.

Note https://forum.lazarus.freepascal.org/index.php/topic,63982.msg488274.html#msg488274 which discussed in some detail the problems of actually determining whether a database connection was usable. The bottom line is that that the graphical components have no idea whether the backend is still interested in them.

MarkMLl

p.s. Please remember to use code tags in your postings.
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

eldonfsr

  • Hero Member
  • *****
  • Posts: 526
Thanks MARK this my code , I imported de units of import is different to USE

Code: Pascal  [Select][+][-]
  1.  
  2. unit fmain;
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, SQLDB, SQLDBLib, mysql57conn, DB, Forms, Controls,
  10.   Graphics, Dialogs, Menus, ActnList, StdCtrls, ExtCtrls, DBTreeView,
  11.   dbcntrlgrid;
  12.  
  13. type
  14.  
  15.   { TForm1 }
  16.  
  17.   TForm1 = class(TForm)
  18.     ActionList1: TActionList;
  19.     AddChild: TAction;
  20.     AddFirstChild: TAction;
  21.     AddSibling: TAction;
  22.     DataSource1: TDataSource;
  23.     DataSource2: TDataSource;
  24.     DBCntrlGrid1: TDBCntrlGrid;
  25.     DBTreeView1: TDBTreeView;
  26.     DeleteNode: TAction;
  27.     ImageList1: TImageList;
  28.     Memo1: TMemo;
  29.     Memo2: TMemo;
  30.     MenuItem1: TMenuItem;
  31.     MenuItem2: TMenuItem;
  32.     MenuItem3: TMenuItem;
  33.     MenuItem4: TMenuItem;
  34.     MySQL57C: TMySQL57Connection;
  35.     Panel1: TPanel;
  36.     Panel2: TPanel;
  37.     PopupMenu1: TPopupMenu;
  38.     SQLDBLLib: TSQLDBLibraryLoader;
  39.     SQLQuery1: TSQLQuery;
  40.     SQLQuery2: TSQLQuery;
  41.     SQLTMyc: TSQLTransaction;
  42.     procedure FormShow(Sender: TObject);
  43.   private
  44.  
  45.   public
  46.  
  47.   end;
  48.  
  49. var
  50.   Form1: TForm1;
  51.  
  52. implementation
  53.  
  54. {$R *.lfm}
  55.  
  56. { TForm1 }
  57.  
  58. procedure TForm1.FormShow(Sender: TObject);
  59. begin
  60.   {$DEFINE TSLQDB}   // Some define like this
  61.   {$IFDEF TMySQl57Connection}  // could be mysql connection because there different versions of mysql client connecttion...
  62.      if mysql57c.Connected = true then begin ;
  63.        SQLQuery1.Open;
  64.      end else begin
  65.        mysql57c.Connected:=true;
  66.        SQLQuery1.Open;
  67.      end;
  68.     {$ENDIF}
  69. {$ENDIF}
  70. end;
  71.  
  72.  
  73. end.
  74.  
  75.  
  76.  

MarkMLl

  • Hero Member
  • *****
  • Posts: 8044
So if you're only importing one type of connector, why do you need to work out which one is being used?

If you decide to import more than one, how do you intend to select the one to be used?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

eldonfsr

  • Hero Member
  • *****
  • Posts: 526
Hi Mark thanks for replay, i don't sure if is right or wrong but is for use on dbtree if i run example with firebird run perfect but when i run with mysql send me error, so check  on procedure updatetree has some changes on sql
here is the code where dbtree make cnahges for that i think if know what connection is used to change syntax of sql query.... you can how could be look changes...

Code: Pascal  [Select][+][-]
  1. procedure TDBTreeView.UpdateSQL;
  2. begin
  3.   if DataSet is TSQLQuery then begin
  4.     if fSQLWherePosition = -1 then
  5.       Raise Exception.Create('No where clause detected.');
  6.     TSQLQuery.SQLConnection.GetConnectionInfo();
  7.     {$if declared( TIBCONNECTION)}
  8.        if not assigned(FExpandNode) and assigned(FUpdateNode)  then begin {Scrolling dataset}
  9.         TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where '+GetRelationNameQualifier+'"' + FKeyField + '" = :KEY_VALUE AND ';
  10.         //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_KEY_VALUE')
  11.        end
  12.        else
  13.         if (Items.Count = 0) then begin
  14.           {Need to Load Root Nodes}
  15.           TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where '+GetRelationNameQualifier+'"' + FParentField + '" is null AND ';
  16.           //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" is null')
  17.         end
  18.       else
  19.       if assigned(FExpandNode) then
  20.        begin
  21.         TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where ( '+GetRelationNameQualifier+'"' + FParentField + '" = :PARENT_VALUE OR '+GetRelationNameQualifier+'"' + FKeyField + '" = :PARENT_VALUE ) AND '
  22.         //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" = :IBX_PARENT_VALUE');
  23.         //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_PARENT_VALUE',true);
  24.       end;
  25.       {$ENDIF}
  26.  
  27.         {$if declared( TMYSQL57Connection) }
  28.            if not assigned(FExpandNode) and assigned(FUpdateNode)  then begin {Scrolling dataset}
  29.             TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where '+GetRelationNameQualifier+ FKeyField + ' = :KEY_VALUE AND ';
  30.             //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_KEY_VALUE')
  31.            end
  32.            else
  33.             if (Items.Count = 0) then begin
  34.               {Need to Load Root Nodes}
  35.               TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where '+GetRelationNameQualifier+ FParentField + ' is null AND ';
  36.               //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" is null')
  37.             end
  38.           else
  39.           if assigned(FExpandNode) then
  40.            begin
  41.             TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where ( '+GetRelationNameQualifier+ FParentField + ' = :PARENT_VALUE OR '+GetRelationNameQualifier + FKeyField + ' = :PARENT_VALUE ) AND '
  42.             //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" = :IBX_PARENT_VALUE');
  43.             //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_PARENT_VALUE',true);
  44.           end;
  45.           {$ENDIF}
  46.  
  47.  
the way we can run sql on mysql we don't use '"' to put values but look firebird accept that... 

MarkMLl

  • Hero Member
  • *****
  • Posts: 8044
But that won't work if you've imported the units for two or more different databases. As I've already said, you need to look at what the class of the connector actually being referenced by your query component is.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Zvoni

  • Hero Member
  • *****
  • Posts: 2754
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018