Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3df0fce

Browse files
author
Hiroshi Inoue
committed
Fix the bug report [ODBC] select from a table having more than 32 fields:
reported by Matteo Cavalleri. Great thanks to Tom for his accurate analysis.
1 parent e14a9de commit 3df0fce

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/interfaces/odbc/parse.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,8 @@ RETCODE result;
658658
else if (fi[i]->name[0] == '*') {
659659

660660
char do_all_tables;
661-
int total_cols, old_size, need, cols;
661+
int total_cols, old_alloc, new_size, cols;
662+
int increased_cols;
662663

663664
mylog("expanding field %d\n", i);
664665

@@ -674,36 +675,37 @@ RETCODE result;
674675
total_cols += QR_get_num_tuples(ti[k]->col_info->result);
675676
}
676677
}
677-
total_cols--; /* makes up for the star */
678+
increased_cols = total_cols - 1;
678679

679680
/* Allocate some more field pointers if necessary */
680681
/*------------------------------------------------------------- */
681-
old_size = (stmt->nfld / FLD_INCR * FLD_INCR + FLD_INCR);
682-
need = total_cols - (old_size - stmt->nfld);
682+
old_alloc = ((stmt->nfld - 1) / FLD_INCR + 1) * FLD_INCR;
683+
new_size = stmt->nfld + increased_cols;
683684

684-
mylog("k=%d, total_cols=%d, old_size=%d, need=%d\n", k,total_cols,old_size,need);
685+
mylog("k=%d, increased_cols=%d, old_alloc=%d, new_size=%d\n", k,increased_cols,old_alloc,new_size);
685686

686-
if (need > 0) {
687-
int new_size = need / FLD_INCR * FLD_INCR + FLD_INCR;
688-
mylog("need more cols: new_size = %d\n", new_size);
689-
fi = (FIELD_INFO **) realloc(fi, (old_size + new_size) * sizeof(FIELD_INFO *));
687+
if (new_size > old_alloc) {
688+
int new_alloc = ((new_size / FLD_INCR) + 1) * FLD_INCR;
689+
mylog("need more cols: new_alloc = %d\n", new_alloc);
690+
fi = (FIELD_INFO **) realloc(fi, new_alloc * sizeof(FIELD_INFO *));
690691
if ( ! fi) {
691692
stmt->parse_status = STMT_PARSE_FATAL;
692693
return FALSE;
693694
}
695+
stmt->fi = fi;
694696
}
695697

696698
/*------------------------------------------------------------- */
697699
/* copy any other fields (if there are any) up past the expansion */
698700
for (j = stmt->nfld - 1; j > i; j--) {
699-
mylog("copying field %d to %d\n", j, total_cols + j);
700-
fi[total_cols + j] = fi[j];
701+
mylog("copying field %d to %d\n", j, increased_cols + j);
702+
fi[increased_cols + j] = fi[j];
701703
}
702704
mylog("done copying fields\n");
703705

704706
/*------------------------------------------------------------- */
705707
/* Set the new number of fields */
706-
stmt->nfld += total_cols;
708+
stmt->nfld += increased_cols;
707709
mylog("stmt->nfld now at %d\n", stmt->nfld);
708710

709711

0 commit comments

Comments
 (0)