List:MySQL++« Previous MessageNext Message »
From:Warren Young Date:August 2 2007 12:31am
Subject:Re: "segment fault" when using mysql++
View as plain text  
I'm replying to you both personally and to the MySQL++ mailing list,
where this message is on topic.  Please reply only on the list, not to
me directly.

wangxu wrote:
> below is my code;these code works very fine until, the length of the 
> field "content"  exceeds 300000,

How certain are you about this threshold?  It seems a very odd number
for a computer to care about.  If you'd said 65536 bytes, or 16.7 MB,
I'd put a lot more credence in your assertion.

>                mysqlpp::Row r;
>                while (r = res.fetch_row()) {
>                        printf (r["content"]);
>              }

I'm not sure it's the problem, but you really shouldn't use printf() for
this.  The main reason is that printf() will scan the resulting string
for % signs and try to interpret them as formatting options.  If it
finds any, it will then try to find varargs, and fail; this would easily
explain your segfault.  The byte count does affect the chances that this
will happen, so maybe that's where your perception that it's data size
related comes from.

Other reasons not to use printf() with MySQL++ data types are
inefficiency and type safety.

See examples/cgi_jpeg.cpp for the right way to emit bulk MySQL++ to stdout.