Example usage for android.database Cursor getColumnNames

List of usage examples for android.database Cursor getColumnNames

Introduction

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

Prototype

String[] getColumnNames();

Source Link

Document

Returns a string array holding the names of all of the columns in the result set in the order in which they were listed in the result.

Usage

From source file:com.mobile.system.db.abatis.AbatisService.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> List<T> executeForBeanList(String sqlId, Map<String, Object> bindParams, Class bean)
        throws SecurityException, IllegalAccessException, InstantiationException, NoSuchMethodException {
    getDbObject();/*from w  w w .j av  a2s  .  com*/
    int pointer = context.getResources().getIdentifier(sqlId, "string", context.getPackageName());
    if (pointer == 0) {
        Log.e(TAG, "undefined sql id : " + sqlId);
        return null;
    }
    String sql = context.getResources().getString(pointer);
    if (bindParams != null) {
        Iterator<String> mapIterator = bindParams.keySet().iterator();
        while (mapIterator.hasNext()) {
            String key = mapIterator.next();
            Object value = bindParams.get(key);
            sql = getFinalSql(sql, key.toLowerCase(), value.toString());
        }
    }
    if (sql.indexOf('#') != -1) {
        Log.e(TAG, "undefined parameter sql : " + sql);
        return null;
    }
    Cursor cursor = dbObj.rawQuery(sql, null);
    Log.d(TAG, "Run sql : " + sql);
    List<T> objectList = new ArrayList<T>();
    if (cursor == null) {
        return null;
    }
    String[] columnNames = cursor.getColumnNames();
    List<String> dataNames = new ArrayList<String>();
    for (String columnName : columnNames) {
        dataNames.add(chgDataName(columnName));
    }
    T beanObj = null;
    // get bean class package

    while (cursor.moveToNext()) {
        beanObj = (T) parseToObject(bean, cursor);
        objectList.add(beanObj);
    }
    cursor.close();
    dbObj.close();
    return objectList;
}

From source file:com.mobile.system.db.abatis.AbatisService.java

/**
 * /* www  . ja  v  a2 s.c  o m*/
 * @param sqlId
 *            SQLID
 * @param bindParams
 *            sql parameter
 * 
 * @return List<Map<String, Object>> result
 * @throws ParseException
 */
public List<Map<String, Object>> executeForMapList(String sqlId, Map<String, Object> bindParams) {
    getDbObject();
    int pointer = context.getResources().getIdentifier(sqlId, "string", context.getPackageName());
    if (pointer == 0) {
        Log.e(TAG, "undefined sql id : " + sqlId);
        return null;
    }
    String sql = context.getResources().getString(pointer);
    if (bindParams != null) {
        Iterator<String> mapIterator = bindParams.keySet().iterator();
        while (mapIterator.hasNext()) {
            String key = mapIterator.next();
            Object value = bindParams.get(key);
            if (value != null && key != null) {
                sql = getFinalSql(sql, key.toLowerCase(), value.toString());
            }
        }
    }
    if (sql.indexOf('#') != -1) {
        Log.e(TAG, "undefined parameter sql : " + sql);
        return null;
    }
    Cursor cursor = dbObj.rawQuery(sql, null);
    Log.d(TAG, "Run sql : " + sql);
    List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
    if (cursor == null) {
        return null;
    }
    String[] columnNames = cursor.getColumnNames();
    while (cursor.moveToNext()) {
        Map<String, Object> map = new HashMap<String, Object>();
        int i = 0;
        for (String columnName : columnNames) {
            map.put(columnName, cursor.getString(i));
            i++;
        }
        mapList.add(map);
    }
    cursor.close();
    dbObj.close();
    return mapList;
}

From source file:com.mobile.system.db.abatis.AbatisService.java

/**
 * /*from  w  w  w  . j  a va  2s .c  o  m*/
 * @param sqlId
 *            SQLID
 * @param bindParams
 *            sql parameter
 * 
 * @return Map<String, Object> result
 */
