Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mx.itsol.switsol;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- import android.util.Log;
- /**
- * Created by MSM on 4/22/2017.
- */
- public class DatabaseHelper extends SQLiteOpenHelper {
- public static final int DATABASE_VERSION = 1;
- public static final String DATABASE_NAME = "swItsol.db";
- public static final String TABLE_NAME = "tokens";
- public static final String COL_1 = "ID";
- public static final String COL_2 = "USERNAME";
- public static final String COL_3 = "PASSWORD";
- public static final String COL_4 = "ACCESSTOKEN";
- public static final String COL_5 = "ACCESSTOKENDATE";
- public SQLiteDatabase db;
- public DatabaseHelper(Context context) {
- super(context, DATABASE_NAME, null, DATABASE_VERSION);
- db=this.getWritableDatabase();
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- Log.i("tag", "=================== ABCA Error");
- db.execSQL("create table if not exists "+TABLE_NAME+" (ID INTEGER PRIMARY KEY AUTOINCREMENT, USERNAME TEXT, PASSWORD TEXT, ACCESSTOKEN TEXT, ACCESSTOKENDATE TEXT)");
- db.execSQL("create table if not exists tcatfrigo (ID INTEGER PRIMARY KEY AUTOINCREMENT, CODIGO TEXT, NOMBRE TEXT, STATUS INTEGER, UBICACION TEXT, ORDEN INTEGER)");
- db.execSQL("create table if not exists tconfig (ID INTEGER PRIMARY KEY AUTOINCREMENT, dburl TEXT, dbuser TEXT,dbpass TEXT)");
- db.execSQL("insert into tconfig (dburl, dbuser, dbpass) values ('jdbc:mysql://127.0.0.1:3307/', 'dbtarimas', '24ac81495a17d8884666ce37f9779aa9')");
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
- onCreate(db);
- }
- public void init() {
- db.execSQL("create table if not exists "+TABLE_NAME+" (ID INTEGER PRIMARY KEY AUTOINCREMENT, USERNAME TEXT, PASSWORD TEXT, ACCESSTOKEN TEXT, ACCESSTOKENDATE TEXT)");
- db.execSQL("create table if not exists tcatfrigo (ID INTEGER PRIMARY KEY AUTOINCREMENT, CODIGO TEXT, NOMBRE TEXT, STATUS INTEGER, UBICACION TEXT, ORDEN INTEGER)");
- db.execSQL("create table if not exists tconfig (ID INTEGER PRIMARY KEY AUTOINCREMENT, dburl TEXT, dbuser TEXT,dbpass TEXT)");
- db.execSQL("insert into tconfig (dburl, dbuser, dbpass) values ('dbtarimas', 'dbtarimas', '24ac81495a17d8884666ce37f9779aa9')");
- }
- public boolean insertData(String username, String password, String accesstkn, String accesstkndate){
- // SQLiteDatabase db = this.getWritableDatabase();
- ContentValues contentValues = new ContentValues();
- contentValues.put(COL_2,username);
- contentValues.put(COL_3,password);
- contentValues.put(COL_4,accesstkn);
- contentValues.put(COL_5,accesstkndate);
- long result = db.insert(TABLE_NAME, null, contentValues);
- db.close();
- if (result == -1) {
- return false;
- } else {
- return true;
- }
- }
- public Cursor getAllData(String username, String password) {
- Cursor res = db.rawQuery("Select * from "+TABLE_NAME+" where USERNAME='"+username+"' and PASSWORD='"+password+"' order by ID desc limit 1", null);
- return res;
- }
- public Cursor extraeconfig(){
- // db = this.getWritableDatabase();
- Cursor res=null;
- try {
- res = db.rawQuery("Select * from tconfig", null);
- if (res==null) {
- }
- } catch (Exception ex) {
- Log.i("tag","==============================ERROR");
- System.out.println(ex.getMessage());
- }
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement