Hi I'm implementing a SQLite database in my Android app, here isan exemple:
private static final String TABLE_FREQUENCE_ACTIVITE = "frequence_activite";
private static final String FREQUENCE_ACTIVITE_TABLE_CREATE = "create table "
+ TABLE_FREQUENCE_ACTIVITE + " ("
+ KEY_ID + " Integer PRIMARY KEY autoincrement, "
+ KEY_LIBELLE + " Varchar (25) NOT NULL);";
private static final String TABLE_UTILISATEURS = "utilisateurs";
private static final String KEY_PSEUDO = "pseudo";
private static final String KEY_INDICE_CALORIQUE = "indice_calorique";
private static final String KEY_AGE = "age";
private static final String KEY_GENRE = "genre";
private static final String KEY_TAILLE = "taille";
private static final String KEY_TAUX_MASSE_GRASSE = "taux_masse_grasse";
private static final String KEY_ID_FREQUENCE_ACTIVITE = "id_frequence_activite";
private static final String UTILISATEURS_TABLE_CREATE = "create table "
+ TABLE_UTILISATEURS + " ("
+ KEY_ID + " Integer PRIMARY KEY autoincrement, "
+ KEY_PSEUDO + " Varchar (25) NOT NULL ,"
+ KEY_INDICE_CALORIQUE + " Integer, "
+ KEY_AGE + " Datetime NOT NULL,"
+ KEY_GENRE + " Char (1) NOT NULL,"
+ KEY_TAILLE + " INTEGER NOT NULL,"
+ KEY_TAUX_MASSE_GRASSE + " INTEGER,"
+ KEY_ID_FREQUENCE_ACTIVITE + " INTEGER REFERENCES "+TABLE_FREQUENCE_ACTIVITE+"("+KEY_ID+"));";
I justfound on google how to do Foreign Key in Android, and when I try to add an "Utilisateur" before addind an "Frenquence_activite" Android don't send references error, I don't understand why because if I add "Utilisateur" before adding one rows in "frenquence_activite" I have to get an error.
db.addUtilisateur(new Utilisateurs("benjyspider",4000,sdf.format(date),"M",177,12,1));
Aucun commentaire:
Enregistrer un commentaire