firmware/demo/query.c

52 lines
1.6 KiB
C
Raw Normal View History

2018-03-12 07:01:29 +00:00
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
2018-06-08 08:58:44 +00:00
int main(int argc, char *argv[])
2018-03-12 07:01:29 +00:00
{
size_t i, lRow = 0;
dbUser stUser, *pstUser = NULL;
SATvm *pstSavm = (SATvm *)pGetSATvm();
/* 初始化TBL_USER_INFO表每张表都需要初始化一次, 对于表重建后,需要重新初始化一次。*/
if(RC_SUCC != lInitSATvm(pstSavm, TBL_USER_INFO))
{
2018-06-08 08:58:44 +00:00
fprintf(stderr, "init failed, err:(%d)(%s)\n", pstSavm->m_lErrno,
sGetTError(pstSavm->m_lErrno));
2018-03-12 07:01:29 +00:00
return RC_FAIL;
}
conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
conditstr(pstSavm, stUser, user_type, "1"); // 查询条件赋值
conditstr(pstSavm, stUser, user_no, "20180223"); // 查询条件赋值
2018-03-12 07:01:29 +00:00
if(RC_SUCC != lQuery(pstSavm, &lRow, (void **)&pstUser))
{
2018-06-08 08:58:44 +00:00
fprintf(stderr, "Query error:(%d)(%s)\n", pstSavm->m_lErrno,
sGetTError(pstSavm->m_lErrno));
2018-03-12 07:01:29 +00:00
return RC_FAIL;
}
for(i = 0; i < lRow; i ++)
{
2018-06-08 08:58:44 +00:00
fprintf(stdout, "acct_id:%ld, user_no:%s, user_type:%s, user_nm:%s, "
"user_addr:%s, user_phone:%s\n", pstUser[i].acct_id, pstUser[i].user_no,
pstUser[i].user_type, pstUser[i].user_nm, pstUser[i].user_addr,
2018-03-12 07:01:29 +00:00
pstUser[i].user_phone);
}
TFree(pstUser);
return RC_SUCC;
}