SELECT
    a.seq
  , a.nm_logi_file
  , a.nm_phys_file
  , a.yn_mbil_add
FROM ddtbt_atch_file_dtil2 a
INNER JOIN ddtbt_tppg b ON a.id_atch_file = b.id_dwg_atch_file
WHERE b.cd_tppg = '';

를 구현한다고 하면...

-(DDTBT_ATCH_FILE_DTIL *) hjhImageFileTitledMapReturn:(NSString *) param
{
    NSString *query = [NSString stringWithFormat:@"select a.seq, a.nm_logi_file, a.nm_phys_file, a.yn_mbil_add from ddtbt_atch_file_dtil2 a \
                       inner join ddtbt_tppg b on a.id_atch_file=b.id_dwg_atch_file \
                       where b.cd_tppg='%@';"
                       ,param
                       ];
    NSLog(@" hjhImageFileTitledMapReturn query = %@", query);
    [self checkBackDB];
    
    if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {  //성공적으로 열림
        const char *sqlStatement = [query cStringUsingEncoding:NSUTF8StringEncoding];
        sqlite3_stmt *compiledStatement;
        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
            // Loop through the results and add them to the feeds array
            while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
                DDTBT_ATCH_FILE_DTIL *atch = [[DDTBT_ATCH_FILE_DTIL alloc] init];
                atch.seq = sqlite3_column_int(compiledStatement, 0);
                atch.nm_logi_file = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
                atch.nm_phys_file = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
                atch.yn_mbil_add = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
                
                NSLog(@"hjhImageFileTitledMapReturn2 %@ %ld %@ %@", atch.nm_logi_file, (long)atch.seq, atch.nm_phys_file, atch.yn_mbil_add);
                sqlite3_finalize(compiledStatement);
                [self checkBackDB];
                return atch;
            }
        }
        // Release the compiled statement from memory
        sqlite3_finalize(compiledStatement);
        [self checkBackDB];
    } else {
        [self checkBackDB];
    }
    
    return nil;
}

 

이렇게 한다.

'Objective-C, SQLite3' 카테고리의 다른 글

UIAlertController  (0) 2021.05.31
nullable, nonnull  (0) 2021.05.26
sqlite3 파일 생성  (0) 2021.05.26
sql 공통 .h, .m 작성법  (0) 2021.05.26
iOS Photokit  (0) 2021.05.26

+ Recent posts