First create custom class UserDetails with NSString userName and userPassword.
Then you can try something like this to read data
- (UserDetails *)getUserDetails:(NSString *)userLogin password:(NSString *)userPassword
{
UserDetails *retVal;
sqlite3 *database;
NSString *dbPath = @"your_db_path";
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK){
const char *sql_statement = [[NSString stringWithFormat:@"select * from Users where UserLogin = '%@' and UserPassword = '%@'", userLogin, userPassword] UTF8String];
sqlite3_stmt *compiled_statement;
if(sqlite3_prepare_v2(database, sql_statement, -1, &compiled_statement, NULL) == SQLITE_OK){
while(sqlite3_step(compiled_statement) == SQLITE_ROW){
[retVal setUsername:[NSString stringWithUTF8String:(const char *)sqlite3_column_text(compiled_statement, 0)]];
[retVal setPassword:[NSString stringWithUTF8String:(const char *)sqlite3_column_text(compiled_statement, 1)]];
}
sqlite3_finalize(compiled_statement);
sqlite3_close(database);
}
}
return retVal;
}
And for inserting data you can use almost the same code but without returning values, so method will return void or some control value if you need it and only if you have errors in execution, while sql statement will be something like
Insert into Users(UserLogin, UserPassword) values ('%@', '%@')