简体   繁体   English

Objective-C字符串

[英]Objective-C Strings

I am reviewing code that makes the following call: 我正在审查进行以下调用的代码:

id<PLResultSet> results = [sqliteDatabase executeQuery:@"select * where id=?",Id];

sqliteDatabase is an instance of PlausibleDatabase (from GoogleCode, I gather). sqliteDatabase是实例PlausibleDatabase (从googlecode上,我收集)。 The code works, but I don't understand it. 该代码有效,但我不理解。 Specifically, how does this section work? 具体来说,本节如何工作?

@"select * where id=?",Id

Is the query being made with ? 进行查询? being replaced by Id ? Id取代? Or is the exeuteQuery function somehow combining the strings? 还是exeuteQuery函数以某种方式组合了字符串? How does this syntax make sense. 这种语法如何有意义。

(Yes, I am new to Obj-C) (是的,我是Obj-C的新手)

Thanks, 谢谢,

KF 肯尼迪

This bit: 这一点:

@"select * where id=?"

is an NSString (as opposed to a c-style string ) which is being passed into a executeQuery: : method on the sqliteDatabase object. 是一个NSString (与c样式字符串相反),它正在传递到sqliteDatabase对象的executeQuery: :方法中。 The second (unnamed) argument to the method is Id , presumably a local variable. 该方法的第二个(未命名)参数是Id ,大概是一个局部变量。

Guessing from the name of the method, the sqlite wrapper probably creates a parameterized query . 从方法的名称猜测,sqlite包装器可能会创建一个参数化查询 The question mark is the syntax used by sqlite to mark where to insert the parameters. 问号是sqlite用于标记在何处插入参数的语法。

It's specific to the method executeQuery , in which ? 它特定于方法executeQuery ,其中? is used as a placeholder, and the appropriate positional argument is used as filler for that placeholder (with quoting, etc. added as necessary). 用作占位符,并且适当的位置参数用作该占位符的填充符(根据需要添加引号等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM