Example usage for android.database Cursor getType

List of usage examples for android.database Cursor getType

Introduction

In this page you can find the example usage for android.database Cursor getType.

Prototype

int getType(int columnIndex);

Source Link

Document

Returns data type of the given column's value.

Usage

From source file:org.opendatakit.utilities.test.AbstractODKDatabaseUtilsTest.java

public void testRawQueryWithData_ExpectPass() {
    String tableId = testTable;/*from  w  ww. j  a va2  s .c  om*/
    String query = "SELECT * FROM " + tableId;
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column("col1", "col1", "string", "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, tableId,
            activeUser, RoleConsts.ADMIN_ROLES_LIST);

    // Check that the user defined rows are in the table
    Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, query, null, null, accessContext);
    Cursor refCursor = db.rawQuery(query, null);

    if (cursor != null && refCursor != null) {
        int index = 0;
        while (cursor.moveToNext() && refCursor.moveToNext()) {
            int testType = cursor.getType(index);
            int refType = refCursor.getType(index);
            assertEquals(testType, refType);

            switch (refType) {
            case Cursor.FIELD_TYPE_BLOB:
                byte[] byteArray = cursor.getBlob(index);
                byte[] refByteArray = refCursor.getBlob(index);
                assertEquals(byteArray, refByteArray);
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                float valueFloat = cursor.getFloat(index);
                float refValueFloat = refCursor.getFloat(index);
                assertEquals(valueFloat, refValueFloat);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                int valueInt = cursor.getInt(index);
                int refValueInt = refCursor.getInt(index);
                assertEquals(valueInt, refValueInt);
                break;
            case Cursor.FIELD_TYPE_STRING:
                String valueStr = cursor.getString(index);
                String refValueStr = refCursor.getString(index);
                assertEquals(valueStr, refValueStr);
                break;
            case Cursor.FIELD_TYPE_NULL:
            default:
                break;
            }
        }
    }

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:org.opendatakit.utilities.test.AbstractODKDatabaseUtilsTest.java

public void testWriteDataIntoExisitingTableWithGeopoint_ExpectPass() throws ActionNotAuthorizedException {
    String tableId = testTable;//from  w w w  .  j a  v  a  2s .c  o m
    String testCol = "testColumn";
    String testColLat = "testColumn_latitude";
    String testColLong = "testColumn_longitude";
    String testColAlt = "testColumn_altitude";
    String testColAcc = "testColumn_accuracy";
    double pos_lat = 5.55;
    double pos_long = 6.6;
    double pos_alt = 7.77;
    double pos_acc = 8.88;
    String testColType = ElementType.GEOPOINT;
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column(testCol, testCol, testColType,
            "[\"" + testColLat + "\",\"" + testColLong + "\",\"" + testColAlt + "\",\"" + testColAcc + "\"]"));
    columns.add(new Column(testColLat, "latitude", ElementDataType.number.name(), "[]"));
    columns.add(new Column(testColLong, "longitude", ElementDataType.number.name(), "[]"));
    columns.add(new Column(testColAlt, "altitude", ElementDataType.number.name(), "[]"));
    columns.add(new Column(testColAcc, "accuracy", ElementDataType.number.name(), "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, tableId,
            activeUser, RoleConsts.ADMIN_ROLES_LIST);

    ContentValues cvValues = new ContentValues();
    cvValues.put(testColLat, pos_lat);
    cvValues.put(testColLong, pos_long);
    cvValues.put(testColAlt, pos_alt);
    cvValues.put(testColAcc, pos_acc);

    ODKDatabaseImplUtils.get().insertRowWithId(db, tableId, orderedColumns, cvValues,
            LocalizationUtils.genUUID(), activeUser, RoleConsts.ADMIN_ROLES_LIST, currentLocale);

    // Select everything out of the table
    String sel = "SELECT * FROM " + tableId + " WHERE " + testColLat + " = ?";
    String[] selArgs = { "" + pos_lat };
    Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext);

    double valLat = 0;
    double valLong = 0;
    double valAlt = 0;
    double valAcc = 0;
    while (cursor.moveToNext()) {
        int ind = cursor.getColumnIndex(testColLat);
        int type = cursor.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_FLOAT);
        valLat = cursor.getDouble(ind);

        ind = cursor.getColumnIndex(testColLong);
        type = cursor.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_FLOAT);
        valLong = cursor.getDouble(ind);

        ind = cursor.getColumnIndex(testColAlt);
        type = cursor.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_FLOAT);
        valAlt = cursor.getDouble(ind);

        ind = cursor.getColumnIndex(testColAcc);
        type = cursor.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_FLOAT);
        valAcc = cursor.getDouble(ind);
    }

    assertEquals(valLat, pos_lat);
    assertEquals(valLong, pos_long);
    assertEquals(valAlt, pos_alt);
    assertEquals(valAcc, pos_acc);

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:org.opendatakit.utilities.test.AbstractODKDatabaseUtilsTest.java

