<optgroup id="r9hwm"></optgroup><nav id="r9hwm"><label id="r9hwm"></label></nav>

    <tt id="r9hwm"><tr id="r9hwm"></tr></tt>
  1. 
    
  2. <optgroup id="r9hwm"><samp id="r9hwm"><dl id="r9hwm"></dl></samp></optgroup>

  3. <optgroup id="r9hwm"><samp id="r9hwm"><dl id="r9hwm"></dl></samp></optgroup>

        1. <listing id="r9hwm"></listing>
          <delect id="r9hwm"></delect>
          <optgroup id="r9hwm"><samp id="r9hwm"><ol id="r9hwm"></ol></samp></optgroup>

          fmdb語句

          FMDB的具體實現

          //單例類#import "FMDatabase.h"static MyData *data = nil;static FMDatabase *db;@implementation MyData+ (instancetype)sharedData{ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ data = [[MyData alloc] init]; [data createTable]; }); return data;}+ (instancetype)allocWithZone:(struct _NSZone *)zone{ if (data == nil) { data = [super allocWithZone:zone]; } return data;}- (void)createTable{ NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, 1) lastObject]; NSString *pathFile = [path stringByAppendingString:@"/*"]; NSLog(@"%@",pathFile); db = [[FMDatabase alloc] initWithPath:pathFile]; if ([db open]) { // CREATE TABLE IF NOT EXISTS student (ids integer PRIMARY KEY AUTOINCREMENT NOT NULL,name text,classes text,grade text NSString *createTable = @"create table student (ID integer primary key autoincrement, name text, age text, price text)"; if ([db executeUpdate:createTable]) { NSLog(@"創建成功"); [db close]; } else { NSLog(@"創建失敗"); } } else { // NSLog(@"創建失敗"); }}- (BOOL)addStudentData:(Student *)stu{ [db open]; BOOL result = [db executeUpdate:@"insert into student values (null,?,?,?)",*,*,*]; if (result) { NSLog(@"成功"); } else { NSLog(@"失敗"); } [db close]; return result;}- (BOOL)deleteData:(NSInteger)ID{ [db open]; BOOL result = [db executeUpdateWithFormat:@"delete from student where ID = %ld",ID]; if (result) { NSLog(@"刪除成功"); } else { NSLog(@"刪除失敗"); } [db close];return result;}- (BOOL)updata:(Student *)stu{ [db open]; BOOL result = [db executeUpdateWithFormat:@"update student set name = %@, age = %@ ,price = %@ where ID = %ld",*, *, *,*]; if (result) { NSLog(@"修改成功"); NSLog(@"==%@==",*); } else { NSLog(@"修改失敗"); } [db close]; return result;}- (NSMutableArray *)selectAllData{ [db open]; NSMutableArray *arr = [[NSMutableArray alloc] init]; FMResultSet *resuitSet = [db executeQuery:@"select * from student"]; while ([resuitSet next]) { Student *stu = [[Student alloc] init]; * = [resuitSet intForColumn:@"ID"]; * = [resuitSet stringForColumn:@"name"]; * = [resuitSet stringForColumn:@"age"]; * = [resuitSet stringForColumn:@"price"]; [arr addObject:stu]; } [db close]; return arr;}@end//ViewController#import "MyData.h"#import "AddViewController.h"@interface ViewController (){ UITableView *table; NSArray *arr;}@end@implementation ViewController- (void)viewWillAppear:(BOOL)animated{ arr = [[MyData sharedData] selectAllData]; [table reloadData];}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.\ table = [[UITableView alloc] initWithFrame:* style:UITableViewStyleGrouped]; *te = self; *urce = self; [* addSubview:table];*arButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(clickAdd)];}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ AddViewController *add = [[AddViewController alloc] init]; * = 0; * = arr[*]; [*tionController pushViewController:add animated:1];}- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ [[MyData sharedData] deleteData:[arr[*] ID]]; arr = [[MyData sharedData] selectAllData]; [table reloadData];}- (void)clickAdd{ AddViewController *add = [[AddViewController alloc] init]; * = 1; [*tionController pushViewController:add animated:1];}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return *;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@""]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@""]; } Student *stu = arr[*]; * = *; return cell;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end//添加和修改ViewController#import "Student.h"#import "MyData.h"@interface AddViewController (){ UITextField *text1, *text2, *text。

          數據庫 fmdb 簡書 為什么是 *

          (一)FMDB的基本介紹FMDB 同時兼容ARC與非ARC工程,會自動根據功臣的配置來調整相關的內存管理。

          FMDB常用類:FMDatabase:一個單一的數據庫,用于執行SQL語句FMResultSet:執行查詢一個FMDatabase的結果集FMDatabaseQueue:在多個線程來執行查詢和更新數據庫的數據(二)數據庫操作:創建數據庫建表(創建一張表)增(向表中插入新數據inset or replace into)刪(刪除表中數據delete)改 (修改數據庫中當前已有的數據update)查(查詢語句select)總結:數據庫增刪改等操作:除了查詢操作,FMDB數據庫操作都執行executeUpdate方法,這個方法返回BOOL型。數據庫查詢操作: 查詢操作使用了executeQuery,并涉及到FMResultSet。

          (三)代碼學習在實際項目中一般使用databaseQueue,創建數據庫- (void)openDBWithFileName:(NSString *)fileName dbName:(NSString *)dbName{//首先判斷傳入的參數if (!* || !*) {return;}//獲取文件目錄NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, NO);NSString *documentDirectory =[paths firstObject];NSString *pathDirectory = nil;if (* !=0 ) {pathDirectory = [documentDirectory stringByAppendingPathComponent:fileName];}// 創建文件夾if (![[NSFileManager defaultManager] fileExistsAtPath:pathDirectory]) {NSError *error ;[[NSFileManager defaultManager] createDirectoryAtPath:pathDirectory withIntermediateDirectories:YES attributes:nil error:&error];//參數YES,表示不管有沒有這個文件夾都會去創建,如果參數為no,則 只會在沒有這個文件夾的時候才會創建if (error) {NSLog(@"%@",[error description]);}}//創建數據庫NSString *dbPath = [pathDirectory stringByAppendingPathComponent:dbName];if (!_dbQueue) {NSLog(@"%@",[FMDatabaseQueue databaseQueueWithPath:dbPath]);*e = [FMDatabaseQueue databaseQueueWithPath:dbPath];NSLog(@"%@__open",*e);}}插入數據。

          ios fmdb為什么存不上數據

          一、簡單說明1.什么是FMDBFMDB是iOS平臺的SQLite數據庫框架FMDB以OC的方式封裝了SQLite的C語言*的優點使用起來更加面向對象,省去了很多麻煩、冗余的C語言代碼對比蘋果自帶的Core Data框架,更加輕量級和靈活提供了多線程安全的數據庫操作方法,有效地防止數據混亂*的github地址https://**ccgus/fmdb二、核心類FMDB有三個主要的類(1)FMDatabase一個FMDatabase對象就代表一個單獨的SQLite數據庫用來執行SQL語句(2)FMResultSet使用FMDatabase執行查詢后的結果集(3)FMDatabaseQueue用于在多線程中執行多個查詢或更新,它是線程安全的三、打開數據庫通過指定SQLite數據庫文件路徑來創建FMDatabase對象FMDatabase *db = [FMDatabase databaseWithPath:path];if (![db open]) { NSLog(@"數據庫打開失敗!");}文件路徑有三種情況(1)具體文件路徑 如果不存在會自動創建(2)空字符串@"" 會在臨時目錄創建一個空的數據庫 當FMDatabase連接關閉時,數據庫文件也被刪除(3)nil 會創建一個內存中臨時數據庫,當FMDatabase連接關閉時,數據庫會被銷毀四、執行更新在FMDB中,除查詢以外的所有操作,都稱為“更新”create、drop、insert、update、delete等使用executeUpdate:方法執行更新- (BOOL)executeUpdate:(NSString*)sql, 。

          - (BOOL)executeUpdateWithFormat:(NSString*)format, 。- (BOOL)executeUpdate:(NSString*)sql withArgumentsInArray:(NSArray *)arguments示例[db executeUpdate:@"UPDATE t_student SET age = ? WHERE name = ?;", @20, @"Jack"]五、執行查詢查詢方法- (FMResultSet *)executeQuery:(NSString*)sql, 。

          - (FMResultSet *)executeQueryWithFormat:(NSString*)format, 。- (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray *)arguments示例// 查詢數據FMResultSet *rs = [db executeQuery:@"SELECT * FROM t_student"];// 遍歷結果集while ([rs next]) { NSString *name = [rs stringForColumn:@"name"]; int age = [rs intForColumn:@"age"]; double score = [rs doubleForColumn:@"score"];}六、代碼示例1.新建一個項目,導入libsqlite3庫,并在項目中包含主頭文件2.下載第三方框架FMDB 3.示例代碼 YYViewController.m文件1 // 2 // YYViewController.m 3 // 04-FMDB基本使用 4 // 5 // Created by apple on 14-7-27. 6 // Copyright (c) 2014年 wendingding. All rights reserved. 7 // 8 9 #import "YYViewController.h"10 #import "FMDB.h"11 12 @interface YYViewController ()13 @property(nonatomic,strong)FMDatabase *db;14 @end15 16 @implementation YYViewController17 18 - (void)viewDidLoad19 {20 [super viewDidLoad];21 //1.獲得數據庫文件的路徑22 NSString *doc=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];23 NSString *fileName=[doc stringByAppendingPathComponent:@"*"];24 25 //2.獲得數據庫26 FMDatabase *db=[FMDatabase databaseWithPath:fileName];27 28 //3.打開數據庫29 if ([db open]) {30 //4.創表31 BOOL result=[db executeUpdate:@"CREATE TABLE IF NOT EXISTS t_student (id integer PRIMARY KEY AUTOINCREMENT, name text NOT NULL, age integer NOT NULL);"];32 if (result) {33 NSLog(@"創表成功");34 }else35 {36 NSLog(@"創表失敗");37 }38 }39 *=db;40 41 }42 43 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event44 {45 [self delete];46 [self insert];47 [self query];48 }49 50 //插入數據51 -(void)insert52 {53 for (int i = 0; i<10; i++) {54 NSString *name = [NSString stringWithFormat:@"jack-%d", arc4random_uniform(100)];55 // executeUpdate : 不確定的參數用?來占位56 [* executeUpdate:@"INSERT INTO t_student (name, age) VALUES (?, ?);", name, @(arc4random_uniform(40))];57 // [* executeUpdate:@"INSERT INTO t_student (name, age) VALUES (?, ?);" withArgumentsInArray:@[name, @(arc4random_uniform(40))]];58 59 // executeUpdateWithFormat : 不確定的參數用%@、%d等來占位60 // [* executeUpdateWithFormat:@"INSERT INTO t_student (name, age) VALUES (%@, %d);", name, arc4random_uniform(40)];61 }62 }63 64 //刪除數據65 -(void)delete66 {67 // [* executeUpdate:@"DELETE FROM t_student;"];68 [* executeUpdate:@"DROP TABLE IF EXISTS t_student;"];69 [* executeUpdate:@"CREATE TABLE IF NOT EXISTS t_student (id integer PRIMARY KEY AUTOINCREMENT, name text NOT NULL, age integer NOT NULL);"];70 }71 72 //查詢73 - (void)query74 {75 // 1.執行查詢語句76 FMResultSet *resu。

          iOS的SQLite利用FMDB進行操作時無法打開數據庫

          SQLite基本使用

          使用步驟:

          1.導入系統框架(C語言). (libsqlite3)

          2.文件#import.

          3. sqlite3_open(*8String, &_db); 打或者創建數據

          *_db自定義sqlite3員變量.進行刪改查要用.

          *3_exec(_db, sql, NULL, NULL,&error);

          *該函數進行insert,delete,update操作.

          5.查詢操作select.

          *sqlite3_prepare_v2(_db, sql, -1, &stmt, NULL);做查詢前準備,檢測SQL語句否確.

          *sqlite3_step(stmt) 提取查詢數據,提取條.

          *sqlite3_column_text(stmt, 0)取第0列數據.

          轉載請注明出處華閱文章網 » fmdb語句

          短句

          萬能英語句子

          閱讀(288)

          英語萬能句子 1.as an old saying goes,.正如一句古老的諺語所說2.be nothing but。 .不過就是。3.from where i stand. 從我的立場來說4.give oneself a chance to.給某人一個機

          短句

          美文語句

          閱讀(257)

          【給一些意境深遠的文章、句子、散文要有哲理的】 1.我曾經沉默地、毫無希望地愛過你.我既忍受著羞怯,又忍受著嫉妒的折磨.我曾經那樣真誠那樣溫柔地愛過你,愿上帝賜給你的也像我一樣堅貞如鐵.——普希金《我曾經愛過你》2.一些年之后,我

          短句

          sql怎么執行語句

          閱讀(255)

          SQL語句是按什么順序執行的 分析器會先看語句的第一個詞,當它發現第一個詞是SELECT關鍵字的時候,它會跳到FROM關鍵字,然后通過FROM關鍵字找到表名并把表裝入內存。接著是找WHE

          短句

          vfp中的if語句

          閱讀(1263)

          vf 中if 語句的用法 IF 。 ENDIF命令有條件地執行一組基于一個邏輯表達式的值的命令。語法IF lExpression [THEN]Commands[ELSECommands]ENDIFArgumentslExpression指定評

          短句

          if語句的用法循環語句

          閱讀(987)

          求助 1.if語句的一般格式if(表達式) {語句組1;}[else{語句組2;} ](1)if語句中的“表達式”必須用“(”和“)”括起來。(2)else子句(可選)是if語句的一部分,必須與if配對使用,不能單

          短句

          以下正確的賦值語句是

          閱讀(275)

          下面正確的賦值語句是A.X+Y=30 B.Y=X+30 C.3Y=X D.Y=π*r*r 每個都解 賦值語句中,賦值號左邊必須是一個變量,而不能是其它表達式。所以A選項沒有意義,x+y不是一個變量,所以錯了

          短句

          示愛的語句

          閱讀(245)

          經典的表白句子, 愛情總是想象比現實美麗,相逢如是,告別亦如是。我們以為愛得很深、很深。來日歲月,會讓你知道,它不過很淺、很淺。最深最重的愛,必須和時日一起成長。因為愛情的緣故,兩個陌生人可以突然熟絡到睡在同一張床上。然而,相同的兩

          短句

          很無語的語句

          閱讀(264)

          求2010年最讓人無語的句子 等待你的關心,等到我關上了心。 ☆ 走完同一條街,回到兩個世界。 ☆ 想你的時候有些幸福,幸福得有些難過。 ☆ 你是我猜不到的不知所措,我是你想不到的無關痛癢。 ☆ 所謂最難忘的,就是從來不曾想起,卻永遠也不會

          短句

          加列的sql語句

          閱讀(277)

          怎么使用sql語句添加列 alter table 表名 add 列名 數據類型。結構化查詢語言(Structured Query Language)簡稱SQL,結構化查詢語言是一種數據庫查詢和程序設計語言,用于存取數

          短句

          hibernate執行語句

          閱讀(301)

          hibernate執行原生SQL語句!!!急等 我在書上看到過執行原生SQL語句,希望對你有幫助String sql="select * from users";List list=session.createSQLQuery(sql,"user","User.clas

          短句

          oracle觸發器語句

          閱讀(263)

          ORACLE中觸發器的判斷IF語句 加一行 NULL 即可例如:SQL> DECLARE 2 testvalue INT; 3 BEGIN 4 testvalue := 200; 5 6 IF testvalue > 100 THEN 7 8 ELSIF

          短句

          語句造句

          閱讀(305)

          問一下有沒有初中的仿寫句子和造句,材料題的練習 1. 請判斷并分析下列句子是否正確: (1)五十年真的好漫長,有歡樂也有痛苦……再苦也還得過. (2)五十年像一部電影,有聲有色……電

          短句

          良心的語句

          閱讀(250)

          沒有良心的經典句子 一路走來,我用我的善良,喂了不少沒有良心的狗! 1、你要錢。要收視。昧著良心做節目。都點小內幕。都說得過去。畢竟大家都要生存。可是連基本的尊重都沒

          短句

          形容辛苦的語句

          閱讀(302)

          表示辛苦勞累的詞語 疲倦 疲憊 奔波忙碌 疲勞 困頓 風塵仆仆 發音 fēng chén pú pú 釋義 風塵:指行旅,含有辛苦之意;仆仆:行路勞累的樣子.形容旅途奔波,忙碌勞累.出處 清·

          短句

          萬能英語句子

          閱讀(288)

          英語萬能句子 1.as an old saying goes,.正如一句古老的諺語所說2.be nothing but。 .不過就是。3.from where i stand. 從我的立場來說4.give oneself a chance to.給某人一個機

          短句

          美文語句

          閱讀(257)

          【給一些意境深遠的文章、句子、散文要有哲理的】 1.我曾經沉默地、毫無希望地愛過你.我既忍受著羞怯,又忍受著嫉妒的折磨.我曾經那樣真誠那樣溫柔地愛過你,愿上帝賜給你的也像我一樣堅貞如鐵.——普希金《我曾經愛過你》2.一些年之后,我

          短句

          sql怎么執行語句

          閱讀(255)

          SQL語句是按什么順序執行的 分析器會先看語句的第一個詞,當它發現第一個詞是SELECT關鍵字的時候,它會跳到FROM關鍵字,然后通過FROM關鍵字找到表名并把表裝入內存。接著是找WHE

          短句

          vfp中的if語句

          閱讀(1263)

          vf 中if 語句的用法 IF 。 ENDIF命令有條件地執行一組基于一個邏輯表達式的值的命令。語法IF lExpression [THEN]Commands[ELSECommands]ENDIFArgumentslExpression指定評

          短句

          if語句的用法循環語句

          閱讀(987)

          求助 1.if語句的一般格式if(表達式) {語句組1;}[else{語句組2;} ](1)if語句中的“表達式”必須用“(”和“)”括起來。(2)else子句(可選)是if語句的一部分,必須與if配對使用,不能單

          短句

          以下正確的賦值語句是

          閱讀(275)

          下面正確的賦值語句是A.X+Y=30 B.Y=X+30 C.3Y=X D.Y=π*r*r 每個都解 賦值語句中,賦值號左邊必須是一個變量,而不能是其它表達式。所以A選項沒有意義,x+y不是一個變量,所以錯了

          短句

          示愛的語句

          閱讀(245)

          經典的表白句子, 愛情總是想象比現實美麗,相逢如是,告別亦如是。我們以為愛得很深、很深。來日歲月,會讓你知道,它不過很淺、很淺。最深最重的愛,必須和時日一起成長。因為愛情的緣故,兩個陌生人可以突然熟絡到睡在同一張床上。然而,相同的兩

          短句

          不公平語句

          閱讀(276)

          不公平的句子說說心情 關于不公平的句子說說例句如下:1、不公平是相對的,不用在條件不同時去和別人比。2、不要抱怨生活對你不公平,因為生活根本就不知道你是誰。3、不要感嘆上帝多么不公平,生命的巨斧在為你雕鑿。在屈辱中成就輝煌的人,從

          <optgroup id="r9hwm"></optgroup><nav id="r9hwm"><label id="r9hwm"></label></nav>

            <tt id="r9hwm"><tr id="r9hwm"></tr></tt>
          1. 
            
          2. <optgroup id="r9hwm"><samp id="r9hwm"><dl id="r9hwm"></dl></samp></optgroup>

          3. <optgroup id="r9hwm"><samp id="r9hwm"><dl id="r9hwm"></dl></samp></optgroup>

                1. <listing id="r9hwm"></listing>
                  <delect id="r9hwm"></delect>
                  <optgroup id="r9hwm"><samp id="r9hwm"><ol id="r9hwm"></ol></samp></optgroup>
                  亚洲丰满少妇xxxxx高潮