热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在c[持有]中从sqlite数据库中选择多个项目-selectmultipleitemfromsqlitedatabaseinc[onhold]

Imtryingtoquerysqliteinc,previouslyIopenandinsertedsomeitemstothedatabasesuccessf

I'm trying to query sqlite in c , previously I open and inserted some items to the database successfully(return SQLITE_OK),When I query total data ("SELECT * FROM TRANS_TABLE ...") I can retrieve my inserted data successfully but when I try to query by a specific item, I do not receive any data,is there any thing wrong with my code ?

我想查询sqlite在c语言中,先前我打开数据库并插入一些项目成功(返回SQLITE_OK),当我查询全部数据(“SELECT * FROM TRANS_TABLE…”)我可以检索数据插入成功,但是当我试着查询一个特定的项目,我不接收任何数据,有什么错我的代码吗?

sql = "SELECT * FROM TRANS_TABLE WHERE F11_STAN = ?";

  cmdStat = sqlite3_prepare_v2(db, sql, -1, &res, 0);

  if (cmdStat == SQLITE_OK)
  {
  sqlite3_bind_text( res, 1,( char *)f11, strlen(( char *)f11), 0);
  }
  else
  {
      netLogMsg(( uint8_t*)sqlite3_errmsg(db));
      return ;
  }

  int step = sqlite3_step(res);

  if (step == SQLITE_ROW)
  {
    netLogMsg(( uint8_t *)sqlite3_column_text(res, 0));
    netLogMsg(( uint8_t *)sqlite3_column_text(res, 1));
  }
else if (step == SQLITE_DONE)
{
  //this line is executed !
  netLogMsg(( uint8_t *)sqlite3_errmsg(db));
}
  memcpy( f11, sqlite3_column_text(res, 1), strlen(( const char *)sqlite3_column_text(res, 1)));

  sqlite3_finalize(res);

1 个解决方案

#1


1  

Try binding the id to the prepared statement:

尝试将id绑定到准备好的语句:

sql = "SELECT * FROM TRANS_TABLE WHERE F11_STAN = ?1";
cmdStat = sqlite3_prepare_v2(db, sql, -1, &res, 0);
sqlite3_bind_int(res, 1, 5);  

推荐阅读
author-avatar
潮流时候男装
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有