Branch: Tag:

2018-03-20

2018-03-20 20:20:30 by Bill Welliver <bill@welliver.org>

Sql.Connection: always attempt to fetch any rows when converting a result to array.

Checking for fields is not sufficient, as some engines do not execute the query until
the first row is fetched (SQLite for example). On queries that use sprintf bindings
but return no rows (such as inserts), this resulted in the query never executing (and
likely leaking the statement).

384:    array(mixed) row;    int i;    +  if (arrayp(res_obj)) +  rows = res_obj; +  else { +  fields = 0; +  rows = ({}); +  while (row = res_obj->fetch_row_array()) +  rows += row; +  } +     if (!fields)    fields = res_obj->fetch_fields();    if(!sizeof(fields)) return res;
402:    if (case_convert)    fieldnames = map(fieldnames, lower_case);    -  if (arrayp(res_obj)) -  rows = res_obj; -  else { -  fields = 0; -  rows = ({}); -  while (row = res_obj->fetch_row_array()) -  rows += row; -  } -  +     if(has_table)    foreach (rows; i; row)    rows[i] = mkmapping(fieldnames, row + row);
552:    }       query = sprintf(query, @args); -  +     if (sizeof(bindings)) return ({ query, bindings });    return ({ query });   }