Sqlite   发布时间:2019-11-06  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在finalize / close期间,sqlite3_column_text返回的数据被破坏大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我不确定这里发生了什么,但我发现在finalize / close sqlite阶段,sqlite3_column_text返回的数据正在被更改.
// rc not handled in this abbreviated code

  sqlite3 *db;
  sqlite3_stmt *stmt;
  char * sql;

  const char * tail;
  int rc;

  char * dbname = "C:\\db\\myblobs.db";
  int myIndex = 0;

  char * myLOCATIOn1;
  String myLOCATIOn2;   

  rc = sqlite3_open(dbName,@R_290_4616@;

  sql = "SELECT LOCATIOn FROM blobs WHERE key = ?";
  rc = sqlite3_prepare(db,sql,strlen(sql),&stmt,&tail);
  sqlite3_bind_int(stmt,1,myIndeX);
  rc = sqlite3_step(stmt);

  myLOCATIOn1 = (char*)sqlite3_column_text(stmt,0);
  myLOCATIOn2 = (char*)sqlite3_column_text(stmt,0);

  // can process myLOCATIOn1 & myLOCATIOn2 fine here

  sqlite3_finalize(stmt); // data myLOCATIOn1 points to get corrupted
  sqlite3_close(db);      // data myLOCATIOn2 points to gets further corrupted

问题与myLOCATIOn1有关.它指向的数据很好,直到它到达sqlite3_finalize和sqlite3_close语句.然而,myLOCATIOn2保持不变.所以不确定这里发生了什么.执行sqlite3_close(db)后,myLOCATIOn1在Visual studio 2010中被标识为“Bad Ptr”.

任何帮助最受赞赏.

解决方法

fine manual

因此,只要调用sqlite3_finalize,sqlite3_column_text的返回值就会变为无效,而myLOCATIOn1和MyLOCATIOn2指针指向垃圾.

如果在调用sqlite3_finalize之后需要这些字符串,则必须将它们复制到您控制的内存中.实际上,由于在类型转换发生之前有效,因此应立即复制它们并仅使用(char *)sqlite3_column_text(stmt,0);而你正在制作自己的副本.

大佬总结

以上是大佬教程为你收集整理的在finalize / close期间,sqlite3_column_text返回的数据被破坏全部内容,希望文章能够帮你解决在finalize / close期间,sqlite3_column_text返回的数据被破坏所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。