Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. package chris.allan.awesome;
  2.  
  3. import android.content.ContentValues;
  4. import android.content.Context;
  5. import android.database.Cursor;
  6. import android.database.sqlite.SQLiteDatabase;
  7.  
  8. /**
  9.  * Created by Allan on 16-09-2014.
  10.  */
  11. public class SQLController
  12. {
  13.     private GameDatabase gd;
  14.  
  15.     private SQLiteDatabase database;
  16.  
  17.     public final static String HIGHSCORES_TABLE="highscores"; // name of table
  18.  
  19.     public final static String PLAYER_NAME="name";  // name of player
  20.     public final static String SCORE="score"; //Score of player
  21.     /**
  22.      *
  23.      * @param context
  24.      */
  25.     public SQLController(Context context){
  26.         gd = new GameDatabase(context);
  27.         database = gd.getWritableDatabase();
  28.     }
  29.  
  30.  
  31.     public void createRecords(String name, String score){
  32.         ContentValues values = new ContentValues();
  33.         values.put(PLAYER_NAME, name);
  34.         values.put(SCORE, score);
  35.         database.insert(HIGHSCORES_TABLE, null, values);
  36.     }
  37.  
  38.     public Cursor getAll() {
  39.         if (database == null) {
  40.             return null;
  41.         }
  42.         return database.rawQuery("select * from highscores",null);
  43.     }
  44.  
  45.  
  46.  
  47.  
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement