ITeye博客

android的sqlite数据库中单引号的诡异作用

ljmdbc7a · 2011-10-17 16:11 · android · 移动开发 · Markdown

今天查询数据库时又遇到了一个诡异的错误:

no such column!!!

 

用终端查询了数据库,没有问题,这是怎么了...

出现问题的代码在这里:

 

public Cursor QueryExamPaperCCByTitle(String title)
	{
		Cursor cursor = database_r.query(TableDefine.EXAMPAPERCC, null, TableDefine.Table_ExamPaperCC.TITLE+" = "+title, null, null, null, null);
		if(cursor.getCount() > 0)
		{
			cursor.moveToFirst();
			return cursor;
		}
		return null;
	}

 第三行!

 

后来终于想到了以前遇到的一个类似的问题,把第三行改为:

 

Cursor cursor = database_r.query(TableDefine.EXAMPAPERCC, null, TableDefine.Table_ExamPaperCC.TITLE+" = "+"'"+title+"'", null, null, null, null);

 

 

 就ok了!

看出来那不同了吧,就是多了一对单引号,好像是转义字符,具体什么时候用还有待研究!

 

研究明白了再续分享!

欢迎留言!

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。