-1

、、、、、という名前の5つNameの列IDを持つSQLiteデータベースがあります。ChildIDParentIDBrotherID

このデータベースには多くのレコードがあり、すべての列の値の 1 つを配列に格納して、この配列を返したいと考えています。たとえば、ParentID列のすべての値を取得したい。私はこのクエリコードを使用します:

Select ParentID from Table1(Table1 はテーブルの名前です)

これは、特定の列から配列を取得するための私のコードです:

/*==================================================================
 METHOD FOR GETTING MIDIFIED FROM DATABASE
 ==================================================================*/
- (NSMutableArray*)readingModified
{
     ModiArray = [[NSMutableArray alloc] init];
    // Setup the database object
    sqlite3 *database2;
    // Open the database from the users filessytem
    if(sqlite3_open([[self DatabaseSqlite] UTF8String], &database2) == SQLITE_OK)
    {
        // Setup the SQL Statement and compile it for faster access
        //SQLIte Statement
        NSString *sqlStatement_userInfo =[NSString stringWithFormat:@"Select ParentID from Table1"];
        sqlite3_stmt *compiledStatement;
        if(sqlite3_prepare_v2(database2, [sqlStatement_userInfo UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)
        {
            // Loop through the results and add them to the feeds array
            while(sqlite3_step(compiledStatement) == SQLITE_ROW)
            {
                // Init the Data Dictionary
                NSMutableDictionary *_dataDictionary2=[[NSMutableDictionary alloc] init];
                NSString *_recordParentID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
                [_dataDictionary2 setObject:[NSString stringWithFormat:@"%@",_recordModified] forKey:@"ParentID"];
                [array addObject:_dataDictionary2];
            }
        }
        else
        {
            NSLog(@"No Data Found");
        }
        // Release the compiled statement from memory
        sqlite3_finalize(compiledStatement);
    }
    sqlite3_close(database2);

    return ModiArray;
}

私の間違いを教えてください。

4

2 に答える 2

4

私の友人は少し気をつけてください。

このコードは正しいですが、間違いがあります: [array addObject:_dataDictionary2];

代わりにarray置くModiArray

/*==================================================================
 METHOD FOR GETTING MIDIFIED FROM DATABASE
 ==================================================================*/
- (NSMutableArray*)readingModified
{
     ModiArray = [[NSMutableArray alloc] init];
    // Setup the database object
    sqlite3 *database2;
    // Open the database from the users filessytem
    if(sqlite3_open([[self DatabaseSqlite] UTF8String], &database2) == SQLITE_OK)
    {
        // Setup the SQL Statement and compile it for faster access
        //SQLIte Statement
        NSString *sqlStatement_userInfo =[NSString stringWithFormat:@"Select ParentID from Table1"];
        sqlite3_stmt *compiledStatement;
        if(sqlite3_prepare_v2(database2, [sqlStatement_userInfo UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)
        {
            // Loop through the results and add them to the feeds array
            while(sqlite3_step(compiledStatement) == SQLITE_ROW)
            {
                // Init the Data Dictionary
                NSMutableDictionary *_dataDictionary2=[[NSMutableDictionary alloc] init];
                NSString *_recordParentID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
                [_dataDictionary2 setObject:[NSString stringWithFormat:@"%@",_recordModified] forKey:@"ParentID"];
                [ModiArray addObject:_dataDictionary2];
            }
        }
        else
        {
            NSLog(@"No Data Found");
        }
        // Release the compiled statement from memory
        sqlite3_finalize(compiledStatement);
    }
    sqlite3_close(database2);

    return ModiArray;
}
于 2013-05-29T11:42:09.523 に答える