public static void cursorRowToContentValues(Cursor paramCursor, ContentValues paramContentValues)
 {
   AbstractWindowedCursor localAbstractWindowedCursor;
   String[] arrayOfString;
   int i;
   if ((paramCursor instanceof AbstractWindowedCursor))
   {
     localAbstractWindowedCursor = (AbstractWindowedCursor)paramCursor;
     arrayOfString = paramCursor.getColumnNames();
     int j = arrayOfString.length;
     i = 0;
     label27:
     if (i >= j) {
       return;
     }
     if ((localAbstractWindowedCursor == null) || (!localAbstractWindowedCursor.isBlob(i))) {
       break label74;
     }
     paramContentValues.put(arrayOfString[i], paramCursor.getBlob(i));
   }
   for (;;)
   {
     i += 1;
     break label27;
     localAbstractWindowedCursor = null;
     break;
     label74:
     paramContentValues.put(arrayOfString[i], paramCursor.getString(i));
   }
 }
 public static void cursorStringToContentValuesIfPresent(Cursor paramCursor, ContentValues paramContentValues, String paramString)
 {
   int i = paramCursor.getColumnIndex(paramString);
   if ((i != -1) && (!paramCursor.isNull(i))) {
     paramContentValues.put(paramString, paramCursor.getString(i));
   }
 }
 public static void dumpCurrentRow(Cursor paramCursor, PrintStream paramPrintStream)
 {
   String[] arrayOfString = paramCursor.getColumnNames();
   paramPrintStream.println(paramCursor.getPosition() + " {");
   int j = arrayOfString.length;
   int i = 0;
   for (;;)
   {
     if (i < j) {
       try
       {
         String str1 = paramCursor.getString(i);
         paramPrintStream.println("   " + arrayOfString[i] + '=' + str1);
         i += 1;
       }
       catch (SQLiteException localSQLiteException)
       {
         for (;;)
         {
           String str2 = "<unprintable>";
         }
       }
     }
   }
   paramPrintStream.println("}");
 }
 public static void dumpCurrentRow(Cursor paramCursor, StringBuilder paramStringBuilder)
 {
   String[] arrayOfString = paramCursor.getColumnNames();
   paramStringBuilder.append(paramCursor.getPosition() + " {\n");
   int j = arrayOfString.length;
   int i = 0;
   for (;;)
   {
     if (i < j) {
       try
       {
         String str1 = paramCursor.getString(i);
         paramStringBuilder.append("   " + arrayOfString[i] + '=' + str1 + "\n");
         i += 1;
       }
       catch (SQLiteException localSQLiteException)
       {
         for (;;)
         {
           String str2 = "<unprintable>";
         }
       }
     }
   }
   paramStringBuilder.append("}\n");
 }
 /**
  * Reads a String out of a column in a Cursor and writes it to a ContentValues. Adds nothing to
  * the ContentValues if the column isn't present or if its value is null.
  *
  * @param cursor The cursor to read from
  * @param column The column to read
  * @param values The {@link ContentValues} to put the value into
  */
 public static void cursorStringToContentValuesIfPresent(
     Cursor cursor, ContentValues values, String column) {
   final int index = cursor.getColumnIndexOrThrow(column);
   if (!cursor.isNull(index)) {
     values.put(column, cursor.getString(index));
   }
 }
 /**
  * Reads the strings from the cursor that are specifed in the columnIndicies array and saves them
  * in values beginning at startingIndex, skipping a slot for each value. If columnIndicies has
  * length 3 and startingIndex is 1, the values will be stored in slots 1, 3, and 5.
  *
  * @param values the String[] to populate
  * @param cursor the cursor from which to read
  * @param columnIndicies the indicies of the values to read from the cursor
  * @param startingIndex the slot in which to start storing values, and must be either 0 or 1.
  */
 private static void populateValues(
     String[] values, Cursor cursor, int[] columnIndicies, int startingIndex) {
   assert startingIndex == 0 || startingIndex == 1;
   for (int i = 0; i < columnIndicies.length; i++) {
     values[startingIndex + i * 2] = cursor.getString(columnIndicies[i]);
   }
 }
    private void buildSQL() throws SQLException {
      StringBuilder sb = new StringBuilder(128);
      sb.append("INSERT INTO ");
      sb.append(mTableName);
      sb.append(" (");

      StringBuilder sbv = new StringBuilder(128);
      sbv.append("VALUES (");

      int i = 1;
      Cursor cur = null;
      try {
        cur = mDb.rawQuery("PRAGMA table_info(" + mTableName + ")", null);
        mColumns = new HashMap<String, Integer>(cur.getCount());
        while (cur.moveToNext()) {
          String columnName = cur.getString(TABLE_INFO_PRAGMA_COLUMNNAME_INDEX);
          String defaultValue = cur.getString(TABLE_INFO_PRAGMA_DEFAULT_INDEX);

          mColumns.put(columnName, i);
          sb.append("'");
          sb.append(columnName);
          sb.append("'");

          if (defaultValue == null) {
            sbv.append("?");
          } else {
            sbv.append("COALESCE(?, ");
            sbv.append(defaultValue);
            sbv.append(")");
          }

          sb.append(i == cur.getCount() ? ") " : ", ");
          sbv.append(i == cur.getCount() ? ");" : ", ");
          ++i;
        }
      } finally {
        if (cur != null) cur.close();
      }

      sb.append(sbv);

      mInsertSQL = sb.toString();
      if (LOCAL_LOGV) Log.v(TAG, "insert statement is " + mInsertSQL);
    }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    String filePickerResult = "";
    if (data != null && resultCode == RESULT_OK) {
      try {
        ContentResolver cr = getContentResolver();
        Uri uri = data.getData();
        Cursor cursor =
            GeckoApp.mAppContext
                .getContentResolver()
                .query(uri, new String[] {OpenableColumns.DISPLAY_NAME}, null, null, null);
        String name = null;
        if (cursor != null) {
          try {
            if (cursor.moveToNext()) {
              name = cursor.getString(0);
            }
          } finally {
            cursor.close();
          }
        }
        String fileName = "tmp_";
        String fileExt = null;
        int period;
        if (name == null || (period = name.lastIndexOf('.')) == -1) {
          String mimeType = cr.getType(uri);
          fileExt = "." + GeckoAppShell.getExtensionFromMimeType(mimeType);
        } else {
          fileExt = name.substring(period);
          fileName = name.substring(0, period);
        }
        File file = File.createTempFile(fileName, fileExt, sGREDir);

        FileOutputStream fos = new FileOutputStream(file);
        InputStream is = cr.openInputStream(uri);
        byte[] buf = new byte[4096];
        int len = is.read(buf);
        while (len != -1) {
          fos.write(buf, 0, len);
          len = is.read(buf);
        }
        fos.close();
        filePickerResult = file.getAbsolutePath();
      } catch (Exception e) {
        Log.e(LOG_FILE_NAME, "showing file picker", e);
      }
    }
    try {
      mFilePickerResult.put(filePickerResult);
    } catch (InterruptedException e) {
      Log.i(LOG_FILE_NAME, "error returning file picker result", e);
    }
  }
  /**
   * Read the entire contents of a cursor row and store them in a ContentValues.
   *
   * @param cursor the cursor to read from.
   * @param values the {@link ContentValues} to put the row into.
   */
  public static void cursorRowToContentValues(Cursor cursor, ContentValues values) {
    AbstractWindowedCursor awc =
        (cursor instanceof AbstractWindowedCursor) ? (AbstractWindowedCursor) cursor : null;

    String[] columns = cursor.getColumnNames();
    int length = columns.length;
    for (int i = 0; i < length; i++) {
      if (awc != null && awc.isBlob(i)) {
        values.put(columns[i], cursor.getBlob(i));
      } else {
        values.put(columns[i], cursor.getString(i));
      }
    }
  }