public void testCreateOrOpenTableWithColumnWhenColumnIsMimeUri_ExpectPass() {
    String tableId = testTable;//from  w  w  w  .j a va  2 s.  c  o  m
    String testCol = "testColumn";
    String uriFrag = "uriFragment";
    String conType = "contentType";
    String testColUriFrag = testCol + "_" + uriFrag;
    String testColContType = testCol + "_" + conType;
    String testColType = DataTypeNamesToRemove.MIMEURI;

    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column(testCol, testCol, testColType,
            "[\"" + testColUriFrag + "\",\"" + testColContType + "\"]"));
    columns.add(new Column(testColUriFrag, "uriFragment", ElementDataType.rowpath.name(), "[]"));
    columns.add(new Column(testColContType, "contentType", ElementDataType.string.name(), "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    OrderedColumns coldefs = ODKDatabaseImplUtils.get().getUserDefinedColumns(db, tableId);
    assertEquals(coldefs.getColumnDefinitions().size(), 3);
    assertEquals(coldefs.getColumnDefinitions().get(0).getElementKey(), testCol);
    assertEquals(coldefs.getColumnDefinitions().get(1).getElementKey(), testColContType);
    assertEquals(coldefs.getColumnDefinitions().get(2).getElementKey(), testColUriFrag);

    List<String> cols = new ArrayList<String>();
    cols.add(uriFrag);
    cols.add(conType);

    for (ColumnDefinition col : coldefs.getColumnDefinitions()) {
        String key = col.getElementKey();
        String name = col.getElementName();
        String type = col.getElementType();
        if (key.equals(testCol)) {
            assertTrue(key.equals(testCol));
            assertTrue(name.equals(testCol));
            assertTrue(type.equals(testColType));
        } else {
            assertTrue(key.equals(testCol + "_" + name));
            assertTrue(cols.contains(name));
            if (name.equals(uriFrag)) {
                assertTrue(type.equals(ElementDataType.rowpath.name()));
            } else {
                assertTrue(type.equals(ElementDataType.string.name()));
            }
        }
    }

    // Select everything out of the table for element key
    String[] selArgs = { "" + testCol };
    Cursor cursor = ODKDatabaseImplUtils.get().queryForTest(db, DatabaseConstants.COLUMN_DEFINITIONS_TABLE_NAME,
            null, elemKey + " = ?", selArgs, null, null, null, null);
    while (cursor.moveToNext()) {
        int ind = cursor.getColumnIndex(listChildElemKeys);
        int type = cursor.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_STRING);
        String valStr = cursor.getString(ind);
        String testVal = "[\"" + testColUriFrag + "\",\"" + testColContType + "\"]";
        assertEquals(valStr, testVal);
    }

    // Select everything out of the table for uriFragment
    String[] selArgs2 = { testColUriFrag };
    cursor = ODKDatabaseImplUtils.get().queryForTest(db, DatabaseConstants.COLUMN_DEFINITIONS_TABLE_NAME, null,
            elemKey + " = ?", selArgs2, null, null, null, null);

    while (cursor.moveToNext()) {
        int ind = cursor.getColumnIndex(elemName);
        int type = cursor.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_STRING);
        String valStr = cursor.getString(ind);
        assertEquals(valStr, uriFrag);
    }

    // Select everything out of the table for contentType
    String[] selArgs3 = { testColContType };
    cursor = ODKDatabaseImplUtils.get().queryForTest(db, DatabaseConstants.COLUMN_DEFINITIONS_TABLE_NAME, null,
            elemKey + " = ?", selArgs3, null, null, null, null);

    while (cursor.moveToNext()) {
        int ind = cursor.getColumnIndex(elemName);
        int type = cursor.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_STRING);
        String valStr = cursor.getString(ind);
        assertEquals(valStr, conType);
    }

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:org.opendatakit.utilities.test.AbstractODKDatabaseUtilsTest.java

public void testWriteDataIntoExisitingTableWithIdWhenIdAlreadyExists_ExpectPass()
        throws ActionNotAuthorizedException {
    String tableId = testTable;//from  w  w  w .jav  a  2s .c om
    String testCol = "testColumn";
    String testColType = ElementDataType.integer.name();
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column(testCol, testCol, testColType, "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, tableId,
            activeUser, RoleConsts.ADMIN_ROLES_LIST);

    int testVal = 5;
    boolean thrown = false;

    ContentValues cvValues = new ContentValues();
    cvValues.put(testCol, testVal);

    String uuid = UUID.randomUUID().toString();
    ODKDatabaseImplUtils.get().insertRowWithId(db, tableId, orderedColumns, cvValues, uuid, activeUser,
            RoleConsts.ADMIN_ROLES_LIST, currentLocale);

    // Select everything out of the table
    String sel = "SELECT * FROM " + tableId + " WHERE " + testCol + " = ?";
    String[] selArgs = { "" + testVal };
    Cursor cursor = null;
    try {
        cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext);
        assertEquals(cursor.getCount(), 1);

        int val = 0;
        while (cursor.moveToNext()) {
            int ind = cursor.getColumnIndex(testCol);
            int type = cursor.getType(ind);
            assertEquals(type, Cursor.FIELD_TYPE_INTEGER);
            val = cursor.getInt(ind);
        }

        assertEquals(val, testVal);
    } finally {
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
    }
    // Try updating that row in the database
    int testVal2 = 25;
    ContentValues cvValues2 = new ContentValues();
    cvValues2.put(testCol, testVal2);

    try {
        ODKDatabaseImplUtils.get().insertRowWithId(db, tableId, orderedColumns, cvValues2, uuid, activeUser,
                RoleConsts.ADMIN_ROLES_LIST, currentLocale);
    } catch (ActionNotAuthorizedException ex) {
        throw ex;
    } catch (IllegalArgumentException e) {
        thrown = true;
        e.printStackTrace();
    }

    assertEquals(thrown, true);

    /**
     * NOTE: we expect the log to report a failure to close this cursor.
     * It is GC'd and closed in its finalizer. This is confirming that
     * the finalizer is doing the right thing.
     */

    // Select everything out of the table
    String sel2 = "SELECT * FROM " + tableId;
    String[] selArgs2 = {};
    Cursor cursor2 = ODKDatabaseImplUtils.get().rawQuery(db, sel2, selArgs2, null, accessContext);
    assertEquals(cursor2.getCount(), 1);

    int val2 = 0;
    while (cursor2.moveToNext()) {
        int ind = cursor2.getColumnIndex(testCol);
        int type = cursor2.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_INTEGER);
        val2 = cursor2.getInt(ind);
    }

    assertEquals(val2, testVal);

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:org.opendatakit.utilities.test.AbstractODKDatabaseUtilsTest.java

