Attention: this is a legacy library and thus not supported by Toradex anymore. We recommend that you use the new libraries for all Toradex modules. Please see the Toradex CE Libraries and Code Samples for up-to-date information.
Amazon Relational Database Service (Amazon RDS) is a web service that makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and scalable storage capacity while managing time-consuming database administration tasks, allowing you up to focus on your applications and business.
Toradex RDS Cloud library provides access to MySQL instance running on Amazon RDS cloud service which allows user application running on a Toradex computer module to access the database and use it from anywhere in the world. Amazon RDS automatically patches the database software and taking backup of database, storing it for user-defined retention period and enabling point-in-time recovery. User will benefit from the flexibility of being able to scale the compute resources or storage capacity associated with your Database Instance (DB Instance) using Amazon Management Console.
Notes:
For more information on Amazon RDS, please refer http://aws.amazon.com/rds/
Please refer:
Before calling any other function, call MySqlOpen() with all input parameters: Sql Account Handle, Amazon RDS Endpoint, Sql User Name, Sql User Password
These required parameters will be available after setting up the MySQL instance through the AWS Management Console.
MYSQL sqlAccount = NULL; // MySQL Account Handle CHAR sqlInput[MYSQL_QUERY_STRING_LENGTH] = {0}; if (!MySqlOpen(&sqlAccount, AMAZON_RDS_MYSQL_INSTANCE_ENDPOINT, SQL_USER, SQL_USER_PASSWORD)) { printf("\nOpen failed %d\n", GetLastError()); } else { printf("\nOpen successful\n"); }
sqlAccount needs to be passed to all function calls after this point.
MySqlConnect() or MySqlConnectWithSsl() is used to connect to the Amazon RDS MySQL instance. Using MySqlConnectWithSsl() results in use of SSL encryption for all later MySQL requests. This is the second function to be called after MySqlOpen(). It is mandatory to call MySqlConnect() or MySqlConnectWithSsl() (depending on whether user requires encryption or not) after MySqlOpen(), otherwise all further calls will automatically fail.
Amazon RDS creates an SSL certificate and installs the certificate on the DB instance when Amazon RDS provisions the instance. These certificates are signed by a certificate authority. The public key is stored at https://rds.amazonaws.com/doc/mysql-ssl-ca-cert.pem . This certificate should be downloaded to the Toradex Module and added to the device via Control Panel, if MySqlConnectWithSsl() needs to be used and SSL is required. Change the extension of the file to .cer before adding. If certificate is not added, MySqlConnectWithSsl() will fail.
if (!MySqlConnect(sqlAccount, 0)) { printf("\nConnect failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } else { printf("\nConnection successful\n"); }
if (!MySqlConnectWithSsl(sqlAccount, 0)) { printf("\nConnect failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } else { printf("\nConnection successful\n"); }
MySqlRowQuery() function is use to query the database for row data, which is stored in a local file after the function call.
if (!MySqlRowQuery(sqlAccount, sqlInput, filePath, &numberOfColumns)) { if (NULL != sqlAccount) { printf("Query failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } } else { printf("\nQuery successful\n"); printf("\nNumber of columns: %d\n", numberOfColumns); }
MySqlListFields() is use to get the column field details, which is stored in a local file after the function call.
if (!MySqlListFields(sqlAccount, sqlInput, filePath, &numberOfColumns)) { if (NULL != sqlAccount) { printf("List fields failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } } else { printf("\nList fields successful\n"); printf("\nNumber of columns: %d\n", numberOfColumns); }
MySqlCreateDb() is used to create a new database table
if (!MySqlCreateDb(sqlAccount, sqlInput)) { if (NULL != sqlAccount) { printf("Create database failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } } else { printf("\nDatabase created\n"); }
MySqlDropDb() is used to delete and existing schema/database
if (!MySqlDropDb(sqlAccount, sqlInput)) { if (NULL != sqlAccount) { printf("Drop database failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } } else { printf("\nDatabase dropped\n"); }
MySqlPing() is used to check if connection to the MySQL instance is alive
if (!MySqlPing(sqlAccount)) { printf("Connect failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); } else { printf("\nServer connection OK\n"); }
MySqlUpdateQuery() is use to update data in the database table
if (!MySqlUpdateQuery(sqlAccount, sqlInput)) { if (NULL != sqlAccount) { printf("Update failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } } else { printf("\nNumber of affected rows is %d\n", MySqlAffectedRows(sqlAccount)); }
MySqlInsertQuery() is use to insert data in the table
if (!MySqlInsertQuery(sqlAccount, sqlInput)) { if (NULL != sqlAccount) { printf("Insert failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } } else { printf("\nNumber of affected rows is %d\n", MySqlAffectedRows(sqlAccount)); }
MySqlDeleteQuery() is used to delete data in the table
if (!MySqlDeleteQuery(sqlAccount, sqlInput)) { if (NULL != sqlAccount) { printf("Delete failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } } else { printf("\nNumber of affected rows is %d\n", MySqlAffectedRows(sqlAccount)); }
MySqlAlterquery() is used to add, delete or modify columns in the table
if (!MySqlAlterQuery(sqlAccount, sqlInput)) { if (NULL != sqlAccount) { printf("Alter failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } } else { printf("\nNumber of affected rows is %d\n", MySqlAffectedRows(sqlAccount)); }
MySqlGetNumberOfRows() is used to get the number of records in the database table
if (!MySqlGetNumberOfRows(sqlAccount, sqlInput, &numberOfRows)) { if (NULL != sqlAccount) { printf("Get records failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } } else { printf("\nNumber of records in table is %d\n", numberOfRows); }
MySqlAffectedRows() returns the number of rows, changed, deleted or inserted
printf("\nNumber of affected rows is %d\n", MySqlAffectedRows(sqlAccount));
MySqlListTables() provides the list of tables in the database
if (!MySqlListTables(sqlAccount, sqlInput, filePath)) { if (NULL != sqlAccount) { printf("List tables failed. Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } } else { printf("\nList of tables read successfully\n"); }
MySqlInitDb() sets the default schema for the currently opened connection
if (!MySqlInitDb(sqlAccount, sqlInput)) { if (NULL != sqlAccount) { printf("Error %d. Network Error %d\n", GetLastError(), WSAGetLastError()); printf("MySQL error number: %d\n", sqlAccount->sqlErrorNumber); printf("MySQL error message: %s\n", sqlAccount->sqlErrorString); } } else { printf("\nDefault schema changed to %s\n", sqlInput); }
MySqlQuit() closes the connection to the MySQL instance
MySqlQuit(sqlAccount);
MySqlClose() closes the handle opened by call to MySqlOpen(). This function must be called before closing any application in which this library is being used.
if (!MySqlClose(&sqlAccount)) { printf("Close failed. Network Error %d\n", WSAGetLastError()); }
MySqlClearError() clears the MySQL error number and error string which would have occurred from a previous error.
MySqlClearError(sqlAccount)