Skip to content

Commit 5f664f2

Browse files
committed
为了64位的项目里去除编译警告,int 统一转成NSInteger
1 parent 8531ee0 commit 5f664f2

21 files changed

+845
-418
lines changed

LKDBHelper/FMDB/src/FMDatabase.h

100755100644
Lines changed: 143 additions & 49 deletions
Large diffs are not rendered by default.

LKDBHelper/FMDB/src/FMDatabase.m

100755100644
Lines changed: 323 additions & 174 deletions
Large diffs are not rendered by default.

LKDBHelper/FMDB/src/FMDatabaseAdditions.h

100755100644
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//
88

99
#import <Foundation/Foundation.h>
10+
#import "FMDatabase.h"
11+
1012

1113
/** Category of additions for `<FMDatabase>` class.
1214
@@ -217,13 +219,15 @@
217219

218220
- (void)setApplicationID:(uint32_t)appID;
219221

222+
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
220223
/** Retrieve application ID string
221224
222225
@return The `NSString` value of the application ID.
223226
224227
@see setApplicationIDString:
225228
*/
226229

230+
227231
- (NSString*)applicationIDString;
228232

229233
/** Set the application ID string
@@ -236,5 +240,28 @@
236240
- (void)setApplicationIDString:(NSString*)string;
237241
#endif
238242

243+
#endif
244+
245+
///-----------------------------------
246+
/// @name user version identifier tasks
247+
///-----------------------------------
248+
249+
/** Retrieve user version
250+
251+
@return The `uint32_t` numeric value of the user version.
252+
253+
@see setUserVersion:
254+
*/
255+
256+
- (uint32_t)userVersion;
257+
258+
/** Set the user-version
259+
260+
@param version The `uint32_t` numeric value of the user version.
261+
262+
@see userVersion
263+
*/
264+
265+
- (void)setUserVersion:(uint32_t)version;
239266

240267
@end

LKDBHelper/FMDB/src/FMDatabaseAdditions.m

