简体   繁体   中英

Mathematical expression evaluation

I've got a question about expression evaluation from string. Currently I'm working on project that requires to calculate mathematical expressions from strings that are stored in DB, I want to make C# method that evaluate this string, and this function will be run from stored procedure or function added to DB. So the problem is that I want to use in my C# function already created solutions like NCalc or Jace.Net, but if I want to run it from db I need to add dlls(for example NCalc.dll or Jace.dll) to db assembly. And adding those solutions are quite problematic, NCalc use unsafe code and Sql server cannot run methods from this dll, while Jace need many additional dlls that needs to be added to DB, this is not acceptable solution. So if any one knows working expression evaluator that can be added to db and run ? Thx in advance for help.

I'm using Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64) 2) and .Net framework 4.5

A. I think you could include embed JavaScript engines to the circle of your interests..

eg http://jurassic.codeplex.com/ - pure dotnet, one dll, easy as pie (but still requires WITH PERMISSION_SET = UNSAFE/EXTERNAL_ACCESS, and I think any not specially desigden for CLR lib would require UNSAFE, eg it is enough to have static not-readonly field to became UNSAFE, other restrictions: http://msdn.microsoft.com/en-us/library/ms403273.aspx ).

B. Don't forget that T-SQL is dynamic language as well. Why you can't just save your expressions in T-SQL ? IMHO Sql Server much more suitable to run "Avg" than any expression evaluator that can be called throug CLR drain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM