Android SQLite

private MySQLiteOpenHelper dbHelper=null;

int version = 1;

   

//table name

String tables[]={"t_favorateExposant"};

//fields’ name of the table

String fieldNames[][] =

{

    { "f_id", "f_name", "f_stand", "f_activity", "f_present", "f_tel", "f_fax", "f_email", "f_website"}

};

//fields’ type of the table

String fieldTypes[][] =

{

    { "INTEGER PRIMARY KEY AUTOINCREMENT", "text", "text", "text", "text", "text", "text", "text", "text"}

};

//columns’name, for which we search the values  

String resultColumn[] = {"f_id", "f_name"};

//create database

dbHelper = new MySQLiteOpenHelper(this, "dbSalon", null, version, tables, fieldNames, fieldTypes);

//recherché

String selectionArgs[] = {selectedExpoName};

Cursor c = dbHelper.select(tables[0], resultColumn, "f_name=?", selectionArgs, null, null, null);

 

//delete

if (c.moveToFirst())

{

        String where = "f_id=?";

        String whereValue[] = {c.getString(0)};

        int col = dbHelper.delete(tables[0], where, whereValue);

        holder.star.setImageResource(R.drawable.p03a_exposants_checkbox);

}

 

//insert

else

{

    String f2[] = {"f_name", "f_stand", "f_activity", "f_present", "f_tel", "f_fax", "f_email", "f_website"};

    for (int i = 0; i < exposantList.size();i++)

    {

       if(!exposantList.get(i).getSociete().equals(selectedExpoName))

        {continue;}

                        

       activity = exposantList.get(i).getActivite();

       present = exposantList.get(i).getPresentation();

       tel = exposantList.get(i).getTelephone();

       fax = exposantList.get(i).getFax();

       email  = exposantList.get(i).getEmail();

       website = exposantList.get(i).getAdresseSiteWeb();

    }

                       

    String value[] = {selectedExpoName,selectedStand,activity,present,tel,fax,email,website};

    long rowid = dbHelper.insert(tables[0], f2, value);

    holder.star.setImageResource(R.drawable.p03a_exposants_checkbox_selected);

}

 

你可能感兴趣的:(android SQLite)