Re: Connect to MySQL server from a c++ application

2012-06-08 Thread Simon Walter


On 06/08/2012 01:55 AM, Claudio Nanni wrote:

Hi,

you guys don't like the official API?

http://dev.mysql.com/downloads/connector/c/



That's C isn't it? I think there is also a C++ connector. I'm interested 
to hear how that performs. It seems like a waste of time to write a 
bunch of wrappers for the C connector.



--
simonsmicrophone.com

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Re: Connect to MySQL server from a c++ application

2012-06-08 Thread Claudio Nanni
Simon,

yes it is C,

C++ here:  http://dev.mysql.com/downloads/connector/cpp/

I did not work with this libraries and to be honest I do not know about
their performances,

If you have the chance it would be extremely useful for the community
having some tests done with both APIs.

Cheers

Claudio

2012/6/8 Simon Walter si...@gikaku.com


 On 06/08/2012 01:55 AM, Claudio Nanni wrote:

 Hi,

 you guys don't like the official API?

 http://dev.mysql.com/**downloads/connector/c/http://dev.mysql.com/downloads/connector/c/


 That's C isn't it? I think there is also a C++ connector. I'm interested
 to hear how that performs. It seems like a waste of time to write a bunch
 of wrappers for the C connector.


 --
 simonsmicrophone.com


 --
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:http://lists.mysql.com/mysql




-- 
Claudio


Re: Connect to MySQL server from a c++ application

2012-06-07 Thread Simon Walter


On 06/07/2012 12:29 PM, Lars Nilsson wrote:


On Wed, Jun 6, 2012 at 10:41 PM, Simon Waltersi...@gikaku.com  wrote:

However, memory leaks are not acceptable. So I am open to suggestions. What
do other c++ programmers use?


I've been happy using SQLAPI++ (http://www.sqlapi.com/) where I work.
Commercial and not open source, but it's cross-platform and supports a
dozen or so different databases.



It looks nice. I'm looking for something open source. I'm fine using one 
of the SQL connectors. I just need to know which one works. How does 
SQLAPI++ connect to MySQL? Is it thread safe?


--
simonsmicrophone.com

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Re: Connect to MySQL server from a c++ application

2012-06-07 Thread Lars Nilsson
On Thu, Jun 7, 2012 at 3:08 AM, Simon Walter si...@gikaku.com wrote:
 On 06/07/2012 12:29 PM, Lars Nilsson wrote:
 I've been happy using SQLAPI++ (http://www.sqlapi.com/) where I work.
 Commercial and not open source, but it's cross-platform and supports a
 dozen or so different databases.

 It looks nice. I'm looking for something open source. I'm fine using one of
 the SQL connectors. I just need to know which one works. How does SQLAPI++
 connect to MySQL? Is it thread safe?

It loads the libmysqlclient dll/so libraries under the hood, mapping
each database client library's particular function set to its own
internal function pointers. I believe it to be thread-safe (pthread
mutexes on Linux/Unix, Windows relies on mutex/critical section
objects). Instances of SAConnection objects should probably not be
used across threads simultaneously though (usual caveats when doing
multi-threaded programming apply, etc).

I do like the high-level abstraction of the databases, and the use of
exceptions for errors so every statement doesn't need to have a check
to see if it was successful (just wrap your sequence of operations in
a try/catch as makes sense for the application). I know it reduced my
database-specific lines of code quite a bit when I changed a MySQL
specific program to using SQLAPI++.

If one need to, it is always possible to get a native database handle
out that can be used with the database-specific API (at which point
your program would have to be linked with the required
database-specific client libraries, and so on), but it is not
something I have really needed personally. If at all possible, I stay
in the realm of SQLAPI++ which makes my program independent of the
database libraries (implies I do not use native handles). It means I
can compile my program without having Oracle installed for instance,
and as long as a user has some means of configuring my program so that
SA_Oracle_Client is passed to a connection object (mapping from string
to the enum value or whatever else make sense), it should just work,
given a proper connection string (as long as one handles the special
cases properly as outlined in database specific notes for the classes
and methods, etc)

I'm sorry if I sound like a sales person for SQLAPI++. I have no
relation to it, just a satisfied user.

Lars Nilsson

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Re: Connect to MySQL server from a c++ application

2012-06-07 Thread Claudio Nanni
Hi,

you guys don't like the official API?

http://dev.mysql.com/downloads/connector/c/

Cheers

Claudio

