Jump to content
Sign in to follow this  
Naqued

Erreur sur un insert Sqllite no column named..

Recommended Posts

Bonjour,

Je vous contact car j'ai un gros soucis.
Je n'arrive pas à accéder aux tables créer ou celle-ci ne se créer pas bien.

Bdd_manager

public class Bdd_manager extends SQLiteOpenHelper {
    public static final String lentus = "lentus";
    public static final String Morning_before = "morning_before";
    public static final String Morning_after = "morning_after";
    public static final String Morning_insu = "morning_insu";

    public static final String Midnight_before = "diner_before";
    public static final String Midnight_after = "diner_after";
    public static final String Midnight_insu = "diner_insu";

    public static final String EndDay_before = "enday_before";
    public static final String EndDay_after = "enday_after";
    public static final String EndDay_insu = "enday_insu";

    public static final String Night = "night";
    public static final String CommentofDay = "commentofday";
    public static final String tdate = "date";
    public static final String TABLE_NAME = "Diabhelp_CDN";
    public static final String TABLE_CREATE = "CREATE TABLE " + TABLE_NAME + " (" + tdate + " TEXT, " + Morning_before + " DOUBLE, " + Morning_after + "DOUBLE," + Morning_insu + "DOUBLE," + Midnight_before + "DOUBLE," + Midnight_after + "DOUBLE," + Midnight_insu + "DOUBLE," + EndDay_before + "DOUBLE," + EndDay_after + "DOUBLE," + EndDay_insu + "DOUBLE," + Night + "DOUBLE," + CommentofDay + "TEXT," + lentus + "DOUBLE);";
    public static final String TABLE_DROP = "DROP TABLE IF EXISTS " + TABLE_NAME + ";";

    public Bdd_manager(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @[member=override]
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(TABLE_CREATE);
    }
    @[member=override]
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(TABLE_DROP);
        onCreate(db);
    }
}



le fichier DAO :

public class DAO extends DAOBase {
    public static final String TABLE_NAME = "Diabhelp_CDN";

    public static final String lentus = "lentus";
    public static final String Morning_before = "morning_before";
    public static final String Morning_after = "morning_after";
    public static final String Morning_insu = "morning_insu";

    public static final String Midnight_before = "diner_before";
    public static final String Midnight_after = "diner_after";
    public static final String Midnight_insu = "diner_insu";

    public static final String EndDay_before = "enday_before";
    public static final String EndDay_after = "enday_after";
    public static final String EndDay_insu = "enday_insu";

    public static final String Night = "night";
    public static final String CommentofDay = "commentofday";
    public static final String tdate = "date";

    public static final String TABLE_CREATE = "CREATE TABLE " + TABLE_NAME + " (" + tdate + " TEXT, " + Morning_before + " DOUBLE, " + Morning_after + "DOUBLE," + Morning_insu + "DOUBLE," + Midnight_before + "DOUBLE," + Midnight_after + "DOUBLE," + Midnight_insu + "DOUBLE," + EndDay_before + "DOUBLE," + EndDay_after + "DOUBLE," + EndDay_insu + "DOUBLE," + Night + "DOUBLE," + CommentofDay + "TEXT," + lentus + "DOUBLE);";
    public static final String TABLE_DROP =  "DROP TABLE IF EXISTS " + TABLE_NAME + ";";

    /**
     * @param m le métier à ajouter à la base
     */

    public DAO(Context context)
    {
        this.mHandler = new Bdd_manager(context, NOM, null, VERSION);
    }

    public void AddDay(DayofCDN m) {
        ContentValues value = new ContentValues();

        value.put(lentus, m.getSlowInsu());
        value.put(Morning_before, m.getGlycMorning(0));
        value.put(Morning_after, m.getGlycMorning(1));
        value.put(Morning_insu, m.getInsuMorning());

        value.put(Midnight_before, m.getGlycMidDay(0));
        value.put(Midnight_after, m.getGlycMidDay(1));
        value.put(Midnight_insu, m.getInsuMidDay());

        value.put(EndDay_before, m.getGlycEnDay(0));
        value.put(EndDay_after, m.getGlycEnDay(1));
        value.put(Midnight_insu, m.getInsuEndDay());

        value.put(Night, m.getNight());
        value.put(CommentofDay, m.getCommentofDay());
        value.put(tdate, m.getDate());

        mDb.insert(DAO.TABLE_NAME, null, value);
    }

    /**
     * @param // l'identifiant du métier à supprimer
     */
    public void deleteDay(String _date) {
        mDb.delete(TABLE_NAME, tdate + " = ?", new String[] {_date});
    }

    /**
     * @param m le métier modifié
     */
    public void Update(DayofCDN m) {
        ContentValues value = new ContentValues();
        value.put(lentus, m.getSlowInsu());

        value.put(Morning_before, m.getGlycMorning(0));
        value.put(Morning_after, m.getGlycMorning(1));
        value.put(Morning_insu, m.getInsuMorning());

        value.put(Midnight_before, m.getGlycMidDay(0));
        value.put(Midnight_after, m.getGlycMidDay(1));
        value.put(Midnight_insu, m.getInsuMidDay());

        value.put(EndDay_before, m.getGlycEnDay(0));
        value.put(EndDay_after, m.getGlycEnDay(1));
        value.put(Midnight_insu, m.getInsuEndDay());

        value.put(Night, m.getNight());
        value.put(CommentofDay, m.getCommentofDay());

        mDb.update(TABLE_NAME, value, tdate  + " = ?", new String[] {String.valueOf(m.getDate())});
    }

