Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit 739f814

Browse files
authored
v1.0.2
### New in v1.0.2 1. Fix crashing bug when Client timeout. 2. Make code more error-proof. 3. Drop support to ESP8266_AT_Webserver. 4. Enhance examples
1 parent d7657fa commit 739f814

File tree

82 files changed

+725
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+725
-560
lines changed

examples/Ethernet/Basic_Insert/Basic_Insert.ino

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
1212
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1313
Licensed under MIT license
14-
Version: 1.0.1
14+
Version: 1.0.2
1515
1616
Version Modified By Date Comments
1717
------- ----------- ---------- -----------
1818
1.0.0 K Hoang 13/08/2020 Initial coding/porting to support nRF52, SAM DUE and SAMD21/SAMD51 boards using W5x00 Ethernet
19-
(using Ethernet, EthernetLarge, Ethernet2, Ethernet3 library) and WiFiNINA
19+
(Ethernet, EthernetLarge, Ethernet2, Ethernet3 library), WiFiNINA and ESP8266/ESP32-AT shields
2020
1.0.1 K Hoang 18/08/2020 Add support to Ethernet ENC28J60. Fix bug, optimize code.
21+
1.0.2 K Hoang 20/08/2020 Fix crashing bug when timeout. Make code more error-proof. Drop support to ESP8266_AT_Webserver.
2122
**********************************************************************************************************************************/
2223

2324
/*
@@ -248,22 +249,23 @@ void setup()
248249
void runInsert(void)
249250
{
250251
// Initiate the query class instance
251-
MySQL_Query *query_mem = new MySQL_Query(&conn);
252+
MySQL_Query query_mem = MySQL_Query(&conn);
252253

253254
if (conn.connected())
254255
{
255256
Serial.println(INSERT_SQL);
256-
query_mem->execute(INSERT_SQL.c_str());
257-
Serial.println("Data Inserted.");
257+
258+
// Execute the query
259+
// KH, check if valid before fetching
260+
if ( !query_mem.execute(INSERT_SQL.c_str()) )
261+
Serial.println("Insert error");
262+
else
263+
Serial.println("Data Inserted.");
258264
}
259265
else
260266
{
261267
Serial.println("Disconnected from Server. Can't insert.");
262268
}
263-
264-
// Note: since there are no results, we do not need to read any data
265-
// Deleting the cursor also frees up memory used
266-
delete query_mem;
267269
}
268270

269271
void loop()

examples/Ethernet/Basic_Insert/defines.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
1212
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1313
Licensed under MIT license
14-
Version: 1.0.1
14+
Version: 1.0.2
1515
1616
Version Modified By Date Comments
1717
------- ----------- ---------- -----------
1818
1.0.0 K Hoang 13/08/2020 Initial coding/porting to support nRF52, SAM DUE and SAMD21/SAMD51 boards using W5x00 Ethernet
19-
(using Ethernet, EthernetLarge, Ethernet2, Ethernet3 library) and WiFiNINA
19+
(Ethernet, EthernetLarge, Ethernet2, Ethernet3 library), WiFiNINA and ESP8266/ESP32-AT shields
2020
1.0.1 K Hoang 18/08/2020 Add support to Ethernet ENC28J60. Fix bug, optimize code.
21+
1.0.2 K Hoang 20/08/2020 Fix crashing bug when timeout. Make code more error-proof. Drop support to ESP8266_AT_Webserver.
2122
**********************************************************************************************************************************/
2223

2324
#ifndef defines_h
@@ -308,14 +309,14 @@
308309

309310
// Only one of the following to be true.
310311
#define USE_ETHERNET false //true
311-
#define USE_ETHERNET_LARGE true
312+
#define USE_ETHERNET_LARGE false
312313
#define USE_ETHERNET2 false //true
313314
#define USE_ETHERNET3 false //true
314315
#define USE_ETHERNET_ESP8266 false //true
315316
#define USE_ETHERNET_LAN8742A false //true
316317

317318
// KH, from v1.0.1
318-
#define USE_UIP_ETHERNET false
319+
#define USE_UIP_ETHERNET true
319320
//////
320321

321322
// Enter a MAC address and IP address for your controller below.

