Statically link your iOS/OSX app with SQLite+ Probe framework. Select Help / Show SQLite+ Library in Finder to show where it is.you need unzip SharedFramework.zip for using it.
For iOS app,you drag Probe framework to your XCode project Framework Group and update Build settings other link flags to Objc as shown below. You can also Download fully probe client test demo from iOSProbeDemo
For OSX app,In addition to adding Probe framework, you must also add Build Phases setting as shown below.
1.Download sample project from CodeDemo,unzip it, open it in XCode,you will see project file like below,copy files of DBCommon Group to your project.
2.Download FMDB from github and add FMDB file to your project.
3.Add sqlite libsqlite3.0.dylib to your project.
4.Run SQLite+,select your database node,right click menu,select Show Generate Objc Code In Finder menu,location your code folder.copy auto-generated Model and DAO files to your project.
before you use DAO access database,you need open database
/*open database in your porject bundle resource*/ [[XXXDBManager sharedXXXDBManager]openDataBaseInBundle:@"SQLiteDemo.sqlite"]; /*or open database in your app document path*/ /*NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"SQLiteDemo.sqlite"]; [[XXXDBManager sharedXXXDBManager]openDataBaseWithPath:path]; */ [[XXXDBManager sharedXXXDBManager]openDataBaseWithPath:path]; */ LibCategoryDAO *dao = [[LibCategoryDAO alloc]init]; /*query all record*/ NSArray *items = [dao findAll]; NSLog(@"items count=%ld",[items count]); for(LibCategory *category in items){ NSLog(@"category=%@",category); } /*query record by attributes(name=you) */ items = [dao findByAttributes:@{@"name":@"you",@"order":@(3)}]; NSLog(@"items count=%ld",[items count]); for(LibCategory *category in items){ NSLog(@"category=%@",category); } /*query record by attributes(name=you and order=3) */ items = [dao findByAttributes:@{@"name":@"you",@"order":@(3)}]; NSLog(@"items count=%ld",[items count]); for(LibCategory *category in items){ NSLog(@"category=%@",category); } /*query record by sql */ items = [dao sqlQuery:@"select * from LibCategory where order > 4"]; NSLog(@"items count=%ld",[items count]); for(LibCategory *category in items){ NSLog(@"category=%@",category); } /*fetch records based on the index of pages*/ items = [dao findByPage:1 pageSize:20]; NSLog(@"items count=%ld",[items count]); for(LibCategory *category in items){ NSLog(@"category=%@",category); } /* primary key fetech */ /*query record by primary key ID=1*/ LibCategory *category1 = [dao findByKey:@{@"ID":@(1)}]; /* record insert */ LibCategory *category3 = [[LibCategory alloc]init]; category3.ID =2; category3.name = @"IOS"; category3.order = 1; [dao insert:category3]; /* record update */ category3.order = 6; [dao update:category3]; /*update record by sql */ BOOL updateResult = [dao sqlUpdate:@"update LibCategory set name = \"test\" where order > 4"]; /* record delete */ [dao delete:category3]; /**/
Click the upper right corner Settings toolbar button,you modify project and author name will apply code generated header comments
In Code Menu,click Code Template Editor,open Editor window,currently there is only one default template.you can add new tempalte T1,T2 etc.
Click seleted template means activate it as code generate template.
Notice:You need select a table in database node,otherwise Code Template Editor right will be a blank view.
New Template you created is same as Default Template.Now you can modify Model.h Model.m DAO.h DAO.m any one,Once you modify the template, the right panel will show in real time.
Close Template Editor window,return main window,select a table,you will see new code based new template.
Template syntax pls reference DMTemplates
table object objc class define
@interface SQLiteTable : NSObject @property(nonatomic,strong)NSString *name; @property(nonatomic,strong)NSMutableArray *columns; @property(nonatomic,strong)NSMutableArray *keys; @property(nonatomic,strong)NSArray *columnsExcludeKeys; @end
column object objc class define
@interface SQLiteColumn : NSObject @property (nonatomic, assign) NSInteger colID; @property (nonatomic, strong) NSString *name; @property (nonatomic, strong) NSString *type; @property (nonatomic, strong) NSString *objcType; @property (nonatomic, assign) BOOL isKey; @property (nonatomic, assign) BOOL isNotNULL; @property (nonatomic, strong) NSString *defaultVal; @property(nonatomic,assign) BOOL isSimpleType; @property(nonatomic,assign) BOOL isBOOL; @property(nonatomic,assign) BOOL isINTEGER; @property(nonatomic,assign) BOOL isNSString; @property(nonatomic,assign) BOOL isINT; @property(nonatomic,assign) BOOL isLONG; @property(nonatomic,assign) BOOL isDOUBLE; @property(nonatomic,assign) BOOL isFLOAT; @property(nonatomic,assign) BOOL isTEXT; @property(nonatomic,assign) BOOL isVARCHAR; @property(nonatomic,assign) BOOL isDATETIME; @property(nonatomic,assign) BOOL isNUMERIC; @property(nonatomic,assign) BOOL isBLOB; @property(nonatomic,assign) BOOL hasDefval; @end