~chuck-bell/mysql-arduino/release-1.0.3-rc

« back to all changes in this revision

Viewing changes to mysql.cpp

  • Committer: chuck.bell at oracle
  • Date: 2015-03-04 15:14:29 UTC
  • Revision ID: chuck.bell@oracle.com-20150304151429-ypi4nx4wn50boaoj
Updates for 1.0.3rc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
  Copyright (c) 2012, 2014 Oracle and/or its affiliates. All rights reserved.
 
2
  Copyright (c) 2012, 2015 Oracle and/or its affiliates. All rights reserved.
3
3
 
4
4
  This program is free software; you can redistribute it and/or modify
5
5
  it under the terms of the GNU General Public License as published by
24
24
  Version 1.0.0b Updated by Dr. Charles A. Bell, October 2013.
25
25
  Version 1.0.1b Updated by Dr. Charles A. Bell, February 2014.
26
26
  Version 1.0.2b Updated by Dr. Charles A. Bell, April 2014.
 
27
  Version 1.0.3rc Updated by Dr. Charles A. Bell, March 2015.
27
28
*/
28
29
#include "Arduino.h"
29
30
#include "mysql.h"
231
232
  Serial.print(rows);
232
233
  print_message(ROWS, true);
233
234
  free_columns_buffer();
 
235
 
 
236
  // Free any post-query messages in queue for stored procedures
 
237
  clear_ok_packet();
 
238
}
 
239
 
 
240
 
 
241
/**
 
242
 * clear_ok_packet - clear last Ok packet (if present)
 
243
 *
 
244
 * This method reads the header and status to see if this is an Ok packet.
 
245
 * If it is, it reads the packet and discards it. This is useful for
 
246
 * processing result sets from stored procedures.
 
247
 *
 
248
 * Returns False if the packet was not an Ok packet.
 
249
*/
 
250
bool Connector::clear_ok_packet() {
 
251
  int num = 0;
 
252
 
 
253
  do {
 
254
    num = client.available();
 
255
    if (num > 0) {
 
256
      read_packet();
 
257
      if (check_ok_packet() != 0) {
 
258
        parse_error_packet();
 
259
        return false;
 
260
      }
 
261
    }
 
262
  } while (num > 0);
 
263
  return true;
234
264
}
235
265
 
236
266
 
392
422
  int num = 0;
393
423
  int timeout = 0;
394
424
  do {
395
 
    delay(50); // adjust for network latency
396
425
    num = client.available();
397
426
    timeout++;
 
427
    if (num < MIN_BYTES_NETWORK and timeout < MAX_TIMEOUT) {
 
428
      delay(100);  // adjust for network latency
 
429
    }
398
430
  } while (num < MIN_BYTES_NETWORK and timeout < MAX_TIMEOUT);
399
431
  return num;
400
432
}
570
602
  wait_for_client();
571
603
#endif
572
604
 
 
605
  int avail_bytes = wait_for_client();
 
606
  while (avail_bytes < 4) {
 
607
    avail_bytes = wait_for_client();
 
608
  }
 
609
 
573
610
  // Read packet header
574
611
  for (int i = 0; i < 4; i++) {
575
612
#if defined WIFI
584
621
  packet_len += ((uint32_t)local[2] << 16);
585
622
#if not defined WIFI
586
623
  // We must wait for slow arriving packets for Ethernet shields only.
587
 
  int avail_bytes = wait_for_client();
 
624
  avail_bytes = wait_for_client();
588
625
  while (avail_bytes < packet_len) {
589
626
    avail_bytes = wait_for_client();
590
627
  }
591
628
#endif
592
 
 
593
629
  // Check for valid packet.
594
630
  if (packet_len < 0) {
595
631
    print_message(PACKET_ERROR, true);