ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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, ×, 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);
}
Distribution: debian, lfs, whatever else i need in qemu
Posts: 268
Rep:
Man, there are so many languages out there, why do people have to shoot their feet off in 2021 with C and C++? Leave it to hardware and firmware designers, please.
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, ×, 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);
}
You keep opening new threads, and never follow up in your others, and they're all incredibly similar to this one. You post incomplete code, and somehow expect us to be able to decipher what you want. You have been programming in C++ for **TEN YEARS** at this point....have you not learned how to use a debugger yet?? You say you're using Codeblocks...fairly sure it has one in there.
AGAIN: Unless you post your COMPLETE CODE, give us an ACTUAL ERROR (past the fairly-useless 'segmentation fault'), there isn't much we can tell you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.