如何隐藏数据库中的列

问题描述 投票:0回答:2

这是我原来的代码:

String sqlQuery = "SELECT * FROM data where company = '"+ Selecteditem +"'"  ;

SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(sqlQuery, null);

if (c.moveToFirst()){
   do{
      temp_array.add(c.getString(c.getColumnIndex("name")) +
                     "," + c.getString(c.getColumnIndex("code")) +
                     "," + c.getString(c.getColumnIndex("company")) 
                    );

我想隐藏列表中的公司,我将“*”更改为

name, code
但没有成功,我删除
" **"," + c.getString(c.getColumnIndex("company"))** "
这行没有成功,

请帮帮我该怎么办

database sqlite
2个回答
0
投票

您可以通过将

c.getString(c.getColumnIndex("company"))
替换为空字符串
""
来删除公司字符串。

String sqlQuery = "SELECT * FROM data where company = '" + Selecteditem + "'";

SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(sqlQuery, null);

if (c.moveToFirst()) {
    do {
        temp_array.add(c.getString(c.getColumnIndex("name")) +
            "," + c.getString(c.getColumnIndex("code")) +
            "," + ""
        );

另一种解决方案是仅选择您需要的列:

String sqlQuery = "SELECT name, code FROM data where company = '" + Selecteditem + "'";

SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery(sqlQuery, null);

if (c.moveToFirst()) {
    do {
        temp_array.add(c.getString(c.getColumnIndex("name")) +
            "," + c.getString(c.getColumnIndex("code"))
        );

0
投票

试试这个:

CREATE TABLE json_tree(
    key ANY,             -- key for current element relative to its parent
    value ANY,           -- value for the current element
    type TEXT,           -- 'object','array','string','integer', etc.
    atom ANY,            -- value for primitive types, null for array & object
    id INTEGER,          -- integer ID for this element
    parent INTEGER,      -- integer ID for the parent of this element
    fullkey TEXT,        -- full path describing the current element
    path TEXT,           -- path to the container of the current row
    json JSON HIDDEN,    -- 1st input parameter: the raw JSON
    root TEXT HIDDEN     -- 2nd input parameter: the PATH at which to start
);
© www.soinside.com 2019 - 2024. All rights reserved.