當(dāng)前位置:首頁 > 芯聞號 > 充電吧
[導(dǎo)讀]分類:?IOS開發(fā)(所有IOS文章)?---sqlite(IOS)?C/C++2012-03-09 13:49?2457人閱讀?評論(2)?收藏?舉報(bào) sqlitecallbackauthoriz

分類:?IOS開發(fā)(所有IOS文章)?---sqlite(IOS)?C/C++2012-03-09 13:49?2457人閱讀?評論(2)?收藏?舉報(bào) sqlitecallbackauthorizationfunction數(shù)據(jù)庫transactions要操縱一個(gè)數(shù)據(jù)庫你就得有一個(gè)這個(gè)數(shù)據(jù)庫的句柄(又碰到這個(gè)難以理解的詞了,不過確實(shí)還沒得一個(gè)更好的詞來替代它)。其實(shí)你跟本不需要去在乎這個(gè)詞叫什么,你只要搞清楚他是一個(gè)什么玩意兒。就如同鞋子為什么叫鞋子,仔細(xì)想想確實(shí)也難以理解,不過 清楚他的功能就OK了,不是嗎?

句柄在很多地方我們見到過,最常見的就是文件的句柄,我們要操縱一個(gè)文件,我們就要取得一個(gè)文件的句柄。句柄是個(gè)什么東東呢?其實(shí)很簡單,句柄是一個(gè)東東的描述,他被定義為一個(gè)結(jié)構(gòu)體,這個(gè)結(jié)構(gòu)體可能會(huì)包含要描述的東東的具體信息,比如位置、大小、類型等等。我們有了這個(gè)描述信息我們就能去找到這個(gè)東東,然后操縱它。

一句話:句柄是物體的描述結(jié)構(gòu)體。

我們來看看sqlite的句柄是怎么定義的(不要被嚇到了,代碼直接跳過就好):

