开发者

Objective-C Strings

I am reviewing code that makes the following call:

i开发者_StackOverflow社区d<PLResultSet> results = [sqliteDatabase executeQuery:@"select * where id=?",Id];

sqliteDatabase is an instance of PlausibleDatabase (from GoogleCode, I gather). 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? Or is the exeuteQuery function somehow combining the strings? How does this syntax make sense.

(Yes, I am new to 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. The second (unnamed) argument to the method is Id, presumably a local variable.

Guessing from the name of the method, the sqlite wrapper probably creates a parameterized query. The question mark is the syntax used by sqlite to mark where to insert the parameters.


It's specific to the method executeQuery, in which ? is used as a placeholder, and the appropriate positional argument is used as filler for that placeholder (with quoting, etc. added as necessary).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