Project

General

Profile

Evolution #15537

Update Contract method to get aliased cols

Added by Erwan L. over 1 year ago. Updated 11 months ago.

Status:
Fermé
Priority:
Normal
Assignee:
Category:
-
Target version:
Start date:
06/20/2019
Due date:
% Done:

100%

Estimated time:
Bdc:
HARMONY

Description

Add methods to get aliased cols

    public static String[] getAliasCols() {
        return getAliasCols(TABLE_NAME);
    }

    public static String[] getAliasCols(@NonNull String alias) {
        return getRefCols(PhotoMetadataContract.COLS, alias);
    }

    private static String[] getRefCols(@NonNull String[] originalCols, String alias) {
        String[] result = new String[originalCols.length];

        if (alias.length > 0) {
            alias = "_" + alias;
        }

        for (int i = 0; i < originalCols.length; i++) {
            result[i] = alias + originalCols[i];
        }

        return result;
    }    

Update cursors to item to handle custom alias

    /**
     * Convert Cursor of database to Message entity.
     * @param cursor Cursor object
     * @param result Message entity
     */
    public static void cursorToItem(
            final Cursor cursor,
            final Message result) {
        cursorToItem(null, cursor, result);
    }

    public static void cursorToItem(
            final String tableAlias,
            final Cursor cursor,
            final Message result) {
        if (cursor.getCount() != 0) {
            String prefix;

            if (!Strings.isNullOrEmpty(tableAlias)) {
                prefix = tableAlias + "_";
            } else {
                prefix = "";
            }

            int index;

            index = cursor.getColumnIndex(prefix + MessageContract.COL_ID);

            if (index > -1) {
                result.setId(cursor.getInt(index));
            }

            index = cursor.getColumnIndex(prefix + MessageContract.COL_CONTENT);

            if (index > -1) {
                result.setId(cursor.getInt(index));
            }

            ...
        }
    }

Recurrences


Related issues

Related to Harmony - Evolution #11023: Add alias to sql request like in doctrineEn cours2017-11-09

History

#1Updated by Jeremy C. over 1 year ago

Appliqué par commit commit:origin|1e1d266434a5ffdd0e5c46478cb9f6837d5504f9.

#3Updated by Jeremy C. over 1 year ago

Appliqué par commit commit:origin|fcdce32ad31631488acea96020bcedfd9b0dc1ff.

Also available in: Atom PDF

Go to top
Add picture from clipboard (Maximum size: 200 MB)