我的應用程序從fmdatabase中讀取一些數據並使用核心圖庫以圖形方式顯示它。在我的應用程序第一次讀取數據庫時,所有這一切都很好,但問題是在將新數據插入數據庫之後,我執行了一個sql select語句,並且它不讀取插入的新行。我不知道可能是什麼問題,因爲在sqlite studio中,我在執行插入操作並獲取數據後執行相同的select語句。我如何從FMDatabase中讀取新插入的數據
我已經閱讀了有關我必須將資源數據庫複製到另一個文件夾,以便我可以讀/寫它,但也不工作。
你有什麼想法嗎?
我的開頭代碼是這樣的。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *writablePath = [docsPath stringByAppendingPathComponent:@"DatabaseName.sqlite"];
//this is the copy db from the resource database
FMDatabase *db = [FMDatabase databaseWithPath:writablePath];
這裏是插入和刪除的代碼。
if([db open]){
for (int i = 0; i < [updatedData count]; i++) {
z_ent = [((NSNumber *)([[updatedData objectAtIndex:i] valueForKey:@"ent"])) intValue];
z_opt = [((NSNumber *)[[updatedData objectAtIndex:i] valueForKey:@"opt"]) intValue];
zaniocorte = [((NSNumber *)[[updatedData objectAtIndex:i] valueForKey:@"anioCorte"]) intValue];
zmescorte = [((NSNumber *)[[updatedData objectAtIndex:i] valueForKey:@"mesCorte"]) intValue];
zestatus = [((NSNumber *)[[updatedData objectAtIndex:i] valueForKey:@"estatus"]) intValue];
zidcontraparte = [((NSNumber *)[[updatedData objectAtIndex:i] valueForKey:@"idContraparte"]) intValue];
zconsumomesa = [((NSNumber *)[[updatedData objectAtIndex:i] valueForKey:@"consumo"]) doubleValue];
zconsumototal = [((NSNumber *)[[updatedData objectAtIndex:i] valueForKey:@"consumoTotal"]) doubleValue];
zlinea = [((NSNumber *)[[updatedData objectAtIndex:i] valueForKey:@"linea"]) doubleValue];
zlineadisponible = [((NSNumber *)[[updatedData objectAtIndex:i] valueForKey:@"lineaDisponible"]) doubleValue];
zcontraparte = ((NSString *)[[updatedData objectAtIndex:i] valueForKey:@"contraparte"]);
zinstitucion = ((NSString *)[[updatedData objectAtIndex:i] valueForKey:@"institucion"]);
zmesa = ((NSString *)[[updatedData objectAtIndex:i] valueForKey:@"mesa"]);
ztiporiesgo = ((NSString *)[[updatedData objectAtIndex:i] valueForKey:@"tipoRiesgo"]);
queryUpdateInsert = [NSString stringWithFormat:@"INSERT INTO ZTESORERIACONSOLIDADO
(Z_ENT, Z_OPT, ZANIOCORTE, ZMESCORTE, ZCONSUMOMESA, ZCONSUMOTOTAL, ZESTATUS, ZLINEA, ZLINEADISPONIBLE, ZCONTRAPARTE, ZIDCONTRAPARTE, ZINSTITUCION, ZMESA, ZTIPORIESGO) VALUES (%d, %d, %d, %d, %f, %f, %f, %f, %f, '%@', %d, '%@', '%@', '%@');",z_ent, z_opt, zaniocorte, zmescorte, zconsumomesa, zconsumototal, zestatus, zlinea, zlineadisponible, zcontraparte, zidcontraparte, zinstitucion, zmesa, ztiporiesgo];
queryUpdateDelete = [NSString stringWithFormat:@"DELETE FROM ZTESORERIACONSOLIDADO WHERE ZMESCORTE = %d AND ZANIOCORTE = %d", zmescorte, zaniocorte-1];
del = [db executeUpdate:queryUpdateDelete];
ins = [db executeUpdate:queryUpdateInsert];
}
}
[db close];
您是否在插入後關閉了光標? – HalR