0

このエラーが発生した場合、以下のメソッドを実行して sqlite テーブルにデータを入力しています。

"DB SUPPORT - ERROR commentTable INSERT". 

私が間違っている場所について何か助けはありますか?

コード:

(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);

        if (sqlResult== SQLITE_OK)
        {
            if (sqlite3_step(statement) == SQLITE_DONE)
            {
                //BOOL ret = YES;
                NSLog(@"DB SUPPORT - commentTable INSERTED");
            }
            else
            {
                NSLog(@"DB SUPPORT - ERROR commentTable INSERT");
            }

        }
        else
        {
            NSLog(@"DB SUPPORT - Sql Preparing Error ( INSERT commentTable)");
        }

        sqlite3_finalize(statement);
    }
}
4

2 に答える 2

0

以下のコードを使用して終了しましたが、うまくいきました。誰かが将来同様の問題を経験した場合に備えて。

                                                                                                       `- (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;

}

} `

于 2013-07-14T08:27:17.487 に答える