代码拉取完成,页面将自动刷新
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "sqlite3.h"
#include "msg_struct.h"
#include "db_op.h"
#include "logger.h"
#include <arpa/inet.h>
sqlite3 *db = NULL;
DB_RET_TYPE db_init(char *dbname)
{
if (SQLITE_OK !=sqlite3_open(dbname, &db))
{
return DB_OPEN_ERROR;
}
return DB_SUCCESS;
}
int select_info(void *arg, int colcount, char **cols, char **clonames)
{
for (int i = 0; i < colcount; i++)
{
printf("%s\t",clonames[i]);
}
printf("\n");
for (int i = 0; i < colcount; i++)
{
printf("%s\t", cols[i]);
}
printf("\n");
msg_rsp_info_t *rsp = (msg_rsp_info_t *)arg;
rsp->info[rsp->num].staffno = atoi(cols[0]);
rsp->info[rsp->num].usertype = atoi(cols[1]);
strcpy(rsp->info[rsp->num].name, cols[2]); // name
printf("name : %s,%s len : %d\n", cols[2], rsp->info[rsp->num].name, strlen(cols[2]));
rsp->info[rsp->num].age = atoi(cols[4]);
strcpy(rsp->info[rsp->num].phone, cols[5]);
printf("phone %s %d\n", rsp->info[rsp->num].phone, strlen(rsp->info[rsp->num].phone));
strcpy(rsp->info[rsp->num].addr, cols[6]); //addr
printf("addr %s %d\n", rsp->info[rsp->num].addr, strlen(rsp->info[rsp->num].addr));
strcpy(rsp->info[rsp->num].post, cols[7]); //work
printf("post %s %d\n", rsp->info[rsp->num].post, strlen(rsp->info[rsp->num].post));
strcpy(rsp->info[rsp->num].date, cols[8]);
rsp->info[rsp->num].level = atoi(cols[9]);
rsp->info[rsp->num].salary = atoi(cols[10]);
LOG_DEBUG("name : %s, age : %d, %d", rsp->info[rsp->num].name, \
rsp->info[rsp->num].age, (unsigned )rsp->info[rsp->num].staffno)
rsp->num++;
return SQLITE_OK;
}
msg_rsp_info_t * get_staff_info(msg_get_info_t *get_info)
{
if(strstr(get_info->tname,"page"))
{
char *start = strtok(get_info->tvalue, ",");
char *pagesize = strtok(NULL, ",");
int count = atoi(pagesize);
char sqlbuf[64] = "select * from usrinfo limit %s,%s\n";
char sql[32] = {0};
sprintf(sql, sqlbuf, start, pagesize);
msg_rsp_info_t *rsp = (msg_rsp_info_t *)malloc(sizeof(staff_info_t)*count + sizeof(int));
memset(rsp, 0, sizeof(staff_info_t)*count + sizeof(int));
if (SQLITE_OK!=sqlite3_exec(db, sql, select_info, rsp, NULL))
{
return NULL;
}
else
{
return rsp;
}
}
return NULL;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。