Exemple #10
0
 @Test
 public void testGetString() throws Exception {
   List<Field.Type> types = Arrays.asList(Field.Type.TYPE_ENUM, Field.Type.TYPE_SET);
   for (Field.Type type : types) {
     try (Cursor cursor =
         new SimpleCursor(
             QueryResult.newBuilder()
                 .addFields(Field.newBuilder().setName("col0").setType(type).build())
                 .addRows(Row.newBuilder().addValues(ByteString.copyFromUtf8("val123")))
                 .build())) {
       cursor.next();
       Assert.assertEquals("val123", cursor.getString("col0"));
     }
   }
 }
 /**
  * Prints the contents of a Cursor's current row to a StringBuilder.
  *
  * @param cursor the cursor to print
  * @param sb the StringBuilder to print to
  */
 public static void dumpCurrentRow(Cursor cursor, StringBuilder sb) {
   String[] cols = cursor.getColumnNames();
   sb.append("" + cursor.getPosition() + " {\n");
   int length = cols.length;
   for (int i = 0; i < length; i++) {
     String value;
     try {
       value = cursor.getString(i);
     } catch (SQLiteException e) {
       // assume that if the getString threw this exception then the column is not
       // representable by a string, e.g. it is a BLOB.
       value = "<unprintable>";
     }
     sb.append("   " + cols[i] + '=' + value + "\n");
   }
   sb.append("}\n");
 }
 private void buildSQL()
 {
   Object localObject1 = null;
   StringBuilder localStringBuilder1 = new StringBuilder(128);
   localStringBuilder1.append("INSERT INTO ");
   localStringBuilder1.append(mTableName);
   localStringBuilder1.append(" (");
   StringBuilder localStringBuilder2 = new StringBuilder(128);
   localStringBuilder2.append("VALUES (");
   Cursor localCursor;
   for (;;)
   {
     try
     {
       localCursor = mDb.rawQuery("PRAGMA table_info(" + mTableName + ")", null);
       localObject1 = localCursor;
       mColumns = new HashMap(localCursor.getCount());
       int i = 1;
       localObject1 = localCursor;
       if (!localCursor.moveToNext()) {
         break;
       }
       localObject1 = localCursor;
       String str1 = localCursor.getString(1);
       localObject1 = localCursor;
       String str3 = localCursor.getString(4);
       localObject1 = localCursor;
       mColumns.put(str1, Integer.valueOf(i));
       localObject1 = localCursor;
       localStringBuilder1.append("'");
       localObject1 = localCursor;
       localStringBuilder1.append(str1);
       localObject1 = localCursor;
       localStringBuilder1.append("'");
       if (str3 == null)
       {
         localObject1 = localCursor;
         localStringBuilder2.append("?");
         localObject1 = localCursor;
         if (i == localCursor.getCount())
         {
           str1 = ") ";
           localObject1 = localCursor;
           localStringBuilder1.append(str1);
           localObject1 = localCursor;
           if (i != localCursor.getCount()) {
             break label335;
           }
           str1 = ");";
           localObject1 = localCursor;
           localStringBuilder2.append(str1);
           i += 1;
         }
       }
       else
       {
         localObject1 = localCursor;
         localStringBuilder2.append("COALESCE(?, ");
         localObject1 = localCursor;
         localStringBuilder2.append(str3);
         localObject1 = localCursor;
         localStringBuilder2.append(")");
         continue;
       }
       str2 = ", ";
     }
     finally
     {
       if (localObject1 != null) {
         ((Cursor)localObject1).close();
       }
     }
     continue;
     label335:
     String str2 = ", ";
   }
   if (localCursor != null) {
     localCursor.close();
   }
   localStringBuilder1.append(localStringBuilder2);
   mInsertSQL = localStringBuilder1.toString();
 }
  public static void cursorFillWindow(
      final Cursor cursor, int position, final android.database.CursorWindow window) {
    if (position < 0 || position >= cursor.getCount()) {
      return;
    }
    final int oldPos = cursor.getPosition();
    final int numColumns = cursor.getColumnCount();
    window.clear();
    window.setStartPosition(position);
    window.setNumColumns(numColumns);
    if (cursor.moveToPosition(position)) {
      do {
        if (!window.allocRow()) {
          break;
        }
        for (int i = 0; i < numColumns; i++) {
          final int type = cursor.getType(i);
          final boolean success;
          switch (type) {
            case Cursor.FIELD_TYPE_NULL:
              success = window.putNull(position, i);
              break;

            case Cursor.FIELD_TYPE_INTEGER:
              success = window.putLong(cursor.getLong(i), position, i);
              break;

            case Cursor.FIELD_TYPE_FLOAT:
              success = window.putDouble(cursor.getDouble(i), position, i);
              break;

            case Cursor.FIELD_TYPE_BLOB:
              {
                final byte[] value = cursor.getBlob(i);
                success =
                    value != null
                        ? window.putBlob(value, position, i)
                        : window.putNull(position, i);
                break;
              }

            default: // assume value is convertible to String
            case Cursor.FIELD_TYPE_STRING:
              {
                final String value = cursor.getString(i);
                success =
                    value != null
                        ? window.putString(value, position, i)
                        : window.putNull(position, i);
                break;
              }
          }
          if (!success) {
            window.freeLastRow();
            break;
          }
        }
        position += 1;
      } while (cursor.moveToNext());
    }
    cursor.moveToPosition(oldPos);
  }
 public static void cursorStringToInsertHelper(Cursor paramCursor, String paramString, InsertHelper paramInsertHelper, int paramInt)
 {
   paramInsertHelper.bind(paramInt, paramCursor.getString(paramCursor.getColumnIndexOrThrow(paramString)));
 }
 /**
  * Reads a String out of a field in a Cursor and writes it to an InsertHelper.
  *
  * @param cursor The cursor to read from
  * @param field The TEXT field to read
  * @param inserter The InsertHelper to bind into
  * @param index the index of the bind entry in the InsertHelper
  */
 public static void cursorStringToInsertHelper(
     Cursor cursor, String field, InsertHelper inserter, int index) {
   inserter.bind(index, cursor.getString(cursor.getColumnIndexOrThrow(field)));
 }
 public static void cursorStringToContentValues(Cursor paramCursor, String paramString1, ContentValues paramContentValues, String paramString2)
 {
   paramContentValues.put(paramString2, paramCursor.getString(paramCursor.getColumnIndexOrThrow(paramString1)));
 }
 /**
  * Reads a String out of a field in a Cursor and writes it to a Map.
  *
  * @param cursor The cursor to read from
  * @param field The TEXT field to read
  * @param values The {@link ContentValues} to put the value into, with the field as the key
  * @param key The key to store the value with in the map
  */
 public static void cursorStringToContentValues(
     Cursor cursor, String field, ContentValues values, String key) {
   values.put(key, cursor.getString(cursor.getColumnIndexOrThrow(field)));
 }
 public static void cursorFillWindow(Cursor paramCursor, int paramInt, CursorWindow paramCursorWindow)
 {
   if ((paramInt < 0) || (paramInt >= paramCursor.getCount())) {
     return;
   }
   int j = paramCursor.getPosition();
   int k = paramCursor.getColumnCount();
   paramCursorWindow.clear();
   paramCursorWindow.setStartPosition(paramInt);
   paramCursorWindow.setNumColumns(k);
   int i;
   if (paramCursor.moveToPosition(paramInt)) {
     if (paramCursorWindow.allocRow()) {
       i = 0;
     }
   }
   for (;;)
   {
     Object localObject;
     boolean bool;
     if (i < k) {
       switch (paramCursor.getType(i))
       {
       case 3: 
       default: 
         localObject = paramCursor.getString(i);
         if (localObject != null) {
           bool = paramCursorWindow.putString((String)localObject, paramInt, i);
         }
         break;
       }
     }
     for (;;)
     {
       if (bool) {
         break label264;
       }
       paramCursorWindow.freeLastRow();
       paramInt += 1;
       if (paramCursor.moveToNext()) {
         break;
       }
       paramCursor.moveToPosition(j);
       return;
       bool = paramCursorWindow.putNull(paramInt, i);
       continue;
       bool = paramCursorWindow.putLong(paramCursor.getLong(i), paramInt, i);
       continue;
       bool = paramCursorWindow.putDouble(paramCursor.getDouble(i), paramInt, i);
       continue;
       localObject = paramCursor.getBlob(i);
       if (localObject != null)
       {
         bool = paramCursorWindow.putBlob((byte[])localObject, paramInt, i);
       }
       else
       {
         bool = paramCursorWindow.putNull(paramInt, i);
         continue;
         bool = paramCursorWindow.putNull(paramInt, i);
       }
     }
     label264:
     i += 1;
   }
 }
