2011-12-15 2 views
0

안녕하세요. 내 앱에 SQLite를 연결하려고하는데 항상 작동하지 않는 경우 로그인이 실패했습니다 !!! 나는 그 때문에이 라인SQLite3을 앱에 연결

// b를 선택, loginTb에서 C의 실패 생각하고 여기서 B = '% 1 @'및 C = '% 1 @' ", loginName.text, password.text]

은 refernce를 내 전체 코드를 찾아주십시오

SQLite는 코드 :.

Last login: Thu Dec 15 11:24:55 on console 
Venkateshs-Mac-mini:~ venkateshnarasimhan$ sqlite3 login.db 
SQLite version 3.7.5 
Enter ".help" for instructions 
Enter SQL statements terminated with a ";" 
sqlite> .dump 
PRAGMA foreign_keys=OFF; 
BEGIN TRANSACTION; 
CREATE TABLE loginTb (a integer, b string, c string); 
INSERT INTO "loginTb" VALUES(1,'pradeep','password'); 
INSERT INTO "loginTb" VALUES(2,'kripya','password'); 
INSERT INTO "loginTb" VALUES(3,'ravi','password'); 
INSERT INTO "loginTb" VALUES(4,'venkatesh','password'); 
INSERT INTO "loginTb" VALUES(5,'veeru','password'); 
COMMIT; 
sqlite> 

XCODE :

-(BOOL)checkindatabase 
    { 
     NSArray *dirPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *docDir =[dirPath objectAtIndex:0]; 
     databasePath =[[NSString alloc] initWithString:[docDir stringByAppendingPathComponent:@"login.db"]]; 

     if(sqlite3_open([databasePath UTF8String], &contactDB) == SQLITE_OK) 
     { 
      NSLog(@"open"); 
      NSString *sql = [[NSString alloc] initWithFormat:@"select b,c from loginTb where b='%@' and c='%@'",loginName.text,password.text];   
      [sql UTF8String]; 
      sqlite3_stmt *statement; 
      if (sqlite3_prepare_v2(contactDB, [sql UTF8String], -1, &statement, NULL) == SQLITE_OK) 
      { if(sqlite3_step(statement) == SQLITE_ROW) 
      { 
       //user name is correct 
       //if u want to print in log use below code 
       uid =[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)]; 
       loginName.text = uid; 

       pwd =[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)]; 
       password.text = pwd; 
       return YES; 

      }else{ uid=0;pwd=0;} 
      }    
      sqlite3_finalize(statement); 
     } 
     sqlite3_close(contactDB); 
     return NO; 
    } 

-(IBAction)homePage: (id)sender 
{ 
    if([self checkindatabase]) 
    { 
     homepage *hvc = [[homepage alloc]initWithNibName: nil bundle: nil]; 
     hvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal; 
     [self presentModalViewController:hvc animated: YES]; 
    } 
    else 
    { 
     UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Login Failed!!!" 
                 message:@"Check your Id and Password" delegate:nil 
               cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
    } 
} 

답변

0
if(sqlite3_open([databasePath UTF8String], &contactDB) == SQLITE_OK) 
    { 
     NSLog(@"open"); 
     NSString *sql = [[NSString alloc] initWithFormat:@"select b,c from loginTb where b=\"%@\" and c=\"%@\"",loginName.text,password.text];  // using this line \"%@\" in b=\"%@\" 
     [sql UTF8String]; 
     sqlite3_stmt *statement; 
    your code follows........ 
0

SQLite를 디버깅하지 말고, 설정하기 쉽고 이해하기 쉬운 FMDB과 같은 래퍼를 사용하는 것이 좋습니다.

관련 문제