Test Mysql
Dependencies: mbed MySQLClient EthernetNetIf
Revision 0:82effba6633e, committed 2010-06-15
- Comitter:
- donatien
- Date:
- Tue Jun 15 16:24:56 2010 +0000
- Child:
- 1:50d2e2aea73b
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetNetIf.lib Tue Jun 15 16:24:56 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MySQLClient.lib Tue Jun 15 16:24:56 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/MySQLClient/#91c24a06d12c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MySQLClientExample.cpp Tue Jun 15 16:24:56 2010 +0000 @@ -0,0 +1,71 @@ +#include "mbed.h" +#include "EthernetNetIf.h" +#include "MySQLClient.h" + +#define SQL_SERVER "" +#define SQL_USER "" +#define SQL_PASSWORD "" +#define SQL_DB "" + +EthernetNetIf eth; +MySQLClient sql; + +MySQLResult sqlLastResult; +void onMySQLResult(MySQLResult r) +{ + sqlLastResult = r; +} + +int main() +{ + printf("Start\n"); + + printf("Setting up...\n"); + EthernetErr ethErr = eth.setup(); + if(ethErr) + { + printf("Error %d in setup.\n", ethErr); + return -1; + } + printf("Setup OK\n"); + + Host host(IpAddr(), 3306, SQL_SERVER); + + //Connect + sqlLastResult = sql.open(host, SQL_USER, SQL_PASSWORD, SQL_DB, onMySQLResult); + while(sqlLastResult == MYSQL_PROCESSING) + { + Net::poll(); + } + if(sqlLastResult != MYSQL_OK) + { + printf("Error %d during connection\n", sqlLastResult); + } + + //SQL Command + //Make command + char cmd[128] = {0}; + const char* msg="Hello World!"; + sprintf(cmd, "INSERT INTO Test (Test) VALUES('%s')", msg); + + //INSERT INTO DB + string cmdStr = string(cmd); + sqlLastResult = sql.sql(cmdStr); + while(sqlLastResult == MYSQL_PROCESSING) + { + Net::poll(); + } + if(sqlLastResult != MYSQL_OK) + { + printf("Error %d during SQL Command\n", sqlLastResult); + } + + sql.exit(); + + while(1) + { + + } + + return 0; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jun 15 16:24:56 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/029aa53d7323