저는 iOS 개발에 초보자입니다. Sqllite 데이터베이스를 처음 사용하십시오.이 질문에 대해서는 유감이지만 너무 혼란 스럽습니다. 해결책을주세요. iOS의 Sqllite 테이블에서 다른 값을 표시하는 방법?
나는 그리고 내가 원하는과 고유 가치를 위해 내가 쓰기 때문에 그것은 또한, 테이블에서 중복 값을 추가로 데이터베이스에 데이터를 추가-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
sqlite3_stmt *statement;
const char *dbpath = [_databasePath UTF8String];
if (sqlite3_open(dbpath, &_myDatabase) == SQLITE_OK) {
NSString *insertSQL = [NSString stringWithFormat:
@"INSERT INTO ALLREADTABLE (PostId, PostTitle, ImageLink, ShortDescription,Category,PostDate) VALUES (\"%@\", \"%@\", \"%@\", \"%@\",\"%@\",\"%@\")",
post_id, cell.headLabel.text, image,self.shortDiscription,cell.categoryLabel.text,cell.timeLabel.text];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(_myDatabase, insert_stmt,
-1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSString *string=[NSString stringWithFormat:@"Value Added %@ %@ %@ %@ %@ %@",post_id, cell.headLabel.text, image,self.shortDiscription,cell.categoryLabel.text,cell.timeLabel.text];
NSLog(@"String %@",string);
} else
{
NSLog(@"Failed to add contact");
}
sqlite3_finalize(statement);
sqlite3_close(_myDatabase);
}
로 내 Sqllite 표 등으로 데이터를 추가 코드는
[NSPlaceholderString initWithUTF8String:]: NULL cString
로 H처럼 나에게 오류를주고 그 다음
- (void)getTextFomDB
{
NSString *docsDir;
NSArray *dirPaths;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
// Build the path to the database file
_databasePath = [[NSString alloc]
initWithString: [docsDir stringByAppendingPathComponent:
@"sampleDatabase.db"]];
const char *dbpath = [_databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &_myDatabase) == SQLITE_OK)
{
NSString *querySQL = @"SELECT DISTINCT PostId, PostTitle, ImageLink, ShortDescription,Category,PostDate FROM ALLREADTABLE";
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(_myDatabase, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
[self.postId removeAllObjects];
[self.postTitle removeAllObjects];
[self.imageLink removeAllObjects];
[self.shortDecsription removeAllObjects];
[self.category removeAllObjects];
[self.postDate removeAllObjects];
while (sqlite3_step(statement) == SQLITE_ROW) {
//NSString *personID = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 0)];
NSString *postId = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 1)];
NSString *postTitle = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 2)];
NSString *ImageLink = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 3)];
NSString *shortDescrip = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 4)];
NSString *Category = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 5)];
NSString *postDate = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 6)];
[self.postId addObject:[NSString stringWithFormat:@"%@ ", postId]];
[self.postTitle addObject:[NSString stringWithFormat:@"%@ ",postTitle]];
[self.imageLink addObject:[NSString stringWithFormat:@"%@",ImageLink]];
[self.shortDecsription addObject:[NSString stringWithFormat:@" %@",shortDescrip]];
[self.category addObject:[NSString stringWithFormat:@" %@",Category]];
[self.postDate addObject:[NSString stringWithFormat:@" %@",postDate]];
}
sqlite3_finalize(statement);
}
sqlite3_close(_myDatabase);
}
}
으로 같은 데이터를 가져 내 SqlliteTable에서 고유 한 값을 원하기 때문에? 제발 해결책을주세요. 나는 그것이 쉽다는 것을 알고있다 그러나 나는 데이터베이스에있는 초보자이다. 그래서 미안하다 그리고 사전에 감사합니다.
왜이 태그가 MySQL로 태그 되나요? – shmosel