Android sqlite中text格式文本的比较

由于开发初期判断上的失误,错误地以一个并不具必唯一性的字段来作为id,导致用户无法添加具体相同title的消息,以前考虑的真是太不周全了。


context = In the present, then, in loving tolerance, in loving association, ever being ready to answer when any aid or help must be given or may be given [is the best way to help someone].


context = <p>

. . . ye are part and parcel of a universal consciousness or God&mdash;and thus of all that is within the universal consciousness, or the universal awareness; as the stars, the planets, the sun, the moon. Do ye rule them or they rule thee? They were made for thy own use, as an individual&mdash;yea, that is the part, the thought thy Maker, thy Father-God thinks of thee.&nbsp;</p>


/**

*

@param context 

@return boolean

@author Samuel.Cai

@date Mar 9, 2012

*/

public boolean alreadyExists(String context) {

//System.out.println(">>>>>>>  context = " + context );

// TODO Auto-generated method stub

Cursor cursor = null;

Boolean flag = true;

if(context != null){

sd=db.getReadableDatabase();

cursor = sd.rawQuery("select * from thoughtsInfo where context=?",new String[]{context.trim()});

if(cursor.getCount() == 0){

flag = false;

}else{

flag = true;

}

}

cursor.close();

sd.close();

return flag;

}

最终结果:比较一般文本,就是把salite里面text格式字段里面值拿出来,与外面String来作比较,有些字符串可能由于编码的原因,并不一定能和自己期望的比较结果符合。

最终solution: 没有办法,只能改表结构(这次考虑很充分了,哈哈!),自己管理数据库的升级,重新发版本,自动处理用户的数据。

思路,自己通过设定标记,来执行换表结构的代码(先把用户数据从旧的表结构中取出,然后再建新表,再插入),这个并不等同于普通的数据库升级。需小心应对才是!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值