package com.example.db01;

import android.os.Bundle;  
import android.app.Activity;  
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.widget.Button;  
import android.widget.EditText;  
import android.widget.TextView;  

public class debug extends Activity 
{  
    
	TextView textView1, textView2;
    Button button1;  
    
    final String EXTRA_POSITION = "extra_position";
	final String EXTRA_ID = "extra_id";
    
	DB_alarm db;
	private SQLiteDatabase dataBase;
	
    @Override  
    protected void onCreate(Bundle savedInstanceState)
    {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.debug_view);  
        
        db = new DB_alarm(getApplicationContext());
        
        textView1=(TextView)findViewById(R.id.textView1);  
        textView2=(TextView)findViewById(R.id.textView2);  
        
        Intent intent = getIntent();
      
        if (intent != null) 
        {
        	textView1.setText(intent.getStringExtra(EXTRA_POSITION) );
        	textView2.setText(intent.getStringExtra(EXTRA_ID) );
        	
        	String id = intent.getStringExtra(EXTRA_ID);
        	
        	// selection d'un élément par son id
        	String requete = "SELECT * FROM " + DB_alarm.TABLE + " WHERE " + DB_alarm.KEY_ID + "='" + id +"'";
            Cursor mCursor = db.DB_query(requete);
            int val = mCursor.getCount();
            
            String val1 = mCursor.getString(mCursor.getColumnIndex(DB_alarm.KEY_ID ));
            String val2 = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COL_NAME ));
            String val3 = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COL_FROMDATE )); 
            String val4 = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COL_TODATE )); 
            String val5 = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COL_DATETIME ));
            String val6 = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COL_STATUS )); 
            String val7 = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COL_CREATEDTIME )); 
            String val9 = mCursor.getString(mCursor.getColumnIndex(DB_alarm.COL_MODIFIEDTIME )); 
            String val10 = mCursor.getString(mCursor.getColumnIndex(DB_alarm.KEY_CREATED_AT )); 
            
            
        	///// mise à jour - update 
        	String valeur = "zorro";
        	requete = "update table_alarm set name = '" + valeur + "'  where _id= '" + id + "' " ;
        	//db.update(requete);
        	
/***************************   POSSIBILITES  ***************************************/
/*			cas 1
 * 
 * db.execSQL("UPDATE DB_TABLE SET YOUR_COLUMN='newValue' WHERE id=6 ");
 */
/*        	cas 2
 * 
        	ContentValues newValues = new ContentValues();
        	newValues.put("YOUR_COLUMN", "newValue");
        	db.update("YOUR_TABLE", newValues, "id=6", null);
*/        	
        	
/*			cas 3
 * 
          	ContentValues newValues = new ContentValues();
			newValues.put("YOUR_COLUMN", "newValue");
			String[] args = new String[]{"user1", "user2"};
			db.update("YOUR_TABLE", newValues, "name=? OR name=?", args);
 */
        	
        }
        
            button1=(Button)findViewById(R.id.button1);  
            button1.setOnClickListener(new OnClickListener() 
            {  
                @Override  
                public void onClick(View arg0) 
                {  
	                    //String message= "dickou";  
	                    //Intent intent=new Intent();  
	                    //intent.putExtra("MESSAGE",message);  
	                    //setResult(2,intent);  
	                    finish();//finishing activity  
                }  
            });  
    }  
    
}  