Recent

Author Topic: MySQL client version: Expected (5.6) , got (5.7.16)  (Read 9872 times)

vasskalinin

  • New Member
  • *
  • Posts: 10
MySQL client version: Expected (5.6) , got (5.7.16)
« on: December 03, 2016, 12:52:31 am »
Is there a way I can use MySQL 5.7 with Lazarus?
I use the last Lazarus versions for both Linux (1.6.0) and Windows (1.6.2) and there doesn't seem to be any support for the MySQL 5.7 client library, and I get an error when I try to connect with my database.
Plus, I can't find the package libmysqlclient-dev version 5.6 or below...
« Last Edit: December 03, 2016, 01:04:27 am by vasskalinin »

vasskalinin

  • New Member
  • *
  • Posts: 10
Re: MySQL client version: Expected (5.6) , got (5.7.16)
« Reply #1 on: December 03, 2016, 06:58:56 am »
Apparently I solved it, at least on windows.
I downloaded an old version of MySQL from right here: http://dev.mysql.com/downloads/mysql/5.0.html and then when it asked for DLLs I copied then from the /lib/ folder in the zip and moved them to System32, and that's it, I think.

Thaddy

  • Hero Member
  • *****
  • Posts: 14213
  • Probably until I exterminate Putin.
Re: MySQL client version: Expected (5.6) , got (5.7.16)
« Reply #2 on: December 03, 2016, 08:36:48 am »
MySQL 5.7 is in fpc trunk. You can use the interface unit in 3.0.x as well.
Specialize a type, not a var.

vasskalinin

  • New Member
  • *
  • Posts: 10
Re: MySQL client version: Expected (5.6) , got (5.7.16)
« Reply #3 on: December 03, 2016, 04:51:05 pm »
How exactly I do that? Thank you.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: MySQL client version: Expected (5.6) , got (5.7.16)
« Reply #4 on: December 03, 2016, 05:18:40 pm »
The connection component holds the version. Switch the 5.6 component for a 5.7 one.

vasskalinin

  • New Member
  • *
  • Posts: 10
Re: MySQL client version: Expected (5.6) , got (5.7.16)
« Reply #5 on: December 03, 2016, 06:28:13 pm »
The connection component holds the version. Switch the 5.6 component for a 5.7 one.
There is no 5.7 component

Thaddy

  • Hero Member
  • *****
  • Posts: 14213
  • Probably until I exterminate Putin.
Re: MySQL client version: Expected (5.6) , got (5.7.16)
« Reply #6 on: December 03, 2016, 06:46:17 pm »
Sigh. Yes there is. In trunk. As I wrote. In package fcl-db. /packages/fcl-db/src/sqldb/mysql/mysql57conn.pas
« Last Edit: December 03, 2016, 08:05:27 pm by Thaddy »
Specialize a type, not a var.

vasskalinin

  • New Member
  • *
  • Posts: 10
Re: MySQL client version: Expected (5.6) , got (5.7.16)
« Reply #7 on: December 03, 2016, 10:14:54 pm »
Sigh. Yes there is. In trunk. As I wrote. In package fcl-db. /packages/fcl-db/src/sqldb/mysql/mysql57conn.pas
And... How do I use it with lazarus?

vrull

  • Full Member
  • ***
  • Posts: 118
Re: MySQL client version: Expected (5.6) , got (5.7.16)
« Reply #8 on: December 04, 2016, 10:44:51 pm »
I asked same question not long ago.
Just add "mysql57conn" to uses  list and that it.

vasskalinin

  • New Member
  • *
  • Posts: 10
Re: MySQL client version: Expected (5.6) , got (5.7.16)
« Reply #9 on: December 05, 2016, 03:10:58 am »
I asked same question not long ago.
Just add "mysql57conn" to uses  list and that it.
And it works only on runtime? Taking note, I used mysql 5.5 on my system...

vrull

  • Full Member
  • ***
  • Posts: 118
