Date: Thursday, January 11, 2007 @ 17:42:36
Author: gilles
Path: /cvsroot/carob/carob
Modified: include/Connection.hpp (1.79 -> 1.80) src/Connection.cpp (1.101
-> 1.102)
Added possibility to *not* delete created statements and ResultSets
Fixes CAROB-120
------------------------+
include/Connection.hpp | 20 +++++++++++++++++++-
src/Connection.cpp | 17 ++++++++++-------
2 files changed, 29 insertions(+), 8 deletions(-)
Index: carob/include/Connection.hpp
diff -u carob/include/Connection.hpp:1.79 carob/include/Connection.hpp:1.80
--- carob/include/Connection.hpp:1.79 Fri Dec 22 11:21:07 2006
+++ carob/include/Connection.hpp Thu Jan 11 17:42:36 2007
@@ -385,8 +385,21 @@
* @param bde exception chain to convert
*/
static SQLWarning* convertToSQLWarnings(BackendException* bde);
+ /**
+ * Avoids or forces deletion of statements in destructor<br>
+ * <b>Warning:</b> Setting this option to false will make destructor leave
all
+ * statements this instance created, which can lead to huge memory leaks...
+ * use only if you know what you are doing!<br>
+ * Note: created statements can still be deleted using
+ * #deleteStatement(Statement*)
+ * @param autoDelete if true (default), the destructor will clean-up all
+ * statements and associated ResultSets
+ * if false, the destructor will leave all statements
open,
+ * leaving ownership to caller
+ */
+ void setAutoDeleteStatements(bool autoDelete)
+ { auto_delete_statements = autoDelete; }
-
protected:
/**
* This function should be used to establish a new connection to another
@@ -525,6 +538,11 @@
*/
std::list<Statement*> created_statements;
/**
+ * If set to false, all statement created by this connection won't be freed
by
+ * destructor (default to true)
+ */
+ bool auto_delete_statements;
+ /**
* Begins a new transaction if needed (<code>mustBeginTransaction</code> is
* set to <code>true</code>).
*/
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.101 carob/src/Connection.cpp:1.102
--- carob/src/Connection.cpp:1.101 Wed Dec 20 19:38:41 2006
+++ carob/src/Connection.cpp Thu Jan 11 17:42:35 2007
@@ -84,7 +84,8 @@
retrieve_sql_warnings(false),
first_warning(NULL),
controller_pool(prms.getControllerPool()),
- parameters(prms)
+ parameters(prms),
+ auto_delete_statements(true)
{
const wstring fctName(L"Connection::Connection");
persistent_connection = parameters.getPersistentConnection();
@@ -276,14 +277,16 @@
if (isDebugEnabled())
logDebug(fctName, L"Deleting statements created by this connection");
- //delete all statement created by this connection
- for (std::list<Statement*>::iterator iter = created_statements.begin();
- iter != created_statements.end(); iter++)
+ // delete all statements created by this connection unless told not to
+ if (auto_delete_statements)
{
- delete *iter;
+ for (std::list<Statement*>::iterator iter = created_statements.begin();
+ iter != created_statements.end(); iter++)
+ {
+ delete *iter;
+ }
+ created_statements.clear();
}
- created_statements.clear();
-
return closeSocket();
}
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits