When we encounter a problem, seeking to explain
brightest Great GodI now want to query about whether the presence of a row of data, if there is data on the update, otherwise insert a row
I was doing:
Cursor cursor = cdb.rawQuery ("SELECT * FROM" + current_table_name + "WHERE begin_class = 10");
If the table does not exist begin_class = row 10 it?? How the cursor from function to return there to judge them?? Because I found that even non-existent, return the cursor is not null. Document seemingly did not explain this problem? Sincerely seeking answers .
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Seeking to explain ah ... stuck in here
Reply:
No value it wants
Reply:
I tried to determine cursor == null and cursor.isNull (0) will not ah .. but the latter also being given
Ask, what are other ways to solve??
Reply:
cursor == null | | cursor.getCount () <= 0
Reply:
In this case still has true ah ... you told me this or condition only cursor == null is the same, right?
Reply:
while (cursor! = null && cursor.getCount ()> 0)
This has been true?????
Reply:
According to your changes, my code is:
cursor = cdb.rawQuery ("?? WHERE begin_class = AND lasting =" "SELECT * FROM" + current_table_name +, new String [] {"" + beginClass, "" + lasting});
if (cursor == null | | cursor.getCount () <= 0) {
cdb.update (current_table_name, values, "begin_class =" + beginClass, null);
}
else {
cdb.insert (current_table_name, null, values);
}
In this case, I found that regardless of whether the result is an empty look, can only perform update statement, the if-else statements exchanged over the two, then it can only perform insert, ie cursor == null | | cursor.getCount () <= 0 results returned has been true
Reply:
cursor.getCount ()
Before and after the update, the print out to see ... whether this change ..
Reply:
I encountered a similar problem with you, now resolved, Reference: http://blog.sina.com.cn/s/blog_4ea108170100rp4y.html
Reply:
if (cursor! = null && cursor.getCount ()> = 0)
{
/ / Operation
}
No comments:
Post a Comment