ThinkPart

Andrey's blog

 

We just broke Connector C++'s interface

 

The topic sounds scary, right? Don't be afraid, we just wanted to mention that we introduced a change in the interface, after we released the beta yesterday. Previous examples which use ConnectionMetaData, ResultSetMetaData and ParameterMetaData won't work anymore. They used to use std::auto_ptr to keep the code from leaking.

What we did is declare the destructors of the three aforementioned classes as protected. Thus, client code can't call them respectively delete the object. In turn we changed the classes that return the metadata objects to create just a single object and keep it alive till they are alive, then clean it up. Hence, the following will not leak anymore, like it used to:

cout << conn->getMetaData->getSchema();

It was going to leak before, because every call of getMetaData() was returning a new object, which the client had to free later. This complicated the code that wants one or two calls to getMetaData() to get some information. Also using the same pointer all the time makes the code even more efficint. A lot less objects are created and every ConnectionMetaData object creation has its overhead.

// This used to work
std::auto_ptr meta(conn->getMetaData());
cout << meta->getSchema() << "\n";
cout << meta->getProcedureTerm() << "\n";

// Now this works
sql::ConnectionMetaData * meta = conn->getMetaData();
cout << meta->getSchema() << "\n";
cout << meta->getProcedureTerm() << "\n";

// Or you can use this without risk of a leak
cout << conn->getMetaData()->getSchema() << "\n";
cout << conn->getMetaData()->getProcedureTerm() << "\n";

 

So, please excuse us for breaking the interface in beta, but we do it for good!

Leave a reply

Comments are disabled for this post.