#include #include #define C(x) x, sizeof(x) - 1 int exec_select(MYSQL *mysql, const char *q, size_t q_len) { MYSQL_RES *res; if (mysql_real_query(mysql, q, q_len)) { fprintf(stderr, "%s.%d: mysql_real_query(%s) failed: %s", __FILE__, __LINE__, "", mysql_error(mysql)); return 0; } if (NULL != (res = mysql_store_result(mysql))) { MYSQL_ROW row; while((row = mysql_fetch_row(res))) { printf("%s\n", row[0]); } mysql_free_result(res); } return 0; } int main() { MYSQL *mysql; mysql = mysql_init(NULL); if (!mysql_real_connect(mysql, "127.0.0.1", "root", "", "", 3350, NULL, 0)) { fprintf(stderr, "%s.%d: mysql_real_connect() failed: %s", __FILE__, __LINE__, mysql_error(mysql)); return -1; } exec_select(mysql, C("use test")); exec_select(mysql, C("drop table if exists t1")); exec_select(mysql, C("create table t1(f1 longtext)")); exec_select(mysql, C("insert into t1 values('adadsadsadasdasdsadasdasdsadasdasdadasdsadsadsadsadsadsadsadsadasdsadasdsadsadsadsadsadsadsadsadsadasdasdasdadadasdasdadasdasdasdasdasdasdasdasdasdadsadasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdadasdasdasdasdasdasdasdasdadsasdasdadasdadasdasdadadasdasdasdasdasdasdasdasdasdasdasdasdsadadadadadasdasdasdasdasdasdasdasdasdasdadasdasdadadassdadadadadasdasdasdasdasdadasdadass255')")); exec_select(mysql, C("select * from t1")); mysql_close(mysql); return 0; }