在遗留C#源代码中分析嵌入式SQL [英] Analyze embedded SQL in legacy C# source code

查看:67
本文介绍了在遗留C#源代码中分析嵌入式SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找分析大量C#源代码以提取嵌入式SQL字符串的选项,我希望分析能够识别哪些表被引用以及哪些列等被引用。

I am looking for options to analyze a large quantity of C# source code to extract embedded SQL strings, I'd like the analysis to be able to identify which tables are referenced and which columns and so on are being referenced.

当然,一些SQL字符串可能是不完整的,或者是"即时"构建的。但也许一个工具可以看到这些,只做一个最小的分析。

Of course some of the SQL strings may be incomplete or built "on the fly" but perhaps a tools could see these and just make a minimal analysis.

有没有人知道VS加载项或VS分析器等可以做这种事情?

Does anyone know of an VS add-ins or VS analyzers etc that can do this kind of thing?

谢谢

推荐答案

这将是艰难的,所以我怀疑有一个工具可以做到这一点。有很多方法可以构建动态SQL,即使是基本猜测也难以提出。您必须搜索包含您关心
的基本SQL命令的所有字符串文字(即SELECT,INSERT等)。当然,这些可能包含在资源文件或代码中。然后你必须有效地解析SQL语言以确定它是否真的是一个SQL命令。

That's going to be tough so I doubt there is a tool to do it. There are so many ways to build dynamic SQL it would be difficult to come up with even a basic guess. You would have to search for all string literals containing basic SQL commands you care about (i.e. SELECT, INSERT, etc). Of course these may be contained in a resource file or in code. Then you'd have to effectively parse the SQL language to figure out whether it is really a SQL command.

从另一个角度来看这可能更容易,找到所有的代码中使用SqlCommand的位置。然后为每个人识别那些不是存储过程(CommandType)。剩下的是你的
代码中的SQL查询。我想在那时你可以做简单的字符串解析来获取基本信息(FROM表,INSERT INTO表等)。 

It might be easier to approach this from an alternative point of view, find all the places in your code that uses a SqlCommand. Then for each one identify those that are not stored procedures (CommandType). What remains are the SQL queries you have in your code. I think at that point you could probably do simple string parsing to get to the basic information (FROM table, INSERT INTO table, etc). 

我想你会结束必须手动执行此操作,但您可以使用Powershell自动执行其中一些操作。它可能枚举文件并至少拉出包含命令的行。

I think you're going to end up having to do this by hand but you might be able to use Powershell to automate some of this. It could probably enumerate the files and pull out the lines containing the commands at least.

可能有一个分析器提供将字符串文字提取到资源文件或其他东西。这也可能为您提供至少一个字符串列表,然后您可以进一步缩小范围。

There may be an analyzer that offers to extract string literals into resource files or something. That may also give you at least a list of the strings that you can then narrow down further.


这篇关于在遗留C#源代码中分析嵌入式SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