[java]?view plaincopyprint? struct?sqlite3?{?? ??sqlite3_vfs?*pVfs;????????????/*?OS?Interface?*/?? ??int?nDb;??????????????????????/*?Number?of?backends?currently?in?use?*/?? ??Db?*aDb;??????????????????????/*?All?backends?*/?? ??int?flags;????????????????????/*?Miscellaneous?flags.?See?below?*/?? ??unsigned?int?openFlags;???????/*?Flags?passed?to?sqlite3_vfs.xOpen()?*/?? ??int?errCode;??????????????????/*?Most?recent?error?code?(SQLITE_*)?*/?? ??int?errMask;??????????????????/*?&?result?codes?with?this?before?returning?*/?? ??u8?autoCommit;????????????????/*?The?auto-commit?flag.?*/?? ??u8?temp_store;????????????????/*?1:?file?2:?memory?0:?default?*/?? ??u8?mallocFailed;??????????????/*?True?if?we?have?seen?a?malloc?failure?*/?? ??u8?dfltLockMode;??????????????/*?Default?locking-mode?for?attached?dbs?*/?? ??signed?char?nextAutovac;??????/*?Autovac?setting?after?VACUUM?if?>=0?*/?? ??u8?suppressErr;???????????????/*?Do?not?issue?error?messages?if?true?*/?? ??u8?vtabOnConflict;????????????/*?Value?to?return?for?s3_vtab_on_conflict()?*/?? ??int?nextPagesize;?????????????/*?Pagesize?after?VACUUM?if?>0?*/?? ??int?nTable;???????????????????/*?Number?of?tables?in?the?database?*/?? ??CollSeq?*pDfltColl;???????????/*?The?default?collating?sequence?(BINARY)?*/?? ??i64?lastRowid;????????????????/*?ROWID?of?most?recent?insert?(see?above)?*/?? ??u32?magic;????????????????????/*?Magic?number?for?detect?library?misuse?*/?? ??int?nChange;??????????????????/*?Value?returned?by?sqlite3_changes()?*/?? ??int?nTotalChange;?????????????/*?Value?returned?by?sqlite3_total_changes()?*/?? ??sqlite3_mutex?*mutex;?????????/*?Connection?mutex?*/?? ??int?aLimit[SQLITE_N_LIMIT];???/*?Limits?*/?? ??struct?sqlite3InitInfo?{??????/*?Information?used?during?initialization?*/?? ????int?iDb;????????????????????/*?When?back?is?being?initialized?*/?? ????int?newTnum;????????????????/*?Rootpage?of?table?being?initialized?*/?? ????u8?busy;????????????????????/*?TRUE?if?currently?initializing?*/?? ????u8?orphanTrigger;???????????/*?Last?statement?is?orphaned?TEMP?trigger?*/?? ??}?init;?? ??int?nExtension;???????????????/*?Number?of?loaded?extensions?*/?? ??void?**aExtension;????????????/*?Array?of?shared?library?handles?*/?? ??struct?Vdbe?*pVdbe;???????????/*?List?of?active?virtual?machines?*/?? ??int?activeVdbeCnt;????????????/*?Number?of?VDBEs?currently?executing?*/?? ??int?writeVdbeCnt;?????????????/*?Number?of?active?VDBEs?that?are?writing?*/?? ??int?vdbeExecCnt;??????????????/*?Number?of?nested?calls?to?VdbeExec()?*/?? ??void?(*xTrace)(void*,const?char*);????????/*?Trace?function?*/?? ??void?*pTraceArg;??????????????????????????/*?Argument?to?the?trace?function?*/?? ??void?(*xProfile)(void*,const?char*,u64);??/*?Profiling?function?*/?? ??void?*pProfileArg;????????????????????????/*?Argument?to?profile?function?*/?? ??void?*pCommitArg;?????????????????/*?Argument?to?xCommitCallback()?*/????? ??int?(*xCommitCallback)(void*);????/*?Invoked?at?every?commit.?*/?? ??void?*pRollbackArg;???????????????/*?Argument?to?xRollbackCallback()?*/????? ??void?(*xRollbackCallback)(void*);?/*?Invoked?at?every?commit.?*/?? ??void?*pUpdateArg;?? ??void?(*xUpdateCallback)(void*,int,?const?char*,const?char*,sqlite_int64);?? #ifndef?SQLITE_OMIT_WAL?? ??int?(*xWalCallback)(void?*,?sqlite3?*,?const?char?*,?int);?? ??void?*pWalArg;?? #endif?? ??void(*xCollNeeded)(void*,sqlite3*,int?eTextRep,const?char*);?? ??void(*xCollNeeded16)(void*,sqlite3*,int?eTextRep,const?void*);?? ??void?*pCollNeededArg;?? ??sqlite3_value?*pErr;??????????/*?Most?recent?error?message?*/?? ??char?*zErrMsg;????????????????/*?Most?recent?error?message?(UTF-8?encoded)?*/?? ??char?*zErrMsg16;??????????????/*?Most?recent?error?message?(UTF-16?encoded)?*/?? ??union?{?? ????volatile?int?isInterrupted;?/*?True?if?sqlite3_interrupt?has?been?called?*/?? ????double?notUsed1;????????????/*?Spacer?*/?? ??}?u1;?? ??Lookaside?lookaside;??????????/*?Lookaside?malloc?configuration?*/?? #ifndef?SQLITE_OMIT_AUTHORIZATION?? ??int?(*xAuth)(void*,int,const?char*,const?char*,const?char*,const?char*);?? ????????????????????????????????/*?Access?authorization?function?*/?? ??void?*pAuthArg;???????????????/*?1st?argument?to?the?access?auth?function?*/?? #endif?? #ifndef?SQLITE_OMIT_PROGRESS_CALLBACK?? ??int?(*xProgress)(void?*);?????/*?The?progress?callback?*/?? ??void?*pProgressArg;???????????/*?Argument?to?the?progress?callback?*/?? ??int?nProgressOps;?????????????/*?Number?of?opcodes?for?progress?callback?*/?? #endif?? #ifndef?SQLITE_OMIT_VIRTUALTABLE?? ??Hash?aModule;?????????????????/*?populated?by?sqlite3_create_module()?*/?? ??VtabCtx?*pVtabCtx;????????????/*?Context?for?active?vtab?connect/create?*/?? ??VTable?**aVTrans;?????????????/*?Virtual?tables?with?open?transactions?*/?? ??int?nVTrans;??????????????????/*?Allocated?size?of?aVTrans?*/?? ??VTable?*pDisconnect;????/*?Disconnect?these?in?next?sqlite3_prepare()?*/?? #endif?? ??FuncDefHash?aFunc;????????????/*?Hash?table?of?connection?functions?*/?? ??Hash?aCollSeq;????????????????/*?All?collating?sequences?*/?? ??BusyHandler?busyHandler;??????/*?Busy?callback?*/?? ??int?busyTimeout;??????????????/*?Busy?handler?timeout,?in?msec?*/?? ??Db?aDbStatic[2];??????????????/*?Static?space?for?the?2?default?backends?*/?? ??Savepoint?*pSavepoint;????????/*?List?of?active?savepoints?*/?? ??int?nSavepoint;???????????????/*?Number?of?non-transaction?savepoints?*/?? ??int?nStatement;???????????????/*?Number?of?nested?statement-transactions??*/?? ??u8?isTransactionSavepoint;????/*?True?if?the?outermost?savepoint?is?a?TS?*/?? ??i64?nDeferredCons;????????????/*?Net?deferred?constraints?this?transaction.?*/?? ??int?*pnBytesFreed;????????????/*?If?not?NULL,?increment?this?in?DbFree()?*/?? ?? #ifdef?SQLITE_ENABLE_UNLOCK_NOTIFY?? ??/*?The?following?variables?are?all?protected?by?the?STATIC_MASTER?? ??**?mutex,?not?by?sqlite3.mutex.?They?are?used?by?code?in?notify.c.?? ??**? ??**?When?X.pUnlockConnection==Y,?that?means?that?X?is?waiting?for?Y?to? ??**?unlock?so?that?it?can?proceed.? ??**? ??**?When?X.pBlockingConnection==Y,?that?means?that?something?that?X?tried? ??**?tried?to?do?recently?failed?with?an?SQLITE_LOCKED?error?due?to?locks? ??**?held?by?Y.? ??*/?? ??sqlite3?*pBlockingConnection;?/*?Connection?that?caused?SQLITE_LOCKED?*/?? ??sqlite3?*pUnlockConnection;???????????/*?Connection?to?watch?for?unlock?*/?? ??void?*pUnlockArg;?????????????????????/*?Argument?to?xUnlockNotify?*/?? ??void?(*xUnlockNotify)(void?**,?int);??/*?Unlock?notify?callback?*/?? ??sqlite3?*pNextBlocked;????????/*?Next?in?list?of?all?blocked?connections?*/?? #endif?? };??


[java]?view plaincopyprint? typedef?struct?sqlite3?sqlite3;//??


是不是被嚇到了,沒關(guān)系,這段代碼本來就是我貼出來嚇唬你的,我也沒認(rèn)真研究過這個(gè)代碼,也不想去研究,除非哪天有人出高價(jià)請我去研究,我現(xiàn)在只知道怎么用就好了。


這個(gè) sqlite3 結(jié)構(gòu)體就是被用來描述我們磁盤里的數(shù)據(jù)庫文件的,有了這個(gè)描述符我們就可以對這個(gè)數(shù)據(jù)庫進(jìn)行各種操作了,操作的具體內(nèi)情我們不必要了解,我們只需要知道怎么去調(diào)用API就好了,當(dāng)然有時(shí)候還是要了解一點(diǎn)點(diǎn)內(nèi)情的,這個(gè)以后碰到再講。

我用這么長的話加一大段嚇人的代碼只有一個(gè)目的:不要對句柄有恐懼感。

好了,開始我們的正題,sqlite 里面你要操縱數(shù)據(jù)庫我們先得創(chuàng)建一個(gè)句柄,然后后面所有對數(shù)據(jù)庫得操作都會(huì)用到這個(gè)句柄。


[java]?view plaincopyprint? sqlite3*?pdb;?? 就 這么簡單,這樣一個(gè)ssqlite的句柄我們就創(chuàng)建完成了,我們以后針對數(shù)據(jù)庫的操作都離不開它了。你可能還有疑問,我也知道你的 疑問是什么,請看下回分解。

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫?dú)角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉(zhuǎn)型技術(shù)解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關(guān)鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認(rèn)證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時(shí)1.5...

關(guān)鍵字: 汽車 人工智能 智能驅(qū)動(dòng) BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運(yùn)行,同時(shí)企業(yè)卻面臨越來越多業(yè)務(wù)中斷的風(fēng)險(xiǎn),如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報(bào)道,騰訊和網(wǎng)易近期正在縮減他們對日本游戲市場的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)開幕式在貴陽舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機(jī) 衛(wèi)星通信

要點(diǎn): 有效應(yīng)對環(huán)境變化,經(jīng)營業(yè)績穩(wěn)中有升 落實(shí)提質(zhì)增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競爭力 堅(jiān)持高質(zhì)量發(fā)展策略,塑強(qiáng)核心競爭優(yōu)勢...

關(guān)鍵字: 通信 BSP 電信運(yùn)營商 數(shù)字經(jīng)濟(jì)

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺(tái)與中國電影電視技術(shù)學(xué)會(huì)聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會(huì)上宣布正式成立。 活動(dòng)現(xiàn)場 NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會(huì)上,軟通動(dòng)力信息技術(shù)(集團(tuán))股份有限公司(以下簡稱"軟通動(dòng)力")與長三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