public void testQueryDistinct_ExpectPass() throws ActionNotAuthorizedException {
    String tableId = testTable;//from   www .  j  av  a2 s  .c  o  m
    String testCol = "testColumn";
    String testColType = ElementDataType.integer.name();
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column(testCol, testCol, testColType, "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, tableId,
            activeUser, RoleConsts.ADMIN_ROLES_LIST);

    int testVal = 5;
    boolean thrown = false;

    ContentValues cvValues = new ContentValues();
    cvValues.put(testCol, testVal);

    String uuid = UUID.randomUUID().toString();
    ODKDatabaseImplUtils.get().insertRowWithId(db, tableId, orderedColumns, cvValues, uuid, activeUser,
            RoleConsts.ADMIN_ROLES_LIST, currentLocale);

    // Select everything out of the table
    String sel = "SELECT * FROM " + tableId + " WHERE " + testCol + " = ?";
    String[] selArgs = { "" + testVal };
    Cursor cursor = null;
    try {
        cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext);
        assertEquals(cursor.getCount(), 1);

        int val = 0;
        while (cursor.moveToNext()) {
            int ind = cursor.getColumnIndex(testCol);
            int type = cursor.getType(ind);
            assertEquals(type, Cursor.FIELD_TYPE_INTEGER);
            val = cursor.getInt(ind);
        }

        assertEquals(val, testVal);
    } finally {
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
    }
    // Add another row in the database with the same value
    String uuid2 = UUID.randomUUID().toString();
    ContentValues cvValues2 = new ContentValues();
    cvValues2.put(testCol, testVal);

    ODKDatabaseImplUtils.get().insertRowWithId(db, tableId, orderedColumns, cvValues2, uuid2, activeUser,
            RoleConsts.ADMIN_ROLES_LIST, currentLocale);

    // Select everything out of the table
    String sel2 = "SELECT * FROM " + tableId;
    String[] selArgs2 = {};
    Cursor cursor2 = ODKDatabaseImplUtils.get().rawQuery(db, sel2, selArgs2, null, accessContext);
    assertEquals(cursor2.getCount(), 2);

    System.out.println("testQueryDistinct_ExpectPass: after select *  query");
    OdkConnectionFactorySingleton.getOdkConnectionFactoryInterface().dumpInfo(false);

    // Make sure the values are correct
    int val2 = 0;
    while (cursor2.moveToNext()) {
        int ind = cursor2.getColumnIndex(testCol);
        int type = cursor2.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_INTEGER);
        val2 = cursor2.getInt(ind);
        assertEquals(val2, testVal);
    }

    // The moment of truth! test the queryDistinct
    // Get all of the rows of the database but only return testCol
    String[] retCols = { testCol };
    Cursor cursor3 = ODKDatabaseImplUtils.get().queryDistinctForTest(db, tableId, retCols, null, null, null,
            null, null, null);
    assertEquals(cursor3.getCount(), 1);

    int val3 = 0;
    while (cursor3.moveToNext()) {
        int ind = cursor3.getColumnIndex(testCol);
        int type = cursor3.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_INTEGER);
        val3 = cursor3.getInt(ind);
    }

    assertEquals(val3, testVal);

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:org.opendatakit.utilities.test.AbstractODKDatabaseUtilsTest.java

