SQlite - iPhone sdk - Assertion Failed
I am trying to save values in SQLite Database in iPhone sdk. When I execute this line
[database executeNonQuery:strQuery1];
This message is printed on the console.
SQLite Step Failed: constraint failed
Here's brief Header file info. I have declared it in my View Controller Header using this line.
Sqlite *database;
And here's the header of SQlite
@interface Sqlite : NSObject
{
NSInteger busyRetryTimeout;
NSString *filePath;
sqlite3 *_db;
}
@property (readwrite) NSInteger busyRetryTimeout;
@property (readonly) NSString *filePath;
+ (NSString *)createUuid;
+ (NSString *)version;
- (id)initWithFile:(NSString *)filePath;
- (BOOL)open:(NSString *)filePath;
- (void)close;
- (NSInteger)errorCode;
- (NSString *)errorMessage;
- (NSArray *)executeQuery:(NSString *开发者_如何学Python)sql, ...;
- (NSArray *)executeQuery:(NSString *)sql arguments:(NSArray *)args;
- (BOOL)executeNonQuery:(NSString *)sql, ...;
- (BOOL)executeNonQuery:(NSString *)sql arguments:(NSArray *)args;
- (BOOL)commit;
- (BOOL)rollback;
- (BOOL)beginTransaction;
- (BOOL)beginDeferredTransaction;
If only there was some sort of on line resource where you could go and enter "constraint failed" in a search box to get the answer.
Since that is sadly not the case, I'll tell you. The problem is most likely that you are violating a key constraint with your query. It's hard to say without seeing the query and the database schema, but you might be, for instance, trying to insert a row with a duplicate primary key or insert a row with a foreign key that does not exist in the referenced table.
Executing it in the SQLliteManager won't help you, it's a bit different on the iPhone. You should be able to get an error from the Database using the errorMessage property. And yes, also give us the query itself.
Are you sure the mystery query isn't an INSERT
query, and are you sure it isn't executed twice by your mystery code?
That would explain that you're not seeing an error when executing the query (once) manually.
精彩评论