You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.2 KiB
35 lines
1.2 KiB
using System.IO; |
|
using Microsoft.Data.Sqlite; |
|
|
|
namespace SparkClient.Model.Helper; |
|
/// <summary> |
|
/// SqLite工具类 |
|
/// </summary> |
|
public class DataBaseHelper |
|
{ |
|
//连接、查询、查询、关闭 |
|
|
|
public static void InitDataBase() |
|
{ |
|
string databasePath = Path.Combine(Common.BasePath, Common.DataBaseTempFileName); |
|
|
|
if (File.Exists(databasePath)) |
|
return; |
|
else |
|
File.Create(databasePath).Close(); |
|
var connection = new SqliteConnection(new SqliteConnectionStringBuilder("data source=" + databasePath) |
|
{ |
|
Mode = SqliteOpenMode.ReadWriteCreate, |
|
Password = Common.DatabasePwd |
|
}.ToString()); |
|
connection.Open(); |
|
using (var command = new SqliteCommand($"ATTACH DATABASE '{Common.DataBaseFileName}' AS {Common.DataBaseName} KEY '{Common.DatabasePwd}';" + |
|
$"SELECT sqlcipher_export('{Common.DataBaseName}');" + |
|
$"DETACH DATABASE {Common.DataBaseName};", connection)) |
|
{ |
|
command.ExecuteNonQuery(); |
|
} |
|
connection.Close(); |
|
|
|
} |
|
} |