 
         return nil
     }
-    
+
     func setData(data: NSData?, forKey recordId: String) {
-        
+
         let fileLink = fileLinkForRecordId(recordId)
-        
+
         if let fileLink = fileLink {
             if let data = data {
                 updateData(data, forRecord:recordId, fileLink:fileLink)

                bridging_sqlite3_finalize(statement)
            }
        })
        
        return result
    }
    
    private func removeRecordsForRecordId(recordId: AnyObject, fileLink: String) {
        
        fileLink.cacheDBFileLinkRemoveFileWithFolder(self.db.folder)
        
        let removeQuery = "DELETE FROM records WHERE record_id='\(recordId)';"
        
        dispatch_barrier_async(db.dispatchQueue, {
            
            var statement: COpaquePointer = nil
            if self.prepareQuery(removeQuery, statement:&statement) {
                if bridging_sqlite3_step(statement) != BRIDGING_SQLITE_DONE {
                    NSLog("\(removeQuery) - \(self.errorMessage)")
                }
                
                bridging_sqlite3_finalize(statement)
            }
        })
    }
    
    private func addData(data: NSData, forRecord recordId: String) {
        
        let fileLink = NSUUID().UUIDString
        
        let addQuery = "INSERT INTO records (record_id, file_link, update_time, access_time) VALUES ('\(recordId)', '\(fileLink)', '\(currentTime)', '\(currentTime)');"
        
        dispatch_barrier_async(db.dispatchQueue, {
            
            var statement: COpaquePointer = nil
            if self.prepareQuery(addQuery, statement:&statement) {
                if bridging_sqlite3_step(statement) == BRIDGING_SQLITE_DONE {

                } else {
                    NSLog("\(addQuery) - \(self.errorMessage)")
                }

                bridging_sqlite3_finalize(statement)
            } else {
                NSLog("\(addQuery) - \(self.errorMessage)")
            }
        })
    }

    //JTODO test !!!!
    private func removeRecordsToDate(date: NSDate, dateFieldName fieldName: String) {

        ///First remove all files
        let query = "SELECT file_link FROM records WHERE \(fieldName) < '\(date.timeIntervalSince1970)';"

        dispatch_barrier_async(db.dispatchQueue, {

            var statement: COpaquePointer = nil

            if self.db.prepareQuery(query, statement:&statement) {
                while bridging_sqlite3_step(statement) == BRIDGING_SQLITE_ROW {

                    autoreleasepool {

                        let str = bridging_sqlite3_column_text(statement, 0)
                        let fileLink = String.fromCString(UnsafePointer<CChar>(str))!

                        fileLink.cacheDBFileLinkRemoveFileWithFolder(self.db.folder)
                    }
                }
                bridging_sqlite3_finalize(statement)
            }

            //////////

            let removeQuery = "DELETE FROM records WHERE \(fieldName) < '\(date.timeIntervalSince1970)';"

            var queryStatement: COpaquePointer = nil

            if self.prepareQuery(removeQuery, statement:&queryStatement) {
                if bridging_sqlite3_step(queryStatement) != BRIDGING_SQLITE_DONE {
                    NSLog("\(removeQuery) - \(self.errorMessage)")
                }

                bridging_sqlite3_finalize(queryStatement)
            }
        })
    }

    private func folderSize() -> Int64 {

        let folderPath  = self.db.folder
        let fileManager = NSFileManager.defaultManager()
        let filesEnumerator = fileManager.enumeratorAtPath(folderPath)

        var fileSize: Int64 = 0

        if let filesEnumerator = filesEnumerator {

            while let fileName = filesEnumerator.nextObject() as? String {
