List:General Discussion« Previous MessageNext Message »
From:Lars Nilsson Date:June 7 2012 5:55pm
Subject:Re: Connect to MySQL server from a c++ application
View as plain text  
On Thu, Jun 7, 2012 at 12:55 PM, Claudio Nanni <claudio.nanni@stripped> 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::map<int, 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
Thread
Connect to MySQL server from a c++ applicationSimon Walter7 Jun
  • Re: Connect to MySQL server from a c++ applicationLars Nilsson7 Jun
  • Re: Connect to MySQL server from a c++ applicationSimon Walter7 Jun
    • Re: Connect to MySQL server from a c++ applicationLars Nilsson7 Jun
      • Re: Connect to MySQL server from a c++ applicationClaudio Nanni7 Jun
        • Re: Connect to MySQL server from a c++ applicationBaron Schwartz7 Jun
        • Re: Connect to MySQL server from a c++ applicationLars Nilsson7 Jun
  • Re: Connect to MySQL server from a c++ applicationSimon Walter8 Jun
    • Re: Connect to MySQL server from a c++ applicationClaudio Nanni8 Jun