MCPcopy Create free account
hub / github.com/MariaDB/server / cli_read_rows

Function cli_read_rows

sql-common/client.c:1262–1360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1260/* Read all rows (fields or data) from server */
1261
1262MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
1263 unsigned int fields)
1264{
1265 uint field;
1266 ulong pkt_len;
1267 ulong len;
1268 uchar *cp;
1269 char *to, *end_to;
1270 MYSQL_DATA *result;
1271 MYSQL_ROWS **prev_ptr,*cur;
1272 NET *net = &mysql->net;
1273 DBUG_ENTER("cli_read_rows");
1274
1275 if ((pkt_len= cli_safe_read(mysql)) == packet_error)
1276 DBUG_RETURN(0);
1277 if (pkt_len == 0) DBUG_RETURN(0);
1278 if (!(result=(MYSQL_DATA*) my_malloc(key_memory_MYSQL_DATA, sizeof(MYSQL_DATA),
1279 MYF(MY_WME | MY_ZEROFILL))))
1280 {
1281 set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
1282 DBUG_RETURN(0);
1283 }
1284 /* Assume rowlength < 8192 */
1285 init_alloc_root(key_memory_MYSQL_DATA, &result->alloc, 8192, 0,
1286 MYF(mysql->options.use_thread_specific_memory ?
1287 MY_THREAD_SPECIFIC : 0));
1288 result->alloc.min_malloc=sizeof(MYSQL_ROWS);
1289 prev_ptr= &result->data;
1290 result->rows=0;
1291 result->fields=fields;
1292
1293 /*
1294 The last EOF packet is either a single 254 character or (in MySQL 4.1)
1295 254 followed by 1-7 status bytes.
1296
1297 This doesn't conflict with normal usage of 254 which stands for a
1298 string where the length of the string is 8 bytes. (see net_field_length())
1299 */
1300
1301 while (*(cp=net->read_pos) != 254 || pkt_len >= 8)
1302 {
1303 result->rows++;
1304 if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc,
1305 sizeof(MYSQL_ROWS))) ||
1306 !(cur->data= ((MYSQL_ROW)
1307 alloc_root(&result->alloc,
1308 (fields+1)*sizeof(char *)+pkt_len))))
1309 {
1310 free_rows(result);
1311 set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
1312 DBUG_RETURN(0);
1313 }
1314 *prev_ptr=cur;
1315 prev_ptr= &cur->next;
1316 to= (char*) (cur->data+fields+1);
1317 end_to=to+pkt_len-1;
1318 for (field=0 ; field < fields ; field++)
1319 {

Callers 2

cli_read_query_resultFunction · 0.85
cli_list_fieldsFunction · 0.85

Calls 8

cli_safe_readFunction · 0.85
my_mallocFunction · 0.85
set_mysql_errorFunction · 0.85
init_alloc_rootFunction · 0.85
alloc_rootFunction · 0.85
free_rowsFunction · 0.85
net_field_lengthFunction · 0.85
uint2korrFunction · 0.85

Tested by

no test coverage detected