Objective c 从数组插入sqlite表
当我得到这个错误时,我正在执行下面提到的方法来填充sqlite表:Objective c 从数组插入sqlite表,objective-c,sqlite,Objective C,Sqlite,当我得到这个错误时,我正在执行下面提到的方法来填充sqlite表: "DB SUPPORT - ERROR commentTable INSERT". 我哪里出了问题,有什么帮助吗 代码: (void)saveSales:(NSMutableArray*)aSalesArray { NSDate*现在=[NSDate日期]; ////////////////////////////////////////////////////////////// 对于(int i=0;i 在第一行末尾有一
"DB SUPPORT - ERROR commentTable INSERT".
我哪里出了问题,有什么帮助吗
代码:
(void)saveSales:(NSMutableArray*)aSalesArray
{
NSDate*现在=[NSDate日期];
//////////////////////////////////////////////////////////////
对于(int i=0;i
在第一行末尾有一个反斜杠\
,我认为它会被解释为导致无效查询的字符串值。(检查您的日志?我使用了下面的代码,它起了作用。以防万一将来有人遇到类似问题
`- (void) saveSales: (NSMutableArray*)aSalesArray
{
NSDate*now=[NSDate-date];
for(int i=0;iI删除了\并且仍然得到相同的错误。我查看了日志,sql语句是正确的。还记录了错误代码和消息;)
NSString *selectSql = [NSString stringWithFormat: @"INSERT INTO Spaza_Sales (fklSpazaID,fklItemID,lSellingPrice,lQuantity,bLooseDraw,bLosDrawPacket,sDeviceUID,dtTimestamp)\
VALUES ('%d','%@','%@','%@',%i,%i,'%@','%@')",0,fklItemID, lSellingPrice, lQuantity, bLooseDraw,bLooseDrawPacket,sDeviceUID,now];
`- (void) saveSales: (NSMutableArray*)aSalesArray
NSDate* now = [NSDate date];
for(int i=0;i<[aSalesArray count];i++)
{
NSMutableDictionary *myDict = [aSalesArray objectAtIndex:i];
NSString * fklItemID =[myDict valueForKey:@"fklItemD"];
NSString * lSellingPrice = [myDict valueForKey:@"lSellingPrice"];
NSString * lQuantity = [myDict valueForKey:@"lQuantity"];
bool bLooseDraw = [myDict valueForKey:@"bLooseDraw"];
bool bLooseDrawPacket = [myDict valueForKey:@"bLooseDrawPacket"];
NSString *sDeviceUID = [myDict valueForKey:@"sDeviceUID"];
NSString *selectSql = [NSString stringWithFormat: @"INSERT INTO Spaza_Sales (fklSpazaID,fklItemID,lSellingPrice,lQuantity,bLooseDraw,bLosDrawPacket,sDeviceUID,dtTimestamp) VALUES ('%d','%@','%@','%@',%i,%i,'%@','%@')",0,fklItemID, lSellingPrice, lQuantity, bLooseDraw,bLooseDrawPacket,sDeviceUID,now];
const char *sql = [selectSql UTF8String];
NSLog(@"The SQl String is %@",selectSql);
sqlite3_stmt *statement;
// Prepare the statement to compile the SQL query into byte-code
int sqlResult = sqlite3_prepare_v2(database, sql, -1, &statement, NULL);
NSLog(@"The SQl String is %d",sqlResult);
sqlite3_step(statement);
NSLog(@"Executed sqlite3_step ");
//If the result is SQLITE_OK, we step through the results one row at a time using the sqlite3_step function:
if ( sqlResult== SQLITE_OK) {
// Step through the results - once for each row.
NSLog(@"Record Updated");
// Finalize the statement to release its resources
sqlite3_finalize(statement);
}
else {
NSLog(@"Problem with the database:");
NSLog(@"%d",sqlResult);
}
//return products;
}