Skip to content

Commit

Permalink
在数据源链接中添加sql 前缀语句,方便设置类似高斯中的set search_path=xxx;
Browse files Browse the repository at this point in the history
  • Loading branch information
NoneDay committed Apr 16, 2024
1 parent 4e61b4d commit c3e97c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Binary file modified end/CellReport.dll
Binary file not shown.
32 changes: 18 additions & 14 deletions end/reportWeb/ReportDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ReportDbContext(ILogger<ReportDbContext> logger)
var report_db = SqliteFactory.Instance.CreateConnection();
report_db.ConnectionString = "Data Source=report.db;";
this.Connection = report_db;
this.Compiler=new SqlKata.Compilers.SqliteCompiler();
this.Compiler = new SqlKata.Compilers.SqliteCompiler();
Logger = result =>
{
_logger.LogDebug(result.ToString());
Expand All @@ -44,15 +44,15 @@ public ReportDbContext(ILogger<ReportDbContext> logger)
public IEnumerable<Rpt_group> getList(string cur_userid)
{
IEnumerable<Rpt_group> ret = rpt_Groups;

if (cur_userid != "admin")
ret=rpt_Groups.Where(x => x.owner == cur_userid);
ret = rpt_Groups.Where(x => x.owner == cur_userid);

return ret;
}
public Rpt_group GetRpt_Group(string id)
{
return rpt_Groups.Where(x=>x.Id==id).FirstOrDefault<Rpt_group>();
return rpt_Groups.Where(x => x.Id == id).FirstOrDefault<Rpt_group>();
}
private bool Rpt_groupExists(string id)
{
Expand All @@ -69,9 +69,9 @@ public async Task DeleteRpt_group(string id)
await Query("Rpt_db_connection").Where(new { rpt_id = id }).DeleteAsync();
await Query("Rpt_group").Where(new { id }).DeleteAsync();
ConcurrentBag<Rpt_group> tmp_list = new();
rpt_Groups.Where(x => x.Id != id).ToList().ForEach(x=> tmp_list.Add(x));
rpt_Groups.Where(x => x.Id != id).ToList().ForEach(x => tmp_list.Add(x));
rpt_Groups = tmp_list;
return ;
return;
}
public async Task UpdateRpt_group(string cur_userid, Rpt_group rpt_group)
{
Expand Down Expand Up @@ -155,7 +155,7 @@ CREATE TABLE IF NOT EXISTS Rpt_db_connection (
db_type TEXT,
conn_str TEXT,
test_conn_str TEXT,
prefix text,
sql_prefix text,
CONSTRAINT FK_Rpt_db_connection_Rpt_group_grp_id FOREIGN KEY(grp_id) REFERENCES Rpt_group(Id),
CONSTRAINT PK_Rpt_db_connection PRIMARY KEY(id AUTOINCREMENT)
);
Expand All @@ -171,7 +171,6 @@ CREATE INDEX IF NOT EXISTS IX_Rpt_db_connection_grp_id ON Rpt_db_connection (
);
COMMIT; "
);
var columns=db.Select("SELECT C.name AS column_name FROM sys.tables AS T JOIN sys.columns AS C ON T.object_id = C.OBJECT_ID where T.name='Rpt_db_connection'").ToList();
var main_path = new DirectoryInfo(Path.Combine(env.ContentRootPath, "..", "reportdefine_root", "default")).FullName;
if (db.Query("Rpt_group").AsCount().First<int>() == 0)
{
Expand Down Expand Up @@ -215,14 +214,19 @@ CREATE INDEX IF NOT EXISTS IX_Rpt_db_connection_grp_id ON Rpt_db_connection (
login_script = "",
});
}
if (0 == db.Select(" SELECT * FROM pragma_table_info('Rpt_db_connection') where name='sql_prefix'").Count())
{
db.Statement("alter table Rpt_db_connection add column sql_prefix text");
};

var rpt_config = db.Query("Rpt_config").First<Rpt_config>();
CellReport.util.KeyAndPassword.yan_zheng_zcm(rpt_config.zcm);

FreshCache(db);
}
private static void FreshCache(QueryFactory db)
{
ConcurrentBag<Rpt_group> tmp_list = new();
ConcurrentBag<Rpt_group> tmp_list = new();
db.Query("Rpt_group").Get<Rpt_group>().ToList().ForEach(x => tmp_list.Add(x));
var rpt_Db_Connections = db.Query("Rpt_db_connection").Get<Rpt_db_connection>().ToList();
foreach (var one in tmp_list)
Expand All @@ -231,7 +235,7 @@ private static void FreshCache(QueryFactory db)
}
rpt_Groups = tmp_list;
}
private static ConcurrentBag<Rpt_group> rpt_Groups = new ();
private static ConcurrentBag<Rpt_group> rpt_Groups = new();
}
public class Rpt_group
{
Expand All @@ -243,13 +247,13 @@ public class Rpt_group
public string default_page { get; set; }
public string allow { get; set; }
public string report_path { get; set; }
public string test_report_path { get; set; }
public string test_report_path { get; set; }
[ForeignKey("grp_id")]
[SqlKata.Ignore]
public List<Rpt_db_connection> db_connection_list { get; set; }
public string members { get; set; }
public string zb_user { get; set; }
public string zb_password { get; set; }
public string zb_user { get; set; }
public string zb_password { get; set; }

public string getPageNameByReportName(string reportName)
{
Expand Down

0 comments on commit c3e97c9

Please sign in to comment.