0

Web サービスから JSON データを取得し、SQLite データベースで更新するアプリを実行しています。私の問題は、Web サービスから値を取得しましたが、アップロード中に「null」と表示されることです。更新されていません。

私のコード:-

-(void) updateSignupTable: (NSDictionary*) json {
    //copying the values from web services

    NSString *balance =  [json objectForKey:@"balance"];
    NSString *phone_number =[json objectForKey:@"sim_number"];
    NSString *call_forward_Status = [json objectForKey:@"call_forward_status"];

//データベースに格納

    sqlExecutObj.sql=[NSString stringWithFormat:@"UPDATE profile_table SET phone_number ='%@' balance = '%@' call_forward_status = '%@' WHERE profile_name= '%@'", phone_number ,balance, call_forward_Status, profileDetailTitle];

    sqlExecutObj.dataTypeArray=[[NSMutableArray alloc]initWithObjects:@"1",@"1",@"1",nil];

    [sqlExecutObj executeSelectQuery];
///reloading the table    
    [profileDetailView.detailsTableView reloadData];

    // fetch and print the  updated datas from SQLite

    sqlExecutObj.sql=[NSString stringWithFormat:@"SELECT call_forward_status,phone_number,balance FROM profile_table WHERE profile_name= '%@'",selectedProfileName];

    sqlExecutObj.dataTypeArray=[[NSMutableArray alloc]initWithObjects:@"1",@"1",@"1",nil];

    [sqlExecutObj executeSelectQuery];

    NSLog(@"result from table are: %@. and  %@, and %@", [[sqlExecutObj.result objectAtIndex:0] objectAtIndex:0],[[sqlExecutObj.result objectAtIndex:1] objectAtIndex:0],[[sqlExecutObj.result objectAtIndex:2]objectAtIndex:0] );
}

私のデバッグ出力:-

2013-05-14 15:54:02.910 Movirtu[44262:19d03] result from table are: (null). and  (null), and (null)
4

1 に答える 1

0

念のため、次の行を示します。

 sqlExecutObj.sql=[NSString stringWithFormat:@"UPDATE profile_table SET phone_number ='%@' balance = '%@' call_forward_status = '%@' WHERE profile_name= '%@'", phone_number ,balance, call_forward_Status, profileDetailTitle];

profile_name として 'profileDetailTitle を指定しますが、データベースからデータを読み取る 2 番目のステートメントは次のとおりです。

sqlExecutObj.sql=[NSString stringWithFormat:@"SELECT call_forward_status,phone_number,balance FROM profile_table WHERE profile_name= '%@'",selectedProfileName];

profile_name が「selectedProfileName」であることを指定します。

コードでは、profileDetailTitle または selectedProfileName が何であるかが明確ではありません。おそらくデバッグのために、両方を同じ値に設定します。

また、念のために言うと、profileDetailTitle または selectedProfileName のいずれかがユーザー主導であるか、英数字以外の文字が含まれているだけの場合は、(いずれか) バインディング、サニティ チェック、それらの値のエスケープを行う必要があります。データベースに入力される他の値についても同じことが言えますが、これは範囲外です ;-)

于 2013-05-14T14:06:55.660 に答える