public void testQueryWithData_ExpectPass() {
    String tableId = testTable;//from   w w  w.j  a  v  a 2 s  .  c  o m
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column("col1", "col1", "string", "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    // Check that the user defined rows are in the table
    Cursor cursor = ODKDatabaseImplUtils.get().queryForTest(db, tableId, null, null, null, null, null, null,
            null);
    Cursor refCursor = db.query(tableId, null, null, null, null, null, null, null);

    if (cursor != null && refCursor != null) {
        int index = 0;
        while (cursor.moveToNext() && refCursor.moveToNext()) {
            int testType = cursor.getType(index);
            int refType = refCursor.getType(index);
            assertEquals(testType, refType);

            switch (refType) {
            case Cursor.FIELD_TYPE_BLOB:
                byte[] byteArray = cursor.getBlob(index);
                byte[] refByteArray = refCursor.getBlob(index);
                assertEquals(byteArray, refByteArray);
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                float valueFloat = cursor.getFloat(index);
                float refValueFloat = refCursor.getFloat(index);
                assertEquals(valueFloat, refValueFloat);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                int valueInt = cursor.getInt(index);
                int refValueInt = refCursor.getInt(index);
                assertEquals(valueInt, refValueInt);
                break;
            case Cursor.FIELD_TYPE_STRING:
                String valueStr = cursor.getString(index);
                String refValueStr = refCursor.getString(index);
                assertEquals(valueStr, refValueStr);
                break;
            case Cursor.FIELD_TYPE_NULL:
            default:
                break;
            }
        }
    }

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:org.opendatakit.utilities.test.AbstractODKDatabaseUtilsTest.java

public void testDeleteServerConflictRowWithIdAndLocDelOldVals_ExpectPass() throws ActionNotAuthorizedException {
    String tableId = testTable;// w w w  . ja va 2s.c  o  m
    String testCol = "testColumn";
    String testColType = ElementDataType.integer.name();
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column(testCol, testCol, testColType, "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, tableId,
            activeUser, RoleConsts.ADMIN_ROLES_LIST);

    int testVal = 5;

    // local record that is synced and pending deletion...

    ContentValues cvValues = new ContentValues();
    String rowId = LocalizationUtils.genUUID();
    cvValues.put(testCol, testVal);
    cvValues.put(DataTableColumns.ROW_ETAG, LocalizationUtils.genUUID());
    cvValues.put(DataTableColumns.SYNC_STATE, SyncState.deleted.name());
    ODKDatabaseImplUtils.get().insertRowWithId(db, tableId, orderedColumns, cvValues, rowId, activeUser,
            RoleConsts.ADMIN_ROLES_LIST, currentLocale);

    // Select everything out of the table
    String sel = "SELECT * FROM " + tableId + " WHERE " + DataTableColumns.ID + " = ? ORDER BY "
            + DataTableColumns.CONFLICT_TYPE + " ASC";
    String[] selArgs = { rowId };
    Cursor cursor = null;

    int val = 0;
    try {
        cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext);
        assertEquals(cursor.getCount(), 1);

        while (cursor.moveToNext()) {
            int ind = cursor.getColumnIndex(testCol);
            int type = cursor.getType(ind);
            assertEquals(type, Cursor.FIELD_TYPE_INTEGER);
            val = cursor.getInt(ind);
        }
    } finally {
        cursor.close();
    }

    assertEquals(val, testVal);

    // NOTE: all metadata fields need to be specified
    // server has a change...
    ContentValues updates = new ContentValues();
    // data value
    updates.put(testCol, testVal + 6);
    // metadata fields
    updates.put(DataTableColumns.CONFLICT_TYPE, ConflictType.SERVER_UPDATED_UPDATED_VALUES);
    updates.put(DataTableColumns.SYNC_STATE, SyncState.in_conflict.name());
    updates.put(DataTableColumns.ROW_ETAG, LocalizationUtils.genUUID());
    // insert in_conflict server row
    updates.put(DataTableColumns.FORM_ID, "serverForm");
    updates.put(DataTableColumns.LOCALE, currentLocale);
    updates.put(DataTableColumns.SAVEPOINT_TIMESTAMP,
            TableConstants.nanoSecondsFromMillis(System.currentTimeMillis()));
    updates.put(DataTableColumns.SAVEPOINT_TYPE, SavepointTypeManipulator.complete());
    updates.put(DataTableColumns.SAVEPOINT_CREATOR, "mailto:server@gmail.com");
    updates.put(DataTableColumns.FILTER_TYPE, RowFilterScope.Type.DEFAULT.name());
    updates.put(DataTableColumns.FILTER_VALUE, "mailto:server@gmail.com");

    // Place row in conflict
    int conflictType = ConflictType.LOCAL_DELETED_OLD_VALUES;
    ODKDatabaseImplUtils.get().privilegedPlaceRowIntoConflictWithId(db, tableId, orderedColumns, updates, rowId,
            conflictType, activeUser, currentLocale);

    // Run the query again and make sure that the place row in conflict worked as expected
    String whereClause = DataTableColumns.ID + "=?";
    String[] selectionArgs = new String[] { rowId };
    String[] orderByKeys = new String[] { DataTableColumns.CONFLICT_TYPE };
    String[] orderByDirs = new String[] { "ASC" };
    List<String> adminColumns = ODKDatabaseImplUtils.get().getAdminColumns();
    String[] adminColArr = adminColumns.toArray(new String[adminColumns.size()]);

    BaseTable baseTable = ODKDatabaseImplUtils.get().query(db, tableId,
            QueryUtil.buildSqlStatement(tableId, whereClause, null, null, orderByKeys, orderByDirs),
            selectionArgs, null, accessContext);
    UserTable table = new UserTable(baseTable, orderedColumns, adminColArr);

    assertEquals(table.getNumberOfRows(), 2);

    Row first = table.getRowAtIndex(0);
    Row second = table.getRowAtIndex(1);

    String v;
    int conflictTypeVal;

    v = first.getDataByKey(DataTableColumns.CONFLICT_TYPE);
    assertNotNull(v);
    conflictTypeVal = Integer.valueOf(v);
    assertEquals(conflictType, conflictTypeVal);

    v = second.getDataByKey(DataTableColumns.CONFLICT_TYPE);
    assertNotNull(v);
    conflictTypeVal = Integer.valueOf(v);
    assertEquals(ConflictType.SERVER_UPDATED_UPDATED_VALUES, conflictTypeVal);

    // Now delete the row
    ODKDatabaseImplUtils.get().resolveServerConflictWithDeleteRowWithId(db, tableId, rowId, activeUser,
            RoleConsts.ADMIN_ROLES_LIST);

    // Run the query yet again to make sure that things worked as expected
    baseTable = ODKDatabaseImplUtils.get().query(db, tableId,
            QueryUtil.buildSqlStatement(tableId, whereClause, null, null, orderByKeys, orderByDirs),
            selectionArgs, null, accessContext);
    table = new UserTable(baseTable, orderedColumns, adminColArr);

    assertEquals(table.getNumberOfRows(), 0);

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:org.opendatakit.utilities.AbstractODKDatabaseUtilsTest.java

@Test
public void testWriteDataIntoExistingTableWithValidValue_ExpectPass() throws ActionNotAuthorizedException {
    String tableId = testTable;//from ww  w.  j a  v  a 2s. co m
    String testCol = "testColumn";
    String testColType = ElementDataType.integer.name();
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column(testCol, testCol, testColType, "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, tableId,
            activeUser, RoleConsts.ADMIN_ROLES_LIST);

    int testVal = 5;

    ContentValues cvValues = new ContentValues();
    cvValues.put(testCol, testVal);
    ODKDatabaseImplUtils.get().insertRowWithId(db, tableId, orderedColumns, cvValues,
            LocalizationUtils.genUUID(), activeUser, RoleConsts.ADMIN_ROLES_LIST, currentLocale);

    // Select everything out of the table
    String sel = "SELECT * FROM " + tableId + " WHERE " + testCol + " = ?";
    String[] selArgs = { "" + testVal };
    Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext);

    int val = 0;
    while (cursor.moveToNext()) {
        int ind = cursor.getColumnIndex(testCol);
        int type = cursor.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_INTEGER);
        val = cursor.getInt(ind);
    }

    assertEquals(val, testVal);

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:org.opendatakit.utilities.AbstractODKDatabaseUtilsTest.java

@Test
public void testWriteDataIntoExistingTableWithBoolean_ExpectPass() throws ActionNotAuthorizedException {
    String tableId = testTable;/*  w w  w .  j  av a 2  s .  co m*/
    String testCol = "testColumn";
    String testColType = ElementDataType.bool.name();
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column(testCol, testCol, testColType, "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, tableId,
            activeUser, RoleConsts.ADMIN_ROLES_LIST);

    int testVal = 1;

    ContentValues cvValues = new ContentValues();
    cvValues.put(testCol, testVal);
    ODKDatabaseImplUtils.get().insertRowWithId(db, tableId, orderedColumns, cvValues,
            LocalizationUtils.genUUID(), activeUser, RoleConsts.ADMIN_ROLES_LIST, currentLocale);

    // Select everything out of the table
    String sel = "SELECT * FROM " + tableId + " WHERE " + testCol + " = ?";
    String[] selArgs = { "" + testVal };
    Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext);

    int val = 0;
    while (cursor.moveToNext()) {
        int ind = cursor.getColumnIndex(testCol);
        int type = cursor.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_INTEGER);
        val = cursor.getInt(ind);
    }

    assertEquals(val, testVal);

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}

