Re: Connect to MySQL server from a c++ application
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
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
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
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
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