2011-12-26 4 views
1

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로 거의 변환 될 수 없기 때문에 왜 이것이 문제를 일으키는 지 알지 못합니다.

답변

0

GDB의 일반적인 영리함을 enum의 실제 값과 혼동하고 있다고 생각합니다. 예, 정수입니다 (다소 차이가 있습니다). 데이터베이스 브라우저에서 삽입 한 값과 데이터베이스를 확인해 보았습니까? 당신이 없다면 당신은 또한 명령 줄을 통해 "sqlite3"을 사용해 볼 수 있습니다.

+0

문제는 NULL 값으로 인해 삽입이 실패한다는 것입니다. '? '를'0'으로 바꾸면 성공하지만 해결책은 아닙니다. – Echilon

+0

정수로 변환 해 보았습니까? –

+0

고마워, 그게 부분적으로 (내 대답을 참조하십시오). – Echilon

2

캐스팅이 작동하지 않음 : (int)comp.componentSorting 그러나 NSNumber로 변환 : [NSNumber numberWithInt:(int)comp.componentSorting]. 이상하게도, 나는 FMDB가 int와 NSNumber에 대해 까다로울 수 있다고 들었다.