Skip to content

Commit 1e623bc

Browse files
committed
added fmdb to Obj-C corpus
1 parent 4a39089 commit 1e623bc

28 files changed

+9200
-0
lines changed

objective-c/fmdb/FMDB.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import "FMDatabase.h"
2+
#import "FMResultSet.h"
3+
#import "FMDatabaseAdditions.h"
4+
#import "FMDatabaseQueue.h"
5+
#import "FMDatabasePool.h"

objective-c/fmdb/FMDBTempDBTests.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// FMDBTempDBTests.h
3+
// fmdb
4+
//
5+
// Created by Graham Dennis on 24/11/2013.
6+
//
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "FMDatabase.h"
11+
12+
@protocol FMDBTempDBTests <NSObject>
13+
14+
@optional
15+
+ (void)populateDatabase:(FMDatabase *)database;
16+
17+
@end
18+
19+
@interface FMDBTempDBTests : XCTestCase <FMDBTempDBTests>
20+
21+
@property FMDatabase *db;
22+
@property (readonly) NSString *databasePath;
23+
24+
@end

objective-c/fmdb/FMDBTempDBTests.m

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// FMDBTempDBTests.m
3+
// fmdb
4+
//
5+
// Created by Graham Dennis on 24/11/2013.
6+
//
7+
//
8+
9+
#import "FMDBTempDBTests.h"
10+
11+
static NSString *const testDatabasePath = @"/tmp/tmp.db";
12+
static NSString *const populatedDatabasePath = @"/tmp/tmp-populated.db";
13+
14+
@implementation FMDBTempDBTests
15+
16+
+ (void)setUp
17+
{
18+
[super setUp];
19+
20+
// Delete old populated database
21+
NSFileManager *fileManager = [NSFileManager defaultManager];
22+
[fileManager removeItemAtPath:populatedDatabasePath error:NULL];
23+
24+
if ([self respondsToSelector:@selector(populateDatabase:)]) {
25+
FMDatabase *db = [FMDatabase databaseWithPath:populatedDatabasePath];
26+
27+
[db open];
28+
[self populateDatabase:db];
29+
[db close];
30+
}
31+
}
32+
33+
- (void)setUp
34+
{
35+
[super setUp];
36+
37+
// Delete the old database
38+
NSFileManager *fileManager = [NSFileManager defaultManager];
39+
[fileManager removeItemAtPath:testDatabasePath error:NULL];
40+
41+
if ([[self class] respondsToSelector:@selector(populateDatabase:)]) {
42+
[fileManager copyItemAtPath:populatedDatabasePath toPath:testDatabasePath error:NULL];
43+
}
44+
45+
self.db = [FMDatabase databaseWithPath:testDatabasePath];
46+
47+
XCTAssertTrue([self.db open], @"Wasn't able to open database");
48+
[self.db setShouldCacheStatements:YES];
49+
}
50+
51+
- (void)tearDown
52+
{
53+
[super tearDown];
54+
55+
[self.db close];
56+
}
57+
58+
- (NSString *)databasePath
59+
{
60+
return testDatabasePath;
61+
}
62+
63+
@end

objective-c/fmdb/FMDatabase+FTS3.h

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//
2+
// FMDatabase+FTS3.h
3+
// fmdb
4+
//
5+
// Created by Andrew on 3/27/14.
6+
// Copyright (c) 2014 Andrew Goodale. All rights reserved.
7+
//
8+
9+
#import "FMDatabase.h"
10+
11+
/**
12+
Names of commands that can be issued against an FTS table.
13+
*/
14+
extern NSString *const kFTSCommandOptimize; // "optimize"
15+
extern NSString *const kFTSCommandRebuild; // "rebuild"
16+
extern NSString *const kFTSCommandIntegrityCheck; // "integrity-check"
17+
extern NSString *const kFTSCommandMerge; // "merge=%u,%u"
18+
extern NSString *const kFTSCommandAutoMerge; // "automerge=%u"
19+
20+
@protocol FMTokenizerDelegate;
21+
22+
/**
23+
This category provides methods to access the FTS3 extensions in SQLite.
24+
*/
25+
@interface FMDatabase (FTS3)
26+
27+
/**
28+
Register a delegate implementation in the global table. This should be used when using a single tokenizer.
29+
*/
30+
+ (void)registerTokenizer:(id<FMTokenizerDelegate>)tokenizer;
31+
32+
/**
33+
Register a delegate implementation in the global table. The key should be used
34+
as a parameter when creating the table.
35+
*/
36+
+ (void)registerTokenizer:(id<FMTokenizerDelegate>)tokenizer withKey:(NSString *)key;
37+
38+
/**
39+
Calls the `fts3_tokenizer()` function on this database, installing tokenizer module with the 'fmdb' name.
40+
*/
41+
- (BOOL)installTokenizerModule;
42+
43+
/**
44+
Calls the `fts3_tokenizer()` function on this database, installing the tokenizer module with specified name.
45+
*/
46+
- (BOOL)installTokenizerModuleWithName:(NSString *)name;
47+
48+
/**
49+
Runs a "special command" for FTS3/FTS4 tables.
50+
*/
51+
- (BOOL)issueCommand:(NSString *)command forTable:(NSString *)tableName;
52+
53+
@end
54+
55+
#pragma mark
56+
57+
/* Extend this structure with your own custom cursor data */
58+
typedef struct FMTokenizerCursor
59+
{
60+
void *tokenizer; /* Internal SQLite reference */
61+
CFStringRef inputString; /* The input text being tokenized */
62+
CFRange currentRange; /* The current offset within `inputString` */
63+
CFStringRef tokenString; /* The contents of the current token */
64+
CFTypeRef userObject; /* Additional state for the cursor */
65+
int tokenIndex; /* Index of next token to be returned */
66+
UInt8 outputBuf[128]; /* Result for SQLite */
67+
} FMTokenizerCursor;
68+
69+
@protocol FMTokenizerDelegate
70+
71+
- (void)openTokenizerCursor:(FMTokenizerCursor *)cursor;
72+
73+
- (BOOL)nextTokenForCursor:(FMTokenizerCursor *)cursor;
74+
75+
- (void)closeTokenizerCursor:(FMTokenizerCursor *)cursor;
76+
77+
@end
78+
79+
#pragma mark
80+
81+
/**
82+
The container of offset information.
83+
*/
84+
@interface FMTextOffsets : NSObject
85+
86+
- (instancetype)initWithDBOffsets:(const char *)offsets;
87+
88+
/**
89+
Enumerate each set of offsets in the result. The column number can be turned into a column name
90+
using `[FMResultSet columnNameForIndex:]`. The `matchRange` is in UTF-8 byte positions, so it must be
91+
modified to use with `NSString` data.
92+
*/
93+
- (void)enumerateWithBlock:(void (^)(NSInteger columnNumber, NSInteger termNumber, NSRange matchRange))block;
94+
95+
@end
96+
97+
/**
98+
A category that adds support for the encoded data returned by FTS3 functions.
99+
*/
100+
@interface FMResultSet (FTS3)
101+
102+
/**
103+
Returns a structure containing values from the `offsets()` function. Make sure the column index corresponds
104+
to the column index in the SQL query.
105+
106+
@param columnIdx Zero-based index for column.
107+
108+
@return `FMTextOffsets` structure.
109+
*/
110+
- (FMTextOffsets *)offsetsForColumnIndex:(int)columnIdx;
111+
112+
@end

0 commit comments

Comments
 (0)