0

For some reason I can't get the single quote with apostrophes in a name field to submit to my sqlite database.

Here's where I get the input and call the database function

if(fnamelabel.contains("'") || fnamelabel.contains("-")){
                    fnamelabel = DatabaseUtils.sqlEscapeString(fnamelabel);
                }else if(lnamelabel.contains("'") || lnamelabel.contains("-")){
                    lnamelabel = DatabaseUtils.sqlEscapeString(lnamelabel);                     
                }

                Log.w("myApp", "fname " + fnamelabel + ".");                        
                Log.w("myApp", "lname " + lnamelabel + ".");        

                try{
                    //if all fields are filled and has a number between 0 and 99
                    LiteHandlerPlayers db = new LiteHandlerPlayers(getApplicationContext());

                    if(db.insertLabel(fnamelabel, lnamelabel, pnumlabel)){                          
                        db.getWritableDatabase();
                        db.insertLabel(fnamelabel, lnamelabel, pnumlabel);
                        Toast.makeText(getApplicationContext(), "#" + pnumlabel + " " + fnamelabel + " " + lnamelabel + " has been added to your team.", Toast.LENGTH_SHORT).show();
                        db.close();
                    }else{
                        Toast.makeText(getApplicationContext(), "That player is already on your team!", Toast.LENGTH_SHORT).show();
                    }

Here's my function within the db

if(flag){
        //no player in db with name
        ContentValues values = new ContentValues();
        values.put(Player_fname, label);
        values.put(Player_lname, label2);
        values.put(Player_num  , label3);
        values.put(Player_gplay, 0);
        values.put(Player_assist, 0);
        values.put(Player_shots, 0);
        values.put(Player_goals, 0);
        values.put(Player_shagn, 0);
        values.put(Player_gallw, 0);
        values.put(Player_assist, 0);
        db.insert(Table_labels, null, values);
        db.close();//close db
        return true;
    }else{
        db.close();
        return false;
    }       

and eventually gets displayed on a spinner on a different screen but the error that i keep getting for an example name like Bob O'Connor (O'Connor is changed to O''Connor at this point) is that there is a syntax error near the O in O''Connor which is pretty vague. ((1) near "O": syntax error , is exactly what it says) If anyone can enlighten me I would be much obliged.

Phenom
  • 23
  • 7

0 Answers0