---
title: "android的sqlite数据库中单引号的诡异作用"
author: "ljmdbc7a"
date: "2011-10-17T16:11:53Z"
tags: []
categories: ["移动开发"]
slug: "android-sqlite"
draft: false
lastmod: "2011-10-17T16:12:50Z"
id: 1198564
url: "https://ljmdbc7a.iteye.com/blog/1198564"
---

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

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了！

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

 

研究明白了再续分享！

欢迎留言！