public Map<String, Object> executeForMap(String sqlId, Map<String, Object> bindParams) {
    getDbObject();
    int pointer = context.getResources().getIdentifier(sqlId, "string", context.getPackageName());
    if (pointer == 0) {
        Log.e(TAG, "undefined sql id : " + sqlId);
        return null;
    }
    String sql = context.getResources().getString(pointer);
    if (bindParams != null) {
        Iterator<String> mapIterator = bindParams.keySet().iterator();
        while (mapIterator.hasNext()) {
            String key = mapIterator.next();
            Object value = bindParams.get(key);
            if (value != null && key != null) {
                sql = getFinalSql(sql, key.toLowerCase(), value.toString());
            }

        }
    }
    if (sql.indexOf('#') != -1) {
        Log.e(TAG, "undefined parameter sql : " + sql);
        return null;
    }
    Cursor cursor = dbObj.rawQuery(sql, null);
    Log.d(TAG, "Run sql : " + sql);
    List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
    if (cursor == null) {
        return null;
    }
    String[] columnNames = cursor.getColumnNames();
    while (cursor.moveToNext()) {
        Map<String, Object> map = new HashMap<String, Object>();
        int i = 0;
        for (String columnName : columnNames) {
            map.put(columnName, cursor.getString(i));
            i++;
        }
        mapList.add(map);
    }
    if (mapList.size() <= 0) {
        return null;
    }
    cursor.close();
    dbObj.close();
    return mapList.get(0);
}

From source file:com.owncloud.android.ui.activity.Uploader.java

public void uploadFiles() {
    try {/*from   w  ww  .j  av  a2  s  .c  om*/

        // ArrayList for files with path in external storage
        ArrayList<String> local = new ArrayList<String>();
        ArrayList<String> remote = new ArrayList<String>();

        // this checks the mimeType 
        for (Parcelable mStream : mStreamsToUpload) {

            Uri uri = (Uri) mStream;
            String data = null;
            String filePath = "";

            if (uri != null) {
                if (uri.getScheme().equals("content")) {
                    String mimeType = getContentResolver().getType(uri);

                    if (mimeType.contains("image")) {
                        String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME,
                                Images.Media.MIME_TYPE, Images.Media.SIZE };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Images.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME));

                    } else if (mimeType.contains("video")) {
                        String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME,
                                Video.Media.MIME_TYPE, Video.Media.SIZE, Video.Media.DATE_MODIFIED };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Video.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));

                    } else if (mimeType.contains("audio")) {
                        String[] CONTENT_PROJECTION = { Audio.Media.DATA, Audio.Media.DISPLAY_NAME,
                                Audio.Media.MIME_TYPE, Audio.Media.SIZE };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Audio.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Audio.Media.DISPLAY_NAME));

                    } else {
                        Cursor cursor = getContentResolver().query(uri,
                                new String[] { MediaStore.MediaColumns.DISPLAY_NAME }, null, null, null);
                        cursor.moveToFirst();
                        int nameIndex = cursor.getColumnIndex(cursor.getColumnNames()[0]);
                        if (nameIndex >= 0) {
                            filePath = mUploadPath + cursor.getString(nameIndex);
                        }
                    }

                } else if (uri.getScheme().equals("file")) {
                    filePath = Uri.decode(uri.toString()).replace(uri.getScheme() + "://", "");
                    if (filePath.contains("mnt")) {
                        String splitedFilePath[] = filePath.split("/mnt");
                        filePath = splitedFilePath[1];
                    }
                    final File file = new File(filePath);
                    data = file.getAbsolutePath();
                    filePath = mUploadPath + file.getName();
                } else {
                    throw new SecurityException();
                }
                if (data == null) {
                    mRemoteCacheData.add(filePath);
                    CopyTmpFileAsyncTask copyTask = new CopyTmpFileAsyncTask(this);
                    Object[] params = { uri, filePath, mRemoteCacheData.size() - 1, getAccount().name,
                            getContentResolver() };
                    mNumCacheFile++;
                    showWaitingCopyDialog();
                    copyTask.execute(params);
                } else {
                    remote.add(filePath);
                    local.add(data);
                }
            } else {
                throw new SecurityException();
            }

            Intent intent = new Intent(getApplicationContext(), FileUploader.class);
            intent.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);
            intent.putExtra(FileUploader.KEY_LOCAL_FILE, local.toArray(new String[local.size()]));
            intent.putExtra(FileUploader.KEY_REMOTE_FILE, remote.toArray(new String[remote.size()]));
            intent.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
            startService(intent);

            //Save the path to shared preferences
            SharedPreferences.Editor appPrefs = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext()).edit();
            appPrefs.putString("last_upload_path", mUploadPath);
            appPrefs.apply();

            finish();
        }

    } catch (SecurityException e) {
        String message = String.format(getString(R.string.uploader_error_forbidden_content),
                getString(R.string.app_name));
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }
}

