userInfo:nil];
}
+ /* run */
#warning TODO: properly escape SQL specials!
error = nil;
now = [NSNumber numberWithUnsignedInt:[nowDate timeIntervalSince1970]];
if (doLogStore)
- [self logWithFormat:@"SHOULD store content: %@\n%@", _name, _content];
+ [self logWithFormat:@"should store content: '%@'\n%@", _name, _content];
storedVersion = [self versionOfContentWithName:_name];
if (doLogStore)
[self releaseChannel:storeChannel];
[self releaseChannel:quickChannel];
+ return error;
+}
+
+- (NSException *)deleteContentWithName:(NSString *)_name {
+ EOAdaptorChannel *storeChannel, *quickChannel;
+ NSException *error;
+ NSString *delsql;
+
+ /* check preconditions */
+ if (_name == nil) {
+ return [NSException exceptionWithName:@"OCSDeleteException"
+ reason:@"no content filename was provided"
+ userInfo:nil];
+ }
+
+ if (doLogStore)
+ [self logWithFormat:@"should delete content: '%@'", _name];
+
+ /* open channels */
+
+ if ((storeChannel = [self acquireStoreChannel]) == nil) {
+ [self logWithFormat:@"ERROR(%s): could not open storage channel!"];
+ return nil;
+ }
+ if ((quickChannel = [self acquireQuickChannel]) == nil) {
+ [self logWithFormat:@"ERROR(%s): could not open quick channel!"];
+ [self releaseChannel:storeChannel];
+ return nil;
+ }
+
+ /* delete rows */
+
+ delsql = [@"DELETE FROM " stringByAppendingString:[self storeTableName]];
+ delsql = [delsql stringByAppendingString:@" WHERE c_name="];
+ delsql = [delsql stringByAppendingString:[self _formatRowValue:_name]];
+ if ((error = [storeChannel evaluateExpressionX:delsql]) != nil) {
+ [self logWithFormat:
+ @"ERROR(%s): cannot delete content '%@': %@",
+ __PRETTY_FUNCTION__, delsql, error];
+ }
+ else {
+ /* content row deleted, now delete the quick row */
+ delsql = [@"DELETE FROM " stringByAppendingString:[self quickTableName]];
+ delsql = [delsql stringByAppendingString:@" WHERE c_name="];
+ delsql = [delsql stringByAppendingString:[self _formatRowValue:_name]];
+ if ((error = [quickChannel evaluateExpressionX:delsql]) != nil) {
+ [self logWithFormat:
+ @"ERROR(%s): cannot delete quick row '%@': %@",
+ __PRETTY_FUNCTION__, delsql, error];
+ /*
+ Note: we now have a "broken" record, needs to be periodically GCed by
+ a script!
+ */
+ }
+ }
+
+ /* release channels and return */
+
+ [self releaseChannel:storeChannel];
+ [self releaseChannel:quickChannel];
return error;
}