version:1.0
update:2021-10-13 18:52:13 fix:去除okgo,rxAndroid1,优化依赖 add:切换到奥乐云平台
This commit is contained in:
208
app/src/main/java/com/aoleyun/sn/utils/MySQLData.java
Normal file
208
app/src/main/java/com/aoleyun/sn/utils/MySQLData.java
Normal file
@@ -0,0 +1,208 @@
|
||||
package com.aoleyun.sn.utils;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
|
||||
|
||||
import com.aoleyun.sn.comm.CommonDatas;
|
||||
import com.aoleyun.sn.database.DBHelper;
|
||||
import com.aoleyun.sn.database.DBSqlBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MySQLData {
|
||||
|
||||
|
||||
public static void ClearData(Context context) {
|
||||
DBHelper helper = new DBHelper(context);
|
||||
List<String> list = new ArrayList<>();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
String sql = "select * from " + DBSqlBuilder.APPLICATION_MESSAGE + " order by _id asc";
|
||||
cursor = helper.getCursorBySql(sql);
|
||||
while (cursor.moveToNext()) {
|
||||
String key = cursor.getString(cursor.getColumnIndex("file_name"));
|
||||
String where = " file_name='" + key + "'";
|
||||
list.add(where);
|
||||
}
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
helper.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
helper.deleteRow(DBSqlBuilder.APPLICATION_MESSAGE,list);
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
public static void SetData(Context context, String key,
|
||||
String value) {
|
||||
DBHelper helper = new DBHelper(context);
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
String sql = "select * from " + DBSqlBuilder.APPLICATION_MESSAGE + " order by _id asc";
|
||||
cursor = helper.getCursorBySql(sql);
|
||||
int count = 0;
|
||||
String file_name = null;
|
||||
if (cursor.moveToFirst()) {
|
||||
file_name = cursor.getString(cursor.getColumnIndex("file_name"));
|
||||
if (file_name.equals(key)){
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
ContentValues values = new ContentValues();
|
||||
if (count > 0) {
|
||||
values.put("key",value);
|
||||
helper.updateValues(DBSqlBuilder.DETAIL_LOG_TABLE, values, "file_name=" + key);
|
||||
}else {
|
||||
values.put("file_name", key);
|
||||
values.put("key",value);
|
||||
helper.insertValues(DBSqlBuilder.APPLICATION_MESSAGE, values);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetIntData(Context context, String key,
|
||||
int value) {
|
||||
DBHelper helper = new DBHelper(context);
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
String sql = "select * from " + DBSqlBuilder.APPLICATION_MESSAGE + " order by _id asc";
|
||||
cursor = helper.getCursorBySql(sql);
|
||||
int count = 0;
|
||||
String file_name = null;
|
||||
if (cursor.moveToFirst()) {
|
||||
file_name = cursor.getString(cursor.getColumnIndex("file_name"));
|
||||
if (file_name.equals(key)){
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
if (count > 0) {
|
||||
values.put("key", String.valueOf(value));
|
||||
helper.updateValues(DBSqlBuilder.DETAIL_LOG_TABLE, values, "file_name=" + key);
|
||||
}else {
|
||||
values.put("file_name", key);
|
||||
values.put("key", String.valueOf(value));
|
||||
helper.insertValues(DBSqlBuilder.APPLICATION_MESSAGE, values);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetBooleanData(Context context, String key,
|
||||
boolean value) {
|
||||
DBHelper helper = new DBHelper(context);
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
String sql = "select * from " + DBSqlBuilder.APPLICATION_MESSAGE + " order by _id asc";
|
||||
cursor = helper.getCursorBySql(sql);
|
||||
int count = 0;
|
||||
String file_name = null;
|
||||
if (cursor.moveToFirst()) {
|
||||
file_name = cursor.getString(cursor.getColumnIndex("file_name"));
|
||||
if (file_name.equals(key)){
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
if (count > 0) {
|
||||
values.put("key",value + "");
|
||||
helper.updateValues(DBSqlBuilder.DETAIL_LOG_TABLE, values, "file_name=" + key);
|
||||
}else {
|
||||
values.put("file_name", key);
|
||||
values.put("key",value + "");
|
||||
helper.insertValues(DBSqlBuilder.APPLICATION_MESSAGE, values);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetIntData(Context context, String key) {
|
||||
int value = -1;
|
||||
String key_date = "";
|
||||
DBHelper helper = new DBHelper(context);
|
||||
Cursor cursor = null;
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
try {
|
||||
String sql = "select * from " + DBSqlBuilder.APPLICATION_MESSAGE
|
||||
+ " where file_name='" + key + "' order by _id asc";
|
||||
cursor = helper.getCursorBySql(sql);
|
||||
while (cursor.moveToNext()) {
|
||||
key_date = cursor.getString(cursor.getColumnIndex("key"));
|
||||
list.add(key_date);
|
||||
}
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
helper.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
if (key_date != null && !key_date.equals("")){
|
||||
value = Integer.parseInt(key_date.trim());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static boolean GetBooleanData(Context context, String key) {
|
||||
boolean value = false;
|
||||
String key_date = null;
|
||||
DBHelper helper = new DBHelper(context);
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
String sql = "select * from " + DBSqlBuilder.APPLICATION_MESSAGE
|
||||
+ " where file_name='" + key + "' order by _id asc";
|
||||
cursor = helper.getCursorBySql(sql);
|
||||
while (cursor.moveToNext()) {
|
||||
key_date = cursor.getString(cursor.getColumnIndex("key"));
|
||||
}
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
helper.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
if (key_date != null && !key_date.equals("")){
|
||||
value = Boolean.parseBoolean(key_date.trim());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user