From source file:com.synox.android.ui.activity.Uploader.java

public void uploadFiles() {
    try {/*from  w w  w.  j a v a2s .  c om*/

        // ArrayList for files with path in external storage
        ArrayList<String> local = new ArrayList<>();
        ArrayList<String> remote = new ArrayList<>();

        // this checks the mimeType
        for (Parcelable mStream : mStreamsToUpload) {

            Uri uri = (Uri) mStream;
            String data = null;
            String filePath = "";

            if (uri != null) {
                if (uri.getScheme().equals("content")) {
                    String mimeType = getContentResolver().getType(uri);

                    if (mimeType.contains("image")) {
                        String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME,
                                Images.Media.MIME_TYPE, Images.Media.SIZE };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Images.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME));

                    } else if (mimeType.contains("video")) {
                        String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME,
                                Video.Media.MIME_TYPE, Video.Media.SIZE, Video.Media.DATE_MODIFIED };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Video.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));

                    } else if (mimeType.contains("audio")) {
                        String[] CONTENT_PROJECTION = { Audio.Media.DATA, Audio.Media.DISPLAY_NAME,
                                Audio.Media.MIME_TYPE, Audio.Media.SIZE };
                        Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null);
                        c.moveToFirst();
                        int index = c.getColumnIndex(Audio.Media.DATA);
                        data = c.getString(index);
                        filePath = mUploadPath + c.getString(c.getColumnIndex(Audio.Media.DISPLAY_NAME));

                    } else {
                        Cursor cursor = getContentResolver().query(uri,
                                new String[] { MediaStore.MediaColumns.DISPLAY_NAME }, null, null, null);
                        cursor.moveToFirst();
                        int nameIndex = cursor.getColumnIndex(cursor.getColumnNames()[0]);
                        if (nameIndex >= 0) {
                            filePath = mUploadPath + cursor.getString(nameIndex);
                        }
                    }

                } else if (uri.getScheme().equals("file")) {
                    filePath = Uri.decode(uri.toString()).replace(uri.getScheme() + "://", "");
                    if (filePath.contains("mnt")) {
                        String splitedFilePath[] = filePath.split("/mnt");
                        filePath = splitedFilePath[1];
                    }
                    final File file = new File(filePath);
                    data = file.getAbsolutePath();
                    filePath = mUploadPath + file.getName();
                } else {
                    throw new SecurityException();
                }
                if (data == null) {
                    mRemoteCacheData.add(filePath);
                    CopyTmpFileAsyncTask copyTask = new CopyTmpFileAsyncTask(this);
                    Object[] params = { uri, filePath, mRemoteCacheData.size() - 1, getAccount().name,
                            getContentResolver() };
                    mNumCacheFile++;
                    showWaitingCopyDialog();
                    copyTask.execute(params);
                } else {
                    remote.add(filePath);
                    local.add(data);
                }
            } else {
                throw new SecurityException();
            }

            Intent intent = new Intent(getApplicationContext(), FileUploader.class);
            intent.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);
            intent.putExtra(FileUploader.KEY_LOCAL_FILE, local.toArray(new String[local.size()]));
            intent.putExtra(FileUploader.KEY_REMOTE_FILE, remote.toArray(new String[remote.size()]));
            intent.putExtra(FileUploader.KEY_ACCOUNT, getAccount());
            startService(intent);

            //Save the path to shared preferences
            SharedPreferences.Editor appPrefs = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext()).edit();
            appPrefs.putString("last_upload_path", mUploadPath);
            appPrefs.apply();

            finish();
        }

    } catch (SecurityException e) {
        String message = String.format(getString(R.string.uploader_error_forbidden_content),
                getString(R.string.app_name));
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    } catch (NullPointerException npe) {
        Log_OC.e(this.getClass().getName(), "Unknown error occurred. Message: " + npe.getLocalizedMessage());
    }
}

