Here is a brief synopsis should you encounter it.
Here is the easy way to iterate some of a db with a ListArray. Notice the " These are the crucial differences from being in sql and not.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void insertIntoTable(){ | |
try{ | |
myDB = openOrCreateDatabase(DBTeam, Context.MODE_PRIVATE,null); | |
///////Iterate the db with List Arrays | |
for (int i = 0; i < playerNames.size(); i++) { | |
myDB.execSQL("INSERT INTO " + TABLE + "(PNUMBER,NAME,NUMBER1 ,NUMBER2) VALUES('" +playerNumbers.get(i)+"','"+playerNames.get(i)+"','1','0')"); | |
Log.d("-----",""+playerNames.get(i));////Testing proof they were working | |
}///End For Loop | |
Toast.makeText(this, "Database filled", Toast.LENGTH_LONG).show(); | |
myDB.close(); | |
}catch(Exception e){ | |
Toast.makeText(this, "Error in inserting into table", Toast.LENGTH_LONG).show(); | |
} | |
} | |
Here is the way to update something with a variable. BOTH ways work, just showing them. I am basically adding a certain id # and location with the variable and updating it. In this case TWOS is an integer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void updateTable(){ | |
int idnum=1; | |
int idnum2=4; | |
int tests=3; | |
try{ | |
mydb = openOrCreateDatabase(DBTeam, Context.MODE_PRIVATE,null); | |
mydb.execSQL("UPDATE " + TABLE + " SET TWOS = TWOS+"+tests+" WHERE ID ="+ idnum); | |
mydb.execSQL("UPDATE " + TABLE + " SET TWOS = TWOS+'"+tests+"' WHERE ID ="+ idnum2); | |
mydb.close(); | |
}catch(Exception e){ | |
Toast.makeText(getApplicationContext(), "OH crap, so sad", Toast.LENGTH_LONG); | |
} | |
} |
No comments:
Post a Comment