示例#1
0
  public void saveTile(Tile tile, ByteArrayOutputStream data, boolean success) {
    byte[] bytes = null;

    if (success) bytes = data.toByteArray();

    synchronized (mCacheBuffers) {
      data.reset();
      mCacheBuffers.add(data);
    }

    if (dbg) log.debug("store tile {} {}", tile, Boolean.valueOf(success));

    if (!success) return;

    synchronized (mStmtPutTile) {
      mStmtPutTile.bindLong(1, tile.tileX);
      mStmtPutTile.bindLong(2, tile.tileY);
      mStmtPutTile.bindLong(3, tile.zoomLevel);
      mStmtPutTile.bindLong(4, 0);
      mStmtPutTile.bindLong(5, 0);
      mStmtPutTile.bindBlob(6, bytes);

      mStmtPutTile.execute();
      mStmtPutTile.clearBindings();
    }
  }
示例#2
0
 /**
  * 绑定参数 Author: hyl Time: 2015-8-17上午10:42:43
  *
  * @param statement
  * @param position
  * @param args
  */
 private void bindArgs(SQLiteStatement statement, int position, Object args) {
   int type = FieldTypeManager.getValueType(args);
   switch (type) {
     case FieldTypeManager.VALUE_TYPE_NULL:
       statement.bindNull(position);
       break;
     case FieldTypeManager.BASE_TYPE_BYTE_ARRAY:
       statement.bindBlob(position, (byte[]) args);
       break;
     case FieldTypeManager.BASE_TYPE_CHAR:
     case FieldTypeManager.BASE_TYPE_STRING:
       statement.bindString(position, args.toString());
       break;
     case FieldTypeManager.BASE_TYPE_DATE:
       statement.bindString(position, DateUtil.formatDatetime((Date) args));
       break;
     case FieldTypeManager.BASE_TYPE_DOUBLE:
     case FieldTypeManager.BASE_TYPE_FLOAT:
       statement.bindDouble(position, Double.parseDouble(args.toString()));
       break;
     case FieldTypeManager.BASE_TYPE_INT:
     case FieldTypeManager.BASE_TYPE_LONG:
     case FieldTypeManager.BASE_TYPE_SHORT:
       statement.bindLong(position, Long.parseLong(args.toString()));
       break;
     case FieldTypeManager.NOT_BASE_TYPE:
       throw new IllegalArgumentException("未知参数类型,请检查绑定参数");
   }
 }
示例#3
0
  public void updateHomeWork(HomeWork hw) {
    try {
      mDb.beginTransaction();
      if (hw != null) {

        mUpdateHomeWorkStatement.clearBindings();
        if (hw.isComplite()) {
          mUpdateHomeWorkStatement.bindLong(1, 1);
          NotificationManager.getInstance().removeNotification(hw);

        } else {
          mUpdateHomeWorkStatement.bindLong(1, 0);
          NotificationManager.getInstance().addNewNotification(hw);
        }

        if (hw.getMessage() != null) {
          mUpdateHomeWorkStatement.bindString(2, hw.getMessage());
        }

        if (hw.getMessage() != null) {
          mUpdateHomeWorkStatement.bindBlob(3, Slipper.serializeObject(hw.getImages()));
        }

        mUpdateHomeWorkStatement.bindLong(4, hw.getId());
        mUpdateHomeWorkStatement.execute();
      }
      mDb.setTransactionSuccessful();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      mDb.endTransaction();
    }
  }
示例#4
0
    private void normalizeIcons(SQLiteDatabase db) {
      Log.d(TAG, "normalizing icons");

      db.beginTransaction();
      Cursor c = null;
      SQLiteStatement update = null;
      try {
        boolean logged = false;
        update = db.compileStatement("UPDATE favorites " + "SET icon=? WHERE _id=?");

        c =
            db.rawQuery(
                "SELECT _id, icon FROM favorites WHERE iconType=" + Favorites.ICON_TYPE_BITMAP,
                null);

        final int idIndex = c.getColumnIndexOrThrow(Favorites._ID);
        final int iconIndex = c.getColumnIndexOrThrow(Favorites.ICON);

        while (c.moveToNext()) {
          long id = c.getLong(idIndex);
          byte[] data = c.getBlob(iconIndex);
          try {
            Bitmap bitmap =
                Utilities.resampleIconBitmap(
                    BitmapFactory.decodeByteArray(data, 0, data.length), mContext);
            if (bitmap != null) {
              update.bindLong(1, id);
              data = ItemInfo.flattenBitmap(bitmap);
              if (data != null) {
                update.bindBlob(2, data);
                update.execute();
              }
              bitmap.recycle();
            }
          } catch (Exception e) {
            if (!logged) {
              Log.e(TAG, "Failed normalizing icon " + id, e);
            } else {
              Log.e(TAG, "Also failed normalizing icon " + id);
            }
            logged = true;
          }
        }
        db.setTransactionSuccessful();
      } catch (SQLException ex) {
        Log.w(TAG, "Problem while allocating appWidgetIds for existing widgets", ex);
      } finally {
        db.endTransaction();
        if (update != null) {
          update.close();
        }
        if (c != null) {
          c.close();
        }
      }
    }
示例#5
0
  // CUD local
  public Boolean salvar(Banco b, byte[] fotoPersonal) {
    /*String SQL = "INSERT INTO Personal (telefonePersonal,nomePersonal,dataDeNascimentoPersonal," +
    "emailPersonal,sexoPersonal,senhaPersonal,usuarioPersonal,fotoPersonal) " +
    "VALUES('" + super.getTelefone() + "','"+ super.getNome() + "','" + super.getDataDeNascimento() +
    "','" + super.getEmail() + "','" + super.getSexo() + "','"  +
    super.getSenha() + "','" 	+ super.getUsuario() + "', '" + super.getFoto() + "')";
    */

    String SQL =
        "INSERT INTO Personal ("
            + "telefonePersonal,"
            + "nomePersonal,"
            + "dataDeNascimentoPersonal,"
            + "emailPersonal,"
            + "sexoPersonal,"
            + "senhaPersonal,"
            + "usuarioPersonal,"
            + "fotoPersonal,"
            + "ativo) values "
            + "(?, ?, ?, ? , ?, ? ,? ,? ,?)";

    SQLiteStatement statement = b.getWritableDatabase().compileStatement(SQL);
    statement.bindString(1, super.getTelefone());
    statement.bindString(2, super.getNome());
    statement.bindString(3, super.getDataDeNascimento());
    statement.bindString(4, super.getEmail());
    statement.bindString(5, super.getSexo());
    statement.bindString(6, super.getSenha());
    statement.bindString(7, super.getUsuario());
    statement.bindBlob(8, fotoPersonal);
    statement.bindString(9, "ativado");

    /*String SQL = "INSERT INTO Personal (telefonePersonal,nomePersonal,dataDeNascimentoPersonal," +
                      "emailPersonal,sexoPersonal,senhaPersonal,usuarioPersonal,fotoPersonal,ativo) " +
                      "VALUES('" + super.getTelefone()+ "','"+ super.getNome() + "','" + super.getDataDeNascimento() +
                      "','" + super.getEmail() + "','" + super.getSexo() + "','"  +
                      super.getSenha() + "','" 	+ super.getUsuario() + "','"+ foto + "','ativado');";
    //  System.out.println(SQL);*/
    try {
      statement.executeInsert();
      return true;
    } catch (Exception ex) {
      // System.out.println(ex.toString());
      ex.printStackTrace();
      return false;
    }
  }
 private void bindArgs(SQLiteStatement stmt, Object[] args, FieldType[] argFieldTypes)
     throws SQLException {
   if (args == null) {
     return;
   }
   for (int i = 0; i < args.length; i++) {
     Object arg = args[i];
     if (arg == null) {
       stmt.bindNull(i + 1);
     } else {
       SqlType sqlType = argFieldTypes[i].getSqlType();
       switch (sqlType) {
         case STRING:
         case LONG_STRING:
         case CHAR:
           stmt.bindString(i + 1, arg.toString());
           break;
         case BOOLEAN:
         case BYTE:
         case SHORT:
         case INTEGER:
         case LONG:
           stmt.bindLong(i + 1, ((Number) arg).longValue());
           break;
         case FLOAT:
         case DOUBLE:
           stmt.bindDouble(i + 1, ((Number) arg).doubleValue());
           break;
         case BYTE_ARRAY:
         case SERIALIZABLE:
           stmt.bindBlob(i + 1, (byte[]) arg);
           break;
         case DATE:
           // this is mapped to a STRING under Android
         case BLOB:
           // this is only for derby serializable
         case BIG_DECIMAL:
           // this should be handled as a STRING
           throw new SQLException("Invalid Android type: " + sqlType);
         case UNKNOWN:
         default:
           throw new SQLException("Unknown sql argument type: " + sqlType);
       }
     }
   }
 }
