android数据库通过SQLiteDatabase
我正在尝试使用 android.sqlite 来学习 SQLite 的 SQL 数据库内容。我看过几个查询的例子......
我有一个关于 android 中的 sqlite 查询的两部分问题。
第 1 部分
假设我想删除某些内容。我使用以下查询。
db.delete(MY_DB_TABLE, "CustomerName = ?", new String[] { customerName });
如果客户名称中包含不良字符会发生什么情况。
例如。如果我使用以下查询
db.execSQL("delete from " + MY_DB_TABLE +
" where customername = '" + customerName + "';");
并在此示例中说我的客户的名字是“Arby's”。
该查询会崩溃,因为 ' 是一个特殊字符,并且查询的格式不正确。
第 2 部分
这种格式是否允许我指定任意数量的参数。
例子:
db.delete(MYTABLE, "val1 = ? and val2 != ?", new String[] { "test", "test2" } );
I am trying to learn the SQL Database stuff for SQLite using the android. I have seen a couple examples of the Queries....
I have a two part question about sqlite queries in android.
Part 1
Say I want to delete something. and I use the following Query.
db.delete(MY_DB_TABLE, "CustomerName = ?", new String[] { customerName });
what would happen if the Customer name had a bad character in it.
For example. If I use the following Query
db.execSQL("delete from " + MY_DB_TABLE +
" where customername = '" + customerName + "';");
and say for this example the name of my customer was "Arby's".
That query would blow up because the ' is a special character and the query would not be formatted correctly.
Part 2
does this format allow me to specify as many paramaters as I want.
Example:
db.delete(MYTABLE, "val1 = ? and val2 != ?", new String[] { "test", "test2" } );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅我的帖子:
将列表存储到数据库并一起检索它们:Android
并简短回答您的问题,是。
每个 '?'意味着需要一个参数,因此对于每个“?”除非您想要例外,否则您将需要传入确切数量的参数:)!
Please refer to my post here:
Storing Lists to A Database, and Retrieving Them All Together : Android
and short answer to your question, yes.
Each '?' means that an argument will be expected, so for each '?' you WILL have an exact number of arguments to pass in unless you want an exception :) !