あれとこれのコンバータ
修訂 | a1229f1946ef2ea825bbc30bd25577293e637f4e (tree) |
---|---|
時間 | 2011-12-03 16:40:23 |
作者 | masakih <masakih@user...> |
Commiter | masakih |
板移転履歴のコンバート
@@ -17,6 +17,7 @@ | ||
17 | 17 | #import "BSBoardInformationObject.h" |
18 | 18 | #import "BSThreadInformationObject.h" |
19 | 19 | #import "BSFavoriteObject.h" |
20 | +#import "BSBoardHistoryObject.h" | |
20 | 21 | |
21 | 22 | |
22 | 23 | @implementation BSDCAppDelegate |
@@ -174,6 +175,30 @@ | ||
174 | 175 | } |
175 | 176 | } |
176 | 177 | |
178 | +- (void)convertFavorites:(BSCoreDataManager *)cdm | |
179 | +{ | |
180 | + panel.message = @"Converting Favorites ..."; | |
181 | + DatabaseManager *dm = [DatabaseManager defaultManager]; | |
182 | + NSArray *favs = [cdm fetchDataForEntityName:@"Favorite" | |
183 | + predicate:nil]; | |
184 | + for(BSFavoriteObject *fav in favs) { | |
185 | + [self updateTime]; | |
186 | +// NSLog(@"%@", fav.thread.board.boardName); | |
187 | + NSUInteger boardID = [dm boardIDForURLString:fav.thread.board.boardURL]; | |
188 | + SQLiteReservedQuery *query = [self sqlForInsertFav]; | |
189 | + [query cursorWithFormat:F_Int F_NSNumberOfInt, | |
190 | + boardID, fav.thread.threadID]; | |
191 | + } | |
192 | +} | |
193 | + | |
194 | +- (void)loggingIfNeeded | |
195 | +{ | |
196 | + SQLiteDB *db = [[DatabaseManager defaultManager]databaseForCurrentThread]; | |
197 | + if([db lastErrorID] != SQLITE_OK) { | |
198 | + NSLog(@"%@", [db lastError]); | |
199 | + } | |
200 | +} | |
201 | + | |
177 | 202 | - (void)doConvertToSQLite |
178 | 203 | { |
179 | 204 | self.startTime = [NSDate dateWithTimeIntervalSinceNow:0.0]; |
@@ -198,10 +223,31 @@ | ||
198 | 223 | [pool release]; |
199 | 224 | [self updateTime]; |
200 | 225 | |
226 | + pool = [[NSAutoreleasePool alloc] init]; | |
201 | 227 | panel.message = @"Converting board histories ..."; |
202 | - // | |
228 | + DatabaseManager *dm = [DatabaseManager defaultManager]; | |
229 | + NSString *sql = [NSString stringWithFormat:@"INSERT INTO %@ (%@, %@, %@) VALUES (?, ?, ?);", | |
230 | + BoardInfoHistoryTableName, | |
231 | + BoardIDColumn, BoardNameColumn, BoardURLColumn]; | |
232 | + SQLiteReservedQuery *query = [[SQLiteReservedQuery alloc] initWithQuery:sql | |
233 | + usingSQLiteDB:[[DatabaseManager defaultManager] databaseForCurrentThread]]; | |
234 | + for(BSBoardInformationObject *board in boards) { | |
235 | + [self updateTime]; | |
236 | + NSUInteger boardID = [dm boardIDForURLString:board.boardURL]; | |
237 | + for(BSBoardHistoryObject *hist in board.histories) { | |
238 | + [self updateTime]; | |
239 | + [query cursorWithFormat:F_Int F_NSString F_NSString, | |
240 | + boardID, hist.boardName, hist.boardURL]; | |
241 | + [self loggingIfNeeded]; | |
242 | + } | |
243 | + } | |
244 | + [query release]; | |
203 | 245 | |
246 | + panel.amount = 0; | |
247 | + panel.count = 0; | |
248 | + [pool release]; | |
204 | 249 | [self updateTime]; |
250 | + | |
205 | 251 | pool = [[NSAutoreleasePool alloc] init]; |
206 | 252 | [self convertThreadsInBoards:boards]; |
207 | 253 | panel.amount = 0; |
@@ -210,21 +256,12 @@ | ||
210 | 256 | [self updateTime]; |
211 | 257 | |
212 | 258 | pool = [[NSAutoreleasePool alloc] init]; |
213 | - panel.message = @"Converting Favorites ..."; | |
214 | - // Fav | |
215 | - DatabaseManager *dm = [DatabaseManager defaultManager]; | |
216 | - NSArray *favs = [cdm fetchDataForEntityName:@"Favorite" | |
217 | - predicate:nil]; | |
218 | - for(BSFavoriteObject *fav in favs) { | |
219 | -// NSLog(@"%@", fav.thread.board.boardName); | |
220 | - NSUInteger boardID = [dm boardIDForURLString:fav.thread.board.boardURL]; | |
221 | - SQLiteReservedQuery *query = [self sqlForInsertFav]; | |
222 | - [query cursorWithFormat:F_Int F_NSNumberOfInt, | |
223 | - boardID, fav.thread.threadID]; | |
224 | - } | |
259 | + [self convertFavorites:cdm]; | |
260 | + panel.amount = 0; | |
261 | + panel.count = 0; | |
262 | + [pool release]; | |
225 | 263 | |
226 | 264 | finish: |
227 | - [pool release]; | |
228 | 265 | [NSApp endModalSession:session]; |
229 | 266 | [panel.window close]; |
230 | 267 | [panel release]; |