sqlite查询大小有限制吗? [英] Is there any limit on sqlite query size?

查看:53
本文介绍了sqlite查询大小有限制吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

选择语句的大小有限制吗?例如,假设我有100名失败的学生作为选择,我的以下代码可以工作吗?

Is there any limit on how big the selection statement can be? for example suppose I have 100 failed student as selection, will my below code work?

ArrayList<Long> ids_toupdate = getFailedStudents();// has size 100.
String selection = String.format(Locale.US, STUDENT._ID + " IN (%s)",TextUtils.join(", ", ids_toupdate));
ContentValues cv = new ContentValues();
cv.put(RawContacts.FAILED, 1);
getContentResolver().update(STUDENT.CONTENT_URI,cv, selection, null);

推荐答案

粗略地说,默认限制为1,000,000字节或1,000,000个字符,因此,除非您的学生"超过100,000个字符,否则您的陈述就可以了.

Roughly speaking the default limit is 1,000,000 bytes or 1,000,000 characters, so unless your 'students' are over 100,000 characters each your statement should be fine.

以下内容摘自 http://www.sqlite.org/limits.html

SQL语句的最大长度

SQL语句文本中的最大字节数限制为SQLITE_MAX_SQL_LENGTH,默认值为1000000.您可以将该限制重新定义为与SQLITE_MAX_LENGTH和1073741824中的较小者一样大.

The maximum number of bytes in the text of an SQL statement is limited to SQLITE_MAX_SQL_LENGTH which defaults to 1000000. You can redefine this limit to be as large as the smaller of SQLITE_MAX_LENGTH and 1073741824.

如果SQL语句的长度限制为一百万个字节,那么很显然,您无法通过将它们作为文字嵌入到INSERT语句中来插入数百万个字节的字符串.但是您无论如何都不应该这样做.对数据使用主机参数.准备这样的简短SQL语句:

If an SQL statement is limited to be a million bytes in length, then obviously you will not be able to insert multi-million byte strings by embedding them as literals inside of INSERT statements. But you should not do that anyway. Use host parameters for your data. Prepare short SQL statements like this:

INSERT INTO tab1 VALUES(?,?,?); 

然后使用sqlite3_bind_XXXX()函数将较大的字符串值绑定到SQL语句.绑定的使用避免了对字符串中的引号字符进行转义的需要,从而降低了SQL注入攻击的风险.由于不需要分析或复制大字符串,因此它的运行速度也更快.

Then use the sqlite3_bind_XXXX() functions to bind your large string values to the SQL statement. The use of binding obviates the need to escape quote characters in the string, reducing the risk of SQL injection attacks. It is also runs faster since the large string does not need to be parsed or copied as much.

使用sqlite3_limit(db,SQLITE_LIMIT_SQL_LENGTH,size)接口可以在运行时减小SQL语句的最大长度.

The maximum length of an SQL statement can be lowered at run-time using the sqlite3_limit(db,SQLITE_LIMIT_SQL_LENGTH,size) interface.

这篇关于sqlite查询大小有限制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