Advertisement
Guest User

Untitled

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