1

我有一张桌子,我在其中存储纬度和经度。我的表架构如下

TestId | Latitude | Longitude | TestName |

其中 testid 是整数主键自动增量。

现在,如果表存在相同的纬度和经度,那么应该更新以前的原始数据。我正在这样做。

为内容添加所有价值

ContentValues values = new ContentValues(); 
values.put(GLNetTestDataContract.TestPinRecord.COLUMN_NAME_TESTNAME, testName);
values.put(GLNetTestDataContract.TestPinRecord.COLUMN_NAME_LATTITUDE, lattitude);
values.put(GLNetTestDataContract.TestPinRecord.COLUMN_NAME_LATTITUDE, lattitude);

/*检查表中是否存在经纬度值,然后更新测试/

        String selectionCheckLatitudeAndLongitude = Gaurav.TestRecord.COLUMN_NAME_LATTITUDE + "=? AND " +
                                            Gaurav.TestRecord.COLUMN_NAME_LATTITUDE + "=?";

        String[] selectionArgslCheckLatitudeAndLongitude = { String.valueOf(lattitude),String.valueOf(longitude)};
        try{
        newRowId = mDatabase.update(GLNetTestDataContract.TestPinRecord.TABLE_NAME, values, selectionCheckLatitudeAndLongitude, selectionArgslCheckLatitudeAndLongitude);
        }
        catch(Exception e)
        {
            mLogger.printLog("pin", "Exception while updating");
            mLogger.printLog("pin", e.getMessage());
        }
if(newRowId>0)
            mLogger.printLog("pin","Test updated with existing geo location");
        // Insert the new row, returning the primary key value of the new row
        else
        {
            newRowId = mDatabase.insert(GLNetTestDataContract.TestPinRecord.TABLE_NAME,null, values);
            mLogger.printLog("pin","Test inserted with existing geo location");
        }

它总是返回 0。这意味着 raw 没有更新。我究竟做错了什么。任何指针将不胜感激。

4

1 回答 1

1

您正在检查同一列两次

Gaurav.TestRecord.COLUMN_NAME_LATTITUDE + "=? AND " +
Gaurav.TestRecord.COLUMN_NAME_LATTITUDE + "=?";

应该:

Gaurav.TestRecord.COLUMN_NAME_LATTITUDE + "=? AND " +
Gaurav.TestRecord.COLUMN_NAME_LONGITUDE + "=?";

同样在你的put声明中:

values.put(GLNetTestDataContract.TestPinRecord.COLUMN_NAME_LATTITUDE, lattitude);
values.put(GLNetTestDataContract.TestPinRecord.COLUMN_NAME_LONGITUDE, longitude);
于 2013-07-26T15:00:13.177 回答