示例#7
0
  public Boolean editarFotoPersonal(Banco b, byte[] fotoPersonal) {

    String SQL = "UPDATE Personal set " + "fotoPersonal = ? " + " where usuarioPersonal = ?";

    SQLiteStatement statement = b.getWritableDatabase().compileStatement(SQL);
    statement.bindString(1, super.getUsuario());
    statement.bindBlob(2, fotoPersonal);

    try {
      statement.executeUpdateDelete();
      return true;
    } catch (Exception ex) {
      // System.out.println(ex.toString());
      ex.printStackTrace();
      return false;
    }
  }
  public void setMateriais(VO_Materiais materiais, int operacao) {
    try {
      String queryString = null;

      switch (operacao) {
        case INSERE:
          queryString = Contrato_VendasFacil.Materiais.INSERT;
          break;

        case ATUALIZA:
          queryString = Contrato_VendasFacil.Materiais.UPDATE;
          break;
      }

      if (materiais.getCodMaterialString().isEmpty()) {
        materiais.setCodMaterial(proximoCodigoMaterial());
      }
      // todo: getWritableDatabase
      DAO_VendasFacil dao = new DAO_VendasFacil(fragmento);
      SQLiteDatabase db = dao.getTabelaGravacao();

      SQLiteStatement query = db.compileStatement(queryString);

      // Ambas as querys (insert e update) estão montadas com os campos na mesma sequencia
      // Assim é possível utilizar o mesmo trecho de código abaixo para ambos os casos.
      query.bindString(1, materiais.getDesMaterial());
      query.bindBlob(2, materiais.getFotoByteArray());
      query.bindDouble(3, materiais.getQtdMinima());
      query.bindDouble(4, materiais.getQtdEstoque());
      query.bindLong(5, materiais.getCodUnidadeMedida());
      query.bindLong(6, materiais.getDataUltimaCompraAsLong());
      query.bindLong(7, materiais.getCodMaterialInteger());

      query.executeInsert();
      db.close();
      // todo: close()
    } catch (Exception e) {
      Toasts.mensagemErro(fragmento, e.getMessage(), "DAO_Material.setMateriais");
    }
  }
  private void insertPhoto(Cursor c, SQLiteStatement insert, SQLiteStatement photoIdUpdate) {
    if (c.isNull(PhotosQuery.DATA)) {
      return;
    }

    long personId = c.getLong(PhotosQuery.PERSON);

    insert.bindLong(PhotoInsert.RAW_CONTACT_ID, personId);
    insert.bindLong(PhotoInsert.MIMETYPE_ID, mPhotoMimetypeId);
    insert.bindBlob(PhotoInsert.PHOTO, c.getBlob(PhotosQuery.DATA));

    String account = c.getString(PhotosQuery._SYNC_ACCOUNT);
    if (!TextUtils.isEmpty(account)) {
      insert.bindString(PhotoInsert.SYNC1, c.getString(PhotosQuery._SYNC_ID));
    } else {
      insert.bindNull(PhotoInsert.SYNC1);
    }

    long rowId = insert(insert);
    photoIdUpdate.bindLong(PhotoIdUpdate.PHOTO_ID, rowId);
    photoIdUpdate.bindLong(PhotoIdUpdate.CONTACT_ID, personId);
    photoIdUpdate.execute();
  }
