commit | author | age
|
6e1425
|
1 |
// |
H |
2 |
// FMDatabaseAdditions.h |
|
3 |
// fmdb |
|
4 |
// |
|
5 |
// Created by August Mueller on 10/30/05. |
|
6 |
// Copyright 2005 Flying Meat Inc.. All rights reserved. |
|
7 |
// |
|
8 |
|
|
9 |
#import <Foundation/Foundation.h> |
|
10 |
#import "FMDatabase.h" |
|
11 |
|
09e73a
|
12 |
NS_ASSUME_NONNULL_BEGIN |
6e1425
|
13 |
|
09e73a
|
14 |
/** Category of additions for @c FMDatabase class. |
6e1425
|
15 |
|
09e73a
|
16 |
See also |
6e1425
|
17 |
|
09e73a
|
18 |
- @c FMDatabase |
6e1425
|
19 |
*/ |
H |
20 |
|
|
21 |
@interface FMDatabase (FMDatabaseAdditions) |
|
22 |
|
|
23 |
///---------------------------------------- |
|
24 |
/// @name Return results of SQL to variable |
|
25 |
///---------------------------------------- |
|
26 |
|
09e73a
|
27 |
/** Return @c int value for query |
6e1425
|
28 |
|
09e73a
|
29 |
@param query The SQL query to be performed, followed by a list of parameters that will be bound to the `?` placeholders in the SQL query. |
6e1425
|
30 |
|
09e73a
|
31 |
@return @c int value. |
6e1425
|
32 |
|
09e73a
|
33 |
@note This is not available from Swift. |
6e1425
|
34 |
*/ |
H |
35 |
|
|
36 |
- (int)intForQuery:(NSString*)query, ...; |
|
37 |
|
09e73a
|
38 |
/** Return @c long value for query |
6e1425
|
39 |
|
09e73a
|
40 |
@param query The SQL query to be performed, followed by a list of parameters that will be bound to the `?` placeholders in the SQL query. |
6e1425
|
41 |
|
09e73a
|
42 |
@return @c long value. |
6e1425
|
43 |
|
09e73a
|
44 |
@note This is not available from Swift. |
6e1425
|
45 |
*/ |
H |
46 |
|
|
47 |
- (long)longForQuery:(NSString*)query, ...; |
|
48 |
|
|
49 |
/** Return `BOOL` value for query |
|
50 |
|
09e73a
|
51 |
@param query The SQL query to be performed, followed by a list of parameters that will be bound to the `?` placeholders in the SQL query. |
6e1425
|
52 |
|
H |
53 |
@return `BOOL` value. |
|
54 |
|
09e73a
|
55 |
@note This is not available from Swift. |
6e1425
|
56 |
*/ |
H |
57 |
|
|
58 |
- (BOOL)boolForQuery:(NSString*)query, ...; |
|
59 |
|
|
60 |
/** Return `double` value for query |
|
61 |
|
09e73a
|
62 |
@param query The SQL query to be performed, followed by a list of parameters that will be bound to the `?` placeholders in the SQL query. |
6e1425
|
63 |
|
H |
64 |
@return `double` value. |
|
65 |
|
09e73a
|
66 |
@note This is not available from Swift. |
6e1425
|
67 |
*/ |
H |
68 |
|
|
69 |
- (double)doubleForQuery:(NSString*)query, ...; |
|
70 |
|
09e73a
|
71 |
/** Return @c NSString value for query |
6e1425
|
72 |
|
09e73a
|
73 |
@param query The SQL query to be performed, followed by a list of parameters that will be bound to the `?` placeholders in the SQL query. |
6e1425
|
74 |
|
09e73a
|
75 |
@return @c NSString value. |
6e1425
|
76 |
|
09e73a
|
77 |
@note This is not available from Swift. |
6e1425
|
78 |
*/ |
H |
79 |
|
09e73a
|
80 |
- (NSString * _Nullable)stringForQuery:(NSString*)query, ...; |
6e1425
|
81 |
|
09e73a
|
82 |
/** Return @c NSData value for query |
6e1425
|
83 |
|
09e73a
|
84 |
@param query The SQL query to be performed, followed by a list of parameters that will be bound to the `?` placeholders in the SQL query. |
6e1425
|
85 |
|
09e73a
|
86 |
@return @c NSData value. |
6e1425
|
87 |
|
09e73a
|
88 |
@note This is not available from Swift. |
6e1425
|
89 |
*/ |
H |
90 |
|
09e73a
|
91 |
- (NSData * _Nullable)dataForQuery:(NSString*)query, ...; |
6e1425
|
92 |
|
09e73a
|
93 |
/** Return @c NSDate value for query |
6e1425
|
94 |
|
09e73a
|
95 |
@param query The SQL query to be performed, followed by a list of parameters that will be bound to the `?` placeholders in the SQL query. |
6e1425
|
96 |
|
09e73a
|
97 |
@return @c NSDate value. |
6e1425
|
98 |
|
09e73a
|
99 |
@note This is not available from Swift. |
6e1425
|
100 |
*/ |
H |
101 |
|
09e73a
|
102 |
- (NSDate * _Nullable)dateForQuery:(NSString*)query, ...; |
6e1425
|
103 |
|
H |
104 |
|
|
105 |
// Notice that there's no dataNoCopyForQuery:. |
|
106 |
// That would be a bad idea, because we close out the result set, and then what |
|
107 |
// happens to the data that we just didn't copy? Who knows, not I. |
|
108 |
|
|
109 |
|
|
110 |
///-------------------------------- |
|
111 |
/// @name Schema related operations |
|
112 |
///-------------------------------- |
|
113 |
|
|
114 |
/** Does table exist in database? |
|
115 |
|
|
116 |
@param tableName The name of the table being looked for. |
|
117 |
|
09e73a
|
118 |
@return @c YES if table found; @c NO if not found. |
6e1425
|
119 |
*/ |
H |
120 |
|
|
121 |
- (BOOL)tableExists:(NSString*)tableName; |
|
122 |
|
|
123 |
/** The schema of the database. |
|
124 |
|
|
125 |
This will be the schema for the entire database. For each entity, each row of the result set will include the following fields: |
|
126 |
|
|
127 |
- `type` - The type of entity (e.g. table, index, view, or trigger) |
|
128 |
- `name` - The name of the object |
|
129 |
- `tbl_name` - The name of the table to which the object references |
|
130 |
- `rootpage` - The page number of the root b-tree page for tables and indices |
|
131 |
- `sql` - The SQL that created the entity |
|
132 |
|
09e73a
|
133 |
@return `FMResultSet` of schema; @c nil on error. |
6e1425
|
134 |
|
09e73a
|
135 |
@see [SQLite File Format](https://sqlite.org/fileformat.html) |
6e1425
|
136 |
*/ |
H |
137 |
|
09e73a
|
138 |
- (FMResultSet * _Nullable)getSchema; |
6e1425
|
139 |
|
H |
140 |
/** The schema of the database. |
|
141 |
|
|
142 |
This will be the schema for a particular table as report by SQLite `PRAGMA`, for example: |
|
143 |
|
|
144 |
PRAGMA table_info('employees') |
|
145 |
|
|
146 |
This will report: |
|
147 |
|
|
148 |
- `cid` - The column ID number |
|
149 |
- `name` - The name of the column |
|
150 |
- `type` - The data type specified for the column |
|
151 |
- `notnull` - whether the field is defined as NOT NULL (i.e. values required) |
|
152 |
- `dflt_value` - The default value for the column |
|
153 |
- `pk` - Whether the field is part of the primary key of the table |
|
154 |
|
|
155 |
@param tableName The name of the table for whom the schema will be returned. |
|
156 |
|
09e73a
|
157 |
@return `FMResultSet` of schema; @c nil on error. |
6e1425
|
158 |
|
09e73a
|
159 |
@see [table_info](https://sqlite.org/pragma.html#pragma_table_info) |
6e1425
|
160 |
*/ |
H |
161 |
|
09e73a
|
162 |
- (FMResultSet * _Nullable)getTableSchema:(NSString*)tableName; |
6e1425
|
163 |
|
H |
164 |
/** Test to see if particular column exists for particular table in database |
|
165 |
|
|
166 |
@param columnName The name of the column. |
|
167 |
|
|
168 |
@param tableName The name of the table. |
|
169 |
|
09e73a
|
170 |
@return @c YES if column exists in table in question; @c NO otherwise. |
6e1425
|
171 |
*/ |
H |
172 |
|
|
173 |
- (BOOL)columnExists:(NSString*)columnName inTableWithName:(NSString*)tableName; |
|
174 |
|
|
175 |
/** Test to see if particular column exists for particular table in database |
|
176 |
|
|
177 |
@param columnName The name of the column. |
|
178 |
|
|
179 |
@param tableName The name of the table. |
|
180 |
|
09e73a
|
181 |
@return @c YES if column exists in table in question; @c NO otherwise. |
6e1425
|
182 |
|
H |
183 |
@see columnExists:inTableWithName: |
|
184 |
|
|
185 |
@warning Deprecated - use `<columnExists:inTableWithName:>` instead. |
|
186 |
*/ |
|
187 |
|
09e73a
|
188 |
- (BOOL)columnExists:(NSString*)tableName columnName:(NSString*)columnName __deprecated_msg("Use columnExists:inTableWithName: instead"); |
6e1425
|
189 |
|
H |
190 |
|
|
191 |
/** Validate SQL statement |
|
192 |
|
|
193 |
This validates SQL statement by performing `sqlite3_prepare_v2`, but not returning the results, but instead immediately calling `sqlite3_finalize`. |
|
194 |
|
|
195 |
@param sql The SQL statement being validated. |
|
196 |
|
09e73a
|
197 |
@param error This is a pointer to a @c NSError object that will receive the autoreleased @c NSError object if there was any error. If this is @c nil , no @c NSError result will be returned. |
6e1425
|
198 |
|
09e73a
|
199 |
@return @c YES if validation succeeded without incident; @c NO otherwise. |
6e1425
|
200 |
|
H |
201 |
*/ |
|
202 |
|
09e73a
|
203 |
- (BOOL)validateSQL:(NSString*)sql error:(NSError * _Nullable __autoreleasing *)error; |
6e1425
|
204 |
|
H |
205 |
|
|
206 |
///----------------------------------- |
|
207 |
/// @name Application identifier tasks |
|
208 |
///----------------------------------- |
|
209 |
|
|
210 |
/** Retrieve application ID |
|
211 |
|
|
212 |
@return The `uint32_t` numeric value of the application ID. |
|
213 |
|
|
214 |
@see setApplicationID: |
|
215 |
*/ |
|
216 |
|
09e73a
|
217 |
@property (nonatomic) uint32_t applicationID; |
6e1425
|
218 |
|
H |
219 |
#if TARGET_OS_MAC && !TARGET_OS_IPHONE |
|
220 |
|
09e73a
|
221 |
/** Retrieve application ID string |
6e1425
|
222 |
|
H |
223 |
@see setApplicationIDString: |
|
224 |
*/ |
|
225 |
|
09e73a
|
226 |
@property (nonatomic, retain) NSString *applicationIDString; |
6e1425
|
227 |
|
H |
228 |
#endif |
|
229 |
|
|
230 |
///----------------------------------- |
|
231 |
/// @name user version identifier tasks |
|
232 |
///----------------------------------- |
|
233 |
|
|
234 |
/** Retrieve user version |
|
235 |
|
|
236 |
@see setUserVersion: |
|
237 |
*/ |
|
238 |
|
09e73a
|
239 |
@property (nonatomic) uint32_t userVersion; |
6e1425
|
240 |
|
H |
241 |
@end |
09e73a
|
242 |
|
L |
243 |
NS_ASSUME_NONNULL_END |