Bonjour,
Je teste les connections base de données en suivant un tuto.
Ca fonctionne mais un probleme de log me chiffone.
Rien de sorcier, j'ai juste rajouté des logs au code tu tuto.
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 public class SQLiteSalarieDAO extends SQLiteOpenHelper { public static final String TABLE_SALARIE = "salarie"; public static final String TABLE_SALARIE_ID = "_id"; private static final String DATABASE_NAME = "salarie.db"; private static final int DATABASE_VERSION = 1; // Commande sql pour la création de la base de données private static final String TABLE_CREATE = "CREATE TABLE salarie (" + " id INTEGER PRIMARY KEY," + " nom TEXT NOT NULL," + " genre INTEGER NOT NULL," + " salarie INTEGER NOT NULL," + " marie INTEGER NOT NULL," + " description TEXT NOT NULL" + " );"; // Creation de la base public SQLiteSalarieDAO(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); Log.i("SQLiteSalarieDAO", "CONSTRUCTOR"); } @Override public void onCreate(SQLiteDatabase database) { Log.i("SQLiteSalarieDAO", "onCreate start"); // Creation des tables et insertion test try { database.execSQL(TABLE_CREATE); database.execSQL("INSERT INTO salarie VALUES (1,'mal peignée',2,2,1,'');"); Log.i("SQLiteSalarieDAO", "insert effectué"); }catch (Exception e){ Log.e("SQLiteSalarieDAO", "ERROR INSERT "+e.getMessage()); } }
Cependant, je ne vois jamais les logs de mon SQLiteSalarieDAO .onCreate()
Je cree mon objet et je lance getReadableDatabase() qui devrait executer le onCreate de la class SQLiteSalarieDAO.
Mais je ne vois toujours aucuns de mes logs.
Je me suis fais un noeud au cerveau avant de tester ma base en lançant une requête,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 SQLiteSalarieDAO sqlDao = new SQLiteSalarieDAO(getApplicationContext()); Log.i("MainAvticity", "constructor lancé"); SQLiteDatabase db = sqlDao.getReadableDatabase(); Log.i("MainActivity", "getReadableDatabase lancé"); Log.i("MainActivity", "db.toString() "+db.toString()); try{ // db.execSQL("INSERT INTO salarie VALUES (1,'mal peignée',2,2,1,'');"); Cursor resultSet = db.rawQuery("Select * from salarie",null); resultSet.moveToFirst(); Log.i("MainActivity salarie:",resultSet.getString(1)); }catch(Exception e){ Log.e("MainActivity", e.toString()); }
j'obtiens bien le résultat preuve que la table as été crée, donc qu'il est passé par le SQLiteSalarieDAO.onCreate().
Pourtant, toujours aucun logs de cette class...
Meme apres un restart de logCat et de l'application.
Si vous avez une piste, je suis preneur.
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 07-26 11:20:47.812 4621-4621/? E/libprocessgroup: failed to make and chown /acct/uid_10059: Read-only file system 07-26 11:20:47.813 4621-4621/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT? 07-26 11:20:47.813 4621-4621/? I/art: Not late-enabling -Xcheck:jni (already on) 07-26 11:20:47.932 4621-4621/com.example.helloemu W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 07-26 11:20:47.943 4621-4621/com.example.helloemu I/MainActivity: onCreate() 07-26 11:20:47.969 4621-4621/com.example.helloemu I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2> 07-26 11:20:47.969 4621-4621/com.example.helloemu I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2> 07-26 11:20:47.983 4621-4634/com.example.helloemu W/art: Suspending all threads took: 12.002ms 07-26 11:20:47.989 4621-4634/com.example.helloemu I/art: Background sticky concurrent mark sweep GC freed 2495(240KB) AllocSpace objects, 0(0B) LOS objects, 25% free, 834KB/1117KB, paused 14.262ms total 34.031ms 07-26 11:20:48.041 4621-4634/com.example.helloemu W/art: Suspending all threads took: 5.998ms 07-26 11:20:48.046 4621-4634/com.example.helloemu I/art: Background partial concurrent mark sweep GC freed 1239(108KB) AllocSpace objects, 0(0B) LOS objects, 52% free, 937KB/1961KB, paused 7.760ms total 32.183ms 07-26 11:20:48.217 4621-4621/com.example.helloemu I/SQLiteSalarieDAO: CONSTRUCTOR 07-26 11:20:48.217 4621-4621/com.example.helloemu I/MainAvticity: constructor lancé 07-26 11:20:48.220 4621-4621/com.example.helloemu I/MainActivity: getReadableDatabase lancé 07-26 11:20:48.220 4621-4621/com.example.helloemu I/MainActivity: db.toString() SQLiteDatabase: /data/data/com.example.helloemu/databases/salarie.db 07-26 11:20:48.222 4621-4621/com.example.helloemu I/MainActivity*salarie:: mal peignée 07-26 11:20:48.230 4621-4640/com.example.helloemu D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true 07-26 11:20:48.234 4621-4621/com.example.helloemu D/Atlas: Validating map... 07-26 11:20:48.261 4621-4640/com.example.helloemu I/OpenGLRenderer: Initialized EGL, version 1.4 07-26 11:20:48.261 4621-4640/com.example.helloemu W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 07-26 11:20:48.269 4621-4640/com.example.helloemu D/EGL_emulation: eglCreateContext: 0xaf0348e0: maj 2 min 0 rcv 2 07-26 11:20:48.294 4621-4640/com.example.helloemu D/EGL_emulation: eglMakeCurrent: 0xaf0348e0: ver 2 0 (tinfo 0xaf039460) 07-26 11:20:48.300 4621-4640/com.example.helloemu D/OpenGLRenderer: Enabling debug mode 0 07-26 11:20:48.315 4621-4640/com.example.helloemu D/EGL_emulation: eglMakeCurrent: 0xaf0348e0: ver 2 0 (tinfo 0xaf039460)
Partager