Article 5E5CH table iteration in C++ and mysql.

table iteration in C++ and mysql.

by
rahulvishwakarma
from LinuxQuestions.org on (#5E5CH)
hi to all, I've mysql server in centos 6 and client in centos 7. I" am building a small project and I want to iterate in table as output of a sql query in mysql server. Now when i iterate a complete table and after that 10-15 lines it gives segmentation fault. here is mine program and output :-
Code:void product::showAllProduct()
{
int times;
char choose;
clrscr();
drawrect();
int l = 5;
int qstate;
int i = 0;
int r = 0;
gotoxy(15, 5);
char ch ;
string strQuery;
cout << "Welcome To Electronic Store";

gotoxy(15, 6);
cout << "Show All Items Menu\n";

do
{
gotoxy(2, 7);
cout << "Enter P -> producname | Stock -> S |\n Rate -> R | ProductID -> I : ";
ch = cin.get();

cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if(toupper(ch) == 'P')
{
strQuery = "select *from tableProductRecords order by productname asc;";
}
else if(toupper(ch) == 'S')
{
strQuery = "select *from tableProductRecords order by Stock asc;";
}
else if(toupper(ch) == 'R')
{
strQuery = "select *from tableProductRecords order by Rate asc;";
}
else if( toupper(ch) == 'I')
{
strQuery = "select *from tableProductRecords order by ProductId asc;";
}
mysql = Conn::connection();
qstate = mysql_query(mysql, strQuery.c_str());
if(!qstate)
{
res = mysql_store_result(mysql);
i = process_result_set(mysql, res, 10, &times, totallen);
}
else
{
cout << " error : " << " "<< mysql_error(mysql) << " " << endl;
}

sql = "select sum(Rate) from tableProductRecords";
mysql->reconnect = true;
mysql = Conn::connection();
qstate = mysql_query(mysql, sql.c_str());

if(!qstate)
{
res = mysql_store_result(mysql);
if((row = mysql_fetch_row(res)) != nullptr)
{
r = atoi(row[0]);
}
gotoxy(2, 9);
cout << "Grand Total of Stock : "<< r;
}
gotoxy(29, 8);
cin.get();
}while(int(ch) != 10);
}how to get rid of this segmentation fault error.
Attached Thumbnailsattachment.php?attachmentid=35614&stc=1& latest?d=yIl2AUoC8zA latest?i=Vq1ubXpXJeM:7CVbe6C9Nsc:F7zBnMy latest?i=Vq1ubXpXJeM:7CVbe6C9Nsc:V_sGLiP latest?d=qj6IDK7rITs latest?i=Vq1ubXpXJeM:7CVbe6C9Nsc:gIN9vFwVq1ubXpXJeM
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments