コード例 #1
0
  public boolean isTermsAvailableForCompany(String compID) {
    String cmp = (compID == null) ? ApplicationUser.getSharedInstance().getCompanyId() : compID;
    SQLiteDatabase db = this.getWritableDatabase();
    /*String searchSql = "SELECT * FROM "+FRSTermsDB.TABLE+" WHERE "+FRSTermsDB.COMPANY_CODE+"= '"+cmp+"'";
    SharedMethods.logError("SQL : "+searchSql);
    Cursor termCursor = db.rawQuery(searchSql, null);
    if(termCursor != null){
    	if(termCursor.moveToNext()){
    		db.close();
    		termCursor.close();
    		return true;
    	}
    }
    db.close();
    termCursor.close();*/

    Cursor usrCursor =
        db.query(TABLE, null, COMPANY_CODE + "=?", new String[] {cmp}, null, null, null);
    if (usrCursor != null) {
      if (usrCursor.moveToNext()) {
        db.close();
        usrCursor.close();
        return true;
      }
    }
    db.close();
    usrCursor.close();
    return false;
  }
コード例 #2
0
 /* addCourse - adds all information for a course to the database adding
  * course, offerings, tasks and contacts information, if information exists
  * for the course then an update is done, otherwise and insert is done
  * @param course - the course information to add to the course table
  */
 public void addCourse(Course course) {
   SQLiteDatabase db = this.getWritableDatabase();
   ContentValues values = new ContentValues();
   long num = 0;
   boolean update = false;
   // check if the course already exists in the table
   num =
       DatabaseUtils.queryNumEntries(
           db,
           TABLE_COURSES,
           KEY_SUBJ + " ='" + course.mSubject + "' AND " + KEY_CODE + "='" + course.mCode + "'");
   if (num > 0) // if it exists then do an update
   update = true;
   // values to be added to the table
   values.put(KEY_SUBJ, course.mSubject); // subject code
   values.put(KEY_CODE, course.mCode);
   values.put(KEY_DESC, course.mDesc);
   values.put(KEY_INSTRUCTOR, course.mInstructor);
   values.put(KEY_INSTREMAIL, course.mInstructor_email);
   // Inserting or updating Row
   if (update)
     db.update(
         TABLE_COURSES,
         values,
         KEY_SUBJ + " ='" + course.mSubject + "' AND " + KEY_CODE + "='" + course.mCode + "'",
         null);
   else db.insert(TABLE_COURSES, null, values);
   db.close(); // Closing database connection
   values.clear();
   addOfferings(course); // add the offerings for the course
   addTasks(course); // add the tasks for the course
   addContacts(course.mContacts); // add the contacts for the course
   db.close(); // close the database
 }
コード例 #3
0
  public boolean isTableExtant(String tableName) {

    mDatabase =
        SQLiteDatabase.openDatabase(
            DATABASE_PATH + DATABASE_NAME, null, SQLiteDatabase.OPEN_READONLY);
    boolean openDb = mDatabase.isOpen();

    if (openDb) {
      if (mDatabase == null || !mDatabase.isOpen()) {
        mDatabase = getReadableDatabase();
      }

      if (!mDatabase.isReadOnly()) {
        mDatabase.close();
        mDatabase = getReadableDatabase();
      }
    }

    Cursor cursor =
        mDatabase.rawQuery(
            "select DISTINCT tbl_name from sqlite_master where tbl_name = '" + tableName + "'",
            null);
    if (cursor != null) {
      if (cursor.getCount() > 0) { // table does exist
        cursor.close();
        mDatabase.close();
        return true;
      }
      cursor.close();
    }
    mDatabase.close();
    return false;
  }
コード例 #4
0
  public Usuario obtenerUsuarioPorIdSQLite(int usuarioId) {
    SQLiteDatabase db = getReadableDatabase();

    String selectQuery = "SELECT * FROM " + TABLE_USUARIO + " WHERE " + COL_ID + " = " + usuarioId;

    Cursor c = db.rawQuery(selectQuery, null);

    if (c.moveToFirst()) {
      Usuario user = new Usuario();
      user.setId(c.getInt(c.getColumnIndex(COL_ID)));
      user.setNombre((c.getString(c.getColumnIndex(COL_NOMBRE))));
      user.setApellido(c.getString(c.getColumnIndex(COL_APELLIDO)));
      user.setLogin(c.getString(c.getColumnIndex(COL_LOGIN)));
      user.setPassword(c.getString(c.getColumnIndex(COL_PASSWORD)));
      user.setPrivilegio(c.getString(c.getColumnIndex(COL_PRIVILEGIO)));
      if (c.getString(c.getColumnIndex(COL_EMAIL)) != null) {
        user.setEmail(c.getString(c.getColumnIndex(COL_EMAIL)));
      }
      if (c.getString(c.getColumnIndex(COL_CELULAR)) != null) {
        user.setCelular(c.getString(c.getColumnIndex(COL_CELULAR)));
      }
      if (c.getString(c.getColumnIndex(COL_ESTADO_VIGENTE)) != null) {
        user.setEstadoVigente(c.getString(c.getColumnIndex(COL_ESTADO_VIGENTE)));
      }
      user.setIdRol(c.getInt(c.getColumnIndex(COL_ROL_ID)));
      // Se cierra la conexión de base de datos
      db.close();
      return user;
    }
    // Se cierra la conexión de base de datos
    db.close();
    return null;
  }
コード例 #5
0
  public void update(Routine updatedRoutine) throws Exception {
    SQLiteDatabase database = dbHelper.getWritableDatabase();

    database.beginTransaction();
    try {
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.UK);
      Date date = new Date();
      ContentValues values = new ContentValues();
      int routineId = updatedRoutine.getId();
      String[] whereArgs = new String[] {Integer.toString(routineId)};
      values.put(DbHelper.ROUTINE_NAME, updatedRoutine.getName());
      values.put(DbHelper.ROUTINE_DATE_UPDATED, dateFormat.format(date));

      database.update(DbHelper.ROUTINES, values, DbHelper.ROUTINE_ID + "=?", whereArgs);
      values.clear();
      database.delete(DbHelper.STEPS, DbHelper.STEP_ROUTINE_ID + "=?", whereArgs);
      saveSteps(updatedRoutine, database);
      database.setTransactionSuccessful();
    } catch (Exception e) {
      database.endTransaction();
      database.close();
      throw e;
    }
    database.endTransaction();
    database.close();
  }
コード例 #6
0
ファイル: Shift.java プロジェクト: khloke/ShiftCalendar
  public static Shift load(Context aContext, int aId) {
    ShiftCalendarDbOpenHelper dbOpener = new ShiftCalendarDbOpenHelper(aContext);
    SQLiteDatabase db = dbOpener.getReadableDatabase();
    Cursor query =
        db.query(TABLE_NAME, null, "id=" + String.valueOf(aId), new String[0], null, null, null);

    try {
      if (query.moveToNext()) {
        Shift shift =
            new Shift(
                query.getInt(query.getColumnIndex(ID_COLUMN)),
                query.getString(query.getColumnIndex(NAME_COLUMN)),
                query.getInt(query.getColumnIndex(COLOUR_COLUMN)),
                query.getString(query.getColumnIndex(TIME_FROM_COLUMN)),
                query.getString(query.getColumnIndex(TIME_TO_COLUMN)),
                query.getInt(query.getColumnIndex(SORT_ORDER_COLUMN)));
        db.close();
        dbOpener.close();
        return shift;
      } else {
        db.close();
        dbOpener.close();
        return null;
      }
    } finally {
      query.close();
    }
  }
コード例 #7
0
  public Step selectStep(int stepId) throws Exception {
    SQLiteDatabase database = dbHelper.getReadableDatabase();
    Step result = new Step();
    try {

      Cursor cur =
          database.query(
              DbHelper.STEPS,
              new String[] {
                DbHelper.STEP_ID, DbHelper.STEP_NAME, DbHelper.STEP_ORDINAL, DbHelper.STEP_SECONDS
              },
              DbHelper.STEP_ID + "=?",
              new String[] {Integer.toString(stepId)},
              null,
              null,
              DbHelper.STEP_ID);
      if (!cur.moveToFirst()) {
        throw new Exception("No step found with step identity of " + Integer.toString(stepId));
      }
      result.setId(cur.getInt(0));
      result.setName(cur.getString(1));
      result.setOrdinal(cur.getInt(2));
      result.setDurationSeconds(cur.getLong(3));
    } catch (Exception e) {
      database.close();
      throw e;
    }
    database.close();

    return result;
  }
コード例 #8
0
 // Special Getters
 public List<Assignment> getTodaysAssignments(int month, int day, int year) {
   Log.d("start:", "came into today assignments");
   String selectQuery =
       "SELECT * FROM Assignment"
           + " WHERE month = "
           + month
           + " AND day = "
           + day
           + " AND year = "
           + year
           + " ORDER BY priority DESC";
   Log.d("select query", selectQuery);
   SQLiteDatabase db = this.getWritableDatabase();
   Cursor cursor = db.rawQuery(selectQuery, null);
   Log.d("Cursor size:", Integer.toString(cursor.getCount()));
   List<Assignment> assignments = new ArrayList<Assignment>();
   if (cursor.moveToFirst()) {
     do {
       assignments.add(getAssignment(cursor.getInt(0)));
     } while (cursor.moveToNext());
     db.close();
     return assignments;
   } else {
     db.close();
     return null;
   }
 }
コード例 #9
0
  public boolean checkDB() {
    SQLiteDatabase checkDB = null;
    try {
      checkDB = SQLiteDatabase.openDatabase(DB_PATH, null, SQLiteDatabase.OPEN_READWRITE);
    } catch (SQLiteException e) {
      Logging.Log(LOG_TAG, "checkDB() - Database not found");
    }

    if (checkDB != null) {
      if (checkDB.getVersion() != DB_VERSION) {
        Logging.Log(
            LOG_TAG,
            "checkDB() - Wrong DB version: old " + checkDB.getVersion() + " new " + DB_VERSION);
        // checkDB.execSQL("DROP TABLE IF EXISTS " + PREF_TABLE);
        // checkDB.execSQL("DROP TABLE IF EXISTS " + "showsTbl");
        checkDB.close();
        needsUpgrade = true;
        return needsUpgrade;
      } else {
        checkDB.close();
        return true;
      }
    } else {
      return false;
    }
  }
コード例 #10
0
ファイル: zzw$zza.java プロジェクト: pankajk87/CompSecurity
    private boolean zza(String s, SQLiteDatabase sqlitedatabase)
    {
        Object obj = null;
        sqlitedatabase = sqlitedatabase.query("SQLITE_MASTER", new String[] {
            "name"
        }, "name=?", new String[] {
            s
        }, null, null, null);
        boolean flag = sqlitedatabase.moveToFirst();
        if (sqlitedatabase != null)
        {
            sqlitedatabase.close();
        }
        return flag;
        sqlitedatabase;
        sqlitedatabase = null;
_L4:
        zzbg.zzan((new StringBuilder()).append("Error querying for table ").append(s).toString());
        if (sqlitedatabase != null)
        {
            sqlitedatabase.close();
        }
        return false;
        s;
        sqlitedatabase = obj;
_L2:
        if (sqlitedatabase != null)
        {
            sqlitedatabase.close();
        }
        throw s;
        s;
        continue; /* Loop/switch isn't completed */
        s;
        if (true) goto _L2; else goto _L1
コード例 #11
0
  @Override
  public void onDestroy() {
    super.onDestroy();

    m_readableDb.close();
    m_writableDb.close();
  }
コード例 #12
0
  public Event get_event_by_id(Long event_id, Context context) {
    SQLiteDatabase db = getInstance(context).getReadableDatabase();
    Cursor cursor =
        db.query(
            TABLE_EVENT,
            allColumns,
            COLUMN_EVENT_ID + "=?",
            new String[] {String.valueOf(event_id)},
            null,
            null,
            null,
            null);

    if (!cursor.moveToFirst()) {
      db.close();
      return null;
    }
    Event e =
        new Event(
            cursor.getString(1),
            cursor.getLong(3),
            cursor.getString(2),
            cursor.getInt(4),
            convertStringToArrayList(cursor.getString(5)));
    db.close();
    return e;
  }
コード例 #13
0
ファイル: DBHUser.java プロジェクト: yuramanko/domova
 public User getUserForToken(String token) {
   DBHelper dbHelper = new DBHelper(context);
   SQLiteDatabase db = dbHelper.getReadableDatabase();
   Cursor cursor =
       db.query(
           DBConfig.TABLE_USER,
           null,
           DBConfig.KEY_TOKEN + "=?",
           new String[] {String.valueOf(token)},
           null,
           null,
           null,
           null);
   if (cursor != null) {
     cursor.moveToFirst();
   }
   User item = new User();
   if (cursor.getCount() == 0) {
     db.close();
     cursor.close();
     return item;
   }
   item.setIdMaster(cursor.getString(0));
   item.setLogin(cursor.getString(1));
   item.setToken(cursor.getString(3));
   item.setName(cursor.getString(4));
   item.setBalance(cursor.getString(5));
   item.setOnLine(cursor.getInt(6));
   item.setTextInfo(cursor.getString(8));
   cursor.close();
   db.close();
   return item;
 }
コード例 #14
0
 public boolean doAdd(String title, String isbn, String price) {
   title = escapeSQL(title);
   isbn = escapeSQL(isbn);
   price = escapeSQL(price);
   SQLiteDatabase myDB = null;
   try {
     Log.i(TAG, "doAdd title=" + title + " ,isbn=" + isbn + " ,price=" + price);
     myDB = openOrCreateDatabase(DATABASE_NAME, MODE_WORLD_WRITEABLE, null);
     myDB.execSQL(
         "INSERT INTO "
             + DATABASE_TABLE
             + " (title, isbn, price)"
             + " VALUES ('"
             + title
             + "', '"
             + isbn
             + "', "
             + price
             + ");");
     myDB.close();
   } catch (Exception e) {
     Log.i("bookdb", e.toString());
     return false;
   } finally {
     if (myDB != null) myDB.close();
   }
   return true;
 }
コード例 #15
0
  public boolean deleteCounter(String id, String type) throws SQLiteException {
    SQLiteDatabase database = getWritableDatabase();

    // if deleting a row that is added by the user
    if (type.equals("user")) {
      try {
        database.delete(USER_COUNTER_TABLE, "id=?", new String[] {id});
        database.close();
        return true;
      } catch (SQLiteException e) {
        e.printStackTrace();
      }
    }
    // else deleting a default row. Only hide default rows.
    else {
      // create new values
      ContentValues values = new ContentValues();
      values.put("visible", "false");

      try {
        // update the database with new values. (make rows disappear)
        database.update(DEFAULT_COUNTER_TABLE, values, "id=?", new String[] {id});
        database.close();
        return true;
      } catch (SQLiteException e) {
        e.printStackTrace();
      }
    }

    database.close();
    return false;
  }
コード例 #16
0
  public void deleteTransaction(Transaction transaction) {
    int transactionId = transaction.getTransactionId();
    int foodId = transaction.getFoodId();
    String deletedTime = transaction.getStrTimeStamp();

    SQLiteDatabase db_write = this.getWritableDatabase();
    db_write.delete(
        TABLE_TRANSACTION, TRANSACTION_ID + "=" + Integer.toString(transactionId), null);
    Log.d("deleteTransaction", "id=" + Integer.toString(transactionId));
    db_write.close();

    SQLiteDatabase db_read = this.getReadableDatabase();
    Cursor cursor =
        db_read.rawQuery(
            GET_LATEST_TRANSACTION_TIME_FOR_FOOD, new String[] {Integer.toString(foodId)});
    String lastTransactionTime;
    if (cursor.getCount() > 0) {
      cursor.moveToFirst();
      lastTransactionTime = cursor.getString(0);
    } else {
      lastTransactionTime = "";
    }
    db_read.close();

    Food food = getFood(foodId);
    food.setFrequency(food.getFrequency() - 1);
    food.setStrLastTransaction(lastTransactionTime);
    Log.d("INFO", food.toString());
    updateFood(foodId, food);
  }
コード例 #17
0
  @Override
  public synchronized void close() {

    if (myDataBase != null) myDataBase.close();
    SQLiteDatabase db = this.getReadableDatabase();
    db.close();
    super.close();
  }
コード例 #18
0
  // get booked date
  public ArrayList<Lesson_Booked> getLessonBooked(String trigger, String date3, String date4) {

    ArrayList<Lesson_Booked> arrayList_booked = new ArrayList<Lesson_Booked>();
    String selectQuery = null;
    if (trigger.equals("all")) {
      selectQuery = "SELECT  * FROM " + TABLE_LESSON_BOOKED;
    } else {
      selectQuery =
          "SELECT  * FROM "
              + TABLE_LESSON_BOOKED
              + " where "
              + LessonDate
              + ">="
              + date3
              + " AND "
              + LessonDate
              + "<="
              + date4;
    }
    SQLiteDatabase db = this.getReadableDatabase();

    try {
      cursor = (SQLiteCursor) db.rawQuery(selectQuery, null);
      if (cursor.moveToFirst()) {
        do {

          Lesson_Booked lesson_booked = new Lesson_Booked();
          lesson_booked.setID(cursor.getString(cursor.getColumnIndex(LID)));
          lesson_booked.setDescription(cursor.getString(cursor.getColumnIndex(Description)));
          lesson_booked.setStart_timing(cursor.getString(cursor.getColumnIndex(Starttime)));
          lesson_booked.setEnd_timing(cursor.getString(cursor.getColumnIndex(Endtime)));
          lesson_booked.setDate(cursor.getString(cursor.getColumnIndex(LessonDate)));

          arrayList_booked.add(lesson_booked);

          // array_studentlist.set(studentList);
        } while (cursor.moveToNext());
      }

      cursor.getWindow().clear();
      cursor.close();
      // close inserting data from database
      db.close();
      // return city list
      return arrayList_booked;

    } catch (Exception e) {
      e.printStackTrace();
      if (cursor != null) {
        cursor.getWindow().clear();
        cursor.close();
      }

      db.close();
      return arrayList_booked;
    }
  }
コード例 #19
0
ファイル: DBHelper.java プロジェクト: lemonstory/android
 /** 关闭连接 */
 public void close() {
   try {
     this.sqhelper.close();
     isDatabaseOprating = false;
     sdb.close();
   } catch (Exception e) {
     if (sdb != null) sdb.close();
     DebugUtils.exception(e);
   }
 }
コード例 #20
0
  public void createUserInDatabase(View view) {
    Database db = new Database(this, "DATABASE", null, 1);
    SQLiteDatabase database = db.getReadableDatabase();

    String usernameString = ((EditText) findViewById(R.id.userNameCreateUser)).getText().toString();
    String passwordString = ((EditText) findViewById(R.id.passwordCreateUser)).getText().toString();
    String firstNameString =
        ((EditText) findViewById(R.id.firstNameCreateUser)).getText().toString();
    String lastNameString = ((EditText) findViewById(R.id.lastNameCreateUser)).getText().toString();
    String retypePasswordString =
        ((EditText) findViewById(R.id.retypePasswordCreateUser)).getText().toString();
    if (usernameString.trim().length() < 5) {
      Toast.makeText(this, "Please have atleast 5 characters in username.", Toast.LENGTH_SHORT)
          .show();
      return;
    }

    if (passwordString.trim().length() < 8) {
      Toast.makeText(this, "Please have atleast 8 characters in password.", Toast.LENGTH_SHORT)
          .show();
      return;
    }

    if (firstNameString.trim().length() == 0 || lastNameString.trim().length() == 0) {
      Toast.makeText(this, "Please enter your first name and last name.", Toast.LENGTH_SHORT)
          .show();
      return;
    }

    if (passwordString.equals(retypePasswordString) == false) {
      Toast.makeText(this, "Passwords donot match.", Toast.LENGTH_SHORT).show();
      return;
    }

    String insertUserSQL = "INSERT INTO User VALUES(?,?,?,?)";

    String checkUserSQL = "SELECT * from User where Username = ?";
    if (database.rawQuery(checkUserSQL, new String[] {usernameString}).getCount() == 0) {

      database.execSQL(
          insertUserSQL,
          new Object[] {usernameString, passwordString, firstNameString, lastNameString});

      Toast.makeText(this, "User created", Toast.LENGTH_SHORT).show();
      CreateUser.this.finish();
      database.close();
      startActivity(new Intent(this, LoginActivity.class));

    } else {
      Toast.makeText(this, "Username is taken. Use different username", Toast.LENGTH_LONG).show();
      database.close();
    }
  }
コード例 #21
0
  public boolean existsEmail(String email) {
    SQLiteDatabase db = getWritableDatabase();
    String[] AND = new String[] {email};
    Cursor c = db.query("table_usuarios", null, "email =?", AND, null, null, null);

    if (c.getCount() > 0) {
      db.close();
      return true;
    }
    db.close();
    return false;
  }
コード例 #22
0
 public boolean cxBuffeListIsNull() {
   mDatabase = mDbOpenHelper.getWritableDatabase();
   Cursor cur = mDatabase.query(TABLE_NAME, null, null, null, null, null, null);
   if (cur.getCount() != 0) {
     cur.close();
     mDatabase.close();
     return false;
   }
   cur.close();
   mDatabase.close();
   return true;
 }
コード例 #23
0
  // get student
  public ArrayList<StudentList> getStudentAll(String trigger, String id) {

    ArrayList<StudentList> aastudentList = new ArrayList<StudentList>();

    String selectQuery = null;
    if (trigger.equals("all")) {
      selectQuery = "SELECT  * FROM " + TABLE_STUDENT_DETAILS;
    } else {
      selectQuery = "SELECT  * FROM " + TABLE_STUDENT_DETAILS + " where " + StudentId + " = " + id;
    }
    SQLiteDatabase db = this.getReadableDatabase();

    try {
      cursor = (SQLiteCursor) db.rawQuery(selectQuery, null);
      if (cursor.moveToFirst()) {
        do {

          StudentList studentList = new StudentList();
          studentList.setStudentId(cursor.getString(cursor.getColumnIndex(StudentId)));
          studentList.setName(cursor.getString(cursor.getColumnIndex(Name)));
          studentList.setEmail(cursor.getString(cursor.getColumnIndex(Email)));
          studentList.setAddress(cursor.getString(cursor.getColumnIndex(Address)));
          studentList.setContactInfo(cursor.getString(cursor.getColumnIndex(ContactInfo)));
          studentList.setGender(cursor.getString(cursor.getColumnIndex(Gender)));
          studentList.setIsActiveInMonth(cursor.getString(cursor.getColumnIndex(IsActiveInMonth)));

          studentList.setFees(cursor.getString(cursor.getColumnIndex(Fees)));
          studentList.setNotes(cursor.getString(cursor.getColumnIndex(Notes)));
          studentList.setParentId(cursor.getString(cursor.getColumnIndex(ParentId)));
          aastudentList.add(studentList);
          // array_studentlist.set(studentList);
        } while (cursor.moveToNext());
      }

      cursor.getWindow().clear();
      cursor.close();
      // close inserting data from database
      db.close();
      // return city list
      return aastudentList;

    } catch (Exception e) {
      e.printStackTrace();
      if (cursor != null) {
        cursor.getWindow().clear();
        cursor.close();
      }

      db.close();
      return aastudentList;
    }
  }
コード例 #24
0
ファイル: DBOrder.java プロジェクト: HaneenYousef/Inventory
 public Exception DeleteOrder(int ID) {
   SQLiteDatabase DB;
   DB = GETSQLOBJ();
   try {
     String Update1 = "DELETE FROM OrderTable WHERE ROWID =" + ID + ";";
     DB.execSQL(Update1);
     DB.close();
     return null;
   } catch (Exception E) {
     DB.close();
     return E;
   }
 }
コード例 #25
0
  public boolean validarUsuarios(String email, String senha) {

    SQLiteDatabase db = getWritableDatabase();
    String[] AND = new String[] {email, senha};
    Cursor c = db.query("table_usuarios", null, "email =? AND senha =?", AND, null, null, null);

    if (c.getCount() > 0) {
      db.close();
      return true;
    }
    db.close();
    return false;
  }
コード例 #26
0
  protected void runArchive() {

    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    // TODO: add check to make sure this is not empty
    File dbFile = new File(db.getPath());
    db.close();
    if (archive.add(dbFile)) {
      dbFile.delete();
    }
    reloadDbHelper(manager);
    db = databaseHelper.getWritableDatabase(); // Build new database
    db.close();
  }
コード例 #27
0
 @Override
 public void onTerminate() {
   if (null != mLocationClient) {
     mLocationClient.stop();
     mLocationClient = null;
   }
   if (null != dbHelper) {
     rdb.close();
     wdb.close();
     dbHelper.close();
   }
   super.onTerminate();
 }
コード例 #28
0
  /**
   * Move data from tags tables into metadata table. We do this by looping through both the tags and
   * tagTaskMap databases, reading data from both and adding to the Metadata table. This way, we are
   * able to do everything in one pass without loading too much into memory
   */
  @SuppressWarnings("nls")
  private void migrateTagsToMetadata() {
    Context context = ContextManager.getContext();

    if (!checkIfDatabaseExists(context, tagsTable) || !checkIfDatabaseExists(context, tagTaskTable))
      return;

    SQLiteDatabase tagsDb =
        new Astrid2UpgradeHelper(context, tagsTable, null, 1).getReadableDatabase();
    SQLiteDatabase tagTaskDb =
        new Astrid2UpgradeHelper(context, tagTaskTable, null, 1).getReadableDatabase();

    Cursor tagCursor =
        tagsDb.rawQuery("SELECT _id, name FROM " + tagsTable + " ORDER BY _id ASC", null);
    Cursor mapCursor = null;
    try {
      mapCursor =
          tagTaskDb.rawQuery("SELECT tag, task FROM " + tagTaskTable + " ORDER BY tag ASC", null);
      if (tagCursor.getCount() == 0) return;

      Metadata metadata = new Metadata();
      metadata.setValue(Metadata.KEY, TaskToTagMetadata.KEY);
      long tagId = -1;
      String tag = null;
      for (mapCursor.moveToFirst(); !mapCursor.isAfterLast(); mapCursor.moveToNext()) {
        long mapTagId = mapCursor.getLong(0);

        while (mapTagId > tagId && !tagCursor.isLast()) {
          tagCursor.moveToNext();
          tagId = tagCursor.getLong(0);
          tag = null;
        }

        if (mapTagId == tagId) {
          if (tag == null) tag = tagCursor.getString(1);
          long task = mapCursor.getLong(1);
          metadata.setValue(Metadata.TASK, task);
          metadata.setValue(Metadata.KEY, TaskToTagMetadata.KEY);
          metadata.setValue(TaskToTagMetadata.TAG_NAME, tag);
          metadataDao.createNew(metadata);
          metadata.clearValue(Metadata.ID);
        }
      }
    } finally {
      tagCursor.close();
      if (mapCursor != null) mapCursor.close();
      tagsDb.close();
      tagTaskDb.close();
    }
  }
コード例 #29
0
ファイル: BBDD.java プロジェクト: nicslabdev/mimessic
  public boolean comprobarPass(String tlf, String pass) {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c =
        db.rawQuery(
            "SELECT * from login where telefono = '" + tlf + "' and pinE = '" + pass + "'", null);

    if (c.getCount() == 0) { // Si el cursor esta vacio, es porque la consulta no ha devuelto nada
      db.close();
      return false;
    } else {
      db.close();
      return true;
    }
  }
コード例 #30
0
ファイル: BBDD.java プロジェクト: nicslabdev/mimessic
 public String getMaxId(String yo) {
   SQLiteDatabase db = this.getReadableDatabase();
   String id;
   Cursor c = db.rawQuery("SELECT maxId from login where telefono = '" + yo + "'", null);
   c.moveToFirst();
   if (c.getCount() == 0) { // Si el cursor esta vacio, es porque la consulta no ha devuelto nada
     db.close();
     return "0";
   } else {
     id = c.getString(0);
     db.close();
     return id;
   }
 }