@@ -172,7 +172,7 @@ -(id) getDBPath:(NSString *)dbFile at:(NSString *)atkey {
172
172
targetBundleDirPath = [targetBundleDirPath stringByAppendingPathComponent: @" www" ];
173
173
assetFilePath = [targetBundleDirPath stringByAppendingPathComponent: dbfilename];
174
174
RCTLog (@" Built path to pre-populated DB asset from app bundle www subdirectory: %@ " ,assetFilePath);
175
- } else if ([assetFilePath characterAtIndex: 0 == ' ~' ] ) {
175
+ } else if ([assetFilePath characterAtIndex: 0 ] == ' ~' ) {
176
176
assetFilePath = [assetFilePath substringFromIndex: 1 ];
177
177
NSString *targetBundleDirPath = [[NSBundle mainBundle ] resourcePath ];
178
178
assetFilePath = [targetBundleDirPath stringByAppendingPathComponent: assetFilePath];
@@ -215,21 +215,28 @@ -(id) getDBPath:(NSString *)dbFile at:(NSString *)atkey {
215
215
return ;
216
216
} else {
217
217
sqlite3_create_function (db, " regexp" , 2 , SQLITE_ANY, NULL , &sqlite_regexp, NULL , NULL );
218
-
219
- // for SQLCipher version:
220
- // NSString *dbkey = options[@"key"];
221
- // const char *key = NULL;
222
- // if (dbkey != NULL) key = [dbkey UTF8String];
223
- // if (key != NULL) sqlite3_key(db, key, strlen(key));
224
-
218
+ const char *key = NULL ;
219
+
220
+ #ifdef SQLCIPHER
221
+ NSString *dbkey = options[@" key" ];
222
+ if (dbkey != NULL ) {
223
+ key = [dbkey UTF8String ];
224
+ if (key != NULL ) {
225
+ sqlite3_key (db, key, strlen (key));
226
+ }
227
+ }
228
+ #endif
225
229
// Attempt to read the SQLite master table [to support SQLCipher version]:
226
230
if (sqlite3_exec (db, (const char *)" SELECT count(*) FROM sqlite_master;" , NULL , NULL , NULL ) == SQLITE_OK) {
227
231
NSValue *dbPointer = [NSValue valueWithPointer: db];
228
232
openDBs[dbfilename] = @{ @" dbPointer" : dbPointer, @" dbPath" : dbname};
229
- pluginResult = [SQLiteResult resultWithStatus: SQLiteStatus_OK messageAsString: @" Database opened" ];
233
+ NSString *msg = (key != NULL ) ? @" Secure database opened" : @" Database opened" ;
234
+ pluginResult = [SQLiteResult resultWithStatus: SQLiteStatus_OK messageAsString: msg];
235
+ RCTLog (msg);
230
236
} else {
231
- pluginResult = [SQLiteResult resultWithStatus: SQLiteStatus_ERROR messageAsString: @" Unable to open DB with key" ];
232
- RCTLog (@" Unable to open db with key" );
237
+ NSString *msg = [NSString stringWithFormat: @" Unable to open %@ " , (key != NULL ) ? @" secure database with key" : @" database" ];
238
+ pluginResult = [SQLiteResult resultWithStatus: SQLiteStatus_ERROR messageAsString: msg];
239
+ RCTLog (msg);
233
240
sqlite3_close (db);
234
241
[openDBs removeObjectForKey: dbfilename];
235
242
}
0 commit comments