views:

49

answers:

2

How to select a value from a table and store in a variable in my sql++

e.g select name from employee;

write this query in c++ and then store the name in variable e_name

+1  A: 

See the mysql++ tutorial:

http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html#simple

The relevant code:

mysqlpp::Query query = conn.query("select item from stock");
if (mysqlpp::StoreQueryResult res = query.store()) {
    cout << "We have:" << endl;
    for (size_t i = 0; i < res.num_rows(); ++i) {
        cout << '\t' << res[i][0] << endl;
    }
}

In this example, the results of the query are stored in the res variable.

Merlyn Morgan-Graham
mysql_init(
Judy
This answers the question you asked. If this isn't what you meant to ask, then please ask another question, or edit this question. I'd suggest you opt for asking another question, at this point, since your question got closed.
Merlyn Morgan-Graham
A: 

I googled and I know the mysql++ tutorials tell this code but I was connecting differently... can you see what is the problem with this.

mysql_init(&mysql); connection = mysql_real_connect(&mysql,..........)

dheck for connection else do this

std::ostringstream query3;
query3<<"select pipe_id from pipe where version_id='"<<id<<"'";
std::storeQueryResult ares=query3.store();
for(size_t i=0;i<ares.num_rows();i++)
    cout<<ares[i]["version_id"]<<ares[i]["pipe_id"]<<std::endl;
mysql_query(&mysql,query3.str().c_str());

the erroer is that store is not a member of ostringstream. thats i understood but in above so how should i proceeed any hints

Judy
-1. This "answer" does not apply to the question that was asked. In fact, it is another question entirely. You should take this and make a new question out of it.
Merlyn Morgan-Graham