Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void handle_existing_db_request(struct mg_connection *nc, void *ev_data)
- {
- struct http_message *hm = (struct http_message *) ev_data;
- sqlite3_stmt *stmt = NULL;
- (void) hm;
- mg_printf(nc, "%s", "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
- if (sqlite3_prepare_v2(s_db_handle, "SELECT mac,mac_vendor FROM t_host;", -1, &stmt, NULL) == SQLITE_OK) {
- mg_printf_http_chunk(nc, "<table>\r\n");
- while (1) {
- int s, i;
- mg_printf_http_chunk(nc, "<rd>\r\n");
- s = sqlite3_step (stmt);
- if (s == SQLITE_ROW) {
- for (i=0; i<2; i++) {
- const unsigned char *text = sqlite3_column_text (stmt, i);;
- mg_printf_http_chunk(nc, "<td>%s</td>", text);
- }
- mg_printf_http_chunk(nc, "\r\n");
- }
- else if (s == SQLITE_DONE) {
- break;
- }
- else {
- fprintf (stderr, "Failed.\n");
- exit (1);
- }
- mg_printf_http_chunk(nc, "</rd>\r\n");
- }
- mg_printf_http_chunk(nc, "</table>\r\n");
- }
- mg_send_http_chunk(nc, "", 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement