0

iPhone開発初心者です。

以下の手順でデータベースからレコードを取得したいと考えています。

しかし、検索した値をsearchDbAuthorId1 or searchDbQuoteIdメソッドに渡すと、BAD ACCESSメッセージが表示されました。

if(sqlite3_open([self.databasePath UTF8String], &database) == SQLITE_OK) 
    {
        NSString *querySQL = [NSString stringWithFormat:@"select distinct(qot.id), key.Authorid,  key.Keyword, qot.Quotes from Keywords key inner JOIN Quotes qot on key.Authorid=qot.AuthorID where key.Keyword like \'%@\'",dataSearch];
        sqlite3_stmt *compiledStatement;
        const char *query_stmt = [querySQL UTF8String];
        if(sqlite3_prepare_v2(database, query_stmt, -1, &compiledStatement, NULL) == SQLITE_OK)
        {
            while (sqlite3_step(compiledStatement)==SQLITE_ROW)
            {
                NSString *searchDbAuthorId1 =  [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(compiledStatement, 1)];
                NSString *searchDbQuoteId1 =  [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(compiledStatement, 0)];
                NSString *searchDbKeyword1 =  [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(compiledStatement, 2)];
                NSString *searchDbQuote1 =  [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(compiledStatement, 3)];

                terms *Objterm = [[terms alloc] init];
                Objterm->searchDbQuoteId = searchDbQuoteId1;
                Objterm->searchDbAuthorId = searchDbAuthorId1; 
                Objterm->searchDbKeyword = searchDbKeyword1;
                Objterm->searchDbQuote = searchDbQuote1;

                NSLog(@"searchDbQuoteId = %@",Objterm->searchDbQuoteId);
                NSLog(@"searchDbAuthorId = %@",Objterm->searchDbAuthorId);
                NSLog(@"searchDbKeyword= %@",Objterm->searchDbKeyword);
                NSLog(@"searchDbQuote= %@",Objterm->searchDbQuote);

                NSLog(@"searchDbQuoteId = %d",Objterm->searchDbQuoteId);
                NSLog(@"searchDbAuthorId = %d",Objterm->searchDbAuthorId);

NSLOG本当の価値を知っていた。

以下は、%@

これらは私が必要とした正しい値です

2011-12-12 23:03:50.612 Quotes[1039:207] searchDbQuoteId = 15
2011-12-12 23:03:50.988 Quotes[1039:207] searchDbAuthorId = 6

と値%d

そして、私はこれらの値を取得しています

2011-12-12 23:03:52.332 Quotes[1039:207] searchDbQuoteId = 109590272
2011-12-12 23:03:53.580 Quotes[1039:207] searchDbAuthorId = 109607456

前もって感謝します。

4

2 に答える 2

4

あなたの質問は私にはあまり意味がありません。もっと情報が必要ですが、あなたはすでに問題を突き止めているようです。だから、あなたのタイトルに答える:

値を Nsstring から NSinteger に変換する方法

-integerValueNSStringのメソッドを使用できます。

NSInteger integer = [string integerValue];
于 2011-12-12T18:16:08.463 に答える
2

NSInteger myInt = [myString intValue];質問のタイトルに対する答えです。ただ、質問内容がいまいちで、何をおっしゃっているのかよくわかりません。

于 2011-12-12T18:15:45.663 に答える