bug fices

This commit is contained in:
Vítor Santos Costa
2016-01-03 02:06:09 +00:00
parent 7a7354fb2b
commit 661f33ac7e
133 changed files with 6000 additions and 9890 deletions

View File

@@ -15,87 +15,75 @@
* *
*************************************************************************/
#include "Yap.h"
#include <string.h>
#include <stdlib.h>
#include <mysql/mysql.h>
#include <myddas_util.h>
#ifdef MYDDAS_MYSQL
/* Auxilary function to table_write*/
static void n_print(Int, char);
#endif
/* Auxilary function to table_write*/
static void
n_print(Int , char );
/* Auxilary function to table_write*/
static void
n_print(Int n, char c)
{
for(;n>0;n--) printf("%c",c);
static void n_print(Int n, char c) {
for (; n > 0; n--)
printf("%c", c);
}
void
myddas_util_table_write(MYSQL_RES *res_set){
void myddas_util_table_write(MYSQL_RES *res_set) {
MYSQL_ROW row;
MYSQL_FIELD *fields;
Int i,f;
Int i, f;
if (mysql_num_rows(res_set) == 0)
{
printf ("Empty Set\n");
return;
}
if (mysql_num_rows(res_set) == 0) {
printf("Empty Set\n");
return;
}
f = mysql_num_fields(res_set);
fields = mysql_fetch_field(res_set);
for(i=0;i<f;i++)
{
for (i = 0; i < f; i++) {
printf("+");
if (strlen(fields[i].name)>fields[i].max_length) fields[i].max_length=strlen(fields[i].name);
n_print(fields[i].max_length+2,'-');
if (strlen(fields[i].name) > fields[i].max_length)
fields[i].max_length = strlen(fields[i].name);
n_print(fields[i].max_length + 2, '-');
}
printf("+\n");
for(i=0;i<f;i++)
{
for (i = 0; i < f; i++) {
printf("|");
printf(" %s ",fields[i].name);
n_print(fields[i].max_length - strlen(fields[i].name),' ');
}
printf(" %s ", fields[i].name);
n_print(fields[i].max_length - strlen(fields[i].name), ' ');
}
printf("|\n");
for(i=0;i<f;i++)
{
for (i = 0; i < f; i++) {
printf("+");
n_print(fields[i].max_length+2,'-');
n_print(fields[i].max_length + 2, '-');
}
printf("+\n");
while ((row = mysql_fetch_row(res_set)) != NULL)
{
for(i=0;i<f;i++)
{
printf("|");
if (row[i] != NULL)
{
printf(" %s ",row[i]);
n_print(fields[i].max_length - strlen(row[i]),' ');
}
else
{
printf(" NULL ");
n_print(fields[i].max_length - 4,' ');
}
}
printf("|\n");
}
for(i=0;i<f;i++)
{
printf("+");
n_print(fields[i].max_length+2,'-');
while ((row = mysql_fetch_row(res_set)) != NULL) {
for (i = 0; i < f; i++) {
printf("|");
if (row[i] != NULL) {
printf(" %s ", row[i]);
n_print(fields[i].max_length - strlen(row[i]), ' ');
} else {
printf(" NULL ");
n_print(fields[i].max_length - 4, ' ');
}
}
printf("|\n");
}
for (i = 0; i < f; i++) {
printf("+");
n_print(fields[i].max_length + 2, '-');
}
printf("+\n");
}