alexus@mbp:~ $ python
Python 2.7.10 (default, Oct 23 2015, 18:05:06)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> from pymongo import MongoClient
>>> client = MongoClient('mongodb://192.168.99.100:32768/')
>>> db = client['test']
>>> collection = db['c']
>>>
>>> obj = 'adc83b19e793491b1c6ea0fd8b46cd9f32e592fc:{tag1:value1}'
>>> print obj
adc83b19e793491b1c6ea0fd8b46cd9f32e592fc:{tag1:value1}
>>> json.dumps(obj, separators=(',', ':'), sort_keys=True)
'"adc83b19e793491b1c6ea0fd8b46cd9f32e592fc:{tag1:value1}"'
>>> db.c.insert(json.dumps(obj, separators=(',', ':'), sort_keys=True))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/pymongo/collection.py", line 2199, in insert
check_keys, manipulate, write_concern)
File "/Library/Python/2.7/site-packages/pymongo/collection.py", line 578, in _insert
gen(), check_keys, self.codec_options, bwc)
File "/Library/Python/2.7/site-packages/pymongo/collection.py", line 546, in gen
doc['_id'] = ObjectId()
TypeError: 'str' object does not support item assignment
>>>
例如我有一个public boolean updateCredential(Credentials credentials){
boolean isSuccessful = true;
SQLiteDatabase db=null;
String whereStatement = Constants.LOGIN_ITEM + "=";
String[] bindValues = new String[] {credentials.getLoginItem().trim()};
ContentValues values = new ContentValues();
try{
db=helper.getWritableDatabase();
db.update(Constants.TABLE_NAME, values, whereStatement, bindValues);
db.close();
IsSuccessful=true;
}finally{
db.close();
}
return isSuccessful;
}
方法,我在表单中称之为
addcredential()
答案 0 :(得分:0)
使用以下方法调用
public void updateRecord(View v){
credentials.setLoginItem(loginItemText.getText().toString());
if(db.updateCredential(credentials))
{
Toast.makeText(this, "Record updated",Toast.LENGTH_SHORT).show();
//show your toast
}
else
{
// updation failed
}
}