package com.example.dbsql01;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import android.content.Context;
import android.database.*;
import android.database.sqlite.*;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;

public class MainActivity extends Activity {

	/*private static final String DATABASE_NAME = "myDatabase.db";
	private static final String DATABASE_TABLE = "mainTable";
	private static final int DATABASE_VERSION = 1;
	// The index (key) column name for use in where clauses.
	public static final String KEY_ID="_id";
	
	public static final String TABLE_NAME = "repertoire";
	public static final String COL_NOM = "pName";
	public static final String COL_PRENOM = "pName";
	public static final String COL_DATE = "pDate";
	private static final String STRING_CREATE =
	"CREATE TABLE "+TABLE_NAME+" (_id INTEGER PRIMARY KEY AUTOINCREMENT, "
	+ COL_NOM  + " TEXT, " 
	+ COL_PRENOM  + " TEXT, " 
	+ COL_DATE + " DATE);";
	*/
	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}

class PlanetesDBAdaptateur 
{

	private static final int BASE_VERSION = 1;
	private static final String BASE_NOM = "planetes.db";
	private static final String TABLE_PLANETES = "table_planetes";
	private static final String COLONNE_ID = "id";
	private static final int COLONNE_ID_ID = 0;
	private static final String COLONNE_NOM = "nom";
	private static final int COLONNE_NOM_ID = 1;
	private static final String COLONNE_RAYON = "rayon";
	private static final int COLONNE_RAYON_ID = 2;
	// La requête de création de la structure de la base de données.
	private static final String REQUETE_CREATION_BD = "create table "
	+ TABLE_PLANETES + " (" + COLONNE_ID
	+ " integer primary key autoincrement, " + COLONNE_NOM
	+ " text not null, " + COLONNE_RAYON + " text not null);";
	
	// L’instance de la base qui sera manipulée au travers de cette classe.
	private SQLiteDatabase maBaseDonnees;
	private MaBaseOpenHelper baseHelper;
	
	public PlanetesDBAdaptateur(Context ctx) 
	{
		baseHelper = new MaBaseOpenHelper(ctx, BASE_NOM, null, BASE_VERSION);
	}
	
}

class MaBaseOpenHelper extends SQLiteOpenHelper {
	
	
	private static final String TABLE_PLANETES = "table_planetes";
	private static final String COLONNE_ID = "id";
	private static final String COLONNE_NOM = "nom";
	private static final String COLONNE_RAYON = "rayon";
	private static final String REQUETE_CREATION_BD = "create table "
	+ TABLE_PLANETES + " (" + COLONNE_ID
	+ " integer primary key autoincrement, " + COLONNE_NOM
	+ " text not null, " + COLONNE_RAYON + " text not null);";
	
	public MaBaseOpenHelper(Context context, String nom,
			CursorFactory cursorfactory, int version) {
			super(context, nom, cursorfactory, version);
			}
	
	@Override
	public void onCreate(SQLiteDatabase db)
	{
		db.execSQL(REQUETE_CREATION_BD);
	}
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
	{
		// Dans notre cas, nous supprimons la base et les données pour en créer
		// une nouvelle ensuite. Vous pouvez créer une logique de mise à jour
		// propre à votre base permettant de garder les données à la place.
		db.execSQL("DROP TABLE" + TABLE_PLANETES + ";");
		// Création de la nouvelle structure.
		onCreate(db);
		
		String nada = "rien";
	}
	
}