pcbddbhelper changed

parent ab222a4c
...@@ -2,6 +2,7 @@ package com.yottacode.pictogram.dao; ...@@ -2,6 +2,7 @@ package com.yottacode.pictogram.dao;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteDatabase.CursorFactory;
...@@ -170,9 +171,9 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -170,9 +171,9 @@ public class PCBDBHelper extends SQLiteOpenHelper {
Log.e(LOG_TAG,"Error setting active scene:"+e.getMessage()); Log.e(LOG_TAG,"Error setting active scene:"+e.getMessage());
} }
Cursor cursor = getReadableDatabase().rawQuery("SELECT * FROM scene",null); /*Cursor cursor = getReadableDatabase().rawQuery("SELECT * FROM scene",null);
Log.i(LOG_TAG,"tam scen: "+cursor.getCount()); Log.i(LOG_TAG,"tam scen: "+cursor.getCount());
cursor.close(); cursor.close();*/
} }
/** /**
...@@ -221,14 +222,24 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -221,14 +222,24 @@ public class PCBDBHelper extends SQLiteOpenHelper {
public void setStudentVocabulary(Vocabulary vocabulary) { public void setStudentVocabulary(Vocabulary vocabulary) {
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
int id_stu = this.getCurrentUser().get_id_stu(); int id_stu = this.getCurrentUser().get_id_stu();
<<<<<<< 4748b817cf03a1d7c60a8b8cde67f05075afe99f
=======
int seconds1 = Calendar.getInstance().get(Calendar.SECOND);
Log.i(LOG_TAG,"tamVoc to insert: "+vocabulary.size());
>>>>>>> dbcde972e39f99c8d77c15874db2f92ed0515887
db.delete("collection", "id_stu=" + id_stu, null); db.delete("collection", "id_stu=" + id_stu, null);
ContentValues values=new ContentValues(6); ContentValues values=new ContentValues(6);
values.put("id_stu", id_stu); values.put("id_stu", id_stu);
db.beginTransaction(); db.beginTransaction();
for (Picto picto : vocabulary) { for (Picto picto : vocabulary) {
<<<<<<< 4748b817cf03a1d7c60a8b8cde67f05075afe99f
=======
Log.i(LOG_TAG,"inserting "+picto.get_id()+":"+picto.get_translation()+":"+picto.get_json_attrs()+"-id_sce: "+getActiveSceneForStudent(id_stu));
newsize++;
>>>>>>> dbcde972e39f99c8d77c15874db2f92ed0515887
values.put("id_picto", picto.get_id()); values.put("id_picto", picto.get_id());
values.put("id_scene", 135/*getActiveSceneForStudent(id_stu)*/); values.put("id_scene", vocabulary.getId_scene());
values.put("url", picto.get_url()); values.put("url", picto.get_url());
values.put("translation",picto.get_translation()); values.put("translation",picto.get_translation());
values.put("attributes",picto.get_json_attrs()); values.put("attributes",picto.get_json_attrs());
...@@ -249,10 +260,11 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -249,10 +260,11 @@ public class PCBDBHelper extends SQLiteOpenHelper {
public void savePicto(Picto picto) { public void savePicto(Picto picto) {
int id_stu = this.getCurrentUser().get_id_stu(); int id_stu = this.getCurrentUser().get_id_stu();
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
ContentValues values=new ContentValues(6); ContentValues values=new ContentValues(7);
values.put("id_stu", id_stu); values.put("id_stu", id_stu);
values.put("id_picto", picto.get_id()); values.put("id_picto", picto.get_id());
//values.put("id_scene",picto.get_scene()); //TODO: Añadir aqui el id de escena activa para el estudiante
values.put("id_scene",getActiveSceneForStudent(id_stu));
values.put("url", picto.get_url()); values.put("url", picto.get_url());
values.put("translation",picto.get_translation()); values.put("translation",picto.get_translation());
values.put("attributes",picto.get_json_attrs()); values.put("attributes",picto.get_json_attrs());
...@@ -269,10 +281,11 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -269,10 +281,11 @@ public class PCBDBHelper extends SQLiteOpenHelper {
*/ */
public void deletePicto(int picto_id) { public void deletePicto(int picto_id) {
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
//TODO: Añadir aqui el id de escena activa para el estudiante
db.delete("collection","id_stu=? AND id_picto=?", db.delete("collection","id_stu=? AND id_picto=? AND id_scene=?",
new String[]{ Integer.toString(this.currentUser.get_id_stu()), new String[]{ Integer.toString(this.currentUser.get_id_stu()),
Integer.toString(picto_id)}); Integer.toString(picto_id),
Integer.toString(getActiveSceneForStudent(this.currentUser.get_id_stu()))});
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ //db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
} }
...@@ -288,7 +301,10 @@ public class PCBDBHelper extends SQLiteOpenHelper { ...@@ -288,7 +301,10 @@ public class PCBDBHelper extends SQLiteOpenHelper {
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues(1); ContentValues values = new ContentValues(1);
values.put("attributes",attrs); values.put("attributes",attrs);
int updates=db.update("collection",values, "id_stu=? AND id_picto=?", new String[] {Integer.toString(id_stu), Integer.toString(picto_id)}); //TODO: Añadir aqui el id de escena activa para el estudiante
int updates=db.update("collection",values, "id_stu=? AND id_picto=? AND id_scene=?", new String[] {Integer.toString(id_stu),
Integer.toString(picto_id),
Integer.toString(getActiveSceneForStudent(this.currentUser.get_id_stu()))});
Log.i(this.getClass().getCanonicalName(),"Modify "+updates+" Picto, id. "+picto_id+" attributes="+attrs);//+ "::"+ Arrays.toString(Thread.currentThread().getStackTrace())); Log.i(this.getClass().getCanonicalName(),"Modify "+updates+" Picto, id. "+picto_id+" attributes="+attrs);//+ "::"+ Arrays.toString(Thread.currentThread().getStackTrace()));
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ //db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment