Solved! Go to Solution.
Thanks for the reply. Yes, I have seen that page.
I found and fixed my issue yesterday. The Server for ArcGIS log file showed an error stating that there was an invalid column data type in the table. As it turns out, the process that creates the SQLite geodatabase does not like fields of type nvarchar(max) (SQL Server).
Also, of note for anyone else, if you initialize the AGSGDBGenerateParameters object with the feature service info it does not automatically include tables. I had to override the layerIDs property for the parameters to add both the layer IDs and table IDs.
Hi Shimin,
We're having the same issue with empty tables in the local geodatabase, unless the tables participate in a relationship with a featureclass. Did you find a solution to this, by chance?
Thanks,
Matt
Hi Matt & Michael,
I did not get any response in this forum but I had to work around it... My workaround is to write the records into a *.sqlite database when the app is going online and then use the data in the sqlite regardless of online or offline. Here is the code:
@property (nonatomic, strong) AGSFeatureSet *quickCodeFeatureSet;
When the app is going online, add and query the table feature layers:
//Add standalone table layers
for (AGSMapServiceTableInfo* info in weakSelf.gdbTask.featureServiceInfo.tableInfos)
{
NSURL* url = [weakSelf.gdbTask.URL URLByAppendingPathComponent:[NSString stringWithFormat:@"%d",info.tableId]];
AGSFeatureLayer* fl = [AGSFeatureLayer featureServiceLayerWithURL:url mode:AGSFeatureLayerModeOnDemand];
fl.outFields = @[@"*"];
fl.delegate = weakSelf;
fl.queryDelegate = weakSelf;
fl.editingDelegate = weakSelf;
AGSQuery *qry = [AGSQuery query];
qry.outFields = @[@"*"];
//qry.outFields = @[@"Type", @"QuickCode", @"Description", @"ObjectID"];
//qry.outFields = @[@"Type", @"QuickCode", @"Description"];
//qry.where = [NSString stringWithFormat:@"QuickCode in (%@)", @"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"];
qry.where = @"QuickCode < 10000";
[fl queryFeatures:qry];
[weakSelf.mapView addMapLayer:fl withName:info.name];
[weakSelf logStatus:[NSString stringWithFormat:@"loading: %@", [fl.URL absoluteString]]];
}
Note that, to be able to query this standalone table layer, it must be added to the map view otherwise zero features are returned.
In the feature layer query delegate write the records to the sqlite
#pragma mark - AGSFeatureLayer query delegate methods
-(void)featureLayer:(AGSFeatureLayer *)featureLayer operation:(NSOperation *)op didQueryFeaturesWithFeatureSet:(AGSFeatureSet *)featureSet
{
NSLog(@"%d", featureSet.features.count);
self.quickCodeFeatureSet = featureSet;
NSLog(@"%d", self.quickCodeFeatureSet.features.count);
[self populateQuickCodeTable];
}
-(void)populateQuickCodeTable
{
DBManager *db = [[DBManager alloc]init];
[db clearQuickCode:@"SPDQuickCode"];
for (AGSGraphic *feature in self.quickCodeFeatureSet.features)
{
NSString *type = [feature safeAttributeForKey:@"Type"];
int code = [((NSNumber *)[feature safeAttributeForKey:@"QuickCode"])intValue];
NSString *description = [feature safeAttributeForKey:@"Description"];
[db insertQuickCode:@"SPDQuickCode" QuickCodeType:type QuickCode:code Description:description];
}
[db closeDatabase];
}
The above workaround is working fine for my purposes.
For your information: I also tried to write the features to the local geodatabase right after the database is created, but I can't use this solution. The reason is below...
//Add local feature/table layers
for (AGSFeatureTable* fTable in geodatabase.featureTables)
{
if ([fTable hasGeometry])
{
AGSFeatureTableLayer *ftl = [[AGSFeatureTableLayer alloc]initWithFeatureTable:fTable];
ftl.delegate = self;
[self.mapView addMapLayer:ftl];
}
/*
else
{
if([fTable.tableName isEqualToString:@"SPDQuickCode"])
{
AGSGDBFeatureServiceTable *fsTable = (AGSGDBFeatureServiceTable *)fTable;
for (AGSGraphic *feature in self.quickCodeFeatureSet.features)
{
AGSGDBFeature *gdbFeature = [fsTable featureWithTemplate:nil];
[gdbFeature setAttribute:[feature safeAttributeForKey:@"Type"] forKey:@"Type"];
[gdbFeature setAttribute:[feature safeAttributeForKey:@"QuickCode"] forKey:@"QuickCode"];
[gdbFeature setAttribute:[feature safeAttributeForKey:@"Description"] forKey:@"Description"];
NSError *error;
[fsTable saveFeature:gdbFeature error:&error];
if(error)
{
NSLog(@"%@", error.localizedDescription);
}
}
}
}
//the commented code is working and saves the quickcode records to the local table
//but the problem is that the database records the edits and the edits flags can't
//be removed and as a result when sync the data is synced back to the corporate database and generates duplicates.
*/
}
Hope it helps.
Cheers,
Shimin
Thanks for the response. We ended up just converting our tables to point feature class and just assigned each record a lat/lon. It works, but isn't ideal. Would be nice to hear from Esri whether this is a bug or if we're overlooking something in the configuration or SDK.
We are also having issues with this - did you ever figure out a work-around or fix?
We are also having issues with related records in a table not being included if the feature is related to it (vs the record being related to the feature).