package com.example.GPS_DB01;

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

public class DBHelper extends SQLiteOpenHelper 
{
    public static final String DB_NAME = "DB09.db";
    public static final int DB_VERSION = 1;

    private static final String TEXT_TYPE = " TEXT";
    private static final String REAL_TYPE = " REAL";
    private static final String NUMERIC_TYPE = " NUMERIC";
    private static final String COMMA_SEP = ",";
    
    
    public static final String TABLE_RUN_SUMMARY = "table_run_summary";
    public static final String COLUMN_ID_RUN = "_id";
    public static final String COLUMN_NAME_RUN = "name";
    public static final String COLUMN_DATE_RUN = "date";
    public static final String COLUMN_START_RUN = "start";
    public static final String COLUMN_STOP_RUN = "stop";
    public static final String COLUMN_STEPS_COUNT_RUN = "steps";
    public static final String COLUMN_MODE_RUN = "mode";  
    public static final String COLUMN_CALORIES_RUN = "calories";  
    public static final String COLUMN_VITESSE_MOYENNE_RUN = "vitesse_moyenne";  
    public static final String COLUMN_DISTANCE_RUN = "distance";
    public static final String COLUMN_DURATION_RUN = "duration";
/*
    private static final String CREATE_TEXTREPORT_TABLE = "CREATE TABLE " + DBtables.TextReport.TABLE_NAME + " (" +
            DBtables.TextReport.COLUMN_ID + TEXT_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_REPORT + TEXT_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_DATETIME + NUMERIC_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_ISREPOETED + NUMERIC_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_LONGITUDE + REAL_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_LATITUDE + REAL_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_ALTITUDE + REAL_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_SPEED + REAL_TYPE + COMMA_SEP +
            DBtables.TextReport.PRIMARY_KEY +
            " )";
*/    
/*    
    private static final String CREATE_TEXTREPORT_TABLE = "CREATE TABLE " + DBtables.TextReport.TABLE_NAME + " (" +
            DBtables.TextReport.COLUMN_ID + " INTEGER PRIMARY KEY," +
            DBtables.TextReport.COLUMN_REPORT + TEXT_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_DATETIME + NUMERIC_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_ISREPOETED + NUMERIC_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_LONGITUDE + REAL_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_LATITUDE + REAL_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_ALTITUDE + REAL_TYPE + COMMA_SEP +
            DBtables.TextReport.COLUMN_SPEED + REAL_TYPE + COMMA_SEP +
            " )";
 */   
    
    private static final String CREATE_TEXTREPORT_TABLE = "CREATE TABLE "
			  +  DBtables.TextReport.TABLE_NAME + "(" 
			  +  DBtables.TextReport.COLUMN_ID + " INTEGER PRIMARY KEY,"
			  +  DBtables.TextReport.COLUMN_REPORT + " TEXT,"
			  +  DBtables.TextReport.COLUMN_DATETIME + " INTEGER,"
			  +  DBtables.TextReport.COLUMN_ISREPOETED + " INTEGER,"
			  +  DBtables.TextReport.COLUMN_LONGITUDE + " INTEGER,"
			  +  DBtables.TextReport.COLUMN_LATITUDE + " INTEGER,"
			  +  DBtables.TextReport.COLUMN_ALTITUDE + " INTEGER,"
			  +  DBtables.TextReport.COLUMN_SPEED + " INTEGER"+")";
    
    
    // INTEGER PRIMARY KEY
    
    private static final String CREATE_TABLE_RUN_SUMMARY = "CREATE TABLE "
								  +  TABLE_RUN_SUMMARY + "(" 
								  +  COLUMN_ID_RUN + " INTEGER PRIMARY KEY,"
								  +  COLUMN_NAME_RUN + " TEXT,"
								  +  COLUMN_DATE_RUN + " INTEGER,"
								  +  COLUMN_START_RUN + " INTEGER,"
								  +  COLUMN_STOP_RUN + " INTEGER,"
								  +  COLUMN_STEPS_COUNT_RUN + " INTEGER,"
						          +  COLUMN_MODE_RUN + " TEXT,"
								  +  COLUMN_CALORIES_RUN + " REAL,"
								  +  COLUMN_VITESSE_MOYENNE_RUN + " REAL,"
								  +  COLUMN_DISTANCE_RUN + " REAL,"
			  					  +  COLUMN_DURATION_RUN + " INTEGER"+")";
    
    /************************************************************************************************************************************/
    
     public static final String TABLE_GPS = "table_gps";
    
     public static final String COLUMN_KEY_ID = "_id";
     public static final String COLUMN_NAME = "name";
	 public static final String COLUMN_LATITUDE = "latitude";
	 public static final String COLUMN_LONGITUDE = "longitude";
	 public static final String COLUMN_ALTITUDE = "altitude";
	 public static final String COLUMN_VITESSE = "vitesse";
				
	
	 public  static final String CREATE_TABLE_GPS = "CREATE TABLE "
	            + TABLE_GPS + "(" 
	    		+ COLUMN_KEY_ID + " INTEGER PRIMARY KEY,"
	    		+ COLUMN_NAME + " TEXT," 
	    		+ COLUMN_LATITUDE + " INTEGER,"
	    		+ COLUMN_LONGITUDE + " INTEGER," 
	    		+ COLUMN_ALTITUDE + " INTEGER," 
	            + COLUMN_VITESSE + " INTEGER" + ")";
    
    
    
    // INTEGER PRIMARY KEY AUTOINCREMENT

    private static final String DELETE_TEXTREPORT_TABLE = "DROP TABLE IF EXISTS " + DBtables.TextReport.TABLE_NAME;

    public DBHelper(Context context) 
    {
        super(context, DB_NAME, null, DB_VERSION);
    }

    public void onCreate(SQLiteDatabase db)
    {
        //db.execSQL(CREATE_TEXTREPORT_TABLE);
        //db.execSQL(CREATE_TABLE_RUN_SUMMARY);
    	db.execSQL(CREATE_TABLE_GPS);
    }

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
    	 //db.execSQL("DROP TABLE IF EXISTS "+ CREATE_TEXTREPORT_TABLE);
         //db.execSQL("DROP TABLE IF EXISTS "+ CREATE_TABLE_RUN_SUMMARY);
    	
     //   db.execSQL(CREATE_TEXTREPORT_TABLE);
     //   db.execSQL(CREATE_TABLE_RUN_SUMMARY);
    	db.execSQL(CREATE_TABLE_GPS);
    	
        onCreate(db);
    }
}
