MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / cli_read_rows

Function cli_read_rows

sql-common/client.c:1506–1600  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1504/* Read all rows (fields or data) from server */
1505
1506MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
1507 unsigned int fields)
1508{
1509 uint field;
1510 ulong pkt_len;
1511 ulong len;
1512 uchar *cp;
1513 char *to, *end_to;
1514 MYSQL_DATA *result;
1515 MYSQL_ROWS **prev_ptr,*cur;
1516 NET *net = &mysql->net;
1517 DBUG_ENTER("cli_read_rows");
1518
1519 if ((pkt_len= cli_safe_read(mysql)) == packet_error)
1520 DBUG_RETURN(0);
1521 if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA),
1522 MYF(MY_WME | MY_ZEROFILL))))
1523 {
1524 set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
1525 DBUG_RETURN(0);
1526 }
1527 init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */
1528 result->alloc.min_malloc=sizeof(MYSQL_ROWS);
1529 prev_ptr= &result->data;
1530 result->rows=0;
1531 result->fields=fields;
1532
1533 /*
1534 The last EOF packet is either a single 254 character or (in MySQL 4.1)
1535 254 followed by 1-7 status bytes.
1536
1537 This doesn't conflict with normal usage of 254 which stands for a
1538 string where the length of the string is 8 bytes. (see net_field_length())
1539 */
1540
1541 while (*(cp=net->read_pos) != 254 || pkt_len >= 8)
1542 {
1543 result->rows++;
1544 if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc,
1545 sizeof(MYSQL_ROWS))) ||
1546 !(cur->data= ((MYSQL_ROW)
1547 alloc_root(&result->alloc,
1548 (fields+1)*sizeof(char *)+pkt_len))))
1549 {
1550 free_rows(result);
1551 set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
1552 DBUG_RETURN(0);
1553 }
1554 *prev_ptr=cur;
1555 prev_ptr= &cur->next;
1556 to= (char*) (cur->data+fields+1);
1557 end_to=to+pkt_len-1;
1558 for (field=0 ; field < fields ; field++)
1559 {
1560 if ((len=(ulong) net_field_length(&cp)) == NULL_LENGTH)
1561 { /* null field */
1562 cur->data[field] = 0;
1563 }

Callers 1

cli_read_query_resultFunction · 0.85

Calls 7

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

Tested by

no test coverage detected