List:MySQL++« Previous MessageNext Message »
From:kartik mahajan Date:December 19 2008 7:08am
Subject:Can a connection be used to execute more than 1 query sequentially(not concurrently)
View as plain text  
Hi

 

Its mentioned in the user manual:

 "An important limitation of the MySQL C API library - which MySQL++ is
built atop, so it shares this limitation - is that you can't have two
concurrent queries running on a single connection. If you try, you get an
obscure error message about "Commands out of sync" from the underlying C API
library. (You get it in a MySQL++ exception unless you have exceptions
disabled, in which case you get a failure code and Connection::error()
returns this message.)"

 

However I am not running concurrent queries on a single connection. All I
want to do is the following( the example is stripped of  some details )

 

int main()

{

            RtConnectionPoolManager* lp_cpm=0;

            

            lp_cpm=RtConnectionPoolManager::rtInstance();

 
lp_cpm->rtCreateConnectionPool("rt_chg_subscriber","10.66.10.77","root","roo
t",0,50,15,5,100);

                        

 

            for(int i=0;i<MAX;i++)

            {

                        foo();

            }

            return 0;

}

void foo()

{

            RtConnectionPoolManager*
l_cpm=RtConnectionPoolManager::rtInstance();

            Connection* conn=0;

            try

            {

                        conn=l_cpm->rtGrab(); // returns the most recently
used connection not in use now

                        if(conn)

                        {

                                    mysqlpp::Query q(conn->query("CALL
getsubscriberdata('pri_1000000001@stripped',1)"));

                                    mysqlpp::StoreQueryResult res =
q.store(); // This throws exception i.e out of sync

                                    

                        }

                                                

                        l_cpm->rtRelease(conn);

            }

            catch(const mysqlpp::Exception& e)

            {

                        cout<<e.what()<<endl;

            }

            catch(exception& e)

            {

                        cout<<e.what()<<endl;

            }

            catch(...)

            {

                        cout<<"\n********Unknown exception thrown"<<endl;

            }

}

 

 

Here I am using a single connection to execute queries, however they are not
being used concurrently as is evident from the code. However it is still
throwing out of sync exception from the store( ) function.

 

Does this mean that once a connection has been used to execute one query, we
need to close it ?  Then this would essentially make a connectionpool
useless.

 

The above code doesn't use the connection pool functionality and is just to
highlight the problem I am facing. Here is the description of the problem I
am facing:

 

Thread1 takes a connection from the pool and executes a query and releases
the connection. 

Thread2 now takes a connection from the pool and executes a query( the same
query). If the connection pool returns the most recently used connection,
then the connection received by thread2 is the same that was released by
thread1 and since thread1 has already used it to execute 1 query on that
connection, when thread2 tries to execute its query it throws out of sync
exception. 

The above query is a procedure.

 

 

I guess I am missing something or else this would be a major flaw. If I am
missing something kindly provide some code snippet of trying to execute a
procedure using cpm.

 

In the connection class its mentioned:

Return a new query object. 

The returned query object is tied to this connection object, so when you
call a method like execute()
<file:///C:\Documents%20and%20Settings\kartik.mahajan\Desktop\Charging\mysql
++\refman\classmysqlpp_1_1Query.html#03ee1b9e393d88de946f5be804ea88cf>  on
that object, the query is sent to the server this object is connected to.

Does the problem has anything to do with above ?

 

Regards

Kartik Mahajan


Thread
Can a connection be used to execute more than 1 query sequentially(not concurrently)kartik mahajan19 Dec
  • Re: Can a connection be used to execute more than 1 query sequentially(notconcurrently)Warren Young19 Dec