Bonjour

Je rencontre un problème avec la mise à jour d'une base de données SQLite.

après la création de la base, j'ajoute les données avec cette fonction :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
	private void Readxml(SQLiteDatabase db, String dataname4, String string) {
		try {
			ContentValues _Values = new ContentValues();
			SAXParserFactory saxparser = SAXParserFactory.newInstance();
			SAXParser parser = saxparser.newSAXParser();
			XMLReader xmlReader = parser.getXMLReader();
			ParsingClass pc = new ParsingClass();
			xmlReader.setContentHandler(pc);
			InputStream is = new ByteArrayInputStream(
					CacheManager.loadCacheByte(Accueil.DIR_DATA, string));
			xmlReader.parse(new InputSource(is));
 
			String nom, adresse, date, jour, latitude, longitude, tel, ville, zip;
			int id;
			Log.w(TAG, "Reading XML " + string);
			for (int i = 0; i < pc.latitude.size() - 1; i++) {
					id = Integer.parseInt(pc.id.get(i));
					nom = pc.nom.get(i);
					adresse = pc.adresse.get(i);
					date = pc.date.get(i);
					jour = pc.jour.get(i);
					latitude = pc.latitude.get(i);
					longitude = pc.longitude.get(i);
					tel = pc.tel.get(i);
					ville = pc.ville.get(i);
					zip = pc.zip.get(i);
 
					_Values.put(COLUMN_ID, id);
					_Values.put(COLUMN_NOM, nom);
					_Values.put(COLUMN_ADR, adresse);
					_Values.put(COLUMN_DAT, date);
					_Values.put(COLUMN_DAY, jour);
					_Values.put(COLUMN_LON, longitude);
					_Values.put(COLUMN_LAT, latitude);
					_Values.put(COLUMN_TEL, tel);
					_Values.put(COLUMN_VIL, ville);
					_Values.put(COLUMN_ZIP, zip);
					Log.e("test", "value : " + nom);
					db.insert(dataname4, null, _Values);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
 
	}
J'utilise SAXparser pour lire les fichers xml stockés en local ainsi que la classe ParssingClass que voici :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
 
public class ParsingClass extends DefaultHandler {
 
	public ArrayList<String> id = new ArrayList<String>();
	public ArrayList<String> adresse = new ArrayList<String>();
	public ArrayList<String> tel = new ArrayList<String>();
	public ArrayList<String> ville = new ArrayList<String>();
	public ArrayList<String> zip = new ArrayList<String>();
	public ArrayList<String> nom = new ArrayList<String>();
	public ArrayList<String> date = new ArrayList<String>();
	public ArrayList<String> jour = new ArrayList<String>();
	public ArrayList<String> latitude = new ArrayList<String>();
	public ArrayList<String> longitude = new ArrayList<String>();
 
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		super.startElement(uri, localName, qName, attributes);
		if (localName.equalsIgnoreCase("nom")) {
			tempStore = "";
		} else if (localName.equalsIgnoreCase("adresse")) {
			tempStore = "";
		} else if (localName.equalsIgnoreCase("zip")) {
			tempStore = "";
		} else if (localName.equalsIgnoreCase("ville")) {
			tempStore = "";
		} else if (localName.equalsIgnoreCase("tel")) {
			tempStore = "";
		} else if (localName.equalsIgnoreCase("jour")) {
			tempStore = "";
		} else if (localName.equalsIgnoreCase("date")) {
			tempStore = "";
		} else if (localName.equalsIgnoreCase("latitude")) {
			tempStore = "";
		} else if (localName.equalsIgnoreCase("longitude")) {
			tempStore = "";
		} else if (localName.equalsIgnoreCase("id")) {
			tempStore = "";
		} else {
			tempStore = "";
		}
	}
 
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		super.endElement(uri, localName, qName);
		if (localName.equalsIgnoreCase(Accueil.KEY_NOM)) {
			nom.add(tempStore);
		} else if (localName.equalsIgnoreCase(Accueil.KEY_ADR)) {
			adresse.add(tempStore);
		} else if (localName.equalsIgnoreCase(Accueil.KEY_ZIP)) {
			zip.add(tempStore);
		} else if (localName.equalsIgnoreCase(Accueil.KEY_VILLE)) {
			ville.add(tempStore);
		} else if (localName.equalsIgnoreCase(Accueil.KEY_TEL)) {
			tel.add(tempStore);
		} else if (localName.equalsIgnoreCase(Accueil.KEY_JOUR)) {
			jour.add(tempStore);
		} else if (localName.equalsIgnoreCase(Accueil.KEY_DATE)) {
			date.add(tempStore);
		} else if (localName.equalsIgnoreCase(Accueil.KEY_LAT)) {
			latitude.add(tempStore);
		} else if (localName.equalsIgnoreCase(Accueil.KEY_LON)) {
			longitude.add(tempStore);
		} else if (localName.equalsIgnoreCase(Accueil.KEY_ID)) {
			id.add(tempStore);
		}
		tempStore = "";
	}
 
	private String tempStore = "";
 
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		super.characters(ch, start, length);
		tempStore += new String(ch, start, length);
	}
}
Lors du premier lancement de l'application, tout fonctionne correctement. En revanche, lorsque l'on doit mettre à jour la base de données (lorsque les xmls ont été modifiés). Le changement s'effectue mais celui-ci est extremement lent. Le temps de traitement passe de 10 secondes au premier lancement à plus de 5 minutes lors d'une mise à jour.

J'ai effectué plusieurs test et il semble que le ralentissement vient de l'ajout des données dans la base.
Avez-vous une idée de ce qui provoque ça ?