I’m using FMDB to serialize an object into a database, I have a non-nullable int column in which I’d like to store an enum value.
Person.h
@interface TreasureChest : NSObject {
...
ComponentSorting componentSorting;
}
@property (nonatomic, readwrite) ComponentSorting componentSorting;
@end
I’m declaring ComponentSorting in a separate class:
Constants.h
typedef enum ComponentSorting {
kSortOrderName = 0,
kSortOrderSortOrder = 1,
} ComponentSorting;
When I try to insert the value in the following statement, I get a “column ComponentSorting cannot be NULL” error, it’s as though either FMDB or the iOS implementation of SQLite is ignoring the enum.
[db executeUpdate:@"INSERT INTO Components (ComponentID, Name, Description, ComponentSorting) VALUES (?,?,?,?)",
comp.componentId,
comp.name,
comp.description,
comp.componentSorting
]
Debugging shows that comp.componentSorting is indeed kSortOrderName (set in the object’s init). Coming from a .NET background, enums are pretty much convertible to ints to I don’t see why this causes a problem.
I think you are confusing the general cleverness of GDB with the actual value of the enum. Yes it is an integer ( more or less ), have you tried checking the database and the values you inserted with an database browser yet? If you don’t have any you can also try using “sqlite3” through the command line.