Демонстрационный код:
MyType getDataFromDB()
{
Driver *driver;
Connection *con;
Statement *stmt;
ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "login", "pass");
/* Connect to the MySQL test database */
con->setSchema("schema");
stmt = con->createStatement();
MyType resultAnythngAndAnother;
// Первый запрос
res = stmt->executeQuery("SELECT anything");
while (res->next())
{
// перебор данных с запроса "SELECT anything"
}
delete res; // <----- Вопрос #1: Нужно ли делать delete res перед новым использованием переменной res?
// Другой запрос
res = stmt->executeQuery("SELECT another");
while (res->next())
{
// перебор данных с запроса "SELECT another"
}
delete res; // <----- Вопрос #2: Достаточно ли сделать delete res только тут?
return resultAnythngAndAnother;
}
- Вопрос #1: Нужно ли делать
delete res
перед новым использованием переменнойres
? - Вопрос #2: Достаточно ли сделать
delete res
только после последнего вызова (когда она уже не будет больше использоваться)?