From 73f135cbae0daae63e73728499e10d711d52826a Mon Sep 17 00:00:00 2001 From: flykhan Date: Wed, 25 Oct 2023 15:21:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E8=B0=83=E5=87=BD=E6=95=B0v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cgi-bin/sqlite_cgi_base.c | 52 +++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/cgi-bin/sqlite_cgi_base.c b/cgi-bin/sqlite_cgi_base.c index 9b749b7..b365776 100644 --- a/cgi-bin/sqlite_cgi_base.c +++ b/cgi-bin/sqlite_cgi_base.c @@ -2,6 +2,7 @@ #include // #include "cJSON.h" #include "sqlite3.h" +#include // sqlite3的回调函数 // sqlite 每查到一条记录,就调用一次这个回调 @@ -79,19 +80,44 @@ int main(int argc, char const *argv[]) return 1; } - // 构建 JSON 数据 - cJSON *result_json = cJSON_CreateObject(); - cJSON_AddItemToObject(result_json, "result", cJSON_CreateString("success")); - cJSON_AddItemToObject(result_json, "username", - cJSON_CreateString(username_from_frontend)); + else if (rc == SQLITE_OK) + { + cJSON *result_json = cJSON_CreateObject(); + + // if ((row = mysql_fetch_row(res))) + // { + cJSON_AddNumberToObject(result_json, "code", 0); + // cJSON_AddStringToObject(result_json, "nickname", "admin"); + // } + // else + // // { + // cJSON_AddNumberToObject(result_json, "code", 1); + // cJSON_AddStringToObject(result_json, "msg", "用户名或密码错误"); + // } + + char *result_json_string = cJSON_Print(result_json); + + // 输出 JSON 结果 + printf("content-type: application/json;charset=utf-8\r\n"); + printf("\r\n"); + printf("%s\n", result_json_string); + + free(result_json_string); + } + + // // 构建 JSON 数据 + // cJSON *result_json = cJSON_CreateObject(); + // cJSON_AddItemToObject(result_json, "result", cJSON_CreateString("success")); + // cJSON_AddItemToObject(result_json, "username", + // cJSON_CreateString(username_from_frontend)); // 打印 JSON 数据 - char *result_json_str = cJSON_Print(result_json); + // char *result_json_str = cJSON_Print(result_json); // printf("%s\n", result_json_str); // 释放资源 cJSON_Delete(json_buf); - cJSON_Delete(result_json); + // cJSON_Delete(result_json); sqlite3_close(db); return 0; @@ -102,11 +128,11 @@ int sql_search_callback(void *NotUsed, char **argv, char **azColName) { - int i; - for (i = 0; i < argc; i++) - { - printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); - } + // int i; + // for (i = 0; i < argc; i++) + // { + // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); + // } - return 0; + return SQLITE_OK; } \ No newline at end of file