examples/Ethernet/Basic_Select/Basic_Select.ino

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
1212
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1313
Licensed under MIT license
14-
Version: 1.0.1
14+
Version: 1.0.2
1515
1616
Version Modified By Date Comments
1717
------- ----------- ---------- -----------
1818
1.0.0 K Hoang 13/08/2020 Initial coding/porting to support nRF52, SAM DUE and SAMD21/SAMD51 boards using W5x00 Ethernet
19-
(using Ethernet, EthernetLarge, Ethernet2, Ethernet3 library) and WiFiNINA
19+
(Ethernet, EthernetLarge, Ethernet2, Ethernet3 library), WiFiNINA and ESP8266/ESP32-AT shields
2020
1.0.1 K Hoang 18/08/2020 Add support to Ethernet ENC28J60. Fix bug, optimize code.
21+
1.0.2 K Hoang 20/08/2020 Fix crashing bug when timeout. Make code more error-proof. Drop support to ESP8266_AT_Webserver.
2122
**********************************************************************************************************************************/
2223

2324
/*
@@ -245,28 +246,32 @@ void runQuery(void)
245246

246247
Serial.println("1) Demonstrating using a dynamically allocated query.");
247248
// Initiate the query class instance
248-
MySQL_Query *query_mem = new MySQL_Query(&conn);
249+
MySQL_Query query_mem = MySQL_Query(&conn);
249250

250251
// Execute the query
251252
Serial.println(query);
252-
query_mem->execute(query.c_str());
253+
254+
// Execute the query
255+
// KH, check if valid before fetching
256+
if ( !query_mem.execute(query.c_str()) )
257+
{
258+
Serial.println("Querying error");
259+
return;
260+
}
253261

254262
// Fetch the columns (required) but we don't use them.
255-
column_names *columns = query_mem->get_columns();
263+
column_names *columns = query_mem.get_columns();
256264

257265
// Read the row (we are only expecting the one)
258266
do
259267
{
260-
row = query_mem->get_next_row();
268+
row = query_mem.get_next_row();
261269

262270
if (row != NULL)
263271
{
264272
head_count = atol(row->values[0]);
265273
}
266274
} while (row != NULL);
267-
268-
// Deleting the cursor also frees up memory used
269-
delete query_mem;
270275

271276
// Show the result
272277
Serial.print(" Toronto pop = ");

examples/Ethernet/Basic_Select/defines.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
1212
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1313
Licensed under MIT license
14-
Version: 1.0.1
14+
Version: 1.0.2
1515
1616
Version Modified By Date Comments
1717
------- ----------- ---------- -----------
1818
1.0.0 K Hoang 13/08/2020 Initial coding/porting to support nRF52, SAM DUE and SAMD21/SAMD51 boards using W5x00 Ethernet
19-
(using Ethernet, EthernetLarge, Ethernet2, Ethernet3 library) and WiFiNINA
19+
(Ethernet, EthernetLarge, Ethernet2, Ethernet3 library), WiFiNINA and ESP8266/ESP32-AT shields
2020
1.0.1 K Hoang 18/08/2020 Add support to Ethernet ENC28J60. Fix bug, optimize code.
21+
1.0.2 K Hoang 20/08/2020 Fix crashing bug when timeout. Make code more error-proof. Drop support to ESP8266_AT_Webserver.
2122
**********************************************************************************************************************************/
2223

2324
#ifndef defines_h
@@ -308,14 +309,14 @@
308309

309310
// Only one of the following to be true.
310311
#define USE_ETHERNET false //true
311-
#define USE_ETHERNET_LARGE true
312+
#define USE_ETHERNET_LARGE false
312313
#define USE_ETHERNET2 false //true
313314
#define USE_ETHERNET3 false //true
314315
#define USE_ETHERNET_ESP8266 false //true
315316
#define USE_ETHERNET_LAN8742A false //true
316317

317318
// KH, from v1.0.1
318-
#define USE_UIP_ETHERNET false
319+
#define USE_UIP_ETHERNET true
319320
//////
320321

321322
// Enter a MAC address and IP address for your controller below.

examples/Ethernet/Complex_Insert/Complex_Insert.ino

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
1212
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1313
Licensed under MIT license
14-
Version: 1.0.1
14+
Version: 1.0.2
1515
1616
Version Modified By Date Comments
1717
------- ----------- ---------- -----------
1818
1.0.0 K Hoang 13/08/2020 Initial coding/porting to support nRF52, SAM DUE and SAMD21/SAMD51 boards using W5x00 Ethernet
19-
(using Ethernet, EthernetLarge, Ethernet2, Ethernet3 library) and WiFiNINA
19+
(Ethernet, EthernetLarge, Ethernet2, Ethernet3 library), WiFiNINA and ESP8266/ESP32-AT shields
2020
1.0.1 K Hoang 18/08/2020 Add support to Ethernet ENC28J60. Fix bug, optimize code.
21+
1.0.2 K Hoang 20/08/2020 Fix crashing bug when timeout. Make code more error-proof. Drop support to ESP8266_AT_Webserver.
2122
**********************************************************************************************************************************/
2223
/*
2324
MySQL Connector/Arduino Example : complex insert
@@ -269,7 +270,7 @@ void setup()
269270
void runInsert(void)
270271
{
271272
// Initiate the query class instance
272-
MySQL_Query *query_mem = new MySQL_Query(&conn);
273+
MySQL_Query query_mem = MySQL_Query(&conn);
273274

274275
if (conn.connected())
275276
{
@@ -279,21 +280,17 @@ void runInsert(void)
279280

280281
// Execute the query
281282
Serial.println(query);
282-
query_mem->execute(query);
283-
284-
// Note: since there are no results, we do not need to read any data
285-
// Deleting the cursor also frees up memory used
286-
delete query_mem;
287-
Serial.println("Complex Data Inserted.");
283+
284+
// KH, check if valid before fetching
285+
if ( !query_mem.execute(query) )
286+
Serial.println("Complex Insert error");
287+
else
288+
Serial.println("Complex Data Inserted.");
288289
}
289290
else
290291
{
291292
Serial.println("Disconnected from Server. Can't insert.");
292293
}
293-
294-
// Note: since there are no results, we do not need to read any data
295-
// Deleting the cursor also frees up memory used
296-
delete query_mem;
297294
}
298295

299296
void loop()

examples/Ethernet/Complex_Insert/defines.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
1212
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1313
Licensed under MIT license
14-
Version: 1.0.1
14+
Version: 1.0.2
1515
1616
Version Modified By Date Comments
1717
------- ----------- ---------- -----------
1818
1.0.0 K Hoang 13/08/2020 Initial coding/porting to support nRF52, SAM DUE and SAMD21/SAMD51 boards using W5x00 Ethernet
19-
(using Ethernet, EthernetLarge, Ethernet2, Ethernet3 library) and WiFiNINA
19+
(Ethernet, EthernetLarge, Ethernet2, Ethernet3 library), WiFiNINA and ESP8266/ESP32-AT shields
2020
1.0.1 K Hoang 18/08/2020 Add support to Ethernet ENC28J60. Fix bug, optimize code.
21+
1.0.2 K Hoang 20/08/2020 Fix crashing bug when timeout. Make code more error-proof. Drop support to ESP8266_AT_Webserver.
2122
**********************************************************************************************************************************/
2223

2324
#ifndef defines_h
@@ -308,14 +309,14 @@
308309

309310
// Only one of the following to be true.
310311
#define USE_ETHERNET false //true
311-
#define USE_ETHERNET_LARGE true
312+
#define USE_ETHERNET_LARGE false
312313
#define USE_ETHERNET2 false //true
313314
#define USE_ETHERNET3 false //true
314315
#define USE_ETHERNET_ESP8266 false //true
315316
#define USE_ETHERNET_LAN8742A false //true
316317

317318
// KH, from v1.0.1
318-
#define USE_UIP_ETHERNET false
319+
#define USE_UIP_ETHERNET true
319320
//////
320321

321322
// Enter a MAC address and IP address for your controller below.

examples/Ethernet/Complex_Select/Complex_Select.ino

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
1212
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1313
Licensed under MIT license
14-
Version: 1.0.1
14+
Version: 1.0.2
1515
1616
Version Modified By Date Comments
1717
------- ----------- ---------- -----------
1818
1.0.0 K Hoang 13/08/2020 Initial coding/porting to support nRF52, SAM DUE and SAMD21/SAMD51 boards using W5x00 Ethernet
19-
(using Ethernet, EthernetLarge, Ethernet2, Ethernet3 library) and WiFiNINA
19+
(Ethernet, EthernetLarge, Ethernet2, Ethernet3 library), WiFiNINA and ESP8266/ESP32-AT shields
2020
1.0.1 K Hoang 18/08/2020 Add support to Ethernet ENC28J60. Fix bug, optimize code.
21+
1.0.2 K Hoang 20/08/2020 Fix crashing bug when timeout. Make code more error-proof. Drop support to ESP8266_AT_Webserver.
2122
**********************************************************************************************************************************/
2223

