public void insertMaps(List <MapDownloadResource> maps, Dictionary <string, string> mapsItemsCodes, Dictionary <string, string> regionItemsCodes, Context applicationContext) { try { if ((maps != null) && (mapsItemsCodes != null) && (regionItemsCodes != null)) { // create a compile statement for inserting the maps using transactions StringBuilder insertCommand = new StringBuilder("INSERT INTO "); insertCommand.Append(MAPS_TABLE).Append(" VALUES (?"); // the number of columns in maps table is 20 for (int i = 0; i < 20; i++) { insertCommand.Append(",?"); } insertCommand.Append(");"); resourcesDAO.getDatabase().BeginTransaction(); SQLiteStatement insertStatement = resourcesDAO.getDatabase().CompileStatement(insertCommand.ToString()); int columnIndex, lineIndex = 0; foreach (MapDownloadResource map in maps) { columnIndex = 1; lineIndex++; insertStatement.ClearBindings(); insertStatement.BindLong(columnIndex++, lineIndex); insertStatement.BindString(columnIndex++, map.Code); insertStatement.BindString(columnIndex++, mapsItemsCodes[map.Code]); if ((map.getSubType() != null) && map.getSubType().Equals(STATE_TYPE)) //ignorecode { insertStatement.BindString(columnIndex++, regionItemsCodes[map.Code]); } else { insertStatement.BindString(columnIndex++, ""); } // compute the string that contains all the name translations StringBuilder nameInAllSpecifiedLanguages = new StringBuilder(); if (map.getNames() != null) { foreach (var currentEntry in map.getNames()) { nameInAllSpecifiedLanguages.Append(currentEntry.Key).Append("=").Append(currentEntry.Value).Append(";"); } } if (nameInAllSpecifiedLanguages.Length > 1) { insertStatement.BindString(columnIndex++, nameInAllSpecifiedLanguages.ToString().Substring(0, nameInAllSpecifiedLanguages.Length - 1)); } else { insertStatement.BindString(columnIndex++, ""); } insertStatement.BindString(columnIndex++, map.getSKMFilePath()); insertStatement.BindString(columnIndex++, map.getZipFilePath()); insertStatement.BindString(columnIndex++, map.getTXGFilePath()); insertStatement.BindLong(columnIndex++, (int)map.getTXGFileSize()); insertStatement.BindLong(columnIndex++, (int)map.getSkmAndZipFilesSize()); insertStatement.BindLong(columnIndex++, (int)map.getSkmFileSize()); insertStatement.BindLong(columnIndex++, (int)map.getUnzippedFileSize()); insertStatement.BindDouble(columnIndex++, map.getBbLatMax()); insertStatement.BindDouble(columnIndex++, map.getBbLatMin()); insertStatement.BindDouble(columnIndex++, map.getBbLongMax()); insertStatement.BindDouble(columnIndex++, map.getBbLongMin()); insertStatement.BindString(columnIndex++, map.getSubType()); insertStatement.BindLong(columnIndex++, map.DownloadState); insertStatement.BindLong(columnIndex++, map.NoDownloadedBytes); insertStatement.BindLong(columnIndex++, 0); insertStatement.BindString(columnIndex, map.DownloadPath); insertStatement.Execute(); } } } finally { if ((maps != null) && (mapsItemsCodes != null)) { SKLogging.WriteLog(TAG, "Maps were inserted into database !!!", SKLogging.LogDebug); // close the GENERAL transaction resourcesDAO.getDatabase().SetTransactionSuccessful(); resourcesDAO.getDatabase().EndTransaction(); } } }