-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSqliteController.java
85 lines (71 loc) · 2.45 KB
/
SqliteController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.puddlesmanagment;
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 dell on 24/02/2018.
*/
public class SqliteController extends SQLiteOpenHelper {
private static final String LOGCAT = null;
public SqliteController(Context applicationcontext) {
super(applicationcontext, "puddlesmanagement.db", null, 1);
Log.d(LOGCAT, "Created");
}
@Override
public void onCreate(SQLiteDatabase database) {
String query;
query = "CREATE TABLE Login ( Username TEXT)";
database.execSQL(query);
Log.d(LOGCAT,"Tables Created");
}
@Override
public void onUpgrade(SQLiteDatabase database, int version_old, int current_version) {
String query;
query = "DROP TABLE IF EXISTS Login";
database.execSQL(query);
onCreate(database);
}
public int directLogin(){
SQLiteDatabase db=getReadableDatabase();
int cnt=0;
String qry="Select * from Login";
Cursor cursor=db.rawQuery(qry,null);
if(cursor.moveToFirst()){
do{
cnt++;
}while (cursor.moveToNext());
}
return cnt;
}
public void checkLogin(String username) {
String uname=username;
SQLiteDatabase database = this.getWritableDatabase();
String deleteQuery = "DELETE FROM Login";
database.execSQL(deleteQuery);
database = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("Username", uname);
database.insert("Login", null, values);
database.close();
}
public void funLogout() {
SQLiteDatabase database = this.getWritableDatabase();
String deleteQuery = "DELETE FROM Login";
database.execSQL(deleteQuery);
}
public String returnUsername() {
String val = "";
SQLiteDatabase database = this.getReadableDatabase();
String selectQuery = "SELECT * FROM Login";
Cursor cursor = database.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
val = cursor.getString(0);
} while (cursor.moveToNext());
}
return val;
}
}