From source file:com.compal.telephonytest.TelephonyTest.java

public void test_6th_ReadPhoneBook() {
    String sName = "name";
    String sNumber = "number";
    String sEmails = "emails";
    String s_id = "_id";
    if (TelephonyBeTest) {
        Log.i(tag, "test_6th_ReadPhoneBook start");
        testCaseId = getTestCaseId(tTelephonyBasicFunc, dSimRead, sId);
        mLog = "Read PhoneBook";
        if (!isIccCardNull) {
            Uri simUri = Uri.parse("content://icc/adn");
            Cursor cursorSim = context.getContentResolver().query(simUri, null, null, null, null);
            Log.i(tag, "getColumnIndex(sName):" + Integer.toString(cursorSim.getColumnIndex(sName)));
            Log.i(tag, "getColumnIndex(sNumber):" + Integer.toString(cursorSim.getColumnIndex(sNumber)));
            Log.i(tag, "sim row count:" + Integer.toString(cursorSim.getCount()));
            String[] simColNm = cursorSim.getColumnNames();
            for (int i = 0; i < simColNm.length; i++)
                Log.i(tag, "simColNm:" + simColNm[i]);

            if (simColNm.length >= 0 && simColNm[0].equals(sName) && simColNm[1].equals(sNumber)
                    && simColNm[2].equals(sEmails) && simColNm[3].equals(s_id)) {
                Log.i(tag, "test_6th_ReadPhoneBook() true");
                outputResult(true, tTelephonyBasicFunc, dSimRead, testCaseId);
            } else {
                Log.i(tag, "test_6th_ReadPhoneBook() false");
                mLog = "simColNm.length < 0 || read column name error";
                outputResult(false, tTelephonyBasicFunc, dSimRead, testCaseId);
            }//from w  w w. jav a  2  s  .  co  m
        } else {
            Log.i(tag, "test_6th_ReadPhoneBook() isIccCardNull");
            mLog = "isIccCardNull";
            outputResult(false, tTelephonyBasicFunc, dSimRead, testCaseId);
        }
    }

    SystemProperties.set("persist.sys.test", "TelephonyTestIsdone");
    enableDataEnabled(false); //turn off 3g in the end
}

From source file:com.openerp.orm.ORM.java

public List<HashMap<String, Object>> executeSQL(String sqlQuery, String[] args) {
    SQLiteDatabase db = getWritableDatabase();

    List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();

    Cursor cursor = db.rawQuery(sqlQuery.toString(), args);
    String[] columns = cursor.getColumnNames();
    if (cursor.moveToFirst()) {
        do {/*from   www. ja va  2 s. c  om*/
            HashMap<String, Object> row = new HashMap<String, Object>();
            if (cursor.getColumnIndex("oea_name") > 0) {
                if (!cursor.getString(cursor.getColumnIndex("oea_name")).equals(user_name)) {
                    continue;
                }
            } else {
                Log.e("ORM::executeSQL() - Column name missing",
                        "You must have to provide oea_name column in your sql syntax.");
                return null;
            }
            for (String key : columns) {
                row.put(key, cursor.getString(cursor.getColumnIndex(key)));
            }
            data.add(row);
        } while (cursor.moveToNext());
    }
    db.close();
    cursor.close();
    return data;
}

From source file:org.zywx.wbpalmstar.plugin.uexcontacts.PFConcactMan.java

