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::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

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

Reply via email to