Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. package mx.itsol.switsol;
  2.  
  3. import android.content.ContentValues;
  4. import android.content.Context;
  5. import android.database.Cursor;
  6. import android.database.sqlite.SQLiteDatabase;
  7. import android.database.sqlite.SQLiteOpenHelper;
  8. /**
  9. * Created by MSM on 4/22/2017.
  10. */
  11.  
  12. public class DatabaseHelper extends SQLiteOpenHelper {
  13. public static final int DATABASE_VERSION = 1;
  14. public static final String DATABASE_NAME = "swItsol.db";
  15. public static final String TABLE_NAME = "tokens";
  16. public static final String COL_1 = "ID";
  17. public static final String COL_2 = "USERNAME";
  18. public static final String COL_3 = "PASSWORD";
  19. public static final String COL_4 = "ACCESSTOKEN";
  20. public static final String COL_5 = "ACCESSTOKENDATE";
  21. public SQLiteDatabase db;
  22. public DatabaseHelper(Context context) {
  23. super(context, DATABASE_NAME, null, DATABASE_VERSION);
  24. db=this.getWritableDatabase();
  25. }
  26.  
  27. @Override
  28. public void onCreate(SQLiteDatabase db) {
  29. db.execSQL("create table if not exists "+TABLE_NAME+" (ID INTEGER PRIMARY KEY AUTOINCREMENT, USERNAME TEXT, PASSWORD TEXT, ACCESSTOKEN TEXT, ACCESSTOKENDATE TEXT)");
  30. db.execSQL("create table if not exists tcatfrigo (ID INTEGER PRIMARY KEY AUTOINCREMENT, CODIGO TEXT, NOMBRE TEXT, STATUS INTEGER, UBICACION TEXT, ORDEN INTEGER)");
  31. db.execSQL("create table if not exists tconfig (ID INTEGER PRIMARY KEY AUTOINCREMENT, dburl TEXT, dbuser TEXT,dbpass TEXT)");
  32. db.execSQL("insert into tconfig (dburl, dbuser, dbpass) values ('dbtarimas', 'dbtarimas', '24ac81495a17d8884666ce37f9779aa9')");
  33. }
  34.  
  35. @Override
  36. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  37. db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
  38. onCreate(db);
  39. }
  40.  
  41. public boolean insertData(String username, String password, String accesstkn, String accesstkndate){
  42. // SQLiteDatabase db = this.getWritableDatabase();
  43. ContentValues contentValues = new ContentValues();
  44. contentValues.put(COL_2,username);
  45. contentValues.put(COL_3,password);
  46. contentValues.put(COL_4,accesstkn);
  47. contentValues.put(COL_5,accesstkndate);
  48. long result = db.insert(TABLE_NAME, null, contentValues);
  49. db.close();
  50. if (result == -1) {
  51. return false;
  52. } else {
  53. return true;
  54. }
  55. }
  56.  
  57. public Cursor getAllData(String username, String password) {
  58. Cursor res = db.rawQuery("Select * from "+TABLE_NAME+" where USERNAME='"+username+"' and PASSWORD='"+password+"' order by ID desc limit 1", null);
  59. return res;
  60. }
  61. public Cursor extraeconfig(){
  62. // db = this.getWritableDatabase();
  63. Cursor res=null;
  64. try {
  65. res = db.rawQuery("Select * from tconfig", null);
  66. if (res==null) {
  67.  
  68.  
  69. }
  70. } catch (Exception ex) {
  71. System.out.println("==============================ERROR");
  72. System.out.println(ex.getMessage());
  73. }
  74. return res;
  75.  
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement