fix:持久化模块的小bug

add:持久化模块的新单元测试
This commit is contained in:
ChessNineeee committed 2021-04-13 17:03:31 +08:00
1 parent 442b4e3544
commit dcde4eeb41
6 files changed
+242 -135

No files matched your search

@@ -36,12 +36,16 @@ public class Sqlite {
}
/**
* 将密码转换为16进制表示
* @return 16进制字符串 String
*/
private String passwd2HexKey(){
return String.format("x'%s'", passwd);
}
/**
* 获取Sqlite object
* 获取Sqlite 实例
* @return Sqlite object
*/
public static Sqlite getInstance() {
@@ -90,10 +94,19 @@ public class Sqlite {
}
}
//自定义文件地址,注意要用/结尾,比如:/min/identity/
/**
* 打开用户指定路径的数据库文件
* @param filePath String
* @throws Exception
*/
public void open(String filePath) throws Exception {
Connection c = null;
Statement stmt = null;
try{
if (filePath == null || filePath.length() == 0){
throw new Exception("invalid db path!");
}
db_path = filePath;
boolean db_exists = SqliteUtil.pathExists(db_path);
if (!db_exists){
@@ -114,6 +127,11 @@ public class Sqlite {
}
}
/**
* 从打开的数据库获取连接
* @return Connection
* @throws Exception
*/
public Connection getConn() throws Exception {
Connection c = null;
try{
@@ -24,9 +24,11 @@ public final class SqliteUtil {
/**
* 判断文件是否存在
* @param path 特定文件路径
* @return 判断结果
* @return 判断结果 boolean
*/
public static boolean pathExists(String path){
if (path == null)
return false;
File file = new File(path);
return file.exists();
}
@@ -214,7 +214,7 @@ public final class Db {
public static void deleteIdentityByName(String name) throws Exception{
Connection c = Sqlite.getInstance().getConn();
PreparedStatement pstmt = c.prepareStatement("elete from identityinfo where name=?");
PreparedStatement pstmt = c.prepareStatement("delete from identityinfo where name=?");
pstmt.setString(1, name);
pstmt.executeUpdate();
pstmt.close();