| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730 |
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="html/html; charset=utf-8" />
- <title>FMDatabaseQueue Class Reference</title>
- <meta id="xcode-display" name="xcode-display" content="render"/>
- <meta name="viewport" content="width=550" />
- <link rel="stylesheet" type="text/css" href="../css/styles.css" media="all" />
- <link rel="stylesheet" type="text/css" media="print" href="../css/stylesPrint.css" />
- <meta name="generator" content="appledoc 2.1 (build 858)" />
- </head>
- <body>
- <header id="top_header">
- <div id="library" class="hideInXcode">
- <h1><a id="libraryTitle" href="../index.html">FMDB </a></h1>
- <a id="developerHome" href="../index.html">ccgus</a>
- </div>
-
- <div id="title" role="banner">
- <h1 class="hideInXcode">FMDatabaseQueue Class Reference</h1>
- </div>
- <ul id="headerButtons" role="toolbar">
- <li id="toc_button">
- <button aria-label="Show Table of Contents" role="checkbox" class="open" id="table_of_contents"><span class="disclosure"></span>Table of Contents</button>
- </li>
- <li id="jumpto_button" role="navigation">
- <select id="jumpTo">
- <option value="top">Jump To…</option>
-
- <option value="overview">Overview</option>
-
-
-
-
- <option value="tasks">Tasks</option>
-
-
-
-
-
-
-
- <option value="class_methods">Class Methods</option>
-
- <option value="//api/name/databaseQueueWithPath:"> + databaseQueueWithPath:</option>
-
-
-
-
- <option value="instance_methods">Instance Methods</option>
-
- <option value="//api/name/close"> - close</option>
-
- <option value="//api/name/inDatabase:"> - inDatabase:</option>
-
- <option value="//api/name/inDeferredTransaction:"> - inDeferredTransaction:</option>
-
- <option value="//api/name/inSavePoint:"> - inSavePoint:</option>
-
- <option value="//api/name/inTransaction:"> - inTransaction:</option>
-
- <option value="//api/name/initWithPath:"> - initWithPath:</option>
-
-
-
- </select>
- </li>
- </ul>
- </header>
- <nav id="tocContainer" class="isShowingTOC">
- <ul id="toc" role="tree">
-
- <li role="treeitem"><span class="nodisclosure"></span><span class="sectionName"><a href="#overview">Overview</a></span></li>
- <li role="treeitem" id="task_treeitem"><span class="nodisclosure"></span><span class="sectionName"><a href="#tasks">Tasks</a></span><ul>
-
- <li><span class="nodisclosure"></span><span class="sectionName"><a href="#task_Initialization, opening, and closing of queue">Initialization, opening, and closing of queue</a></span></li>
-
- <li><span class="nodisclosure"></span><span class="sectionName"><a href="#task_Dispatching database operations to queue">Dispatching database operations to queue</a></span></li>
-
- </ul></li>
- <li role="treeitem" class="children"><span class="disclosure"></span><span class="sectionName"><a href="#class_methods">Class Methods</a></span><ul>
-
- <li><span class="nodisclosure"></span><span class="sectionName"><a href="#//api/name/databaseQueueWithPath:">databaseQueueWithPath:</a></span></li>
-
- </ul></li>
- <li role="treeitem" class="children"><span class="disclosure"></span><span class="sectionName"><a href="#instance_methods">Instance Methods</a></span><ul>
-
- <li><span class="nodisclosure"></span><span class="sectionName"><a href="#//api/name/close">close</a></span></li>
-
- <li><span class="nodisclosure"></span><span class="sectionName"><a href="#//api/name/inDatabase:">inDatabase:</a></span></li>
-
- <li><span class="nodisclosure"></span><span class="sectionName"><a href="#//api/name/inDeferredTransaction:">inDeferredTransaction:</a></span></li>
-
- <li><span class="nodisclosure"></span><span class="sectionName"><a href="#//api/name/inSavePoint:">inSavePoint:</a></span></li>
-
- <li><span class="nodisclosure"></span><span class="sectionName"><a href="#//api/name/inTransaction:">inTransaction:</a></span></li>
-
- <li><span class="nodisclosure"></span><span class="sectionName"><a href="#//api/name/initWithPath:">initWithPath:</a></span></li>
-
- </ul></li>
- </ul>
- </nav>
- <article>
- <div id="contents" class="isShowingTOC" role="main">
- <a title="FMDatabaseQueue Class Reference" name="top"></a>
- <div class="main-navigation navigation-top">
- <ul>
- <li><a href="../index.html">Index</a></li>
- <li><a href="../hierarchy.html">Hierarchy</a></li>
- </ul>
- </div>
- <div id="header">
- <div class="section-header">
- <h1 class="title title-header">FMDatabaseQueue Class Reference</h1>
- </div>
- </div>
- <div id="container">
-
- <div class="section section-specification"><table cellspacing="0"><tbody>
- <tr>
- <td class="specification-title">Inherits from</td>
- <td class="specification-value">NSObject</td>
- </tr><tr>
- <td class="specification-title">Declared in</td>
- <td class="specification-value">FMDatabaseQueue.h<br />FMDatabaseQueue.m</td>
- </tr>
- </tbody></table></div>
-
-
-
-
- <div class="section section-overview">
- <a title="Overview" name="overview"></a>
- <h2 class="subtitle subtitle-overview">Overview</h2>
- <p>To perform queries and updates on multiple threads, you’ll want to use <code>FMDatabaseQueue</code>.</p>
- <p>Using a single instance of <a href="../Classes/FMDatabase.html"><code>FMDatabase</code></a> from multiple threads at once is a bad idea. It has always been OK to make a <a href="../Classes/FMDatabase.html"><code>FMDatabase</code></a> object <em>per thread</em>. Just don’t share a single instance across threads, and definitely not across multiple threads at the same time.</p>
- <p>Instead, use <code>FMDatabaseQueue</code>. Here’s how to use it:</p>
- <p>First, make your queue.</p>
- <pre><code>FMDatabaseQueue *queue = [FMDatabaseQueue databaseQueueWithPath:aPath];
- </code></pre>
- <p>Then use it like so:</p>
- <pre><code>[queue inDatabase:^(FMDatabase *db) {
- [db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:1]];
- [db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:2]];
- [db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:3]];
- FMResultSet *rs = [db executeQuery:@"select * from foo"];
- while ([rs next]) {
- //…
- }
- }];
- </code></pre>
- <p>An easy way to wrap things up in a transaction can be done like this:</p>
- <pre><code>[queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
- [db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:1]];
- [db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:2]];
- [db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:3]];
- if (whoopsSomethingWrongHappened) {
- *rollback = YES;
- return;
- }
- // etc…
- [db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:4]];
- }];
- </code></pre>
- <p><code>FMDatabaseQueue</code> will run the blocks on a serialized queue (hence the name of the class). So if you call <code>FMDatabaseQueue</code>’s methods from multiple threads at the same time, they will be executed in the order they are received. This way queries and updates won’t step on each other’s toes, and every one is happy.</p>
- <h3>See also</h3>
- <ul>
- <li><a href="../Classes/FMDatabase.html"><code>FMDatabase</code></a></li>
- </ul>
- <div class="warning"><p><strong>Warning:</strong> Do not instantiate a single <a href="../Classes/FMDatabase.html"><code>FMDatabase</code></a> object and use it across multiple threads. Use <code>FMDatabaseQueue</code> instead.</p></div><div class="warning"><p><strong>Warning:</strong> The calls to <code>FMDatabaseQueue</code>’s methods are blocking. So even though you are passing along blocks, they will <strong>not</strong> be run on another thread.</p></div>
- </div>
-
-
-
-
-
- <div class="section section-tasks">
- <a title="Tasks" name="tasks"></a>
- <h2 class="subtitle subtitle-tasks">Tasks</h2>
-
-
- <a title="Initialization, opening, and closing of queue" name="task_Initialization, opening, and closing of queue"></a>
- <h3 class="subsubtitle task-title">Initialization, opening, and closing of queue</h3>
- <ul class="task-list">
- <li>
- <span class="tooltip">
- <code><a href="#//api/name/databaseQueueWithPath:">+ databaseQueueWithPath:</a></code>
- <span class="tooltip"><p>Create queue using path.</p></span>
- </span>
-
-
- </li><li>
- <span class="tooltip">
- <code><a href="#//api/name/initWithPath:">– initWithPath:</a></code>
- <span class="tooltip"><p>Create queue using path.</p></span>
- </span>
-
-
- </li><li>
- <span class="tooltip">
- <code><a href="#//api/name/close">– close</a></code>
- <span class="tooltip"><p>Close database used by queue.</p></span>
- </span>
-
-
- </li>
- </ul>
-
-
- <a title="Dispatching database operations to queue" name="task_Dispatching database operations to queue"></a>
- <h3 class="subsubtitle task-title">Dispatching database operations to queue</h3>
- <ul class="task-list">
- <li>
- <span class="tooltip">
- <code><a href="#//api/name/inDatabase:">– inDatabase:</a></code>
- <span class="tooltip"><p>Synchronously perform database operations on queue.</p></span>
- </span>
-
-
- </li><li>
- <span class="tooltip">
- <code><a href="#//api/name/inTransaction:">– inTransaction:</a></code>
- <span class="tooltip"><p>Synchronously perform database operations on queue, using transactions.</p></span>
- </span>
-
-
- </li><li>
- <span class="tooltip">
- <code><a href="#//api/name/inDeferredTransaction:">– inDeferredTransaction:</a></code>
- <span class="tooltip"><p>Synchronously perform database operations on queue, using deferred transactions.</p></span>
- </span>
-
-
- </li><li>
- <span class="tooltip">
- <code><a href="#//api/name/inSavePoint:">– inSavePoint:</a></code>
- <span class="tooltip"><p>Synchronously perform database operations using save point.</p></span>
- </span>
-
-
- </li>
- </ul>
-
- </div>
-
-
-
-
-
-
-
- <div class="section section-methods">
- <a title="Class Methods" name="class_methods"></a>
- <h2 class="subtitle subtitle-methods">Class Methods</h2>
-
- <div class="section-method">
- <a name="//api/name/databaseQueueWithPath:" title="databaseQueueWithPath:"></a>
- <h3 class="subsubtitle method-title">databaseQueueWithPath:</h3>
-
-
-
- <div class="method-subsection brief-description">
- <p>Create queue using path.</p>
- </div>
-
-
- <div class="method-subsection method-declaration"><code>+ (instancetype)databaseQueueWithPath:(NSString *)<em>aPath</em></code></div>
-
-
- <div class="method-subsection arguments-section parameters">
- <h4 class="method-subtitle parameter-title">Parameters</h4>
-
- <dl class="argument-def parameter-def">
- <dt><em>aPath</em></dt>
- <dd><p>The file path of the database.</p></dd>
- </dl>
-
- </div>
-
-
-
- <div class="method-subsection return">
- <h4 class="method-subtitle parameter-title">Return Value</h4>
- <p>The <code>FMDatabaseQueue</code> object. <code>nil</code> on error.</p>
- </div>
-
-
-
-
-
-
-
-
-
-
-
- <div class="method-subsection declared-in-section">
- <h4 class="method-subtitle">Declared In</h4>
- <code class="declared-in-ref">FMDatabaseQueue.h</code><br />
- </div>
-
-
- </div>
-
- </div>
-
-
-
- <div class="section section-methods">
- <a title="Instance Methods" name="instance_methods"></a>
- <h2 class="subtitle subtitle-methods">Instance Methods</h2>
-
- <div class="section-method">
- <a name="//api/name/close" title="close"></a>
- <h3 class="subsubtitle method-title">close</h3>
-
-
-
- <div class="method-subsection brief-description">
- <p>Close database used by queue.</p>
- </div>
-
-
- <div class="method-subsection method-declaration"><code>- (void)close</code></div>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <div class="method-subsection declared-in-section">
- <h4 class="method-subtitle">Declared In</h4>
- <code class="declared-in-ref">FMDatabaseQueue.h</code><br />
- </div>
-
-
- </div>
-
- <div class="section-method">
- <a name="//api/name/inDatabase:" title="inDatabase:"></a>
- <h3 class="subsubtitle method-title">inDatabase:</h3>
-
-
-
- <div class="method-subsection brief-description">
- <p>Synchronously perform database operations on queue.</p>
- </div>
-
-
- <div class="method-subsection method-declaration"><code>- (void)inDatabase:(void ( ^ ) ( FMDatabase *db ))<em>block</em></code></div>
-
-
- <div class="method-subsection arguments-section parameters">
- <h4 class="method-subtitle parameter-title">Parameters</h4>
-
- <dl class="argument-def parameter-def">
- <dt><em>block</em></dt>
- <dd><p>The code to be run on the queue of <code>FMDatabaseQueue</code></p></dd>
- </dl>
-
- </div>
-
-
-
-
-
-
-
-
-
-
-
-
-
- <div class="method-subsection declared-in-section">
- <h4 class="method-subtitle">Declared In</h4>
- <code class="declared-in-ref">FMDatabaseQueue.h</code><br />
- </div>
-
-
- </div>
-
- <div class="section-method">
- <a name="//api/name/inDeferredTransaction:" title="inDeferredTransaction:"></a>
- <h3 class="subsubtitle method-title">inDeferredTransaction:</h3>
-
-
-
- <div class="method-subsection brief-description">
- <p>Synchronously perform database operations on queue, using deferred transactions.</p>
- </div>
-
-
- <div class="method-subsection method-declaration"><code>- (void)inDeferredTransaction:(void ( ^ ) ( FMDatabase *db , BOOL *rollback ))<em>block</em></code></div>
-
-
- <div class="method-subsection arguments-section parameters">
- <h4 class="method-subtitle parameter-title">Parameters</h4>
-
- <dl class="argument-def parameter-def">
- <dt><em>block</em></dt>
- <dd><p>The code to be run on the queue of <code>FMDatabaseQueue</code></p></dd>
- </dl>
-
- </div>
-
-
-
-
-
-
-
-
-
-
-
-
-
- <div class="method-subsection declared-in-section">
- <h4 class="method-subtitle">Declared In</h4>
- <code class="declared-in-ref">FMDatabaseQueue.h</code><br />
- </div>
-
-
- </div>
-
- <div class="section-method">
- <a name="//api/name/inSavePoint:" title="inSavePoint:"></a>
- <h3 class="subsubtitle method-title">inSavePoint:</h3>
-
-
-
- <div class="method-subsection brief-description">
- <p>Synchronously perform database operations using save point.</p>
- </div>
-
-
- <div class="method-subsection method-declaration"><code>- (NSError *)inSavePoint:(void ( ^ ) ( FMDatabase *db , BOOL *rollback ))<em>block</em></code></div>
-
-
- <div class="method-subsection arguments-section parameters">
- <h4 class="method-subtitle parameter-title">Parameters</h4>
-
- <dl class="argument-def parameter-def">
- <dt><em>block</em></dt>
- <dd><p>The code to be run on the queue of <code>FMDatabaseQueue</code></p></dd>
- </dl>
-
- </div>
-
-
-
-
-
-
-
-
-
-
-
-
-
- <div class="method-subsection declared-in-section">
- <h4 class="method-subtitle">Declared In</h4>
- <code class="declared-in-ref">FMDatabaseQueue.h</code><br />
- </div>
-
-
- </div>
-
- <div class="section-method">
- <a name="//api/name/inTransaction:" title="inTransaction:"></a>
- <h3 class="subsubtitle method-title">inTransaction:</h3>
-
-
-
- <div class="method-subsection brief-description">
- <p>Synchronously perform database operations on queue, using transactions.</p>
- </div>
-
-
- <div class="method-subsection method-declaration"><code>- (void)inTransaction:(void ( ^ ) ( FMDatabase *db , BOOL *rollback ))<em>block</em></code></div>
-
-
- <div class="method-subsection arguments-section parameters">
- <h4 class="method-subtitle parameter-title">Parameters</h4>
-
- <dl class="argument-def parameter-def">
- <dt><em>block</em></dt>
- <dd><p>The code to be run on the queue of <code>FMDatabaseQueue</code></p></dd>
- </dl>
-
- </div>
-
-
-
-
-
-
-
-
-
-
-
-
-
- <div class="method-subsection declared-in-section">
- <h4 class="method-subtitle">Declared In</h4>
- <code class="declared-in-ref">FMDatabaseQueue.h</code><br />
- </div>
-
-
- </div>
-
- <div class="section-method">
- <a name="//api/name/initWithPath:" title="initWithPath:"></a>
- <h3 class="subsubtitle method-title">initWithPath:</h3>
-
-
-
- <div class="method-subsection brief-description">
- <p>Create queue using path.</p>
- </div>
-
-
- <div class="method-subsection method-declaration"><code>- (instancetype)initWithPath:(NSString *)<em>aPath</em></code></div>
-
-
- <div class="method-subsection arguments-section parameters">
- <h4 class="method-subtitle parameter-title">Parameters</h4>
-
- <dl class="argument-def parameter-def">
- <dt><em>aPath</em></dt>
- <dd><p>The file path of the database.</p></dd>
- </dl>
-
- </div>
-
-
-
- <div class="method-subsection return">
- <h4 class="method-subtitle parameter-title">Return Value</h4>
- <p>The <code>FMDatabaseQueue</code> object. <code>nil</code> on error.</p>
- </div>
-
-
-
-
-
-
-
-
-
-
-
- <div class="method-subsection declared-in-section">
- <h4 class="method-subtitle">Declared In</h4>
- <code class="declared-in-ref">FMDatabaseQueue.h</code><br />
- </div>
-
-
- </div>
-
- </div>
-
-
- </div>
- <div class="main-navigation navigation-bottom">
- <ul>
- <li><a href="../index.html">Index</a></li>
- <li><a href="../hierarchy.html">Hierarchy</a></li>
- </ul>
- </div>
- <div id="footer">
- <hr />
- <div class="footer-copyright">
- <p><span class="copyright">© 2013 ccgus. All rights reserved. (Last updated: 2013-08-02)</span><br />
-
- <span class="generator">Generated by <a href="http://appledoc.gentlebytes.com">appledoc 2.1 (build 858)</a>.</span></p>
-
- </div>
- </div>
- </div>
- </article>
- <script type="text/javascript">
- function jumpToChange()
- {
- window.location.hash = this.options[this.selectedIndex].value;
- }
-
- function toggleTOC()
- {
- var contents = document.getElementById('contents');
- var tocContainer = document.getElementById('tocContainer');
-
- if (this.getAttribute('class') == 'open')
- {
- this.setAttribute('class', '');
- contents.setAttribute('class', '');
- tocContainer.setAttribute('class', '');
-
- window.name = "hideTOC";
- }
- else
- {
- this.setAttribute('class', 'open');
- contents.setAttribute('class', 'isShowingTOC');
- tocContainer.setAttribute('class', 'isShowingTOC');
-
- window.name = "";
- }
- return false;
- }
-
- function toggleTOCEntryChildren(e)
- {
- e.stopPropagation();
- var currentClass = this.getAttribute('class');
- if (currentClass == 'children') {
- this.setAttribute('class', 'children open');
- }
- else if (currentClass == 'children open') {
- this.setAttribute('class', 'children');
- }
- return false;
- }
-
- function tocEntryClick(e)
- {
- e.stopPropagation();
- return true;
- }
-
- function init()
- {
- var selectElement = document.getElementById('jumpTo');
- selectElement.addEventListener('change', jumpToChange, false);
-
- var tocButton = document.getElementById('table_of_contents');
- tocButton.addEventListener('click', toggleTOC, false);
-
- var taskTreeItem = document.getElementById('task_treeitem');
- if (taskTreeItem.getElementsByTagName('li').length > 0)
- {
- taskTreeItem.setAttribute('class', 'children');
- taskTreeItem.firstChild.setAttribute('class', 'disclosure');
- }
-
- var tocList = document.getElementById('toc');
-
- var tocEntries = tocList.getElementsByTagName('li');
- for (var i = 0; i < tocEntries.length; i++) {
- tocEntries[i].addEventListener('click', toggleTOCEntryChildren, false);
- }
-
- var tocLinks = tocList.getElementsByTagName('a');
- for (var i = 0; i < tocLinks.length; i++) {
- tocLinks[i].addEventListener('click', tocEntryClick, false);
- }
-
- if (window.name == "hideTOC") {
- toggleTOC.call(tocButton);
- }
- }
-
- window.onload = init;
-
- // If showing in Xcode, hide the TOC and Header
- if (navigator.userAgent.match(/xcode/i)) {
- document.getElementById("contents").className = "hideInXcode"
- document.getElementById("tocContainer").className = "hideInXcode"
- document.getElementById("top_header").className = "hideInXcode"
- }
-
- </script>
- </body>
- </html>
|