From source file:org.opendatakit.utilities.AbstractODKDatabaseUtilsTest.java

@Test
public void testWriteDataIntoExistingTableWithInteger_ExpectPass() throws ActionNotAuthorizedException {
    String tableId = testTable;//from   w w w .  ja va  2 s.  c  om
    String testCol = "testColumn";
    String testColType = ElementDataType.integer.name();
    List<Column> columns = new ArrayList<Column>();
    columns.add(new Column(testCol, testCol, testColType, "[]"));
    OrderedColumns orderedColumns = ODKDatabaseImplUtils.get().createOrOpenTableWithColumns(db, tableId,
            columns);

    ODKDatabaseImplUtils.AccessContext accessContext = ODKDatabaseImplUtils.get().getAccessContext(db, tableId,
            activeUser, RoleConsts.ADMIN_ROLES_LIST);

    int testVal = 5;

    ContentValues cvValues = new ContentValues();
    cvValues.put(testCol, testVal);
    ODKDatabaseImplUtils.get().insertRowWithId(db, tableId, orderedColumns, cvValues,
            LocalizationUtils.genUUID(), activeUser, RoleConsts.ADMIN_ROLES_LIST, currentLocale);

    // Select everything out of the table
    String sel = "SELECT * FROM " + tableId + " WHERE " + testCol + " = ?";
    String[] selArgs = { "" + testVal };
    Cursor cursor = ODKDatabaseImplUtils.get().rawQuery(db, sel, selArgs, null, accessContext);

    int val = 0;
    while (cursor.moveToNext()) {
        int ind = cursor.getColumnIndex(testCol);
        int type = cursor.getType(ind);
        assertEquals(type, Cursor.FIELD_TYPE_INTEGER);
        val = cursor.getInt(ind);
    }

    assertEquals(val, testVal);

    // Drop the table now that the test is done
    ODKDatabaseImplUtils.get().deleteTableAndAllData(db, tableId);
}