Kordosch Posté(e) 4 février 2015 Share Posté(e) 4 février 2015 Bonjour à tous. Bon, j'ai une problème avec ma base de données android faite avec le code suivant : package com.example.kordosch.parionslol; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class BDDOpenHelperLOL extends SQLiteOpenHelper{ private final static String TAG = BDDOpenHelperLOL.class.getName(); private final static String DB_name = "lol.db"; private final static int DB_CURRENT_VERSION = 11; public BDDOpenHelperLOL(Context context) { super(context, DB_name, null, DB_CURRENT_VERSION); } @[member=override] public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub try { db.beginTransaction(); db.execSQL("Create table Utilisateurs" + "(pseudo TEXT PRIMARY KEY," + "password TEXT," + "point INTEGER);"); db.execSQL("Create table tournois" + "(nom TEXT PRIMARY KEY);"); db.execSQL("Create table Equipe" + "(idEquipe INTEGER PRIMARY KEY AUTOINCREMENT," + "nomEquipe TEXT," + "abrEquipe TEXT);"); db.execSQL("Create table Parties(" + "idParties int AUTO_INCREMENT," + "date Date," + "heureDebut int," + "tempMinute int," + "nom Varchar(25)," + "idEquipe1 int," + "idEquipe2 int," + "CONSTRAINT pk_Parties PRIMARY KEY (idParties)," + "CONSTRAINT fk_Nom FOREIGN key (nom) REFERENCES Tournois(nom)," + "CONSTRAINT fk_idEquipe1 FOREIGN key (idEquipe1) REFERENCES Equipe(idEquipe)," + "CONSTRAINT fk_idEquipe2 FOREIGN key (idEquipe2) REFERENCES Equipe(idEquipe));"); db.execSQL("Create table Score(" + "idScore int AUTO_INCREMENT," + "idEquipe int," + "idParties int," + "scoreEffectif int," + "CONSTRAINT pk_Score PRIMARY KEY (idScore)," + "CONSTRAINT fk_idParties FOREIGN key (idParties) REFERENCES Parties(idParties)," + "CONSTRAINT fk_idEquipe FOREIGN key (idEquipe) REFERENCES Equipe(idEquipe));"); db.execSQL("Create table Pari(" + "IdPari int AUTO_INCREMENT," + "Duree int," + "ScoreEq1 int," + "ScoreEq2 int," + "pseudo Varchar(25)," + "idParties int," + "CONSTRAINT pk_Pari PRIMARY KEY (IdPari)," + "CONSTRAINT fk_idPartie_pari FOREIGN key (idParties) REFERENCES Parties(idParties)," + "CONSTRAINT fk_Pseudo FOREIGN key (pseudo) REFERENCES Utilisateurs(pseudo));"); db.execSQL("Insert into Utilisateurs (pseudo, password, point)"+ "Values ('Kordosch', 'kabuki', 150),"+ "('Truite', 'javier', 100)," + "('Moko', 'turquoise', 10);" + "Insert into tournois (nom)" + "Values ('LCS Spring 2014')," + "('LCS Summer 2014')," + "('Mondiale 2014')," + "('LCS Spring 2015');" + "Insert into Equipe (idEquipe, nomEquipe, abrEquipe)" + "Values ('1', 'Samsung blue', 'SB')," + "('2', 'Moscow 5', 'M5')," + "('3', 'Samsung white', 'SW')," + "('4', 'Team Liquid', 'TL')," + "('5', 'Gravity', 'Gra')," + "('6', 'WinterFox', 'WF')," + "('7', 'Cloud9', 'Cl9')," + "('8', 'Fnatic', 'Fna')," + "('9', 'Roccat', 'Roc');" + "" + "insert into Parties (idParties, date, heureDebut, tempMinute, nom, idEquipe1, idEquipe2)" + "Values(1, '2014-02-05', 11, 35, 'LCS Spring 2014', 1, 2)," + "(2, '2014-02-08', 11, 40, 'LCS Spring 2014', 3, 4)," + "(3, '2014-02-10', 11, 24, 'LCS Spring 2014', 5, 6)," + "(4, '2014-02-12', 11, 18, 'LCS Spring 2014', 7, 8)," + "(5, '2014-03-08', 11, 28, 'LCS Spring 2014', 1, 4)," + "(6, '2014-03-16', 11, 40, 'LCS Spring 2014', 5, 8)," + "(7, '2014-04-05', 11, 20, 'LCS Spring 2014', 1, 8);" + "" + "insert into Parties (idParties, date, heureDebut, tempMinute, nom, idEquipe1, idEquipe2)" + "Values(8, '2014-06-05', 11, 35, 'LCS Spring 2014', 1, 2)," + "(9, '2014-06-08', 11, 40, 'LCS Summer 2014', 3, 4)," + "(10, '2014-06-10', 11, 24, 'LCS Summer 2014', 5, 9)," + "(11, '2014-06-12', 11, 18, 'LCS Summer 2014', 7, 8)," + "(12, '2014-07-08', 11, 28, 'LCS Summer 2014', 1, 3)," + "(13, '2014-07-16', 11, 40, 'LCS Summer 2014', 9, 8)," + "(14, '2014-08-05', 11, 20, 'LCS Summer 2014', 3, 8);" + "" + "insert into Parties (idParties, date, heureDebut, tempMinute, nom, idEquipe1, idEquipe2)" + "Values(15, '2014-09-05', 11, 35, 'Mondiale 2014', 1, 4)," + "(16, '2014-09-08', 11, 40, 'Mondiale 2014', 5, 2)," + "(17, '2014-09-10', 11, 24, 'Mondiale 2014', 3, 6)," + "(18, '2014-09-12', 11, 18, 'Mondiale 2014', 9, 8)," + "(19, '2014-10-08', 11, 28, 'Mondiale 2014', 2, 4)," + "(20, '2014-10-16', 11, 40, 'Mondiale 2014', 6, 8)," + "(21, '2014-11-05', 11, 20, 'Mondiale 2014', 4, 6);" + "" + "insert into Parties (idParties, date, heureDebut, tempMinute, nom, idEquipe1, idEquipe2)" + "Values(22, '2015-02-05', 11, 35, 'LCS Spring 2015', 1, 4)," + "(23, '2015-02-08', 11, 40, 'LCS Spring 2015', 5, 2)," + "(24, '2015-02-10', 11, 24, 'LCS Spring 2015', 3, 6)," + "(25, '2015-02-12', 11, 18, 'LCS Spring 2015', 9, 8);" + "" + "Insert into Score (idScore, idEquipe, idParties, scoreEffectif)" + "Values (1,1,1, 18)," + "(2,2,1,19)," + "(3,3,2,15)," + "(4,4,2,23)," + "(5,5,3,14)," + "(6,6,3,28)," + "(7,7,4,16)," + "(8,8,4,3)," + "(9,1,5,42)," + "(10,4,5,10)," + "(11,5,6,15)," + "(12,8,6,18)," + "(13,1,7,20)," + "(14,8,7,19)," + "(15,1,8,42)," + "(16,2,8,26)," + "(17,3,9,37)," + "(18,4,9,49)," + "(19,5,10,12)," + "(20,9,10,15)," + "(21,7,11,16)," + "(22,8,11,19)," + "(23,1,12,7)," + "(24,3,12,16)," + "(25,9,13,21)," + "(26,8,13,22)," + "(27,3,14,11)," + "(28,8,14,49)," + "(29,1,15,45)," + "(30,4,15,46)," + "(31,5,16,15)," + "(32,2,16,16)," + "(33,3,17,17)," + "(34,6,17,16)," + "(35,9,18,19)," + "(36,8,18,26)," + "(37,2,19,14)," + "(38,4,19,18)," + "(39,6,20,11)," + "(40,8,20,20)," + "(41,4,21,15)," + "(42,6,21,4)," + "(43,1,22,16)," + "(44,4,22,30);" + "" + "insert into Pari (IdPari, Duree,ScoreEq1,ScoreEq2,pseudo,idParties)" + "Values(1, 27, 12, 16, 'Kordosch', 1)," + "(2, 27, 12, 16, 'Truite', 1)," + "(3, 18, 18, 18, 'Moko', 1);"); db.setTransactionSuccessful(); } catch (Exception e) { Log.e(TAG, "db exception : " + e); } finally { db.endTransaction(); } } @[member=override] public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) { // TODO Auto-generated method stub } } Bref, il créé plusieurs table. Ma première table permet à l’utilisateur de se connecter, ça ne relève pas d'erreur. Pour la suite je créé un curseur récupérant les tournois. Cursor c = null; c = db.query("tournois", new String[]{"nom"}, null, null, null, null, null); Ce curseur devrait donc récupérer tout les noms des tournois. Mais je l'affiche avec une alerte et le décompte de ces tournois renvois un 0. J'ai tenté avec les autres tables de ma base de donnée et toute sont vide, sauf la 1ère. (Il devrait y avoir une erreur relevé par le programme lors des inserts qui sont fait en une seule requête, mais l'exception n'est jamais relevé.) Voila bien longtemps que je suis bloqué à cause de ce problème. Si quelqu'un veux m'aider et souhaite que je lui communique plus de code, je suis dispo. Ah, et je n'ai pas de log d'erreur... C'est juste que la table... n'éxiste pas. Merci d'avance ! Citer Lien vers le commentaire Partager sur d’autres sites More sharing options...
Recommended Posts
Rejoignez la conversation
Vous pouvez poster maintenant et vous enregistrez plus tard. Si vous avez un compte, connectez-vous maintenant pour poster.