Principle
The corresponding relationship between IOS and SQL
Model class structure = SQL table structure
Model instance = one row in the SQL table
Properties of the model instance-a column in the SQL table
The corresponding model and table
@interface Testmodel:nsobject@property (Assign, nonatomic) Nsinteger age; @property (assign, nonatomic) CGFloat height;@ Property (Assign, nonatomic) long distance; @property (assign, nonatomic) double maxdistance; @property (Assign, nonatomic ) BOOL IsOK; @property (assign, nonatomic) char Mchar; @property (assign, nonatomic) CGRect rect; @property (Assign, Nonatomi c) Cgpoint Point; @property (assign, nonatomic) cgsize size; @property (assign, nonatomic) Nsrange range; @property (Strong, nonatomic) NSNumber *number; @property (Strong, nonatomic) NSString *string; @property (Strong, nonatomic) Uicolor *color; @property (Strong, nonatomic) NSDate *date; @property (Strong, nonatomic) NSData *data;//Convert to Data@property (strong, nonatomic) Nsvalue *value; @property (Strong, nonatomic) UIImage *image; @end
The appropriate table structure is table Testmodel (age type,height type,distance type,isok Type,mchar type,...)
Method
Here are some available methods, still in good condition ...
+ (modeltotablemap*) getmodeltotablemap;+ (nsstring*) getdbpath;+ (nsstring*) gettablename;+ (NSArray*) GetPrimaryKeys ; + (Nsdictionary *) getpropertytocolumnmap;+ (nsdictionary *) getdefaultvaluedictionary;+ (NSDictionary *) getlengthdictionary;+ (Nsdictionary *) getcheckvaluedictionary;+ (nsdictionary *) getisuniquedictionary;+ ( Nsdictionary *) getisnotnulldictionary;+ (BOOL) shouldmodeltotablemapcontainparentproperties;+ (BOOL) shouldmodeltotablemapcontainselfproperties;+ (NSString *) getdateformatterstring;+ (NSString *) Getdbimagepathwithimagename: (NSString *) imgname; + (NSString *) Getdbdatapathwithdataname: (NSString *) dataName;+ ( BOOL) createtable;+ (BOOL) droptable;+ (ID) Firstmodelwhere: (NSObject *) where;+ (ID) Firstmodelwhere: (NSObject *) where By: (nsstring*), + (Nsarray *) allmodels;+ (Nsarray *) Findmodelswhere: (NSObject *) where;+ (Nsarray *) Findmodelswhere: (NSObject *) where the clause is: (nsstring*) by offset: (int) offset count: (int) count;+ (BOOL) Insertmodel: (NSObject *) model;+ (BOOL) insertmodelwhennotexists: (NSObject *) model;+ (BOOL) Deletemodel: (NSObject *) model;+ (BOOL) Deletemodelswhere: (NSObject *) where;+ (BOOL) Updatemodelswithmodel: (NSObject *) model Where: (NSObject *) where;+ (BOOL) updatemodelswithdictionary: (Nsdictionary *) DIC Where: (NSObject *) where;+ (BOOL) ismodelexists: (NSObject *) model;-(BOOL) savemodel;-(BOOL) deletemodel;-(BOOL) Updatemodel: (NSObject *) thenewmodel;-(BOOL) updatemodelwithdictionary: (Nsdictionary *) dic;
Use
Testmodel *model = [[Testmodel alloc] init];model.age = 20;model.image = [UIImage imagenamed:@ "img.jpg"];
Add [model Savemodel]
Delete [model Deletemodel]
Change [model updatemodelwithdictionary:@{@ "age": @ (21)}]
Find [Testmodel Allmodels]
: Click here
iOS Development line of code series: one line to get the database