自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone開發(fā)之Ssqlite3數(shù)據(jù)庫操作

移動開發(fā) iOS
本文介紹的是iPhone開發(fā)之Ssqlite 3數(shù)據(jù)庫操作,主要介紹了iphone中數(shù)據(jù)庫的操作,先來詳細內(nèi)容。

iPhone開發(fā)Ssqlite3數(shù)據(jù)庫操作是本文要介紹的內(nèi)容,下面是對sqlite3數(shù)據(jù)庫的操作,首先是要倒入類,最基本的,但不要忘記。我對數(shù)據(jù)庫的操作進行了單獨的處理,自己看著比較舒服,也好明白,需要用到時,直接調(diào)用久好了,也可以有代理,一直沒研究,日后好好看看,先總結(jié)這些,方便自己查看,忘記時找找,老不用會很快忘記,方便自己吧!

  1. #import  
  2. #define kFilename @"data.sqlite3"   

1、打開數(shù)據(jù)庫操作  

  1. -(void)openDB {    
  2. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    
  3.     NSString *documentsDirectory = [paths objectAtIndex:0];    
  4. NSString *dataFilePath =  [documentsDirectory stringByAppendingPathComponent:kFilename];     
  5. if (sqlite3_open([dataFilePath UTF8String], &database) != SQLITE_OK) {    
  6. sqlite3_close(database);    
  7. }    
  8.    

2、創(chuàng)建表,結(jié)構(gòu),類型 

  1. - (void)initDB {    
  2.  char *errorMsg;    
  3.  NSString *sql = @"CREATE TABLE IF NOT EXISTS USER (USER_ID INTEGER PRIMARY KEY,USERNAME TEXT,PASSWORD TEXT);";    
  4.  if (sqlite3_exec(database, [sql UTF8String], NULL, NULL, &errorMsg) != SQLITE_OK) {    
  5.    sqlite3_close(database);    
  6.  }    
  7.  }  

3、執(zhí)行添加方法   

  1. - (void)insertUsername:(NSString *)username insertPassword:(NSString *)password {     
  2.  [self openDB];//調(diào)用打開庫    
  3.  [self initDB];//調(diào)用創(chuàng)建表    
  4.  char *errorMsg;    
  5. char *update = "INSERT OR REPLACE INTO USER (USERNAME,PASSWORD) VALUES (?,?);";//添加語句    
  6.      
  7.  NSString *sql = [NSString stringWithFormat:@"SELECT USERNAME,PASSWORD FROM USER"];//查詢語句    
  8.  sql = @"DELETE FROM USER;";//刪除語句    
  9.  sqlite3_stmt *statement;    
  10. if (sqlite3_prepare_v2(database, update, -1, &statement, nil) == SQLITE_OK) {    
  11.  sqlite3_bind_text(statement, 1, [username UTF8String], -1, SQLITE_TRANSIENT);    
  12.  sqlite3_bind_text(statement, 2, [password UTF8String], -1, SQLITE_TRANSIENT);    
  13. }      
  14. if (sqlite3_step(statement) != SQLITE_DONE)    
  15.  NSAssert1(0,@"Error updating table:%s",errorMsg);    
  16. sqlite3_finalize(statement);    
  17. sqlite3_close(database);   

小結(jié):iPhone開發(fā)Ssqlite3數(shù)據(jù)庫操作的內(nèi)容介紹完了,希望本文對你有所幫助。

責(zé)任編輯:zhaolei 來源: 博客園
相關(guān)推薦

2011-07-07 16:42:38

iPhone Sqlite3 數(shù)據(jù)庫

2011-08-02 16:16:08

iPhone開發(fā) SQLite 數(shù)據(jù)庫

2011-08-05 16:31:47

iPhone 數(shù)據(jù)庫

2011-07-26 18:11:56

iPhone Sqlite 數(shù)據(jù)庫

2011-07-27 10:16:41

iPhone SQLite 數(shù)據(jù)庫

2014-11-05 10:37:44

Windows Pho數(shù)據(jù)庫

2021-07-29 14:03:35

鴻蒙HarmonyOS應(yīng)用

2009-08-19 16:40:26

C#操作Access數(shù)

2011-07-12 15:22:04

SQLite數(shù)據(jù)庫

2011-08-22 16:08:46

IOS開發(fā)數(shù)據(jù)庫

2011-08-03 16:01:24

iPhone應(yīng)用開發(fā) 自動登陸

2011-08-17 15:19:38

iPhone應(yīng)用數(shù)據(jù)

2011-06-07 17:16:47

iPhone 數(shù)據(jù)

2011-07-21 15:05:14

iPhone 數(shù)據(jù)庫

2011-08-01 18:27:58

iPhone開發(fā) UISearchBa

2011-08-10 10:10:21

iPhoneUIPopoverCo

2010-09-27 14:54:38

SQL數(shù)據(jù)庫

2010-09-30 09:11:01

2010-09-30 08:27:48

2021-09-06 10:24:12

鴻蒙HarmonyOS應(yīng)用
點贊
收藏

51CTO技術(shù)棧公眾號