Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added remove column method on table #49

Merged
merged 3 commits into from
Mar 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2014-03-07
==========
* Adding appendRow to TightdbTable.
* Adding method removeColumn on table.

2014-03-05
==========
Expand Down
2 changes: 2 additions & 0 deletions src/tightdb/objc/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@
-(size_t)addColumnWithType:(TightdbType)type andName:(NSString *)name;
-(size_t)addColumnWithType:(TightdbType)type andName:(NSString *)name error:(NSError *__autoreleasing *)error;

-(void)removeColumnWithIndex:(size_t)columnIndex;

/* Searching */
/* FIXME: Should be findBool:(BOOL)value inColumn:(size_t)colNdx; */
-(size_t)findBool:(size_t)colNdx value:(BOOL)value;
Expand Down
17 changes: 17 additions & 0 deletions src/tightdb/objc/table_objc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ -(BOOL)addColumnWithType:(TightdbType)type andName:(NSString*)name error:(NSErro
return YES;
}




-(TightdbDescriptor*)addColumnTable:(NSString*)name
{
return [self addColumnTable:name error:nil];
Expand Down Expand Up @@ -1219,6 +1222,20 @@ -(size_t)addColumnWithType:(TightdbType)type andName:(NSString*)name error:(NSEr
0);
}

-(void)removeColumnWithIndex:(size_t)columnIndex
{
TIGHTDB_EXCEPTION_HANDLER_COLUMN_INDEX_VALID(columnIndex);

try {
m_table->remove_column(columnIndex);
}
catch(std::exception& ex) {
NSException* exception = [NSException exceptionWithName:@"tightdb:core_exception"
reason:[NSString stringWithUTF8String:ex.what()]
userInfo:[NSMutableDictionary dictionary]];
[exception raise];
}
}

-(size_t)findBool:(size_t)col_ndx value:(BOOL)value
{
Expand Down
31 changes: 31 additions & 0 deletions src/tightdb/objc/test/dynamic_table.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,37 @@ - (void)testTable
STFail(@"1 row excepted");
}

-(void)testRemoveColumns
{

TightdbTable *t = [[TightdbTable alloc] init];
[t addColumnWithType:tightdb_Int andName:@"col0"];
STAssertTrue([t getColumnCount] == 1,@"1 column added" );

[t removeColumnWithIndex:0];
STAssertTrue([t getColumnCount] == 0, @"Colum removed");

for (int i=0;i<10;i++) {
[t addColumnWithType:tightdb_Int andName:@"name"];
}

STAssertThrows([t removeColumnWithIndex:10], @"Out of bounds");
STAssertThrows([t removeColumnWithIndex:-1], @"Less than zero colIndex");

STAssertTrue([t getColumnCount] == 10, @"10 columns added");

for (int i=0;i<10;i++) {
[t removeColumnWithIndex:0];
}

STAssertTrue([t getColumnCount] == 0, @"Colums removed");

STAssertThrows([t removeColumnWithIndex:1], @"No columns added");
STAssertThrows([t removeColumnWithIndex:-1], @"Less than zero colIndex");


}

- (void)testDataTypes_Dynamic
{
TightdbTable* table = [[TightdbTable alloc] init];
Expand Down
8 changes: 8 additions & 0 deletions src/tightdb/objc/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ catch(std::exception& ex) { \
[exception raise]; \
}

#define TIGHTDB_EXCEPTION_HANDLER_COLUMN_INDEX_VALID(columnIndex) \
if (columnIndex >= [self getColumnCount]) { \
NSException* exception = [NSException exceptionWithName:@"tightdb:column_index_out_of_bounds" \
reason:@"The specified column index is not within the table bounds" \
userInfo:[NSMutableDictionary dictionary]]; \
[exception raise]; \
} \

#define TIGHTDB_EXCEPTION_HANDLER_CORE_EXCEPTION(action) \
try { action } \
catch(std::exception& ex) { \
Expand Down