dbTalk Databases Forums  

Mysql++ && printf

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


Discuss Mysql++ && printf in the mailing.database.mysql-plusplus forum.



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

Default Mysql++ && printf - 04-06-2005 , 02:20 AM






I am having troubles getting my output to work with printf.

gmod.cc:cannot pass objects of non-POD type `const class

This is part of the code I am playing with

Connection con(use_exceptions);
con.connect("netjuke", "127.0.0.1", "******", "******");
Query query = con.query();
query << "SELECT location FROM netjuke_tracks Where al_id=17 AND
track_number=1";
Result res = query.store();
Row row;
Result::iterator i;
for(i=res.begin();i!=res.end();i++)
{
row = *i;
printf("%s", row[0]);
}

I change it from

for(i=res.begin();i!=res.end();i++)
{
row = *i;
cout << row[0];
}

and this worked fine, but using printf doesnt

--
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
  #2  
Old   
Chris Frey
 
Posts: n/a

Default Re: Mysql++ && printf - 04-06-2005 , 03:18 AM






On Wed, Apr 06, 2005 at 12:19:58AM -0700, timothy johnson wrote:
Quote:
I am having troubles getting my output to work with printf.

gmod.cc:cannot pass objects of non-POD type `const class

This is part of the code I am playing with

Connection con(use_exceptions);
con.connect("netjuke", "127.0.0.1", "******", "******");
Query query = con.query();
query << "SELECT location FROM netjuke_tracks Where al_id=17 AND
track_number=1";
Result res = query.store();
Row row;
Result::iterator i;
for(i=res.begin();i!=res.end();i++)
{
row = *i;
printf("%s", row[0]);
row[0] can be converted to a number of types, so try casting to the type
you want:

static_cast<const char *> (row[0])

Quote:
}

I change it from

for(i=res.begin();i!=res.end();i++)
{
row = *i;
cout << row[0];
This uses overloaded operator<<(), so no cast is needed, and hence works.

- Chris


--
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   
timothy johnson
 
Posts: n/a

Default Re: Mysql++ && printf - 04-10-2005 , 09:47 PM



What about using vars in the query line?

query << "SELECT * FROM table WHERE id=" . var;
this way didnt work

sprintf(query. "SELECT * FROM table WHERE id=%i". var);
nor did this way work.




On Apr 6, 2005 1:12 AM, Chris Frey <cdfrey (AT) netdirect (DOT) ca> wrote:
Quote:
On Wed, Apr 06, 2005 at 12:19:58AM -0700, timothy johnson wrote:
I am having troubles getting my output to work with printf.

gmod.cc:cannot pass objects of non-POD type `const class

This is part of the code I am playing with

Connection con(use_exceptions);
con.connect("netjuke", "127.0.0.1", "******", "******");
Query query = con.query();
query << "SELECT location FROM netjuke_tracks Where al_id=17 AND
track_number=1";
Result res = query.store();
Row row;
Result::iterator i;
for(i=res.begin();i!=res.end();i++)
{
row = *i;
printf("%s", row[0]);

row[0] can be converted to a number of types, so try casting to the type
you want:

static_cast<const char *> (row[0])

}

I change it from

for(i=res.begin();i!=res.end();i++)
{
row = *i;
cout << row[0];

This uses overloaded operator<<(), so no cast is needed, and hence works.

- Chris

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...mail (DOT) com


--
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
  #4  
Old   
Chris Frey
 
Posts: n/a

Default Re: Mysql++ && printf - 04-10-2005 , 10:25 PM



On Sun, Apr 10, 2005 at 07:47:52PM -0700, timothy johnson wrote:
Quote:
What about using vars in the query line?

query << "SELECT * FROM table WHERE id=" . var;
this way didnt work

sprintf(query. "SELECT * FROM table WHERE id=%i". var);
nor did this way work.
This is C++, not PHP or perl.

query << "SELECT * FROM table WHERE id=" << var;

If you're building SQL from scratch, make sure you quote properly as well.
Going from memory, I think you use the quote manipulator like this,
but I could be wrong, I don't use it regularly:

query << "SELECT * FROM table WHERE id=" << quote << var;

- Chris


--
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
  #5  
Old   
Warren Young
 
Posts: n/a

Default Re: Mysql++ && printf - 04-12-2005 , 03:31 AM



Chris Frey wrote:
Quote:
Going from memory, I think you use the quote manipulator like this,
but I could be wrong, I don't use it regularly:

query << "SELECT * FROM table WHERE id=" << quote << var;
True.

--
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
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.