Hi Tommi !
Your example works fine without errors !
But if I replace conn.prepare in line
> tntdb::Statement ins = conn.prepare(
> "insert into foo(a, b) values (:a, :b)");
with conn.prepareCached
then there is no more 'mysql_close' messages in the log,
which leads to connections leak - they are not returned
to the pool and are not freed.
May be this is due to my misunderstanding of conn.prepareCached
usage rules - documentation can be expanded with correct usage scenarios
for this function.
Dima
22 янв. 2014 г., в 13:30, [email protected]
написал(а):
> Hi Dmitry,
>
> I can't reproduce the problem. I tried with this program:
>
> #include <iostream>
> #include <cxxtools/log.h>
> #include <tntdb/connect.h>
> #include <tntdb/transaction.h>
> #include <tntdb/statement.h>
>
> int main(int argc, char* argv[])
> {
> try
> {
> log_init();
> for (unsigned n = 0; n < 1000; ++n)
> {
> tntdb::Connection conn =
> tntdb::connectCached("mysql:dbname=test");
> tntdb::Transaction trans(conn);
>
> tntdb::Statement ins = conn.prepare(
> "insert into foo(a, b) values (:a, :b)");
> ins.set("a", 17)
> .set("b", "hello")
> .execute();
>
> trans.rollback();
> }
> }
> catch (const std::exception& e)
> {
> std::cerr << e.what() << std::endl;
> }
> }
>
>
> It works fine. I can read in the log:
>
> 2014-01-22 00:40:53.36423 [18903.139766890641216] DEBUG
> tntdb.transaction - rollback transaction
> 2014-01-22 00:40:53.36424 [18903.139766890641216] DEBUG
> tntdb.mysql.connection - mysql_rollback(0x14fd530)
> 2014-01-22 00:40:53.38789 [18903.139766890641216] DEBUG
> tntdb.mysql.connection - mysql_autocommit(0x14fd530, 1)
> 2014-01-22 00:40:53.38798 [18903.139766890641216] DEBUG
> tntdb.mysql.statement - mysql_stmt_close(0x1517a70)
> 2014-01-22 00:40:53.38800 [18903.139766890641216] DEBUG
> tntdb.poolconnection - don't reuse connection 0x14fd4f0
> 2014-01-22 00:40:53.38801 [18903.139766890641216] DEBUG
> tntdb.mysql.connection - *mysql_close*(0x14fd530)
>
>
> The mysql_close is important here. It frees the actual database
> connection correctly. There must be something else wrong.
>
> Tommi
------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general