dbTalk Databases Forums  

MySQL++ crash on << and more

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss MySQL++ crash on << and more in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
 
Posts: n/a

Default MySQL++ crash on << and more - 10-23-2006 , 08:48 AM






------=_NextPart_000_0003_01C6F6B8.8B008400
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hey all
Ive got the following code, the comments show whats wrong with it


ofstream ofin;
ofin.open("log.log");
if (!con.connect("database", "host", "username", "password", 3306))
{
return;
}
if (!con.select_db("teamin_fate"))

{
return;
}

mysqlpp::Query query =3D con.query();

// Following crashes the application
//query << "SELECT * FROM news";
//query.execute();

// following 2 methods work, but cause error:
// Commands out of sync; you cant run this command now
query.execute("SELECT * FROM news");


//std::string sql =3D "SELECT * FROM news";
//query.exec(sql);


mysqlpp::Result res =3D query.store();

if (res)
{
//code
}
else
{
ofin << query.error();
}

What comes out is the error Commands out of sync. res must be null in =
order to write stuff to the file. Ive checked where exactly the error =
occures and it is at the following line:
mysqlpp::Result res =3D query.store();

Ive also debugged and see what went wrong but I couldn't figure it out. =
The variable res is not null, or shouldn't be, because there are various =
values set according to the debugging information. So two questions =
here: Why is the << operator not working and why is it causing the error =
I described?

Thanks
------=_NextPart_000_0003_01C6F6B8.8B008400--



Reply With Quote
  #2  
Old   
Warren Young
 
Posts: n/a

Default Re: MySQL++ crash on << and more - 10-23-2006 , 11:07 AM






webmaster (AT) team-inqontrol (DOT) com wrote:
Quote:
What comes out is the error Commands out of sync.
This means you're trying to overlap two queries. MySQL doesn't allow
that on a single connection. Any time you issue a query that returns
results, you must consume all of those results before you can issue a
new query. See the C API documentation for details.

If you must overlap two queries, you can create a connection for each
one to get around this limitation.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
 
Posts: n/a

Default Re: MySQL++ crash on << and more - 10-23-2006 , 01:42 PM



------=_NextPart_000_000B_01C6F6E3.D99186C0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

This is basically all the code I have, so I don't see where I'm trying =
to overlap two queries. Apart from that, it throws an exception =
(probably) at query.store(). I don't see whats wrong with that?

Thank you for your brief reply.
------=_NextPart_000_000B_01C6F6E3.D99186C0--



Reply With Quote
  #4  
Old   
Drew M.
 
Posts: n/a

Default Re: MySQL++ crash on << and more - 10-23-2006 , 03:23 PM



------=_Part_256660_6383126.1161634956166
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

You are not consuming (i.e., storing or resetting) the results from the
query. In short, either store all the results between your two calls to
execute(), or just reset your query object.

On 10/23/06, webmaster (AT) team-inqontrol (DOT) com <webmaster (AT) team-inqontrol (DOT) com>
wrote:
Quote:
This is basically all the code I have, so I don't see where I'm trying to
overlap two queries. Apart from that, it throws an exception (probably) at
query.store(). I don't see whats wrong with that?

Thank you for your brief reply.

------=_Part_256660_6383126.1161634956166--


Reply With Quote
  #5  
Old   
Warren Young
 
Posts: n/a

Default Re: MySQL++ crash on << and more - 10-23-2006 , 04:36 PM



webmaster (AT) team-inqontrol (DOT) com wrote:
Quote:
This is basically all the code I have, so I don't see where I'm
trying to overlap two queries.
I think you have multiple problems, actually.

Quote:
Apart from that, it throws an
exception (probably) at query.store(). I don't see whats wrong with
that?
It would help if you'd catch that exception and print out what its
what() method returns, to see what it's trying to tell you.

If it's not an exception, it may be that you're mixing a library built
with one build setup with an executable built another way. That's a
pretty good way to crash a program.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #6  
Old   
 
Posts: n/a

Default Re: MySQL++ crash on << and more - 10-24-2006 , 05:21 AM



------=_NextPart_000_0011_01C6F767.03D85840
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Drew M.: I am actually storing the results with the query.store() call, =
and after all, I am not using another query object, and I am not sending =
another query to execute. Only one query is to be executed.

Warren Young: I have caught the exception. The exceptions what() returns =
the same error as before:
Commands out of sync; you can't run this command now.
"If it's not an exception, it may be that you're mixing a library built=20
with one build setup with an executable built another way. That's a=20
pretty good way to crash a program."Yes. I actually am mixing another =
library. Its WxWidgets, but I have checked and I'm using the right build =
setups (If you mean release/debug). Apart from that, WxWidgets is =
compiled in UNICODE. Maybe that could have something to do with it.

Ive updated the code to make it a bit clearer:

ofstream ofin;
ofin.open("log.log");

mysqlpp::Query query =3D con.query();
query.enable_exceptions();

query.execute("SELECT * FROM eqdkp_news");

if (!query.success())
{
ofin << "Query wasn't succesfull: " << query.error() << std::endl;
}

mysqlpp::Result res;
try
{
res =3D query.store();
}
catch (mysqlpp::Exception &e)
{
ofin << "exception" << e.what() << " end\n\n";
}
if (res)
{
ofin.close();
ofin.open("news.html");
if (ofin.is_open())
{
mysqlpp::Row row;
while (row =3D res.fetch_row())=20
{
// Probably need to use utf8trans but irrelevant for =
now.
ofin << row["news_headline"];
ofin << row["news_message"];
ofin << row["news_id"];
ofin << row["news_date"];
ofin << row["user_id"];
}
ofin.close();
}
}
else
{
ofin << "else: " << query.error() << std::endl;
return;
}
------=_NextPart_000_0011_01C6F767.03D85840--



Reply With Quote
  #7  
Old   
 
Posts: n/a

Default Re: MySQL++ crash on << and more - 10-24-2006 , 06:29 AM



------=_NextPart_000_0008_01C6F770.714FC990
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Ooh. store() actually executes a query! Thats why I'm executing two =
query's. I should have looked up store() meaning earlier. I thought it =
meant "store everything that a previously executed query has received".

So if I get it right now:

query << "select item from stock"; // Stored a query in the object
mysqlpp::Result res =3D query.store(); // Executes and stores the =
objectWherequery.execute(); // directly executes a query without storing =
anythingIm sorry I misunderstood. I know realise you didn't knew I was =
thinking that the store function only stores the results gotten from =
earlier executed query's. I guess it's working now.One more thing:query =
<< "SELECT * FROM news";res =3D query.store();makes it crash right at =
query <<. Its not of any high priority as the other way of executing =
query's works, but this operator is quite cool to use. Would be nice if =
it would be working aswell.Thanks
------=_NextPart_000_0008_01C6F770.714FC990--



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.