diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 61a9130..b589d56 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 32bd02b..66baa28 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -4,10 +4,8 @@
diff --git a/.idea/misc.xml b/.idea/misc.xml
index f1315a1..676d401 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,7 +1,7 @@
-
+
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
deleted file mode 100644
index e497da9..0000000
--- a/.idea/runConfigurations.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index be78e56..e1c409c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,11 +1,11 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 29
+ compileSdkVersion 30
defaultConfig {
applicationId "com.kongzue.dbv3demo"
minSdkVersion 19
- targetSdkVersion 29
+ targetSdkVersion 30
versionCode 16
versionName "3.0.3.6"
}
@@ -15,6 +15,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_11
+ targetCompatibility JavaVersion.VERSION_11
+ }
}
dependencies {
diff --git a/build.gradle b/build.gradle
index 17f3b79..79ae019 100644
--- a/build.gradle
+++ b/build.gradle
@@ -7,9 +7,7 @@ buildscript {
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.5.1'
- classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
- classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
+ classpath 'com.android.tools.build:gradle:7.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
diff --git a/dbv3/build.gradle b/dbv3/build.gradle
index a74890d..592aa4a 100644
--- a/dbv3/build.gradle
+++ b/dbv3/build.gradle
@@ -1,12 +1,4 @@
apply plugin: 'com.android.library'
-apply plugin: 'com.github.dcendents.android-maven'
-apply plugin: 'com.jfrog.bintray'
-
-def siteUrl = 'https://github.com/kongzue/DBV3' //项目在github主页地址
-def gitUrl = 'https://github.com/kongzue/DBV3.git' //Git仓库的地址
-
-group = "com.kongzue.db"//发布aar前缀根节点
-version = "3.0.3.8"//发布aar的库版本
android {
compileSdkVersion 30
@@ -14,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 30
- versionCode 18
- versionName "3.0.3.8"
+ versionCode 19
+ versionName "3.0.4"
}
buildTypes {
@@ -25,58 +17,58 @@ android {
}
}
}
-install {
- repositories.mavenInstaller {
- // This generates POM.xml with proper parameters
- pom {
- project {
- packaging 'aar'
- name 'dbv3'//添加项目描述
- url siteUrl
- licenses {
- license {
- name 'The Apache Software License, Version 2.0'
- url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
- }
- }
- developers {
- developer {
- id 'myzchh'//设置自己ID
- name 'myzchh'//设置自己名字
- email 'myzcxhh@live.cn'//设置自己邮箱
- }
- }
- scm {
- connection gitUrl
- developerConnection gitUrl
- url siteUrl
- }
- }
- }
- }
-}
-task sourcesJar(type: Jar) {
- from android.sourceSets.main.java.srcDirs
- classifier = 'sources'
-}
-artifacts {
- archives sourcesJar
-}
-Properties properties = new Properties()
-properties.load(project.rootProject.file('local.properties').newDataInputStream())
-bintray {
- user = properties.getProperty("bintray.user")
- key = properties.getProperty("bintray.apikey")
- configurations = ['archives']
- pkg {
- repo = "maven"
- name = "DBV3" //项目在JCenter的名字
- websiteUrl = siteUrl
- vcsUrl = gitUrl
- licenses = ["Apache-2.0"]
- publish = true
- }
-}
+//install {
+// repositories.mavenInstaller {
+// // This generates POM.xml with proper parameters
+// pom {
+// project {
+// packaging 'aar'
+// name 'dbv3'//添加项目描述
+// url siteUrl
+// licenses {
+// license {
+// name 'The Apache Software License, Version 2.0'
+// url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+// }
+// }
+// developers {
+// developer {
+// id 'myzchh'//设置自己ID
+// name 'myzchh'//设置自己名字
+// email 'myzcxhh@live.cn'//设置自己邮箱
+// }
+// }
+// scm {
+// connection gitUrl
+// developerConnection gitUrl
+// url siteUrl
+// }
+// }
+// }
+// }
+//}
+//task sourcesJar(type: Jar) {
+// from android.sourceSets.main.java.srcDirs
+// classifier = 'sources'
+//}
+//artifacts {
+// archives sourcesJar
+//}
+//Properties properties = new Properties()
+//properties.load(project.rootProject.file('local.properties').newDataInputStream())
+//bintray {
+// user = properties.getProperty("bintray.user")
+// key = properties.getProperty("bintray.apikey")
+// configurations = ['archives']
+// pkg {
+// repo = "maven"
+// name = "DBV3" //项目在JCenter的名字
+// websiteUrl = siteUrl
+// vcsUrl = gitUrl
+// licenses = ["Apache-2.0"]
+// publish = true
+// }
+//}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
diff --git a/dbv3/src/main/java/com/kongzue/dbv3/util/DBHelper.java b/dbv3/src/main/java/com/kongzue/dbv3/util/DBHelper.java
index 5a62179..5768d1b 100644
--- a/dbv3/src/main/java/com/kongzue/dbv3/util/DBHelper.java
+++ b/dbv3/src/main/java/com/kongzue/dbv3/util/DBHelper.java
@@ -25,21 +25,21 @@
* @createTime: 2019/10/22 16:38
*/
public class DBHelper {
-
+
public static boolean DEBUGMODE = false;
private String dbName = "";
-
+
private DBHelper() {
}
-
+
private static DBHelper helper;
private SQLiteDatabase db;
private Context context;
-
+
public void init(Context context, String dbName) {
helper.context = context;
helper.dbName = dbName;
-
+
try {
SQLiteOpenHelper sqLiteOpenHelper = new SQLiteHelperImpl(context, dbName, oldVer);
helper.db = sqLiteOpenHelper.getWritableDatabase();
@@ -50,16 +50,39 @@ public void init(Context context, String dbName) {
if (DEBUGMODE) {
e.printStackTrace();
}
+ retryOpenDb(context, dbName);
}
}
-
+
+ private void retryOpenDb(Context context, String dbName) {
+ SQLiteDatabase db = null;
+ int version = 0;
+
+ try {
+ db = SQLiteDatabase.openDatabase(context.getDatabasePath(dbName + ".db").getAbsolutePath(), null, SQLiteDatabase.OPEN_READONLY);
+ version = db.getVersion();
+
+ oldVer = version;
+ init(context,dbName);
+ } catch (Exception e) {
+ // 处理打开数据库时的异常
+ if (DEBUGMODE) {
+ e.printStackTrace();
+ }
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ }
+ }
+
private int oldVer = 1;
-
+
public void init(Context context, String dbName, int oldVer) {
helper.context = context;
helper.dbName = dbName;
- helper.oldVer=oldVer;
-
+ helper.oldVer = oldVer;
+
try {
SQLiteOpenHelper sqLiteOpenHelper = new SQLiteHelperImpl(context, dbName, oldVer);
helper.db = sqLiteOpenHelper.getWritableDatabase();
@@ -72,11 +95,11 @@ public void init(Context context, String dbName, int oldVer) {
}
}
}
-
+
public void init(Context context, File dbFile) {
helper.context = context;
helper.dbName = dbName;
-
+
try {
helper.db = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
if (db == null) {
@@ -88,7 +111,7 @@ public void init(Context context, File dbFile) {
}
}
}
-
+
public static DBHelper getInstance() {
synchronized (DBHelper.class) {
if (helper == null) {
@@ -97,11 +120,11 @@ public static DBHelper getInstance() {
return helper;
}
}
-
+
public SQLiteDatabase getDb() {
return db;
}
-
+
public boolean isHaveTable(String tableName) {
synchronized (DBHelper.class) {
if (db == null) {
@@ -134,7 +157,7 @@ public boolean isHaveTable(String tableName) {
return false;
}
}
-
+
public boolean addData(String tableName, DBData data, boolean allowDuplicate) {
synchronized (DBHelper.class) {
if (db == null) {
@@ -184,7 +207,7 @@ public boolean addData(String tableName, DBData data, boolean allowDuplicate) {
}
}
}
-
+
//创建表
public boolean createNewTable(String tableName, DBData dbData) {
synchronized (DBHelper.class) {
@@ -218,7 +241,7 @@ public boolean createNewTable(String tableName, DBData dbData) {
return true;
}
}
-
+
//更新表
public boolean updateTable(String tableName, DBData dbData) {
synchronized (DBHelper.class) {
@@ -253,7 +276,7 @@ public boolean updateTable(String tableName, DBData dbData) {
return true;
}
}
-
+
//获取一个表内的所有字段名
private List getTableAllKeys(String tableName) {
synchronized (DBHelper.class) {
@@ -278,7 +301,7 @@ private List getTableAllKeys(String tableName) {
return result;
}
}
-
+
//根据查询条件dbData获取一个表内的所有数据
public List findData(String tableName, DBData findConditions, DB.SORT sort, List whereConditions, long start, long count) {
synchronized (DBHelper.class) {
@@ -346,7 +369,7 @@ public List findData(String tableName, DBData findConditions, DB.SORT so
return result;
}
}
-
+
//根据查询条件dbData获取一个表内的所有符合条件数据的数量
public long findDataCount(String tableName, DBData findData, List whereConditions) {
synchronized (DBHelper.class) {
@@ -394,7 +417,7 @@ public long findDataCount(String tableName, DBData findData, List whereC
return count;
}
}
-
+
public long rawCount(String sql) {
synchronized (DBHelper.class) {
if (db == null) {
@@ -416,7 +439,7 @@ public long rawCount(String sql) {
return result;
}
}
-
+
public boolean delete(String tableName, DBData dbData, List whereConditions) {
synchronized (DBHelper.class) {
if (db == null) {
@@ -464,7 +487,7 @@ public boolean delete(String tableName, DBData dbData, List whereConditi
return true;
}
}
-
+
public boolean update(String tableName, DBData dbData) {
synchronized (DBHelper.class) {
if (db == null) {
@@ -503,7 +526,7 @@ public boolean update(String tableName, DBData dbData) {
return true;
}
}
-
+
public boolean deleteTable(String tableName) {
synchronized (DBHelper.class) {
if (db == null) {
@@ -532,14 +555,14 @@ public boolean deleteTable(String tableName) {
return true;
}
}
-
+
private class SQLiteHelperImpl extends SQLiteOpenHelper {
-
+
public SQLiteHelperImpl(Context context, String dbName, int dbVersion) {
//CursorFactory设置为null,使用默认值
super(context, dbName + ".db", null, dbVersion == 0 ? dbVersion + 1 : dbVersion);
}
-
+
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
//if (!isNull(createTableSQLCommand)) {
@@ -547,7 +570,7 @@ public void onCreate(SQLiteDatabase sqLiteDatabase) {
// createTableSQLCommand = null;
//}
}
-
+
//数据库升级用
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
@@ -563,7 +586,7 @@ public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVers
//}
}
}
-
+
public void closeDB() {
synchronized (DBHelper.class) {
if (db != null) {
@@ -573,7 +596,7 @@ public void closeDB() {
db = null;
}
}
-
+
public void restartDB() {
log("# restartDB");
synchronized (DBHelper.class) {
@@ -585,24 +608,24 @@ public void restartDB() {
db = sqLiteOpenHelper.getWritableDatabase();
}
}
-
+
private boolean isNull(String s) {
if (s == null || s.trim().isEmpty() || "null".equals(s)) {
return true;
}
return false;
}
-
+
private void log(Object o) {
if (DEBUGMODE) {
Log.i("DB>>>", o.toString());
}
}
-
+
private void error(Object o) {
if (DEBUGMODE) {
Log.e("DB>>>", o.toString());
}
}
-
+
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 18e79b2..0059dac 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip