在SQLite中使用KEY_ROWID获取列值

时间:2013-08-18 05:19:53

标签: android

我正在尝试使用Android中的SQLite表中的KEY_ROWID从列中获取值。但我的错误价值。例如,当我尝试从第六行获取值时,我从第二行获取值。然后第五行,我得到第一行值。对于第四行,我得到了null。我的数据库总共有六行。可能有什么不对? 我的数据库是

public static final String KEY_ROWID   = "_id";
 public static final String KEY_IDNUM   = "_idnum";
 public static final String KEY_SIMCARD = "_simcard";
 public static final String KEY_DESCRIPTION = "_description";
 public static final String KEY_MODEL = "_model";
 public static final String KEY_TIMEINSTANCE = "timeinstance";
 public static final String KEY_PASSWORD = "password";
 public static final String KEY_LOCATIONAUTOUPDATE = "locationupdate";
 public static final String KEY_OVERSPEED = "overspeed";
 public static final String KEY_MOVEMENT = "movement";
 public static final String KEY_GEOFENCE = "geofence";
 public static final String KEY_TIMEZONE = "timezone";
 public static final String KEY_AUTHORIZE = "authorize";
 public static final String KEY_IMAGE  = "image";
 public static final String KEY_ACTIVATE  = "activate";
 public static final String KEY_NUMOFUSE  = "number_of_use";
 private static final String TAG = "TrackerDBAdapter";
 private static final String DATABASE_NAME = "DBTrackerList";
 private static final String SQLITE_TABLE = "TBTrackerList";
 private static final int DATABASE_VERSION = 5;
 private final Context mCtx;
 private static final String DATABASE_CREATE =
          "CREATE TABLE if not exists " + SQLITE_TABLE + " (" +
          KEY_ROWID + " integer PRIMARY KEY autoincrement," +
          KEY_IDNUM + "," +
          KEY_SIMCARD + "," +
          KEY_DESCRIPTION + "," +
          KEY_MODEL + "," +
          KEY_TIMEINSTANCE + "," +
          KEY_PASSWORD + "," +
          KEY_LOCATIONAUTOUPDATE + "," +
          KEY_OVERSPEED + "," +
          KEY_MOVEMENT + "," +
          KEY_GEOFENCE + "," +
          KEY_TIMEZONE + "," +
          KEY_AUTHORIZE + "," + 
          KEY_IMAGE + "," + 
          KEY_ACTIVATE + "," +
          KEY_NUMOFUSE + "," + 
          " UNIQUE (" + KEY_ROWID +"));";

 private DatabaseHelper mDbHelper;
 private SQLiteDatabase mDb;

我正在尝试使用rowid(KEY_ROWID)获取idnum(KEY_IDNUM),如下所示。

public String fetchIDnumByRowid(long rowid) throws SQLException{             
     Cursor mCursor = null;
     String retstring = null;
     mCursor = mDb.query(true, SQLITE_TABLE, new String[] {KEY_ROWID,
               KEY_IDNUM, KEY_SIMCARD, KEY_DESCRIPTION, KEY_MODEL, KEY_TIMEINSTANCE, KEY_PASSWORD,
               KEY_LOCATIONAUTOUPDATE, KEY_OVERSPEED, KEY_MOVEMENT, KEY_GEOFENCE, KEY_TIMEZONE, KEY_AUTHORIZE, KEY_IMAGE, KEY_ACTIVATE, KEY_NUMOFUSE}, 
               KEY_ROWID + "=" + rowid, null, null, null, null, null);  

     if(mCursor != null){
        mCursor.moveToFirst();
        retstring = mCursor.getString(1);
     }

     return retstring;
 } 

EDIT1: 当我获取所有行并逐行检查这些idnum时,一切都是正确的。 就像我上面提到的那样,我有问题。

0 个答案:

没有答案