2324
/*
@@ -72,7 +73,7 @@ char default_table[] = "city"; //"test_arduino";
7273
// Notice the "%lu" - that's a placeholder for the parameter we will
7374
// supply. See sprintf() documentation for more formatting specifier
7475
// options
75-
unsigned long QUERY_POPULATION = 8000000;
76+
unsigned long QUERY_POPULATION = 800000;
7677

7778
const char QUERY_POP[] = "SELECT name, population FROM world.city WHERE population < %lu ORDER BY population DESC LIMIT 12;";
7879

@@ -249,17 +250,22 @@ void runQuery(void)
249250
// to allocate one buffer for all formatted queries or allocate the
250251
// memory as needed (just make sure you allocate enough memory and
251252
// free it when you're done!).
252-
sprintf(query, QUERY_POP, QUERY_POPULATION);
253+
sprintf(query, QUERY_POP, QUERY_POPULATION + (( millis() % 100000 ) * 10) );
253254
Serial.println(query);
254255

255256
// Initiate the query class instance
256-
MySQL_Query *query_mem = new MySQL_Query(&conn);
257+
MySQL_Query query_mem = MySQL_Query(&conn);
257258

258259
// Execute the query
259-
query_mem->execute(query);
260+
// KH, check if valid before fetching
261+
if ( !query_mem.execute(query) )
262+
{
263+
Serial.println("Querying error");
264+
return;
265+
}
260266

261267
// Fetch the columns and print them
262-
column_names *cols = query_mem->get_columns();
268+
column_names *cols = query_mem.get_columns();
263269

264270
for (int f = 0; f < cols->num_fields; f++)
265271
{
@@ -278,7 +284,7 @@ void runQuery(void)
278284

279285
do
280286
{
281-
row = query_mem->get_next_row();
287+
row = query_mem.get_next_row();
282288

283289
if (row != NULL)
284290
{
@@ -295,9 +301,6 @@ void runQuery(void)
295301
Serial.println();
296302
}
297303
} while (row != NULL);
298-
299-
// Deleting the cursor also frees up memory used
300-
delete query_mem;
301304
}
302305

303306
void loop()
@@ -319,5 +322,5 @@ void loop()
319322
Serial.println("\nSleeping...");
320323
Serial.println("================================================");
321324

322-
delay(60000);
325+
delay(10000);
323326
}

examples/Ethernet/Complex_Select/defines.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
1212
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1313
Licensed under MIT license
14-
Version: 1.0.1
14+
Version: 1.0.2
1515
1616
Version Modified By Date Comments
1717
------- ----------- ---------- -----------
1818
1.0.0 K Hoang 13/08/2020 Initial coding/porting to support nRF52, SAM DUE and SAMD21/SAMD51 boards using W5x00 Ethernet
19-
(using Ethernet, EthernetLarge, Ethernet2, Ethernet3 library) and WiFiNINA
19+
(Ethernet, EthernetLarge, Ethernet2, Ethernet3 library), WiFiNINA and ESP8266/ESP32-AT shields
2020
1.0.1 K Hoang 18/08/2020 Add support to Ethernet ENC28J60. Fix bug, optimize code.
21+
1.0.2 K Hoang 20/08/2020 Fix crashing bug when timeout. Make code more error-proof. Drop support to ESP8266_AT_Webserver.
2122
**********************************************************************************************************************************/
2223

2324
#ifndef defines_h
@@ -308,14 +309,14 @@
308309

309310
// Only one of the following to be true.
310311
#define USE_ETHERNET false //true
311-
#define USE_ETHERNET_LARGE true
312+
#define USE_ETHERNET_LARGE false
312313
#define USE_ETHERNET2 false //true
313314
#define USE_ETHERNET3 false //true
314315
#define USE_ETHERNET_ESP8266 false //true
315316
#define USE_ETHERNET_LAN8742A false //true
316317

317318
// KH, from v1.0.1
318-
#define USE_UIP_ETHERNET false
319+
#define USE_UIP_ETHERNET true
319320
//////
320321

321322
// Enter a MAC address and IP address for your controller below.

examples/Ethernet/Connect/Connect.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
1212
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1313
Licensed under MIT license
14-
Version: 1.0.1
14+
Version: 1.0.2
1515
1616
Version Modified By Date Comments
1717
------- ----------- ---------- -----------
1818
1.0.0 K Hoang 13/08/2020 Initial coding/porting to support nRF52, SAM DUE and SAMD21/SAMD51 boards using W5x00 Ethernet
19-
(using Ethernet, EthernetLarge, Ethernet2, Ethernet3 library) and WiFiNINA
19+
(Ethernet, EthernetLarge, Ethernet2, Ethernet3 library), WiFiNINA and ESP8266/ESP32-AT shields
2020
1.0.1 K Hoang 18/08/2020 Add support to Ethernet ENC28J60. Fix bug, optimize code.
21+
1.0.2 K Hoang 20/08/2020 Fix crashing bug when timeout. Make code more error-proof. Drop support to ESP8266_AT_Webserver.
2122
**********************************************************************************************************************************/
2223

2324
/*

0 commit comments

Comments
 (0)