android - How check if one column value from the Cursor is empty? -


i trying insert value db depends on status of values.

if column_fields_parameter empty, insert data.

if column_fields_parameter not empty, update data.

i use button when user click on following method comes:

public string putparameters(string parameterslist, string exercise) {          contentvalues cv = new contentvalues();         cv.put(column_fields_parameter, parameterslist);         cv.put(column_exercise, exercise);          string whereclause =  column_exercise + "= '"+ exercise+ "'";          if(checkparameters(exercise) == false)         {             ourdatabase.insert(table_name, null, cv);             string = "insert";             return i;         }            else         {             ourdatabase.update(table_name, cv, whereclause, null);             string u = "update";             return u;         }     } 

checkparameters method code:

public string getparameters(string exercise){      string foo = "";      string whereclause = column_exercise + "= '" +  exercise + "'";      string[] columns = new string[]{column_fields_parameter};      cursor c = ourdatabase.query(table_name, columns, whereclause , null, null, null, null);      int parameter = c.getcolumnindex(column_fields_parameter);       try{     c.movetofirst();     foo = c.getstring(parameter);     if (foo == null)         return null;     }     catch(exception f)     {         foo = "bad";         return foo;     }     return "";     }         public boolean checkparameters(string exercise){           string whereclause = column_exercise + "= '" +  exercise + "'";          string[] columns = new string[]{column_fields_parameter};          cursor c = ourdatabase.query(table_name, columns, whereclause , null, null, null, null);          int parameter = c.getcolumnindex(column_fields_parameter);          c.movetofirst();         if(c.isnull(parameter))             return false;         return true;         } 

my problem never c.isnull(parameter) == false. "insert" message. how can check if column_fields_parameter empty? code correct? thank helping :)

maybe column_fields_parameter have default value. why don't check value yourself?

 int parameter = c.getcolumnindex(column_fields_parameter);  string value = c.getstring(parameter);  if(textutils.isempty(value) {     return false;  }  return true; 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -