Iphone Sqlite数据库没有';t更新来自web服务的数据
我正在做一个从web服务获取JSON数据并在SQLite数据库中更新它的应用程序。我的问题是我从web服务中获取了值,但在上载时它显示为“null”。它没有更新 我的代码:-Iphone Sqlite数据库没有';t更新来自web服务的数据,iphone,ios,Iphone,Ios,我正在做一个从web服务获取JSON数据并在SQLite数据库中更新它的应用程序。我的问题是我从web服务中获取了值,但在上载时它显示为“null”。它没有更新 我的代码:- -(void) updateSignupTable: (NSDictionary*) json { //copying the values from web services NSString *balance = [json objectForKey:@"balance"]; NSStrin
-(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)
为了谨慎起见,以下几行:
sqlExecutObj.sql=[NSString stringWithFormat:@"UPDATE profile_table SET phone_number ='%@' balance = '%@' call_forward_status = '%@' WHERE profile_name= '%@'", phone_number ,balance, call_forward_Status, profileDetailTitle];
将'profileDetailTitle'指定为概要文件名称,但第二条语句是从数据库中读取数据的语句:
sqlExecutObj.sql=[NSString stringWithFormat:@"SELECT call_forward_status,phone_number,balance FROM profile_table WHERE profile_name= '%@'",selectedProfileName];
指定配置文件名称为“selectedProfileName”
在代码中,profileDetailTitle或selectedProfileName是什么并不明显。也许为了调试,您将它们都设置为相同的值
另外,可以肯定的是,如果profileDetailTitle或selectedProfileName是用户驱动的,或者可能只是包含非字母数字字符,那么您应该(或者)绑定、健全性检查和转义这些值。输入到数据库中的任何其他值也是如此-但这不适用于作用域;-) 什么是
sqlExecuteObj
?为什么要使用executeSelectQuery
执行更新
?sqlExecute.obj是类SQLite的变量,我在SQLite.h中有它,executeQuery是执行sqlExecuteobj.sql持有的查询的方法。我使用相同的过程在代码的不同位置存储任何静态变量,它可以工作,但是听说它坏了。也许它坏了?坏了?我怎样才能摆脱这个问题。嗨,谢谢你的回答。事实上,我通过更改变量名做了很多代码检查,这就是原因。但是“selectedProfileNAme”和“ProfileDEtailTitle”都具有相同的值。