热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ios之coredata

CoreData数据持久化是对SQLite的一个升级,它是ios集成的,在说CoreData之前,我们先说说在CoreData中使用的几个

Core Data数据持久化是对SQLite的一个升级,它是ios集成的,在说Core Data之前,我们先说说在CoreData中使用的几个类。

   (1)NSManagedObjectModel(被管理的对象模型)

           相当于实体,不过它包含 了实体间的关系

    (2)NSManagedObjectContext(被管理的对象上下文)

         操作实际内容

        作用:插入数据  查询  更新  删除

  (3)NSPersistentStoreCoordinator(持久化存储助理)

          相当于数据库的连接器

    (4)NSFetchRequest(获取数据的请求)    

        相当于查询语句

     (5)NSPredicate(相当于查询条件)

    (6)NSEntityDescription(实体结构)

    (7)后缀名为.xcdatamodel的包

        里面的.xcdatamodel文件,用数据模型编辑器编辑

       编译后为.momd或.mom文件,这就是为什么文件中没有这个东西,而我们的程序中用到这个东西而不会报错的原因

   首先我们要建立模型对象

   

  其次我们要生成模型对象的实体User,它是继承NSManagedObjectModel的

  

    点击之后你会发现它会自动的生成User,现在主要说一下,生成的User对象是这种形式的

 


这里解释一下dynamic  平常我们接触的是synthesize

 dynamic和synthesize有什么区别呢?它的setter和getter方法不能自已定义

 

打开CoreData的SQL语句输出开关

1.打开Product,点击EditScheme...
2.点击Arguments,在ArgumentsPassed On Launch中添加2项
1> -com.apple.CoreData.SQLDebug
2> 1

 

 

[plain] view plaincopyprint?
  1. #import   
  2. #import   
  3. @class ViewController;  
  4.   
  5. @interface AppDelegate : UIResponder   
  6.   
  7. @property (strong, nonatomic) UIWindow *window;  
  8.   
  9. @property (strong, nonatomic) ViewController *viewController;  
  10.   
  11. @property(strong,nonatomic,readonly)NSManagedObjectModel* managedObjectModel;  
  12.   
  13. @property(strong,nonatomic,readonly)NSManagedObjectContext* managedObjectContext;  
  14.   
  15. @property(strong,nonatomic,readonly)NSPersistentStoreCoordinator* persistentStoreCoordinator;  
  16. @end  

#import
#import
@class ViewController;@interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window;@property (strong, nonatomic) ViewController *viewController;@property(strong,nonatomic,readonly)NSManagedObjectModel* managedObjectModel;@property(strong,nonatomic,readonly)NSManagedObjectContext* managedObjectContext;@property(strong,nonatomic,readonly)NSPersistentStoreCoordinator* persistentStoreCoordinator;
@end

 

