开发者

How do I read a big SQL query string from a file?

开发者 https://www.devze.com 2023-01-23 15:00 出处:网络
I\'m writing a database project on the iPhone and I\'d like to store some big SQL queries in a separate, project-included file.

I'm writing a database project on the iPhone and I'd like to store some big SQL queries in a separate, project-included file.

Then, I'd like to read this query into an NSString * (or, well, const char * is also ok) reference, and then perform it with an sqlite3.

I'm a newbie to iPhone developing, and I have never worked with files, neither I know any de开发者_运维技巧tails of their storage.

Could you please give me a hint on:

  1. The appropriate file format to store the strings.
  2. How do I store it into the iPhone;
  3. How do I read from it.

Thanks a lot!


You can use:

  1. Any simple character based (text) file would be more than enough
  2. Just put it in a folder in your project, it will get deployed with your Application
  3. Use NSString class.

For issue #3 you can use:

NSString *sqlString = 
   [NSString 
      stringWithContentsOfFile:@"yourqueryfile.sql" 
      encoding:NSUTF8StringEncoding
      errors:nil //unless yuo are interested in errors.
   ];
0

精彩评论

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