public static boolean deletes(final Context context, String inName) {
    ContentResolver cr = context.getContentResolver();
    try {/*from  ww  w . j a va2 s. c o m*/
        ContentResolver contentResolver = context.getContentResolver();
        if (inName != null) {
            SearchOptionVO searchOptionVO = new SearchOptionVO(500, "", inName, false, false, false, false,
                    false, false, false);
            JSONArray jsonsArray = search(context, searchOptionVO);
            if (jsonsArray != null && jsonsArray.length() > 0) {
                int length = jsonsArray.length();
                boolean hasName = false;
                for (int i = 0; i < length; i++) {
                    JSONObject item = jsonsArray.getJSONObject(i);
                    if (inName.equals(item.getString(EUExCallback.F_JK_NAME))) {
                        hasName = true;
                        break;
                    }
                }
                if (!hasName) {
                    ToastShow(context, finder.getString(context, "plugin_contact_delete_fail"));
                    return false;
                }
                int sdkVersion = Build.VERSION.SDK_INT;
                if (sdkVersion <= 8) {// ?2.2
                    Cursor cur = cr.query(android.provider.Contacts.People.CONTENT_URI, null, null, null, null);
                    cur.moveToFirst();
                    while (cur.moveToNext()) {
                        String name = cur
                                .getString(cur.getColumnIndex(android.provider.Contacts.People.DISPLAY_NAME));
                        String contactName = name;// ??
                        if (contactName != null && contactName.indexOf(" ") != -1) {// 
                            contactName = contactName.replaceAll(" ", "");
                        }
                        if (name != null && contactName.equals(inName)) {
                            contentResolver.delete(android.provider.Contacts.People.CONTENT_URI,
                                    android.provider.Contacts.People.NAME + "=?", new String[] { name });
                        }
                    }
                    cur.close();
                } else if (sdkVersion < 14) {// ?4.0
                    Cursor cur = cr.query(android.provider.ContactsContract.RawContacts.CONTENT_URI, null, null,
                            null, null);
                    cur.moveToFirst();
                    String[] idName = cur.getColumnNames();
                    while (cur.moveToNext()) {
                        String name = cur.getString(
                                cur.getColumnIndex(android.provider.ContactsContract.Contacts.DISPLAY_NAME));
                        String contactId = cur
                                .getString(cur.getColumnIndex(android.provider.ContactsContract.Contacts._ID));
                        String contactName = name;// ??
                        if (contactName != null && contactName.indexOf(" ") != -1) {// 
                            contactName = contactName.replaceAll(" ", "");
                        }
                        if (name != null && contactName.equals(inName)) {
                            contentResolver.delete(android.content.ContentUris.withAppendedId(
                                    android.provider.ContactsContract.Contacts.CONTENT_URI,
                                    Long.parseLong(contactId)), null, null);
                        }
                    }
                    cur.close();
                } else {
                    Cursor cur = cr.query(android.provider.ContactsContract.Contacts.CONTENT_URI, null, null,
                            null, null);
                    while (cur.moveToNext()) {
                        String name = cur.getString(
                                cur.getColumnIndex(android.provider.ContactsContract.Contacts.DISPLAY_NAME));
                        String id = cur
                                .getString(cur.getColumnIndex(android.provider.ContactsContract.Contacts._ID));
                        String contactName = name;// ??
                        if (contactName != null && contactName.indexOf(" ") != -1) {// 
                            contactName = contactName.replaceAll(" ", "");
                        }
                        if (name != null && contactName.equals(inName)) {
                            contentResolver.delete(android.content.ContentUris.withAppendedId(
                                    android.provider.ContactsContract.Contacts.CONTENT_URI, Long.parseLong(id)),
                                    null, null);
                            break;
                        }
                    }
                    cur.close();
                }
                ToastShow(context, finder.getString(context, "plugin_contact_delete_succeed"));
            } else {
                ToastShow(context, finder.getString(context, "plugin_contact_delete_fail"));
                return false;
            }
        }
    } catch (Exception e) {
        ToastShow(context, finder.getString(context, "plugin_contact_delete_fail"));
        return false;
    }
    return true;
}

From source file:com.openerp.orm.ORM.java

/**
 * Gets the result.//  w ww . j a  v  a 2  s . co m
 * 
 * @param dbHelper
 *            the db helper
 * @param fetch_columns
 * @param result
 *            the result
 * @return the result
 */
@SuppressWarnings("unchecked")
private List<HashMap<String, Object>> getResult(BaseDBHelper dbHelper, String[] fetch_columns, Cursor result) {

    HashMap<String, Object> m2m = dbHelper.getMany2ManyColumns();
    HashMap<String, Object> m2o = dbHelper.getMany2OneColumns();
    List<HashMap<String, Object>> results = null;
    String[] columns = result.getColumnNames();
    if (result.moveToFirst()) {
        results = new ArrayList<HashMap<String, Object>>();
        HashMap<String, Object> row;
        do {
            row = new HashMap<String, Object>();
            for (String col : columns) {
                String value = result.getString(result.getColumnIndex(col));
                row.put(col, value);
            }
            List<String> user_columns = null;
            if (fetch_columns != null) {
                user_columns = Arrays.asList(fetch_columns);
            }

            // Getting many2many ids for row
            if (m2m.size() > 0) {
                String id = result.getString(result.getColumnIndex("id"));
                for (String key : m2m.keySet()) {
                    if (user_columns != null && user_columns.contains(key)) {
                        Many2Many m2mObj = (Many2Many) m2m.get(key);
                        BaseDBHelper newdb = generateM2MHelper(dbHelper, m2mObj);
                        String col1 = newdb.getColumns().get(0).getName();
                        String col2 = newdb.getColumns().get(1).getName();
                        String col3 = newdb.getColumns().get(2).getName();
                        HashMap<String, Object> rel_row = newdb.search(newdb,
                                new String[] { col1 + " = ?", "AND", col3 + " = ?" },
                                new String[] { id, user_name });
                        int total = Integer.parseInt(rel_row.get("total").toString());
                        if (total > 0) {
                            JSONArray ids_list = new JSONArray();
                            for (int i = 0; i < total; i++) {
                                JSONArray ids = new JSONArray();
                                HashMap<String, Object> rowdata = ((List<HashMap<String, Object>>) rel_row
                                        .get("records")).get(i);
                                BaseDBHelper rel_obj = m2mObj.getM2mObject();
                                HashMap<String, Object> rel_data = rel_obj.search(rel_obj,
                                        new String[] { "id = ? " },
                                        new String[] { rowdata.get(col2).toString() });
                                ids.put(Integer.parseInt(rowdata.get(col2).toString()));
                                if (Integer.parseInt(rel_data.get("total").toString()) > 0) {
                                    ids.put(((List<HashMap<String, Object>>) rel_data.get("records")).get(0)
                                            .get("name").toString());
                                }
                                ids_list.put(ids);
                            }
                            row.put(key, ids_list);
                        }
                    }
                }
            }

            // Getting many2one [id, name]
            if (m2o.size() > 0) {
                for (String key : m2o.keySet()) {
                    if (user_columns != null && user_columns.contains(key)) {
                        JSONArray ids_list = new JSONArray();
                        String ref_id = result.getString(result.getColumnIndex(key));
                        if (!ref_id.equals("false")) {
                            Many2One m2oObj = (Many2One) m2o.get(key);
                            JSONArray ids = new JSONArray();
                            HashMap<String, Object> rel_data = m2oObj.getM2OObject().search(
                                    m2oObj.getM2OObject(), new String[] { "id", "name" },
                                    new String[] { "id = ? " }, new String[] { ref_id });
                            ids.put(ref_id);
                            if (Integer.parseInt(rel_data.get("total").toString()) > 0) {
                                ids.put(((List<HashMap<String, Object>>) rel_data.get("records")).get(0)
                                        .get("name").toString());
                            }
                            ids_list.put(ids);
                        }
                        if (ids_list.length() != 0) {
                            row.put(key, ids_list);
                        } else {
                            row.put(key, false);
                        }
                    }
                }
            }
            results.add(row);

        } while (result.moveToNext());
    }
    result.close();
    return results;
}

From source file:com.odoo.orm.OModel.java

public ODataRow createRowFromCursor(Cursor cr) {
    ODataRow row = new ODataRow();
    for (String col_name : cr.getColumnNames()) {
        OColumn col = new OColumn(col_name).setDefault(false);
        col.setName(col_name);// w ww  .  ja va 2  s  .co  m
        row.put(col_name, createRecordRow(col, cr));
    }
    if (row.getInt("id") == 0 || row.getString("id").equals("false"))
        row.put("id", 0);
    return row;
}