100755100644
Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ - (FMResultSet*)getSchema {
9090
- (FMResultSet*)getTableSchema:(NSString*)tableName {
9191

9292
//result colums: cid[INTEGER], name,type [STRING], notnull[INTEGER], dflt_value[],pk[INTEGER]
93-
FMResultSet *rs = [self executeQuery:[NSString stringWithFormat: @"PRAGMA table_info('%@')", tableName]];
93+
FMResultSet *rs = [self executeQuery:[NSString stringWithFormat: @"pragma table_info('%@')", tableName]];
9494

9595
return rs;
9696
}
@@ -137,7 +137,7 @@ - (uint32_t)applicationID {
137137
}
138138

139139
- (void)setApplicationID:(uint32_t)appID {
140-
NSString *query = [NSString stringWithFormat:@"PRAGMA application_id=%d", appID];
140+
NSString *query = [NSString stringWithFormat:@"pragma application_id=%d", appID];
141141
FMResultSet *rs = [self executeQuery:query];
142142
[rs next];
143143
[rs close];
@@ -171,6 +171,26 @@ - (void)setApplicationIDString:(NSString*)s {
171171

172172
#endif
173173

174+
- (uint32_t)userVersion {
175+
uint32_t r = 0;
176+
177+
FMResultSet *rs = [self executeQuery:@"pragma user_version"];
178+
179+
if ([rs next]) {
180+
r = (uint32_t)[rs longLongIntForColumnIndex:0];
181+
}
182+
183+
[rs close];
184+
return r;
185+
}
186+
187+
- (void)setUserVersion:(uint32_t)version {
188+
NSString *query = [NSString stringWithFormat:@"pragma user_version = %d", version];
189+
FMResultSet *rs = [self executeQuery:query];
190+
[rs next];
191+
[rs close];
192+
}
193+
174194
#pragma clang diagnostic push
175195
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
176196

@@ -180,32 +200,19 @@ - (BOOL)columnExists:(NSString*)tableName columnName:(NSString*)columnName __att
180200

181201
#pragma clang diagnostic pop
182202

203+
183204
- (BOOL)validateSQL:(NSString*)sql error:(NSError**)error {
184205
sqlite3_stmt *pStmt = NULL;
185206
BOOL validationSucceeded = YES;
186-
BOOL keepTrying = YES;
187-
int numberOfRetries = 0;
188-
189-
while (keepTrying == YES) {
190-
keepTrying = NO;
191-
int rc = sqlite3_prepare_v2(_db, [sql UTF8String], -1, &pStmt, 0);
192-
if (rc == SQLITE_BUSY || rc == SQLITE_LOCKED) {
193-
keepTrying = YES;
194-
usleep(FMDatabaseSQLiteBusyMicrosecondsTimeout);
195-
196-
if (_busyRetryTimeout && (numberOfRetries++ > _busyRetryTimeout)) {
197-
NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [self databasePath]);
198-
NSLog(@"Database busy");
199-
}
200-
}
201-
else if (rc != SQLITE_OK) {
202-
validationSucceeded = NO;
203-
if (error) {
204-
*error = [NSError errorWithDomain:NSCocoaErrorDomain
205-
code:[self lastErrorCode]
206-
userInfo:[NSDictionary dictionaryWithObject:[self lastErrorMessage]
207-
forKey:NSLocalizedDescriptionKey]];
208-
}
207+
208+
int rc = sqlite3_prepare_v2(_db, [sql UTF8String], -1, &pStmt, 0);
209+
if (rc != SQLITE_OK) {
210+
validationSucceeded = NO;
211+
if (error) {
212+
*error = [NSError errorWithDomain:NSCocoaErrorDomain
213+
code:[self lastErrorCode]
214+
userInfo:[NSDictionary dictionaryWithObject:[self lastErrorMessage]
215+
forKey:NSLocalizedDescriptionKey]];
209216
}
210217
}
211218

LKDBHelper/FMDB/src/FMDatabasePool.h

100755100644
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,26 @@
4040
__unsafe_unretained id _delegate;
4141

4242
NSUInteger _maximumNumberOfDatabasesToCreate;
43+
int _openFlags;
4344
}
4445

46+
/** Database path */
47+
4548
@property (atomic, retain) NSString *path;
49+
50+
/** Delegate object */
51+
4652
@property (atomic, assign) id delegate;
53+
54+
/** Maximum number of databases to create */
55+
4756
@property (atomic, assign) NSUInteger maximumNumberOfDatabasesToCreate;
4857

58+
/** Open flags */
59+
60+
@property (atomic, readonly) int openFlags;
61+
62+
4963
///---------------------
5064
/// @name Initialization
5165
///---------------------
@@ -59,6 +73,16 @@
5973

6074
+ (instancetype)databasePoolWithPath:(NSString*)aPath;
6175

76+
/** Create pool using path and specified flags
77+
78+
@param aPath The file path of the database.
79+
@param openFlags Flags passed to the openWithFlags method of the database
80+
81+
@return The `FMDatabasePool` object. `nil` on error.
82+
*/
83+
84+
+ (instancetype)databasePoolWithPath:(NSString*)aPath flags:(int)openFlags;
85+
6286
/** Create pool using path.
6387
6488
@param aPath The file path of the database.
@@ -68,6 +92,16 @@
6892

6993
- (instancetype)initWithPath:(NSString*)aPath;
7094

95+
/** Create pool using path and specified flags.
96+
97+
@param aPath The file path of the database.
98+
@param openFlags Flags passed to the openWithFlags method of the database
99+
100+
@return The `FMDatabasePool` object. `nil` on error.
101+
*/
102+
103+
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags;
104+
71105
///------------------------------------------------
72106
/// @name Keeping track of checked in/out databases
73107
///------------------------------------------------
@@ -127,6 +161,8 @@
127161
/** Synchronously perform database operations in pool using save point.
128162
129163
@param block The code to be run on the `FMDatabasePool` pool.
164+
165+
@return `NSError` object if error; `nil` if successful.
130166
131167
@warning You can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock. If you need to nest, use `<[FMDatabase startSavePointWithName:error:]>` instead.
132168
*/
@@ -137,9 +173,32 @@
137173
@end
138174

139175

176+
/** FMDatabasePool delegate category
177+
178+
This is a category that defines the protocol for the FMDatabasePool delegate
179+
*/
180+
140181
@interface NSObject (FMDatabasePoolDelegate)
141182

183+
/** Asks the delegate whether database should be added to the pool.
184+
185+
@param pool The `FMDatabasePool` object.
186+
@param database The `FMDatabase` object.
187+
188+
@return `YES` if it should add database to pool; `NO` if not.
189+
190+
*/
191+
142192
- (BOOL)databasePool:(FMDatabasePool*)pool shouldAddDatabaseToPool:(FMDatabase*)database;
143193

194+
/** Tells the delegate that database was added to the pool.
195+
196+
@param pool The `FMDatabasePool` object.
197+
@param database The `FMDatabase` object.
198+
199+
*/
200+
201+
- (void)databasePool:(FMDatabasePool*)pool didAddDatabase:(FMDatabase*)database;
202+
144203
@end
145204

0 commit comments

Comments
 (0)