2012/6/7 Lars Nilsson chamael...@gmail.com

 On Thu, Jun 7, 2012 at 3:08 AM, Simon Walter si...@gikaku.com wrote:
  On 06/07/2012 12:29 PM, Lars Nilsson wrote:
  I've been happy using SQLAPI++ (http://www.sqlapi.com/) where I work.
  Commercial and not open source, but it's cross-platform and supports a
  dozen or so different databases.

  It looks nice. I'm looking for something open source. I'm fine using one
 of
  the SQL connectors. I just need to know which one works. How does
 SQLAPI++
  connect to MySQL? Is it thread safe?

 It loads the libmysqlclient dll/so libraries under the hood, mapping
 each database client library's particular function set to its own
 internal function pointers. I believe it to be thread-safe (pthread
 mutexes on Linux/Unix, Windows relies on mutex/critical section
 objects). Instances of SAConnection objects should probably not be
 used across threads simultaneously though (usual caveats when doing
 multi-threaded programming apply, etc).

 I do like the high-level abstraction of the databases, and the use of
 exceptions for errors so every statement doesn't need to have a check
 to see if it was successful (just wrap your sequence of operations in
 a try/catch as makes sense for the application). I know it reduced my
 database-specific lines of code quite a bit when I changed a MySQL
 specific program to using SQLAPI++.

 If one need to, it is always possible to get a native database handle
 out that can be used with the database-specific API (at which point
 your program would have to be linked with the required
 database-specific client libraries, and so on), but it is not
 something I have really needed personally. If at all possible, I stay
 in the realm of SQLAPI++ which makes my program independent of the
 database libraries (implies I do not use native handles). It means I
 can compile my program without having Oracle installed for instance,
 and as long as a user has some means of configuring my program so that
 SA_Oracle_Client is passed to a connection object (mapping from string
 to the enum value or whatever else make sense), it should just work,
 given a proper connection string (as long as one handles the special
 cases properly as outlined in database specific notes for the classes
 and methods, etc)

 I'm sorry if I sound like a sales person for SQLAPI++. I have no
 relation to it, just a satisfied user.

 Lars Nilsson

 --
 MySQL General Mailing List
 For list archives: http://lists.mysql.com/mysql
 To unsubscribe:http://lists.mysql.com/mysql




-- 
Claudio


Re: Connect to MySQL server from a c++ application

2012-06-07 Thread Baron Schwartz
There is also libdrizzle.

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Re: Connect to MySQL server from a c++ application

2012-06-07 Thread Lars Nilsson
On Thu, Jun 7, 2012 at 12:55 PM, Claudio Nanni claudio.na...@gmail.com wrote:
 Hi,

 you guys don't like the official API?

 http://dev.mysql.com/downloads/connector/c/

 Cheers

 Claudio

Personally? Not really.

For instance, memory leaks are not acceptable according to Simon's
expressed desire.

SQLAPI++ allows me to completely avoid explicit memory/resource
allocation, if I put things on the stack.

class Foo { int x; std::string y; }
typedef std::mapint, Foo FooV;

FooV vFoo;

try
{
  SAConnection db(db, user, password);
  SACommand cmd(db);

  cmd.setCommandText(SELECT id, name FROM foo);
  cmd.Execute();

  while (cmd.FetchNext())
  {
Foo foo;
foo.x = cmd.Field(1).asLong();
foo.y = (const char *)cmd.Field(2).asString();
vFoo[foo.x] = foo;
  }
}
catch (SAException e)
{
  std::cerr  Failure:   (const char *)e.ErrText();
}

Using MySQL's API I'd need to make sure I close connections I open,
free result sets I get back, etc. SQLAPI++ perform these operations
behind the scenes for me when objects are created/initialized and
destroyed. If I happen to use pointers for some of these instead of
putting them on the stack, the ball is back in my court again to make
sure I don't lose track of something.

This is my personal preference. YMMV.

Lars Nilsson

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Connect to MySQL server from a c++ application

2012-06-06 Thread Simon Walter


What is the most stable and performant way to connect to a MySQL server 
from a c++ application?


I've been using libmyodbc via unixODBC running under Debian squeeze. 
Suffice it to say, I am sorely disappointed. First of all the libmyodbc 
driver that's included with Debian is quite old. However, even after 
building and utilizing the latest version, there are still memory leaks 
in the driver.


I'm not stuck on using ODBC. Though it's nice to be able to is use an 
ODBC library so that I can connect to various DBs without having to 
learn new APIs. There is also the benefit of being able to change 
databases without much effort.


However, memory leaks are not acceptable. So I am open to suggestions. 
What do other c++ programmers use?


(note: I know this is probably not the place to ask this, but the 
libmyodbc mailing is dead as a door nail with people's auto-responders 
going off like a digital ghost town. :/)


Thanks,

Simon

--
simonsmicrophone.com


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



Re: Connect to MySQL server from a c++ application

2012-06-06 Thread Lars Nilsson
On Wed, Jun 6, 2012 at 10:41 PM, Simon Walter si...@gikaku.com wrote:
 However, memory leaks are not acceptable. So I am open to suggestions. What
 do other c++ programmers use?

I've been happy using SQLAPI++ (http://www.sqlapi.com/) where I work.
Commercial and not open source, but it's cross-platform and supports a
dozen or so different databases.

One of the example programs (without comments and the wrapping try/catch block)

con.Connect(test, tester, tester, SA_Oracle_Client);
cmd.setConnection(con);
cmd.setCommandText(
Insert into test_tbl(fid, fvarchar20) values(:1, :2));
cmd.Param(1).setAsLong() = 2;
cmd.Param(2).setAsString() = Some string (2);
cmd.Execute();
cmd  (long)3  Some string (3);
cmd.Execute();
con.Commit();

Simply replace SA_Oracle_Client with SA_MySQL_Client, etc, and you'll
be working against MySQL. Only requirement is that the dll/so
libraries for each database you want to connect to are installed
properly.

Lars Nilsson

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql