提交 3df0fce8 编写于 作者: H Hiroshi Inoue

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.
上级 e14a9deb
...@@ -658,7 +658,8 @@ RETCODE result; ...@@ -658,7 +658,8 @@ RETCODE result;
else if (fi[i]->name[0] == '*') { else if (fi[i]->name[0] == '*') {
char do_all_tables; char do_all_tables;
int total_cols, old_size, need, cols; int total_cols, old_alloc, new_size, cols;
int increased_cols;
mylog("expanding field %d\n", i); mylog("expanding field %d\n", i);
...@@ -674,36 +675,37 @@ RETCODE result; ...@@ -674,36 +675,37 @@ RETCODE result;
total_cols += QR_get_num_tuples(ti[k]->col_info->result); total_cols += QR_get_num_tuples(ti[k]->col_info->result);
} }
} }
total_cols--; /* makes up for the star */ increased_cols = total_cols - 1;
/* Allocate some more field pointers if necessary */ /* Allocate some more field pointers if necessary */
/*------------------------------------------------------------- */ /*------------------------------------------------------------- */
old_size = (stmt->nfld / FLD_INCR * FLD_INCR + FLD_INCR); old_alloc = ((stmt->nfld - 1) / FLD_INCR + 1) * FLD_INCR;
need = total_cols - (old_size - stmt->nfld); new_size = stmt->nfld + increased_cols;
mylog("k=%d, total_cols=%d, old_size=%d, need=%d\n", k,total_cols,old_size,need); mylog("k=%d, increased_cols=%d, old_alloc=%d, new_size=%d\n", k,increased_cols,old_alloc,new_size);
if (need > 0) { if (new_size > old_alloc) {
int new_size = need / FLD_INCR * FLD_INCR + FLD_INCR; int new_alloc = ((new_size / FLD_INCR) + 1) * FLD_INCR;
mylog("need more cols: new_size = %d\n", new_size); mylog("need more cols: new_alloc = %d\n", new_alloc);
fi = (FIELD_INFO **) realloc(fi, (old_size + new_size) * sizeof(FIELD_INFO *)); fi = (FIELD_INFO **) realloc(fi, new_alloc * sizeof(FIELD_INFO *));
if ( ! fi) { if ( ! fi) {
stmt->parse_status = STMT_PARSE_FATAL; stmt->parse_status = STMT_PARSE_FATAL;
return FALSE; return FALSE;
} }
stmt->fi = fi;
} }
/*------------------------------------------------------------- */ /*------------------------------------------------------------- */
/* copy any other fields (if there are any) up past the expansion */ /* copy any other fields (if there are any) up past the expansion */
for (j = stmt->nfld - 1; j > i; j--) { for (j = stmt->nfld - 1; j > i; j--) {
mylog("copying field %d to %d\n", j, total_cols + j); mylog("copying field %d to %d\n", j, increased_cols + j);
fi[total_cols + j] = fi[j]; fi[increased_cols + j] = fi[j];
} }
mylog("done copying fields\n"); mylog("done copying fields\n");
/*------------------------------------------------------------- */ /*------------------------------------------------------------- */
/* Set the new number of fields */ /* Set the new number of fields */
stmt->nfld += total_cols; stmt->nfld += increased_cols;
mylog("stmt->nfld now at %d\n", stmt->nfld); mylog("stmt->nfld now at %d\n", stmt->nfld);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册