This tool generates C++ data access class for MySQL table. It can be used in any C++ project requiring convenient and fast access to MySQL database.
Without DAO class (plain MySQL API):
#include <mysql.h>
char sql[SQLBUF];
MYSQL_RES *result;
MYSQL_ROW row;
sprintf(sql, "SELECT name FROM users WHERE id=%d", id);
mysql_query(G_dbconn, sql);
result = mysql_store_result(G_dbconn);
row = mysql_fetch_row(result);
if ( row )
printf("Name: %s\n", row[0]?row[0]:"");
else
printf("Record not found\n");
mysql_free_result(result);
| With DAO class:
#include "Cusers.h"
static Cusers u;
if ( u.Get(id) )
printf("Name: %s\n", u.name);
else
printf("Record not found\n");
|
DAO version is also:
- faster – SQL statements are prepared and reused for subsequent calls;
- safer – no need to worry about
id
sanitization.
When both database and client are on the same server, the latency is a couple of hundreds microseconds. For smaller tables it means that the client process gets the query result in less than millisecond (commodity hardware Linux).
It can also be used together with this generated RESTful API or HTML view. In this case DAO class needs to be generated with C-style strings.
Generator v.2.1.0, last update 2024-03-06 (BLOB length available)
Paste the |