    /**
     * @param //id l'identifiant du métier à récupérer
     */
    public DayofCDN SelectDay(String mtDate) {
        DayofCDN m = null;

        Cursor c = mDb.rawQuery("SELECT * from " + TABLE_NAME + " where " + tdate + " = '" + mtDate +"'", null);

        String[] i = c.getColumnNames();
        c.moveToNext();

       if (c.getColumnIndex(tdate) == 0)
           return null;
       double morning_before = c.getDouble(c.getColumnIndex(Morning_before));
       double morning_after = c.getDouble(c.getColumnIndex(Morning_after));
       double morning_insu = c.getDouble(c.getColumnIndex(Morning_insu));

       double midDay_before = c.getDouble(c.getColumnIndex(Midnight_after));
       double midDay_after = c.getDouble(c.getColumnIndex(Midnight_after));
       double midDay_insu = c.getDouble(c.getColumnIndex(Midnight_insu));

       double night = c.getDouble(c.getColumnIndex(Night));

       double endDay_before = c.getDouble(c.getColumnIndex(EndDay_before));
       double endDay_after = c.getDouble(c.getColumnIndex(EndDay_after));
       double endDay_insu = c.getDouble(c.getColumnIndex(EndDay_insu));

       double mlentus = c.getDouble(c.getColumnIndex(lentus));

       String tCommentodday = c.getString(c.getColumnIndex(CommentofDay));

       m = new DayofCDN(mtDate);

       m.setCommentofDay(tCommentodday);
       m.SetSlowInsu(mlentus);
       m.setNight(night);


       m.setGlycMorning(morning_before, morning_after);
       m.setInsuMorning(morning_insu);
       m.setInsuMidDay(midDay_insu);
       m.setInsuEndDay(endDay_insu);

       m.setGlycMidDay(midDay_before, midDay_after);
       m.setGlycEndDay(endDay_before, endDay_after);

       return m;
    }
}

DAOBASE (Abstraction)
 

package fr.diabhelp.carnetdesuivi;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

/**
 * Created by Damien on 11/02/2015.
 */
public abstract class DAOBase {
    // Nous sommes à la première version de la base
    // Si je décide de la mettre à jour, il faudra changer cet attribut
    protected final static int VERSION = 2;
    // Le nom du fichier qui représente ma base
    protected final static String NOM = "dh_db.db";

    protected SQLiteDatabase mDb = null;
    protected Bdd_manager mHandler = null;

    public DAOBase(Context pContext) {
        this.mHandler = new Bdd_manager(pContext, NOM, null, VERSION);
    }
     public DAOBase() // pas sur de ça
    {
        this.mHandler = new Bdd_manager(null, NOM, null, VERSION);
    }
    public SQLiteDatabase open() {
        // Pas besoin de fermer la dernière base puisque getWritableDatabase s'en charge
        mDb = mHandler.getWritableDatabase();
        return mDb;
    }

    public void close() {
        mDb.close();
    }

    public SQLiteDatabase getDb() {
        return mDb;
    }
}

J'avoue commencer à désespérer après avoir vérifier 1 millions de fois mes requêtes et mon code..

l'erreur : 

03-11 13:04:14.417      938-938/fr.diabhelp.carnetdesuivi E/SQLiteLog﹕ (1) table Diabhelp_CDN has no column named enday_before

03-11 13:04:14.457      938-938/fr.diabhelp.carnetdesuivi E/SQLiteDatabase﹕ Error inserting enday_before=0.0 morning_insu=0.0 morning_after=2.0 commentofday= enday_after=0.0 diner_after=0.0 lentus=0.0 morning_before=1.0 night=0.0 date=11-Mars-2015 diner_insu=0.0 diner_before=0.0

    android.database.sqlite.SQLiteException: table Diabhelp_CDN has no column named enday_before (code 1): , while compiling: INSERT INTO Diabhelp_CDN(enday_before,morning_insu,morning_after,commentofday,enday_after,diner_after,lentus,morning_before,night,date,diner_insu,diner_before) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)

le soucis serais qu'il n'y a pas de colonne nommée enday_before (mais c'est la première valeur de l'insert, donc je suppose qu'aucune colonne n'est crée).

Je vous remercie par avance,
Naqued
 


Bon j'était sur se soucis depuis 6h, d'ou ma frustration...

je ne trouve pas le moyen d'effacer le poste. Donc la solution est que :
Mes tables sont bien créer comme il faut (c'est pour ça que ma requete de CREATE passe).
Malheuresement.. j'ai oublié un espace dans ma requete de CREATE avant tout mes typages. càd que mes tables s'appelaient : enday_beforeDOUBLE et non enday_before.


Sujet Clos...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  





×
×
  • Create New...