Exemple #19
0
        public void onClick(View v) {
          ContentResolver cr = getContentResolver();
          switch (v.getId()) {
              // 전부 읽기
            case R.id.readall:
              Cursor cursor = cr.query(Uri.parse(WORDURI), null, null, null, null);

              String Result = "";
              while (cursor.moveToNext()) {
                String eng = cursor.getString(0);
                String han = cursor.getString(1);
                Result += (eng + " = " + han + "\n");
              }

              if (Result.length() == 0) {
                mText.setText("Empyt Set");
              } else {
                mText.setText(Result);
              }
              cursor.close();
              break;
              // 하나만 읽기
            case R.id.readone:
              Cursor cursor2 = cr.query(Uri.parse(WORDURI + "/boy"), null, null, null, null);

              String Result2 = "";
              if (cursor2.moveToFirst()) {
                String eng = cursor2.getString(0);
                String han = cursor2.getString(1);
                Result2 += (eng + " = " + han + "\n");
              }

              if (Result2.length() == 0) {
                mText.setText("Empyt Set");
              } else {
                mText.setText(Result2);
              }
              cursor2.close();
              break;
              // 삽입
            case R.id.insert:
              ContentValues row = new ContentValues();
              row.put("eng", "school");
              row.put("han", "학교");

              cr.insert(Uri.parse(WORDURI), row);
              mText.setText("Insert Success");
              break;
              // 삭제
            case R.id.delete:
              cr.delete(Uri.parse(WORDURI), null, null);
              mText.setText("Delete Success");
              break;
              // 수정
            case R.id.update:
              ContentValues row2 = new ContentValues();
              row2.put("han", "핵교");
              cr.update(Uri.parse(WORDURI + "/school"), row2, null, null);
              mText.setText("Update Success");
              break;
          }
        }