rahulvishwakarma |
12-07-2020 02:52 AM |
printing database column name so much times.
1 Attachment(s)
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;
}
|