#1 2013-03-31 17:01:23

wai-kit
Member
From: Amsterdam, the Netherlands
Registered: 2012-11-27
Posts: 90

Using SynDBZeos.

Hi Arnaud,

I'm trying to use SynDBZeos to connect to a MySQL Database using the following:
   fDatabase:TSQLDBConnectionProperties;
   ...
   ...
   fDatabase := TSQLDBZEOSConnectionProperties.Create(ServerName, Databasename, Username, Password);

Servername is the hostname of the computer, Databasename is the databasename as created in MySQL, etc. etc.

The create seems to be executed without a problem, but when I get to 'res := fDatabase.ExecuteInlined(aSQLQuery, true);' I get a
EZSQLException with the message 'Requested Database driver was not found'. Apparently, it is unknown what the database is.

The question is, how do I provide the information to the constructor that the database is a MySQL database?

Cheers,
Wai


fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...

Offline

#2 2013-03-31 19:25:45

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: Using SynDBZeos.

You have all the information at the constructor level of the class:

    /// initialize the properties to connect to the ZEOS engine
    // - aServerName shall contain the ZEOS URI, e.g:
    // $ zdbc:firebird-2.0://127.0.0.1:3050/model?username=sysdba;password=masterkey
    // $ sqlite
    // i.e. '[zdbc:]PROTOCOL://HOST:PORT[/DATABASE][?paramname=value]'
    // - you can define the TZConnection.LibraryLocation property by setting a
    // '?LibLocation=...' parameter within the aServerName URL value
    // - or simple use TSQLDBZEOSConnectionProperties.URI() class method
    // - aDatabaseName, aUserID, aPassword are used if not already set as URI
    // in aServerName value
    // - you can use Protocols property to retrieve all available protocol names
    constructor Create(const aServerName, aDatabaseName, aUserID, aPassWord: RawUTF8); override;

In short, the easiest is to use TSQLDBZEOSConnectionProperties.URI():

    /// compute the ZEOS URI from a given database engine
    // - you can set an optional full path to the client library name,
    // to be completed on the left side with the executable path
    // - possible use may be:
    // ! PropsOracle := TSQLDBZEOSConnectionProperties.Create(
    // !   TSQLDBZEOSConnectionProperties.URI(dOracle,'oci64\oci.dll'),
    // !   'tnsname','user',pass');
    // ! PropsFirebird := TSQLDBZEOSConnectionProperties.Create(
    // !   TSQLDBZEOSConnectionProperties.URI(dFirebird,'Firebird\fbembed.dll'),
    // !   'databasefilename','',');
    class function URI(aServer: TSQLDBDefinition;
      const aLibraryLocation: TFileName='';
      aLibraryLocationAppendExePath: boolean=true): RawUTF8;

Take a look at the sample unit PerfMain.pas, in sample 15.

Note that MySQL is not fully tested (we do not use it here), so feedback is warmly welcome!

Offline

#3 2013-05-06 15:34:47

wai-kit
Member
From: Amsterdam, the Netherlands
Registered: 2012-11-27
Posts: 90

Re: Using SynDBZeos.

back again fiddling with SynDBZeos.

so when using function URI of TSQLDBZEOSConnectionProperties the function call would look like:

  fDatabase := TSQLDBZEOSConnectionProperties.Create(TSQLDBZEOSConnectionProperties.URI(dMySQL, 'libmysql.dll'),
                                                DatabaseProperties.DatabaseName,
                                                DatabaseProperties.Username,
                                                DatabaseProperties.Password );

I assume I have to provide the name of the MySQL lib, 'libmysql.dll' to the function.

Now I get an EZSQLException with the message 'Requested database driver was not found'. In my code this exception is raised at this statement:

res := fDatabase.ExecuteInlined(aSQLQuery, true);

aSQLQuery being a valid SQL statement.

If I inspect fDatabase, I see that fServerName is 'mysql'. Shouldn't this be
the name of the server where MySQL is running?

Last edited by wai-kit (2013-05-06 15:39:42)


fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...

Offline

#4 2013-05-06 15:44:26

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: Using SynDBZeos.

I did not check dMySQL kind of engine by now (only Oracle + FireBird + SQlite3).

But using TSQLDBZEOSConnectionProperties.URI() sounds the right way to do it.

Please step in the debugger to see what is happening.

Offline

Board footer

Powered by FluxBB