示例#10
0
  public void saveHomeWork(HomeWork homeWork) {

    mDb.beginTransaction();
    try {
      mSaveHomeWorkStatement.clearBindings();
      if (homeWork.getDate() != null) {
        mSaveHomeWorkStatement.bindLong(
            1, homeWork.getDate().getTime() / CalendarManager.MILISECONDS_PER_DAY);
      }

      mSaveHomeWorkStatement.bindLong(2, homeWork.getLessonId());

      if (homeWork.getMessage() != null) {
        mSaveHomeWorkStatement.bindString(3, homeWork.getMessage());
      }

      if (homeWork.getImages() != null) {
        mSaveHomeWorkStatement.bindBlob(4, Slipper.serializeObject(homeWork.getImages()));
      }

      if (homeWork.isComplite()) {
        mSaveHomeWorkStatement.bindLong(5, 1);
      } else {
        mSaveHomeWorkStatement.bindLong(5, 0);
      }

      mSaveHomeWorkStatement.bindLong(6, PreferenceManager.getInstance().getGroupId());

      homeWork.setId(mSaveHomeWorkStatement.executeInsert());
      mDb.setTransactionSuccessful();
      NotificationManager.getInstance().addNewNotification(homeWork);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      mDb.endTransaction();
    }
  }
  /** 数据绑定 * */
  private void bindValues(SQLiteStatement stmt, T entity) {
    for (int i = 0; i < mSetArgs.length; i++) {
      int stmtIndex = i + 1;
      try {
        Field field = mClazz.getDeclaredField(mSetArgs[i]);
        field.setAccessible(true);

        Type columnType = field.getType();
        if (String.class.equals(columnType)) {
          String value = (String) field.get(entity);
          if (value == null) {
            stmt.bindNull(stmtIndex);
          } else {
            stmt.bindString(stmtIndex, value);
          }

        } else if (columnType.equals(Integer.class) || columnType.equals(int.class)) {
          int value = field.getInt(entity);
          stmt.bindLong(stmtIndex, value);

        } else if (columnType.equals(Float.class) || columnType.equals(float.class)) {
          float value = field.getFloat(entity);
          stmt.bindDouble(stmtIndex, value);

        } else if (columnType.equals(Double.class) || columnType.equals(double.class)) {
          double value = field.getDouble(entity);
          stmt.bindDouble(stmtIndex, value);

        } else if (columnType.equals(Long.class) || columnType.equals(long.class)) {
          long value = field.getLong(entity);
          stmt.bindLong(stmtIndex, value);

        } else {
          Object obj = field.get(entity);
          if (obj == null) {
            stmt.bindNull(stmtIndex);
          } else {
            byte[] value = SerializeHelper.serialize(obj);
            stmt.bindBlob(stmtIndex, value);
          }
        }

      } catch (NoSuchFieldException e) {
        e.printStackTrace();
        stmt.bindNull(stmtIndex);
        continue;
      } catch (IllegalAccessException e) {
        e.printStackTrace();
        stmt.bindNull(stmtIndex);
        continue;
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
        stmt.bindNull(stmtIndex);
        continue;
      }
    }

    if (mWhereArgs != null) {
      for (int i = 0; i < mWhereArgs.length; i++) {
        int columnIndex = mSetArgs.length + i + 1;
        stmt.bindString(columnIndex, mWhereArgValues[i]);
      }
    }
  }