iOS tips-How to save an Nsarray array property in a table when using Fmdb

Source: Internet
Author: User

http://blog.csdn.net/github_29614995/article/details/46797917

In the development, often encountered in order to persist the data to use the Fmdb, but encountered in the model of the property has an array, but Fmdb store properties are usually only text, then we change how to do?

Idea: 1. Create a table that writes the other attributes of the model's divisor group to the table, named T_groupbuymodel
2. Create a table to load the array text in the model named T_images
3. When you deposit the model into the table, iterate through the array attributes in the model and let each piece of data be stored in the T_images table.

Since to use to Fmdb, certainly must contain Fmdb's header file put, these things I will not say more, direct rush focus#import"FMDatabase.h" >Small series like in the object of the Initialize method inside the creation table (PS: Very strange, blog does not write ">" code color will not change, what problem?)Static Fmdatabase *_db;+ (void) initialize{nsstring *path = [[ Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) Objectatindex:0] stringbyappendingpathcomponent:@ " Ajkgroupbuymodels.db "]; _db =[fmdatabase Databasewithpath:path]; [_db Open]; //creation table [_db executeupdate:@ "CREATE table IF not EXISTS t_ Groupbuymodel (ID integer PRIMARY key,act_title text,cover_image text, avg_price text,region_name text,join_num text, Date_end text,act_rebate text,loupan_id text,loupan_name text,address text,see_detail text); "]; //create a table to load the array text in the model [_db executeupdate:@ "CREATE TABLE IF not EXISTS t_images (id interger PRIMARY KEY, loupan_id text, image text) "];       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

———-Gorgeous Split-line

+ (void) Addmodel: (Ajkgroupbuymodel *) model{[_db executeupdatewithformat:@INSERT into T_groupbuymodel (act_title,cover_image,avg_price,region_name,join_num,date_end,act_rebate,loupan_id, Loupan_name,address,see_detail) VALUES (%@,%@,%@,%@,%@,%@,%@,%@,%@,%@,%@); ", model. Act_title,model.cover_image,model.avg_price,model.region_name,model.join_num,model .date_end,model.act_rebate,model.loupan_id,model.loupan_name,model .address,model.see_detail] 0  "INSERT into T_images (loupan_id,image) VALUES (%@,%@)", Model.loupan_id,model.images[i]]; }} 

iOS Tips-How to save an Nsarray array property in a fmdb when using a table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.