github.com/dolthub/go-mysql-server@v0.18.0/_integration/c/test.c (about) 1 #include <my_global.h> 2 #include <mysql.h> 3 4 #include <string.h> 5 #include <assert.h> 6 7 #define TEST(s1, s2) do { printf("'%s' =?= '%s'\n", s1, s2); assert(0 == strcmp(s1, s2)); } while(0) 8 9 static void finish_with_error(MYSQL *con) 10 { 11 fprintf(stderr, "%s\n", mysql_error(con)); 12 mysql_close(con); 13 exit(1); 14 } 15 16 int main(int argc, char **argv) 17 { 18 MYSQL *con = NULL; 19 MYSQL_RES *result = NULL; 20 MYSQL_ROW row; 21 22 int n = 0; 23 const int expected_num_records = 4; 24 const char *expected_name[expected_num_records] = { 25 "John Doe\0", 26 "John Doe\0", 27 "Jane Doe\0", 28 "Evil Bob\0" 29 }; 30 const char *expected_email[expected_num_records] = { 31 "john@doe.com\0", 32 "johnalt@doe.com\0", 33 "jane@doe.com\0", 34 "evilbob@gmail.com\0" 35 }; 36 37 printf("MySQL client version: %s\n", mysql_get_client_info()); 38 39 con = mysql_init(NULL); 40 if (con == NULL) { 41 finish_with_error(con); 42 } 43 44 if (mysql_real_connect(con, "127.0.0.1", "root", "", "mydb", 3306, NULL, 0) == NULL) { 45 finish_with_error(con); 46 } 47 48 if (mysql_query(con, "SELECT name, email FROM mytable")) { 49 finish_with_error(con); 50 } 51 52 result = mysql_store_result(con); 53 if (result == NULL) { 54 finish_with_error(con); 55 } 56 57 while ((row = mysql_fetch_row(result))) { 58 TEST(expected_name[n], row[0]); 59 TEST(expected_email[n], row[1]); 60 ++n; 61 } 62 assert(expected_num_records == n); 63 64 mysql_free_result(result); 65 mysql_close(con); 66 67 return 0; 68 }