[plain] view plaincopyprint?
  1. #import "AppDelegate.h"  
  2.   
  3. #import "ViewController.h"  
  4.   
  5. @implementation AppDelegate  
  6. @synthesize managedObjectModel=_managedObjectModel;  
  7. @synthesize managedObjectContext=_managedObjectContext;  
  8. @synthesize persistentStoreCoordinator=_persistentStoreCoordinator;  
  9. - (void)dealloc  
  10. {  
  11.     [_window release];  
  12.     [_viewController release];  
  13.     [_managedObjectContext release];  
  14.     [_managedObjectModel release];  
  15.     [_persistentStoreCoordinator release];  
  16.     [super dealloc];  
  17. }  
  18.   
  19. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  20. {  
  21.     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];  
  22.     // Override point for customization after application launch.  
  23.     self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];  
  24.     self.window.rootViewController = self.viewController;  
  25.     [self.window makeKeyAndVisible];  
  26.     return YES;  
  27. }  
  28.   
  29. - (void)applicationWillResignActive:(UIApplication *)application  
  30. {  
  31.     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.  
  32.     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.  
  33. }  
  34.   
  35. - (void)applicationDidEnterBackground:(UIApplication *)application  
  36. {  
  37.     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.   
  38.     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.  
  39. }  
  40.   
  41. - (void)applicationWillEnterForeground:(UIApplication *)application  
  42. {  
  43.     // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.  
  44. }  
  45.   
  46. - (void)applicationDidBecomeActive:(UIApplication *)application  
  47. {  
  48.     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.  
  49. }  
  50.   
  51. - (void)applicationWillTerminate:(UIApplication *)application  
  52. {  
  53.     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.  
  54. }  
  55. //托管对象  
  56. -(NSManagedObjectModel *)managedObjectModel  
  57. {  
  58.     if (_managedObjectModel!=nil) {  
  59.         return _managedObjectModel;  
  60.     }  
  61. //    NSURL* modelURL=[[NSBundle mainBundle] URLForResource:@"CoreDataExample" withExtension:@"momd"];  
  62. //    _managedObjectModel=[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];  
  63.     _managedObjectModel=[[NSManagedObjectModel mergedModelFromBundles:nil] retain];  
  64.     return _managedObjectModel;  
  65. }  
  66. //托管对象上下文  
  67. -(NSManagedObjectContext *)managedObjectContext  
  68. {  
  69.     if (_managedObjectContext!=nil) {  
  70.         return _managedObjectContext;  
  71.     }  
  72.       
  73.     NSPersistentStoreCoordinator* coordinator=[self persistentStoreCoordinator];  
  74.     if (coordinator!=nil) {  
  75.         _managedObjectContext=[[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];  
  76.           
  77.         [_managedObjectContext setPersistentStoreCoordinator:coordinator];  
  78.     }  
  79.     return _managedObjectContext;  
  80. }  
  81. //持久化存储协调器  
  82. -(NSPersistentStoreCoordinator *)persistentStoreCoordinator  
  83. {  
  84.     if (_persistentStoreCoordinator!=nil) {  
  85.         return _persistentStoreCoordinator;  
  86.     }  
  87. //    NSURL* storeURL=[[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreaDataExample.CDBStore"];  
  88. //    NSFileManager* fileManager=[NSFileManager defaultManager];  
  89. //    if(![fileManager fileExistsAtPath:[storeURL path]])  
  90. //    {  
  91. //        NSURL* defaultStoreURL=[[NSBundle mainBundle] URLForResource:@"CoreDataExample" withExtension:@"CDBStore"];  
  92. //        if (defaultStoreURL) {  
  93. //            [fileManager copyItemAtURL:defaultStoreURL toURL:storeURL error:NULL];  
  94. //        }  
  95. //    }  
  96.     NSString* docs=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];  
  97.     NSURL* storeURL=[NSURL fileURLWithPath:[docs stringByAppendingPathComponent:@"CoreDataExample.sqlite"]];  
  98.     NSLog(@"path is %@",storeURL);  
  99.     NSError* error=nil;  
  100.     _persistentStoreCoordinator=[[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];  
  101.     if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {  
  102.         NSLog(@"Error: %@,%@",error,[error userInfo]);  
  103.     }  
  104.     return _persistentStoreCoordinator;  
  105. }  
  106. //-(NSURL *)applicationDocumentsDirectory  
  107. //{  
  108. //    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];  
  109. //}  
  110. @end  

#import "AppDelegate.h"#import "ViewController.h"@implementation AppDelegate
@synthesize managedObjectModel=_managedObjectModel;
@synthesize managedObjectContext=_managedObjectContext;
@synthesize persistentStoreCoordinator=_persistentStoreCoordinator;
- (void)dealloc
{[_window release];[_viewController release];[_managedObjectContext release];[_managedObjectModel release];[_persistentStoreCoordinator release];[super dealloc];
}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];// Override point for customization after application launch.self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];self.window.rootViewController = self.viewController;[self.window makeKeyAndVisible];return YES;
}- (void)applicationWillResignActive:(UIApplication *)application
{// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}- (void)applicationDidEnterBackground:(UIApplication *)application
{// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}- (void)applicationWillEnterForeground:(UIApplication *)application
{// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}- (void)applicationDidBecomeActive:(UIApplication *)application
{// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}- (void)applicationWillTerminate:(UIApplication *)application
{// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
//托管对象
-(NSManagedObjectModel *)managedObjectModel
{if (_managedObjectModel!=nil) {return _managedObjectModel;}
// NSURL* modelURL=[[NSBundle mainBundle] URLForResource:@"CoreDataExample" withExtension:@"momd"];
// _managedObjectModel=[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];_managedObjectModel=[[NSManagedObjectModel mergedModelFromBundles:nil] retain];return _managedObjectModel;
}
//托管对象上下文
-(NSManagedObjectContext *)managedObjectContext
{if (_managedObjectContext!=nil) {return _managedObjectContext;}NSPersistentStoreCoordinator* coordinator=[self persistentStoreCoordinator];if (coordinator!=nil) {_managedObjectContext=[[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];[_managedObjectContext setPersistentStoreCoordinator:coordinator];}return _managedObjectContext;
}
//持久化存储协调器
-(NSPersistentStoreCoordinator *)persistentStoreCoordinator
{if (_persistentStoreCoordinator!=nil) {return _persistentStoreCoordinator;}
// NSURL* storeURL=[[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreaDataExample.CDBStore"];
// NSFileManager* fileManager=[NSFileManager defaultManager];
// if(![fileManager fileExistsAtPath:[storeURL path]])
// {
// NSURL* defaultStoreURL=[[NSBundle mainBundle] URLForResource:@"CoreDataExample" withExtension:@"CDBStore"];
// if (defaultStoreURL) {
// [fileManager copyItemAtURL:defaultStoreURL toURL:storeURL error:NULL];
// }
// }NSString* docs=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];NSURL* storeURL=[NSURL fileURLWithPath:[docs stringByAppendingPathComponent:@"CoreDataExample.sqlite"]];NSLog(@"path is %@",storeURL);NSError* error=nil;_persistentStoreCoordinator=[[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {NSLog(@"Error: %@,%@",error,[error userInfo]);}return _persistentStoreCoordinator;
}
//-(NSURL *)applicationDocumentsDirectory
//{
// return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
//}
@end

 

[plain] view plaincopyprint?
  1. #import   
  2. #import "AppDelegate.h"  
  3. @interface ViewController : UIViewController  
  4. @property (retain, nonatomic) IBOutlet UITextField *nameText;  
  5. @property (retain, nonatomic) IBOutlet UITextField *ageText;  
  6. @property (retain, nonatomic) IBOutlet UITextField *sexText;  
  7. @property(nonatomic,retain)AppDelegate* myAppDelegate;  
  8. - (IBAction)addIntoDataSource:(id)sender;  
  9. - (IBAction)query:(id)sender;  
  10. - (IBAction)update:(id)sender;  
  11. - (IBAction)del:(id)sender;  

#import
#import "AppDelegate.h"
@interface ViewController : UIViewController
@property (retain, nonatomic) IBOutlet UITextField *nameText;
@property (retain, nonatomic) IBOutlet UITextField *ageText;
@property (retain, nonatomic) IBOutlet UITextField *sexText;
@property(nonatomic,retain)AppDelegate* myAppDelegate;
- (IBAction)addIntoDataSource:(id)sender;
- (IBAction)query:(id)sender;
- (IBAction)update:(id)sender;
- (IBAction)del:(id)sender;

 

[plain] view plaincopyprint?
  1. #import "ViewController.h"  
  2. #import "User.h"  
  3. @interface ViewController ()  
  4.   
  5. @end  
  6.   
  7. @implementation ViewController  
  8.   
  9. - (void)viewDidLoad  
  10. {  
  11.     [super viewDidLoad];  
  12.     // Do any additional setup after loading the view, typically from a nib.  
  13.     _myAppDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];  
  14. }  
  15.   
  16. - (void)didReceiveMemoryWarning  
  17. {  
  18.     [super didReceiveMemoryWarning];  
  19.     // Dispose of any resources that can be recreated.  
  20. }  
  21.   
  22. - (void)dealloc {  
  23.     [_nameText release];  
  24.     [_ageText release];  
  25.     [_sexText release];  
  26.     [super dealloc];  
  27. }  
  28. //插入数据  
  29. - (IBAction)addIntoDataSource:(id)sender {  
  30.     User* user=(User *)[NSEntityDescription insertNewObjectForEntityForName:@"User" inManagedObjectContext:self.myAppDelegate.managedObjectContext];  
  31.     [user setName:_nameText.text];  
  32.     [user setAge:[NSNumber numberWithInteger:[_ageText.text integerValue]]];  
  33.     [user setSex:_sexText.text];  
  34.     NSError* error;  
  35.     BOOL isSaveSuccess=[_myAppDelegate.managedObjectContext save:&error];  
  36.     if (!isSaveSuccess) {  
  37.         NSLog(@"Error:%@",error);  
  38.     }else{  
  39.         NSLog(@"Save successful!");  
  40.     }  
  41.       
  42. }  
  43. //查询  
  44. - (IBAction)query:(id)sender {  
  45.     NSFetchRequest* request=[[NSFetchRequest alloc] init];  
  46.     NSEntityDescription* user=[NSEntityDescription entityForName:@"User" inManagedObjectContext:_myAppDelegate.managedObjectContext];  
  47.     [request setEntity:user];  
  48. //    NSSortDescriptor* sortDescriptor=[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];  
  49. //    NSArray* sortDescriptions=[[NSArray alloc] initWithObjects:sortDescriptor, nil];  
  50. //    [request setSortDescriptors:sortDescriptions];  
  51. //    [sortDescriptions release];  
  52. //    [sortDescriptor release];  
  53.     NSError* error=nil;  
  54.     NSMutableArray* mutableFetchResult=[[_myAppDelegate.managedObjectContext executeFetchRequest:request error:&error] mutableCopy];  
  55.     if (mutableFetchResult==nil) {  
  56.         NSLog(@"Error:%@",error);  
  57.     }  
  58.     NSLog(@"The count of entry: %i",[mutableFetchResult count]);  
  59.     for (User* user in mutableFetchResult) {  
  60.         NSLog(@"name:%@----age:%@------sex:%@",user.name,user.age,user.sex);  
  61.     }  
  62.     [mutableFetchResult release];  
  63.     [request release];  
  64. }  
  65. //更新  
  66. - (IBAction)update:(id)sender {  
  67.     NSFetchRequest* request=[[NSFetchRequest alloc] init];  
  68.     NSEntityDescription* user=[NSEntityDescription entityForName:@"User" inManagedObjectContext:_myAppDelegate.managedObjectContext];  
  69.     [request setEntity:user];  
  70.     //查询条件  
  71.     NSPredicate* predicate=[NSPredicate predicateWithFormat:@"name==%@",@"chen"];  
  72.     [request setPredicate:predicate];  
  73.     NSError* error=nil;  
  74.     NSMutableArray* mutableFetchResult=[[_myAppDelegate.managedObjectContext executeFetchRequest:request error:&error] mutableCopy];  
  75.     if (mutableFetchResult==nil) {  
  76.         NSLog(@"Error:%@",error);  
  77.     }  
  78.     NSLog(@"The count of entry: %i",[mutableFetchResult count]);  
  79.     //更新age后要进行保存,否则没更新  
  80.     for (User* user in mutableFetchResult) {  
  81.         [user setAge:[NSNumber numberWithInt:12]];  
  82.           
  83.     }  
  84.     [_myAppDelegate.managedObjectContext save:&error];  
  85.     [mutableFetchResult release];  
  86.     [request release];  
  87.       
  88. }  
  89. //删除  
  90. - (IBAction)del:(id)sender {  
  91.     NSFetchRequest* request=[[NSFetchRequest alloc] init];  
  92.     NSEntityDescription* user=[NSEntityDescription entityForName:@"User" inManagedObjectContext:_myAppDelegate.managedObjectContext];  
  93.     [request setEntity:user];  
  94.     NSPredicate* predicate=[NSPredicate predicateWithFormat:@"name==%@",@"chen"];  
  95.     [request setPredicate:predicate];  
  96.     NSError* error=nil;  
  97.     NSMutableArray* mutableFetchResult=[[_myAppDelegate.managedObjectContext executeFetchRequest:request error:&error] mutableCopy];  
  98.     if (mutableFetchResult==nil) {  
  99.         NSLog(@"Error:%@",error);  
  100.     }  
  101.     NSLog(@"The count of entry: %i",[mutableFetchResult count]);  
  102.     for (User* user in mutableFetchResult) {  
  103.         [_myAppDelegate.managedObjectContext deleteObject:user];  
  104.     }  
  105.       
  106.     if ([_myAppDelegate.managedObjectContext save:&error]) {  
  107.         NSLog(@"Error:%@,%@",error,[error userInfo]);  
  108.     }  
  109. }  
  110. @end  

#import "ViewController.h"
#import "User.h"
@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad
{[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib._myAppDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
}- (void)didReceiveMemoryWarning
{[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}- (void)dealloc {[_nameText release];[_ageText release];[_sexText release];[super dealloc];
}
//插入数据
- (IBAction)addIntoDataSource:(id)sender {User* user=(User *)[NSEntityDescription insertNewObjectForEntityForName:@"User" inManagedObjectContext:self.myAppDelegate.managedObjectContext];[user setName:_nameText.text];[user setAge:[NSNumber numberWithInteger:[_ageText.text integerValue]]];[user setSex:_sexText.text];NSError* error;BOOL isSaveSuccess=[_myAppDelegate.managedObjectContext save:&error];if (!isSaveSuccess) {NSLog(@"Error:%@",error);}else{NSLog(@"Save successful!");}}
//查询
- (IBAction)query:(id)sender {NSFetchRequest* request=[[NSFetchRequest alloc] init];NSEntityDescription* user=[NSEntityDescription entityForName:@"User" inManagedObjectContext:_myAppDelegate.managedObjectContext];[request setEntity:user];
// NSSortDescriptor* sortDescriptor=[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
// NSArray* sortDescriptions=[[NSArray alloc] initWithObjects:sortDescriptor, nil];
// [request setSortDescriptors:sortDescriptions];
// [sortDescriptions release];
// [sortDescriptor release];NSError* error=nil;NSMutableArray* mutableFetchResult=[[_myAppDelegate.managedObjectContext executeFetchRequest:request error:&error] mutableCopy];if (mutableFetchResult==nil) {NSLog(@"Error:%@",error);}NSLog(@"The count of entry: %i",[mutableFetchResult count]);for (User* user in mutableFetchResult) {NSLog(@"name:%@----age:%@------sex:%@",user.name,user.age,user.sex);}[mutableFetchResult release];[request release];
}
//更新
- (IBAction)update:(id)sender {NSFetchRequest* request=[[NSFetchRequest alloc] init];NSEntityDescription* user=[NSEntityDescription entityForName:@"User" inManagedObjectContext:_myAppDelegate.managedObjectContext];[request setEntity:user];//查询条件NSPredicate* predicate=[NSPredicate predicateWithFormat:@"name==%@",@"chen"];[request setPredicate:predicate];NSError* error=nil;NSMutableArray* mutableFetchResult=[[_myAppDelegate.managedObjectContext executeFetchRequest:request error:&error] mutableCopy];if (mutableFetchResult==nil) {NSLog(@"Error:%@",error);}NSLog(@"The count of entry: %i",[mutableFetchResult count]);//更新age后要进行保存,否则没更新for (User* user in mutableFetchResult) {[user setAge:[NSNumber numberWithInt:12]];}[_myAppDelegate.managedObjectContext save:&error];[mutableFetchResult release];[request release];}
//删除
- (IBAction)del:(id)sender {NSFetchRequest* request=[[NSFetchRequest alloc] init];NSEntityDescription* user=[NSEntityDescription entityForName:@"User" inManagedObjectContext:_myAppDelegate.managedObjectContext];[request setEntity:user];NSPredicate* predicate=[NSPredicate predicateWithFormat:@"name==%@",@"chen"];[request setPredicate:predicate];NSError* error=nil;NSMutableArray* mutableFetchResult=[[_myAppDelegate.managedObjectContext executeFetchRequest:request error:&error] mutableCopy];if (mutableFetchResult==nil) {NSLog(@"Error:%@",error);}NSLog(@"The count of entry: %i",[mutableFetchResult count]);for (User* user in mutableFetchResult) {[_myAppDelegate.managedObjectContext deleteObject:user];}if ([_myAppDelegate.managedObjectContext save:&error]) {NSLog(@"Error:%@,%@",error,[error userInfo]);}
}
@end


对于多线程它是不安全的,需要进行特殊处理下次再说吧

转:https://www.cnblogs.com/yulang314/p/3566891.html



推荐阅读
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 本文详细介绍了SQL日志收缩的方法,包括截断日志和删除不需要的旧日志记录。通过备份日志和使用DBCC SHRINKFILE命令可以实现日志的收缩。同时,还介绍了截断日志的原理和注意事项,包括不能截断事务日志的活动部分和MinLSN的确定方法。通过本文的方法,可以有效减小逻辑日志的大小,提高数据库的性能。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文介绍了在Linux下安装Perl的步骤,并提供了一个简单的Perl程序示例。同时,还展示了运行该程序的结果。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • Linux环境变量函数getenv、putenv、setenv和unsetenv详解
    本文详细解释了Linux中的环境变量函数getenv、putenv、setenv和unsetenv的用法和功能。通过使用这些函数,可以获取、设置和删除环境变量的值。同时给出了相应的函数原型、参数说明和返回值。通过示例代码演示了如何使用getenv函数获取环境变量的值,并打印出来。 ... [详细]
  • Oracle seg,V$TEMPSEG_USAGE与Oracle排序的关系及使用方法
    本文介绍了Oracle seg,V$TEMPSEG_USAGE与Oracle排序之间的关系,V$TEMPSEG_USAGE是V_$SORT_USAGE的同义词,通过查询dba_objects和dba_synonyms视图可以了解到它们的详细信息。同时,还探讨了V$TEMPSEG_USAGE的使用方法。 ... [详细]
  • Python操作MySQL(pymysql模块)详解及示例代码
    本文介绍了使用Python操作MySQL数据库的方法,详细讲解了pymysql模块的安装和连接MySQL数据库的步骤,并提供了示例代码。内容涵盖了创建表、插入数据、查询数据等操作,帮助读者快速掌握Python操作MySQL的技巧。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
author-avatar
浮云
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有