FMDB를 사용하여 개체를 데이터베이스로 serialize 할 때 enum 값을 저장하려는 null이 아닌 int 열이 있습니다.FMDB typedef enum 값 저장
Person.h 내가 별도의 클래스에 ComponentSorting
를 선언하고있어
@interface TreasureChest : NSObject {
...
ComponentSorting componentSorting;
}
@property (nonatomic, readwrite) ComponentSorting componentSorting;
@end
: 나는의 값을 삽입 할 때
Constants.h
typedef enum ComponentSorting {
kSortOrderName = 0,
kSortOrderSortOrder = 1,
} ComponentSorting;
다음 진술, "열 ComponentSorting NULL 수 없습니다"얻을 오류, 그것은 FMDB 나 SQLite의 iOS 구현은 enum을 무시하고 있습니다.
[db executeUpdate:@"INSERT INTO Components (ComponentID, Name, Description, ComponentSorting) VALUES (?,?,?,?)",
comp.componentId,
comp.name,
comp.description,
comp.componentSorting
]
디버깅 comp.componentSorting
실제로 kSortOrderName
(에서 설정 한 객체의 init
)임을 보여줍니다. .NET 배경에서 나오기 때문에 enum은 ints로 거의 변환 될 수 없기 때문에 왜 이것이 문제를 일으키는 지 알지 못합니다.
문제는 NULL 값으로 인해 삽입이 실패한다는 것입니다. '? '를'0'으로 바꾸면 성공하지만 해결책은 아닙니다. – Echilon
정수로 변환 해 보았습니까? –
고마워, 그게 부분적으로 (내 대답을 참조하십시오). – Echilon