Forum > Databases

How I can validate if conntection to server is Mysql, sqlserver or firebird

(1/2) > >>

eldonfsr:
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:
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.

eldonfsr:
Thanks MARK this my code , I imported de units of import is different to USE


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- unit fmain; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, SQLDB, SQLDBLib, mysql57conn, DB, Forms, Controls,  Graphics, Dialogs, Menus, ActnList, StdCtrls, ExtCtrls, DBTreeView,  dbcntrlgrid; type   { TForm1 }   TForm1 = class(TForm)    ActionList1: TActionList;    AddChild: TAction;    AddFirstChild: TAction;    AddSibling: TAction;    DataSource1: TDataSource;    DataSource2: TDataSource;    DBCntrlGrid1: TDBCntrlGrid;    DBTreeView1: TDBTreeView;    DeleteNode: TAction;    ImageList1: TImageList;    Memo1: TMemo;    Memo2: TMemo;    MenuItem1: TMenuItem;    MenuItem2: TMenuItem;    MenuItem3: TMenuItem;    MenuItem4: TMenuItem;    MySQL57C: TMySQL57Connection;    Panel1: TPanel;    Panel2: TPanel;    PopupMenu1: TPopupMenu;    SQLDBLLib: TSQLDBLibraryLoader;    SQLQuery1: TSQLQuery;    SQLQuery2: TSQLQuery;    SQLTMyc: TSQLTransaction;    procedure FormShow(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormShow(Sender: TObject);begin  {$DEFINE TSLQDB}   // Some define like this  {$IFDEF TMySQl57Connection}  // could be mysql connection because there different versions of mysql client connecttion...      if mysql57c.Connected = true then begin ;       SQLQuery1.Open;     end else begin       mysql57c.Connected:=true;       SQLQuery1.Open;     end;    {$ENDIF}{$ENDIF}end;  end.   

MarkMLl:
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

eldonfsr:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TDBTreeView.UpdateSQL;begin  if DataSet is TSQLQuery then begin    if fSQLWherePosition = -1 then      Raise Exception.Create('No where clause detected.');    TSQLQuery.SQLConnection.GetConnectionInfo();    {$if declared( TIBCONNECTION)}        if not assigned(FExpandNode) and assigned(FUpdateNode)  then begin {Scrolling dataset}        TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where '+GetRelationNameQualifier+'"' + FKeyField + '" = :KEY_VALUE AND ';        //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_KEY_VALUE')       end       else        if (Items.Count = 0) then begin          {Need to Load Root Nodes}          TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where '+GetRelationNameQualifier+'"' + FParentField + '" is null AND ';          //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" is null')        end      else      if assigned(FExpandNode) then       begin        TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where ( '+GetRelationNameQualifier+'"' + FParentField + '" = :PARENT_VALUE OR '+GetRelationNameQualifier+'"' + FKeyField + '" = :PARENT_VALUE ) AND '        //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" = :IBX_PARENT_VALUE');        //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_PARENT_VALUE',true);      end;      {$ENDIF}         {$if declared( TMYSQL57Connection) }           if not assigned(FExpandNode) and assigned(FUpdateNode)  then begin {Scrolling dataset}            TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where '+GetRelationNameQualifier+ FKeyField + ' = :KEY_VALUE AND ';            //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_KEY_VALUE')           end           else            if (Items.Count = 0) then begin              {Need to Load Root Nodes}              TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where '+GetRelationNameQualifier+ FParentField + ' is null AND ';              //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" is null')            end          else          if assigned(FExpandNode) then           begin            TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where ( '+GetRelationNameQualifier+ FParentField + ' = :PARENT_VALUE OR '+GetRelationNameQualifier + FKeyField + ' = :PARENT_VALUE ) AND '            //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" = :IBX_PARENT_VALUE');            //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_PARENT_VALUE',true);          end;          {$ENDIF}  the way we can run sql on mysql we don't use '"' to put values but look firebird accept that... 

Navigation

[0] Message Index

[#] Next page

Go to full version