Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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 am building a small project using mysql as back end in server ( cenos 6.10 ) and client as c++ in client machine( centos 7.5). Now i stuck in following code as it is showing lines after end of
rows of mysql tables based on mysql Connection and result set. output is showing in image :-
Code:
int sqlprocess::process_result_set(MYSQL *mysql, MYSQL_RES *res )
{
MYSQL_ROW row;
MYSQL_FIELD *field;
unsigned columnLen;
unsigned int i;
int offset1 = 1;
int offset2 = 0;
int totallen = 0;
int times = 0;
int j = 0;
int l = 0;
int intlines = 0;
int intl = 0;
mysql_field_seek(res, 0);
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
int numf = mysql_num_fields(res);
for(int i = 0; i < numf; i++ )
{
field = mysql_fetch_field(res);
columnLen = strlen(field->name);
if(columnLen < field->max_length)
{
columnLen = field->max_length;
}
if(columnLen < 4 && !IS_NOT_NULL(field->flags))
{
columnLen = 4;
}
field->max_length = columnLen;
totallen += columnLen;
}
offset1 = totallen;
k = 8;
do
{
printDashes(res, 0);
mysql_field_seek(res, 0);
gotoxy(l, k);
cout << "|";
int nums = mysql_num_fields(res);
for(int i = 0; i < nums; i++)
{
field = mysql_fetch_field(res);
cout << std::setw(field->max_length) << field->name << "|";
}
k++;
gotoxy(l, k);
printDashes(res, l);
if(times > 0)
{
l = totallen * times + 7;
}
else
{
l = totallen*times;
}
while ((row = mysql_fetch_row(res)) != nullptr && k < w.ws_row)
{
intlines++;
if(times > 0)
{
l = totallen * times + 7;
}
else
{
l = totallen*times;
}
gotoxy(l, ++k);
mysql_field_seek(res, 0);
cout << "|";
for(int i = 0; i < mysql_num_fields(res); i++)
{
field = mysql_fetch_field(res);
if(row[i] == nullptr)
{
cout << std::setw(field->max_length) << "NULL" << "|";
}
else
{
cout << std::setw(field->max_length) << row[i] << "|";
}
}
if( k >= w.ws_row)
{
times++;
k = 8;
gotoxy(l, k);
}
}
gotoxy(l + 7, intl +1);
l = mysql_num_rows(res);
}while(k < w.ws_row && intlines <= l);
cout << "No of affected rows : " << l;
cin.get();
printDashes(res, l+7);
return l;
}
hi to all, i am building a small project using mysql as back end in server ( cenos 6.10 ) and client as c++ in client machine( centos 7.5). Now i stuck in following code as it is showing lines after end of rows of mysql tables based on mysql Connection and result set. output is showing in image :-
Code:
int sqlprocess::process_result_set(MYSQL *mysql, MYSQL_RES *res )
{
MYSQL_ROW row;
MYSQL_FIELD *field;
unsigned columnLen;
unsigned int i;
int offset1 = 1;
int offset2 = 0;
int totallen = 0;
int times = 0;
int j = 0;
int l = 0;
int intlines = 0;
int intl = 0;
mysql_field_seek(res, 0);
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
int numf = mysql_num_fields(res);
for(int i = 0; i < numf; i++ )
{
field = mysql_fetch_field(res);
columnLen = strlen(field->name);
if(columnLen < field->max_length)
{
columnLen = field->max_length;
}
if(columnLen < 4 && !IS_NOT_NULL(field->flags))
{
columnLen = 4;
}
field->max_length = columnLen;
totallen += columnLen;
}
offset1 = totallen;
k = 8;
do
{
printDashes(res, 0);
mysql_field_seek(res, 0);
gotoxy(l, k);
cout << "|";
int nums = mysql_num_fields(res);
for(int i = 0; i < nums; i++)
{
field = mysql_fetch_field(res);
cout << std::setw(field->max_length) << field->name << "|";
}
k++;
gotoxy(l, k);
printDashes(res, l);
if(times > 0)
{
l = totallen * times + 7;
}
else
{
l = totallen*times;
}
while ((row = mysql_fetch_row(res)) != nullptr && k < w.ws_row)
{
intlines++;
if(times > 0)
{
l = totallen * times + 7;
}
else
{
l = totallen*times;
}
gotoxy(l, ++k);
mysql_field_seek(res, 0);
cout << "|";
for(int i = 0; i < mysql_num_fields(res); i++)
{
field = mysql_fetch_field(res);
if(row[i] == nullptr)
{
cout << std::setw(field->max_length) << "NULL" << "|";
}
else
{
cout << std::setw(field->max_length) << row[i] << "|";
}
}
if( k >= w.ws_row)
{
times++;
k = 8;
gotoxy(l, k);
}
}
gotoxy(l + 7, intl +1);
l = mysql_num_rows(res);
}while(k < w.ws_row && intlines <= l);
cout << "No of affected rows : " << l;
cin.get();
printDashes(res, l+7);
return l;
}
Ok...since you wrote your code, can you go back and comment it, so it can be easily read, before asking others to debug your program for you?? And you don't tell us what's in the database, how many records, etc., so we can't tell you if you're outputting SOMETHING (or nothing), nor how you want your program to work.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.