Re: MySQL client version: Expected (5.6) , got (5.7.16)
« Reply #10 on: December 05, 2016, 08:24:40 am »
Yes, I create connections dynamically at runtime. The full code is below, it is a public function in DataModule:
Code: Pascal  [Select][+][-]
  1. unit uDM;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, sqlite3conn, sqldb, sqldblib, IBConnection, mysql40conn,
  9.   mysql56conn, mysql57conn, mysql55conn, mssqlconn, db, LazFileUtils;
  10.  
  11. const
  12.   connList : array [0..4] of string =
  13.      ('SQLite3', 'MySQL 4.0', 'MySQL 5.5', 'MySQL 5.6', 'MS SQL');
  14. type
  15.  
  16.   { TDM }
  17.  
  18.   TDM = class(TDataModule)
  19.     dsDataSource: TDataSource;
  20.     qSQLQuery: TSQLQuery;
  21.     SQLDBLibraryLoader: TSQLDBLibraryLoader;
  22.     SQLTransaction: TSQLTransaction;
  23.     SQLTranUpdate: TSQLTransaction;
  24.     connSQL : TSQLConnection;
  25.     procedure DataModuleCreate(Sender: TObject);
  26.     procedure DataModuleDestroy(Sender: TObject);
  27.   private
  28.     FconnType: integer;
  29.     paramList : TStringList;
  30.     procedure SetconnType(AValue: integer);
  31.   public
  32.     function GetCLParameter(const paramName : string; const defValue : string = '') : string;
  33.     function FindConfigName(const fName : string) : string;
  34.     function ConnectToDatabase(var SQLConnection : TSQLConnection; const test : boolean = false) : boolean;
  35.     property connType : integer read FconnType write SetconnType;
  36.   end;
  37.  
  38. var
  39.   DM: TDM;
  40.  
  41. implementation
  42. {$R *.lfm}
  43. uses uGlobal;
  44.  
  45. // this part is skipped
  46. .....
  47.  
  48. // ConnectToDatabase is to create a new connection depending on what connection type is in the configuration file
  49. // parameters: SQLconnection returns working connection
  50. //  test is true on program start to find out if we can connect at all; the returned connection serves system tables
  51. function TDM.ConnectToDatabase(var SQLConnection : TSQLConnection; const test : boolean = false) : boolean;
  52. var
  53.   connName : string;
  54.   i : integer;
  55. begin
  56.   Result := false;
  57.   if test then
  58.     begin
  59.       connName := gConf.ReadString(secConn, 'connectionType', connList[0]);
  60.       if gConf.ReadError then exit; // connection type does not exists
  61.       FconnType := -1;
  62.       for i := 0 to High(connList) do
  63.         if connName = connList[i] then
  64.           FconnType := i;
  65.       if FconnType = -1 then exit; // no match
  66.       SQLconnection := connSQL;
  67.       SQLTranUpdate.DataBase := SQLConnection;
  68.     end;
  69.   SQLDBLibraryLoader.ConnectionType := connList[FconnType];
  70.   case FconnType of
  71.     0 : begin         // SQLite3
  72.           SQLiteLibraryName := gConf.ReadString(secConn, 'libraryName', SQLiteLibraryName);
  73.           SQLConnection := TSQLite3Connection.Create(self);
  74.         end;
  75.     1 : begin         //MySQL4.0
  76.           SQLConnection := TMySQL40Connection.Create(self);
  77.           TMySQL40Connection(SQLConnection).Port := gConf.ReadInteger(secConn, 'port');
  78.         end;
  79.     2 : begin         //MySQL5.5
  80.           SQLConnection := TMySQL55Connection.Create(self);
  81.           TMySQL55Connection(SQLConnection).Port := gConf.ReadInteger(secConn, 'port');
  82.         end;
  83.     3 : begin         //MySQL5.7
  84.           SQLConnection := TMySQL57Connection.Create(self);
  85.           TMySQL57Connection(SQLConnection).Port := gConf.ReadInteger(secConn, 'port');
  86.           TMySQL57Connection(SQLConnection).SkipLibraryVersionCheck:= true;
  87.           {$IFDEF UNIX}
  88.           SQLDBLibraryLoader.LibraryName := gConf.ReadString(secConn, 'libraryName', 'libmysqlclient.so');
  89.           {$ENDIF}
  90.         end;
  91.     4 : begin         //MSSQL
  92.           SQLConnection := TMSSQLConnection.Create(self);
  93.         end;
  94.     end;
  95.   SQLConnection.DatabaseName := gConf.ReadString(secConn, 'databaseName');
  96.   SQLConnection.HostName := gConf.ReadString(secConn, 'hostName');
  97.   SQLConnection.UserName := gConf.ReadString(secConn, 'userName');
  98.   SQLConnection.Password := gConf.ReadString(secConn, 'password');
  99.   SQLConnection.LoginPrompt := gConf.ReadBoolean(secConn, 'loginPrompt');
  100.   if test then
  101.     begin
  102.       SQLDBLibraryLoader.Enabled := true;
  103.       SQLDBLibraryLoader.LoadLibrary;
  104.     end;
  105.   SQLConnection.Open;
  106.   Result := SQLConnection.Connected;
  107.   if test then SQLConnection.Close;
  108. end;
  109.  
  110.  
gConf is an XML configuration file, it works exactly same way as TINIFile. For example:
Code: Pascal  [Select][+][-]
  1.   SQLConnection.HostName := gConf.ReadString(secConn, 'hostName');
reads HostName key from section which name is in secConn constant. Third parameter is the default value, it is not present here, so it would return empty string, if there were no such key.

You can throw away all that complexity, I did not do it just to avoid deleting something important. The above code was tested and worked with
SQLite 3  on Windows and Linux;
mySQL 5.6 and 5.7 on Linux;
MSSQL (SQLServer 2012) on Windows.

The chain is
TSQLConnection -> TSQLTransaction -> TSQLQuery -> [TDataSource]
Other components are not dependent on connection type, they usually reside on forms, where needed, along with DBGrids and other data-aware components.

Thaddy

  • Hero Member
  • *****
  • Posts: 14213
  • Probably until I exterminate Putin.
Re: MySQL client version: Expected (5.6) , got (5.7.16)
« Reply #11 on: December 05, 2016, 08:39:39 am »
If you have Laz 1.6 or 1.7 AND very important FPC 3.0 or higher the component is also installed.
So 5.7 was already in 3.0.x. Ergo : Your Lazarus may be up to date but you are using an old and unsupported version of FPC (maybe 2.6.4?) FPC 3.0 is the current release version.
Specialize a type, not a var.

vrull

  • Full Member
  • ***
  • Posts: 118
Re: MySQL client version: Expected (5.6) , got (5.7.16)
« Reply #12 on: December 06, 2016, 05:24:46 am »
In Lazarus 1.6 the unit mysql57conn is installed, but the component does not exist in the component palette. Not sure how it is in 1.7.

 

TinyPortal © 2005-2018