diff --git a/LICENSE b/LICENSE index 87a5df2..3bd0c8d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Need more precision? info@zzzprojects.com +Need more precision? info@zzzprojects.com DUAL LICENSING - Copyright © ZZZ Projects Inc. 2014 - 2016 diff --git a/README.md b/README.md index 9e7dbc2..5d11721 100644 --- a/README.md +++ b/README.md @@ -1,185 +1,164 @@ -##Evaluate C# code and expression in T-SQL stored procedure, function and trigger## - -**Extend SQL with the full C# Syntax and get the best of both languages:** - -- Access to .NET features and objects - - LINQ - - Math - - Regex - - String Interpolation - - Web Service -- Evaluate expression at runtime - - Use column value as formula - - Use column value as parameter -- Perform File Operation - - Replace xp_cmdshell with C# Syntax - - Use DirectoryInfo, FileInfo - - Impersonate context -- T-SQL Function Enhancement - - Error Handling (Try/Catch) - - Call stored procedure - - Modify Table State - - Run dynamic SQL - - +# What's Eval-SQL.Net? +Eval SQL.NET is a library that allows evaluating C# expression dynamically directly in T-SQL. + +It provides to your SQL Server all missing pieces like regular expression and dynamic arithmetic string evaluation. + ```sql --- Evaluate dynamically expression in T-SQL -DECLARE @tableFormula TABLE ( - Formula VARCHAR(255), X INT, Y INT, Z INT -) - -INSERT INTO @tableFormula VALUES ('x+y*z', 1, 2, 3 ), - ('(x+y)*z', 1, 2, 3 ) --- SELECT 7 --- SELECT 9 -SELECT SQLNET::New(Formula) - .Val('x', X) - .Val('y', Y) - .Val('z', Z).EvalInt() -FROM @tableFormula +-- SELECT 3 +SELECT SQLNET::New('x+y').ValueInt('x', 1).ValueInt('y', 2).EvalInt() as Result ``` +**Try it online** + +**Find your solutions:** +- Dynamic Arithmetic Expression +- Dynamic Pivot Table +- Regular Expression +- String Interpolation +- Replace xp_cmdshell with DirectoryInfo & FileInfo + +## Performance & Scalability +Performance tuning is one of the most important tasks for a DBA. Don’t miss the chance to **dramatically improve query performance** by **300%** for simple expression and more than **2000%** for complex code over User-Defined Function (UDF) and Table-Valued Function (TVF). + +_Benchmark to split string with delimiters in SQL_ + +| Methods | 1,000 rows | 10,000 rows | 100,000 rows | 1,000,000 rows | +| ------------- | ---------: | ----------: | -----------: | -------------: | +|Eval-SQL.NET | 4 ms | 13 ms | 160 ms | 1,650 ms | +|fn_split (TVF) | 100 ms | 625 ms | 5,500 ms | 55,000 ms | ## Download -**[SQLNET.zip](https://github.com/zzzprojects/Eval-SQL.NET/releases)** +**[Eval-SQL.NET-Install.sql](https://github.com/zzzprojects/Eval-SQL.NET/releases)** -_Minimum Requirements_ -- SQL CLR Permission Level: **SAFE** -- SQL 2012 -- .NET Framework 4.0 +_* PRO Version unlocked for the current month_ -Stay updated with latest changes +_Minimum Requirements:_ +- SQL 2012 / SQL Azure v12 +- SAFE Permission (SQL CLR) -Twitter Follow -Facebook Like +## Evaluate dynamic arithmetic/math expression in SQL +_Make the impossible now possible. Evaluate C# expression in SQL to overcome limitations._ -## SQL Server Eval -Dynamically evaluate arithmetic operation and expression in SQL +- Allow trusted users to create report field and filter +- Consume Web Service +- Replace text in the template with String Interpolation -```sql -CREATE PROCEDURE [dbo].[Select_Switch] @x INT, @y INT, @z INT -AS - BEGIN - DECLARE @result INT - - SET @result = SQLNET::New(' -switch(x) -{ - case 1: return y + z; - case 2: return y - z; - case 3: return y * z; - default: return Convert.ToInt32(y ^^ z); // Pow -} - ').Val('x', @x).Val('y', @y).Val('z', @z).EvalInt() - - SELECT @result - END - -GO - --- RETURN 5 -EXEC Select_Switch 1, 2, 3 --- RETURN -1 -EXEC Select_Switch 2, 2, 3 --- RETURN 6 -EXEC Select_Switch 3, 2, 3 --- RETURN 8 -EXEC Select_Switch 4, 2, 3 +```csharp +-- CREATE test +DECLARE @table TABLE ( X INT, Y INT, Z INT ) +INSERT INTO @table VALUES ( 2, 4, 6 ), ( 3, 5, 7 ), ( 4, 6, 8 ) + +-- Result: 14, 22, 32 +DECLARE @sqlnet SQLNET = SQLNET::New('x*y+z') +SELECT @sqlnet.ValueInt('x', X) + .ValueInt('y', Y) + .ValueInt('z', Z) + .EvalInt() as Result +FROM @table ``` +**Try it online** -**[Learn more](https://github.com/zzzprojects/Eval-SQL.NET/wiki/SQL-Server-Eval-%7C-Dynamically-evaluate-arithmetic-operation-and-expression-in-SQL)** +## Split text with delimiter +_Improve performance and capability for splitting text with an easy to use split function and LINQ expression_ +- Split text with multiple delimiters +- Split text using a regular expression +- Include row index -## SQL Server Regex -Use regular expression to search, replace and split text in SQL +``` +-- CREATE test +DECLARE @t TABLE (Id INT , Input VARCHAR(MAX)) +INSERT INTO @t VALUES ( 1, '1, 2, 3; 4; 5' ), ( 2, '6;7,8;9,10' ) + +-- SPLIT with many delimiters: ',' and ';' +DECLARE @sqlnet SQLNET = SQLNET::New('Regex.Split(input, ",|;")') + +SELECT * +FROM @t AS A + CROSS APPLY ( SELECT * + FROM dbo.SQLNET_EvalTVF_1(@sqlnet.ValueString('input', Input)) + ) AS B +``` +**Try it online** + +## Use regular expression in SQL Server +_Use Regex flexibility to overcome “LIKE” and “PATHINDEX” limitations._ +- IsMatch +- Match +- Matches +- Replace +- Split ```sql -CREATE FUNCTION [dbo].[fn_Split] - ( - @input VARCHAR(MAX) , - @pattern VARCHAR(8000) = ',' - ) -RETURNS @split TABLE ( item VARCHAR(8000) ) - BEGIN - DECLARE @regex_split SQLNET = SQLNET::New('Regex.Split(input, pattern)') - .ValueString('input', @input) - .Val('pattern', @pattern) - - INSERT INTO @split - SELECT CAST(Value_1 AS VARCHAR(8000)) - FROM [dbo].[SQLNET_EvalTVF_1](@regex_split) - RETURN - END - -GO - --- SPLIT with multiple delimiters (',' and ';') -SELECT * FROM dbo.fn_Split('1, 2, 3; 4; 5', ',|;') -``` +DECLARE @customer TABLE ( Email VARCHAR(255) ) -**[Learn more](https://github.com/zzzprojects/Eval-SQL.NET/wiki/SQL-Server-Regex-%7C-Use-regular-expression-to-search,-replace-and-split-text-in-SQL)** +INSERT INTO @customer +VALUES ( 'info@zzzprojects.com' ), + ( 'invalid.com' ), + ( 'sales@zzzprojects.com' ) -## SQL Server File Operation -xp_cmdshell alternative to read and write files in SQL +DECLARE @valid_email SQLNET = SQLNET::New('Regex.IsMatch(email, +@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")') -```sql +-- SELECT 'invalid.com' +SELECT * FROM @customer WHERE @valid_email.ValueString('email', Email).EvalBit() = 0 +``` +**Try it online** + +## Replace xp_cmdshell with restrictive alternative +_Avoid enabling xp_cmdshell and compromising your SQL Server and use a more restrictive solution instead._ +- Impersonate Context +- Improve maintainability +- Improve readability +- Improve security + +```csharp -- REQUIRE EXTERNAL_ACCESS permission DECLARE @sqlnet SQLNET = SQLNET::New(' string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var dir = new DirectoryInfo(path); -return dir.GetFiles("*.*").Select(x => x.FullName).OrderBy(x => x).ToList();') - .Impersonate() +return dir.GetFiles("*.*") + .Select(x => new { x.FullName, FileContent = File.ReadAllText(x.FullName) }) + .OrderBy(x => x.FullName)') + .Impersonate() --- SELECT * FROM DesktopFiles ORDER BY File.Fullname +-- SELECT FullName, FileContext FROM DesktopFiles ORDER BY Fullname EXEC dbo.SQLNET_EvalResultSet @sqlnet ``` -**[Learn more](https://github.com/zzzprojects/Eval-SQL.NET/wiki/SQL-Server-File-Operation-%7C-xp_cmdshell-alternative-to-read-and-write-files-in-SQL)** - ## FREE vs PRO -Every month, a **[FREE trial](https://github.com/zzzprojects/Eval-SQL.NET/releases)** of the PRO version is available to let you evaluate all its features without limitations. - -Features | FREE Version | PRO Version ------------- | :-------------: | :-------------: -Maximum Characters | 50 | Unlimited -Commercial License | No | Yes -Support & Upgrades (1 year) | No | Yes +Features | **[PRO Version](http://eval-sql.net/#pro)** +------------ | :-------------: +Maximum Characters | Unlimited +Commercial License | Yes +Support & Upgrades (1 year) | Yes Learn more about the **[PRO Version](http://eval-sql.net/#pro)** -## Contribution - -Supporting & developing FREE features takes **hundreds** and **thousands** of hours! If you like our product please consider making a donation to keep us running. +## Contribute -Contribute +The best way to contribute is by **spreading the word** about the library: -Contribution isn't all about money! - Blog it - Comment it - - Fork it - Star it - Share it - -A **HUGE thanks** for your extra support. + +A **HUGE THANKS** for your help. ## More Projects -**Entity Framework** -- [Entity Framework Extensions](http://www.zzzprojects.com/products/dotnet-development/entity-framework-extensions/) -- [Entity Framework Plus](https://github.com/zzzprojects/EntityFramework-Plus) - -**Bulk Operations** -- [NET Entity Framework Extensions](http://www.zzzprojects.com/products/dotnet-development/entity-framework-extensions/) -- [NET Bulk Operations](http://www.zzzprojects.com/products/dotnet-development/bulk-operations/) - -**Expression Evaluator** -- [Eval SQL.NET](https://github.com/zzzprojects/Eval-SQL.NET) -- [Eval Expression.NET](https://github.com/zzzprojects/Eval-Expression.NET) - -**Others** -- [Extension Methods Library](https://github.com/zzzprojects/Z.ExtensionMethods/) -- [LINQ Async](https://github.com/zzzprojects/Linq-AsyncExtensions) - -**Need more info?** info@zzzprojects.com - -Contact our outstanding customer support for any request. We usually answer within the next business day, hour, or minutes! +- Projects: + - [EntityFramework Extensions](https://entityframework-extensions.net/) + - [Dapper Plus](https://dapper-plus.net/) + - [C# Eval Expression](https://eval-expression.net/) +- Learn Websites + - [Learn EF Core](https://www.learnentityframeworkcore.com/) + - [Learn Dapper](https://www.learndapper.com/) +- Online Tools: + - [.NET Fiddle](https://dotnetfiddle.net/) + - [SQL Fiddle](https://sqlfiddle.com/) + - [ZZZ Code AI](https://zzzcode.ai/) +- and much more! + +To view all our free and paid projects, visit our website [ZZZ Projects](https://zzzprojects.com/). diff --git a/src/Z.Expressions.SqlServer.Eval/Eval/Eval.Compile.cs b/src/Z.Expressions.SqlServer.Eval/Eval/Eval.Compile.cs new file mode 100644 index 0000000..bf314c7 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/Eval/Eval.Compile.cs @@ -0,0 +1,168 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Z.Expressions +{ + public static partial class Eval + { + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code) + { + return EvalManager.DefaultContext.Compile(code); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// Parameter types used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code, IEnumerable parameterTypes) + { + return EvalManager.DefaultContext.Compile(code, parameterTypes); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// Parameter types used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code, params Type[] parameterTypes) + { + return EvalManager.DefaultContext.Compile(code, parameterTypes); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// Parameter types used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code, IDictionary parameterTypes) + { + return EvalManager.DefaultContext.Compile(code, parameterTypes); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code, Type type1) + { + return EvalManager.DefaultContext.Compile(code, type1); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code, Type type1, Type type2) + { + return EvalManager.DefaultContext.Compile(code, type1, type2); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code, Type type1, Type type2, Type type3) + { + return EvalManager.DefaultContext.Compile(code, type1, type2, type3); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// The fourth type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code, Type type1, Type type2, Type type3, Type type4) + { + return EvalManager.DefaultContext.Compile(code, type1, type2, type3, type4); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// The fourth type used to compile the code or expression. + /// The fifth type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5) + { + return EvalManager.DefaultContext.Compile(code, type1, type2, type3, type4, type5); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// The fourth type used to compile the code or expression. + /// The fifth type used to compile the code or expression. + /// The sixth type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5, Type type6) + { + return EvalManager.DefaultContext.Compile(code, type1, type2, type3, type4, type5, type6); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// The fourth type used to compile the code or expression. + /// The fifth type used to compile the code or expression. + /// The sixth type used to compile the code or expression. + /// The seventh type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7) + { + return EvalManager.DefaultContext.Compile(code, type1, type2, type3, type4, type5, type6, type7); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// The fourth type used to compile the code or expression. + /// The fifth type used to compile the code or expression. + /// The sixth type used to compile the code or expression. + /// The seventh type used to compile the code or expression. + /// The eighth type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7, Type type8) + { + return EvalManager.DefaultContext.Compile(code, type1, type2, type3, type4, type5, type6, type7, type8); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// The fourth type used to compile the code or expression. + /// The fifth type used to compile the code or expression. + /// The sixth type used to compile the code or expression. + /// The seventh type used to compile the code or expression. + /// The eighth type used to compile the code or expression. + /// The ninth type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public static Func Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7, Type type8, Type type9) + { + return EvalManager.DefaultContext.Compile(code, type1, type2, type3, type4, type5, type6, type7, type8, type9); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/Eval/Eval.Compile`.cs b/src/Z.Expressions.SqlServer.Eval/Eval/Eval.Compile`.cs new file mode 100644 index 0000000..c1bddd8 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/Eval/Eval.Compile`.cs @@ -0,0 +1,43 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System.Collections.Generic; + +namespace Z.Expressions +{ + public static partial class Eval + { + /// Compile the code or expression and return a TDelegate of type Func or Action to execute. + /// Type of the delegate (Func or Action) to use to compile the code or expression. + /// The code or expression to compile. + /// A TDelegate of type Func or Action that represents the compiled code or expression. + public static TDelegate Compile(string code) + { + return EvalManager.DefaultContext.Compile(code); + } + + /// Compile the code or expression and return a TDelegate of type Func or action to execute. + /// Type of the delegate (Func or Action) to use to compile the code or expression. + /// The code or expression to compile. + /// Parameter names used to compile the code or expressions. + /// A TDelegate of type Func or Action that represents the compiled code or expression. + public static TDelegate Compile(string code, IEnumerable parameterNames) + { + return EvalManager.DefaultContext.Compile(code, parameterNames); + } + + /// Compile the code or expression and return a TDelegate of type Func or Action to execute. + /// Type of the delegate (Func or Action) to use to compile the code or expression. + /// The code or expression to compile. + /// Parameter names used to compile the code or expressions. + /// A TDelegate of type Func or Action that represents the compiled code or expression. + public static TDelegate Compile(string code, params string[] parameterNames) + { + return EvalManager.DefaultContext.Compile(code, parameterNames); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/Eval/Eval.Execute.cs b/src/Z.Expressions.SqlServer.Eval/Eval/Eval.Execute.cs new file mode 100644 index 0000000..4ae73d1 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/Eval/Eval.Execute.cs @@ -0,0 +1,38 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +namespace Z.Expressions +{ + public static partial class Eval + { + /// Compile and evaluate the code or expression and return the result. + /// The code or expression to evaluate. + /// The evaluated result or null that represents the evaluted code or expression. + public static object Execute(string code) + { + return EvalManager.DefaultContext.Execute(code); + } + + /// Compile and evaluate the code or expression and return the result. + /// The code or expression to evaluate. + /// The parameter values used to evaluates the code or expression. + /// The evaluated result or null that represents the evaluted code or expression. + public static object Execute(string code, object parameters) + { + return EvalManager.DefaultContext.Execute(code, parameters); + } + + /// Compile and evaluate the code or expression and return the result. + /// The code or expression to evaluate. + /// The parameter values used to evaluates the code or expression. + /// The evaluated result or null that represents the evaluted code or expression. + public static object Execute(string code, params object[] parameters) + { + return EvalManager.DefaultContext.Execute(code, parameters); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/Eval/Eval.Execute`.cs b/src/Z.Expressions.SqlServer.Eval/Eval/Eval.Execute`.cs new file mode 100644 index 0000000..385ddef --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/Eval/Eval.Execute`.cs @@ -0,0 +1,41 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +namespace Z.Expressions +{ + public static partial class Eval + { + /// Compile and evaluate the code or expression and return the result of type TResult. + /// Type of the result of the evaluted code or expression. + /// The code or expression to evaluate. + /// The evaluated result of type TResult or null that represents the evaluted code or expression. + public static TResult Execute(string code) + { + return EvalManager.DefaultContext.Execute(code); + } + + /// Compile and evaluate the code or expression and return the result of type TResult. + /// Type of the result of the evaluted code or expression. + /// The code or expression to evaluate. + /// The parameter values used to evaluates the code or expression. + /// The evaluated result of type TResult or null that represents the evaluted code or expression. + public static TResult Execute(string code, object parameters) + { + return EvalManager.DefaultContext.Execute(code, parameters); + } + + /// Compile and evaluate the code or expression and return the result of type TResult. + /// Type of the result of the evaluted code or expression. + /// The code or expression to evaluate. + /// The parameter values used to evaluates the code or expression. + /// The evaluated result of type TResult or null that represents the evaluted code or expression. + public static TResult Execute(string code, params object[] parameters) + { + return EvalManager.DefaultContext.Execute(code, parameters); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalCompiler/EvalCompiler.cs b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/EvalCompiler.cs index 45708d1..33f1dfc 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalCompiler/EvalCompiler.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/EvalCompiler.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Collections; @@ -27,7 +27,7 @@ internal static partial class EvalCompiler /// The dictionary of parameter (name / type) used in the code or expression to compile. /// Type of the compiled code or expression result. /// A TDelegate of type Func or Action that represents the compiled code or expression. - internal static EvalDelegate Compile(EvalContext context, string code, ListDictionary parameterTypes, Type resultType) + internal static EvalDelegate CompileSQLNET(EvalContext context, string code, IDictionary parameterTypes, Type resultType) { var cacheKey = ResolveCacheKey(context, typeof (Func), code, parameterTypes); @@ -37,12 +37,6 @@ internal static EvalDelegate Compile(EvalContext context, string code, ListDicti return cachedDelegate; } - Dictionary parameterDict = new Dictionary(); - foreach (DictionaryEntry parameterType in parameterTypes) - { - parameterDict.Add((string)parameterType.Key, (Type)parameterType.Value); - } - // Options var scope = new ExpressionScope { @@ -80,7 +74,7 @@ internal static EvalDelegate Compile(EvalContext context, string code, ListDicti } // Resolve Parameter - var parameterExpressions = ResolveParameter(scope, parameterDict); + var parameterExpressions = ResolveParameter(scope, EvalCompilerParameterKind.Dictionary, parameterTypes); // CodeAnalysis var syntaxRoot = SyntaxParser.ParseText(code); @@ -96,5 +90,75 @@ internal static EvalDelegate Compile(EvalContext context, string code, ListDicti return evalDelegate; } + + /// Compile the code or expression and return a TDelegate of type Func or Action to execute. + /// Type of the delegate (Func or Action) to use to compile the code or expression. + /// The eval context used to compile the code or expression. + /// The code or expression to compile. + /// The dictionary of parameter (name / type) used in the code or expression to compile. + /// Type of the compiled code or expression result. + /// The parameter kind for the code or expression to compile. + /// A TDelegate of type Func or Action that represents the compiled code or expression. + internal static TDelegate Compile(EvalContext context, string code, IDictionary parameterTypes, Type resultType, EvalCompilerParameterKind parameterKind) + { + var cacheKey = ResolveCacheKey(context, typeof (Func), code, parameterTypes); + + EvalDelegate cachedDelegate; + if (EvalManager.CacheDelegate.TryGetValue(cacheKey, out cachedDelegate)) + { + return (TDelegate) cachedDelegate.InnerDelegate; + } + + // Options + var scope = new ExpressionScope + { + AliasExtensionMethods = context.AliasExtensionMethods, + AliasNames = context.AliasNames, + AliasStaticMembers = context.AliasStaticMembers, + AliasTypes = context.AliasTypes, + BindingFlags = context.BindingFlags, + UseCaretForExponent = context.UseCaretForExponent + }; + + // Resolve Parameter + var parameterExpressions = ResolveParameter(scope, parameterKind, parameterTypes); + + // ADD global constants + if (context.AliasGlobalConstants.Count > 0) + { + scope.Constants = new Dictionary(context.AliasGlobalConstants); + } + + // ADD global variables + if (context.AliasGlobalVariables.Count > 0) + { + foreach (var keyValue in context.AliasGlobalVariables) + { + scope.CreateLazyVariable(keyValue.Key, new LazySingleThread(() => + { + var innerParameter = scope.CreateVariable(keyValue.Value.GetType(), keyValue.Key); + var innerExpression = Expression.Assign(innerParameter, Expression.Constant(keyValue.Value)); + scope.Expressions.Add(innerExpression); + return innerParameter; + })); + } + } + + // CodeAnalysis + var syntaxRoot = SyntaxParser.ParseText(code); + + // CodeCompiler + var expression = ExpressionParser.ParseSyntax(scope, syntaxRoot, resultType); + + // Compile the expression + var compiled = Expression.Lambda(expression, parameterExpressions).Compile(); + + var evalDelegate = new EvalDelegate(cacheKey, null); + evalDelegate.InnerDelegate = compiled; + + EvalManager.CacheDelegate.TryAdd(cacheKey, evalDelegate); + + return compiled; + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveCacheKey.cs b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveCacheKey.cs index e2b6c48..a4eaa6e 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveCacheKey.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveCacheKey.cs @@ -1,12 +1,13 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; -using System.Text; +using System.Collections.Generic; +using System.Linq; namespace Z.Expressions { @@ -17,16 +18,9 @@ internal static partial class EvalCompiler /// Type of the delegate (Func or Action) to use to compile the code or expression. /// The code or expression to compile. /// List of parameter types used to compile the code or expression. - /// A string representing a unique key for the combination delegate/code/parameter types. - private static string ResolveCacheKey(EvalContext context, Type tdelegate, string code, ListDictionary parameterTypes) + /// A string representing a unique key for the combinaison delegate/code/parameter types. + private static string ResolveCacheKey(EvalContext context, Type tdelegate, string code, IDictionary parameterTypes) { - var sb = new StringBuilder(); - - foreach (var value in parameterTypes.Values) - { - sb.Append(((Type)value).FullName); - } - // Concatenate: // - CacheKey Prefix // - Code or expression @@ -38,7 +32,7 @@ private static string ResolveCacheKey(EvalContext context, Type tdelegate, strin ";", tdelegate.FullName, ";", - sb.ToString()); + parameterTypes == null ? "" : string.Join(";", parameterTypes.Values.Select(x => x.FullName))); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveLazyMember.cs b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveLazyMember.cs new file mode 100644 index 0000000..fa34b6d --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveLazyMember.cs @@ -0,0 +1,60 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using Z.Expressions.CodeCompiler.CSharp; + +namespace Z.Expressions +{ + internal static partial class EvalCompiler + { + /// Resolve lazy member from the member type + /// The expression scope for the code or expression to compile. + /// The dictionary of parameter (name / type) used in the code or expression to compile. + /// The main parameter name. + /// The member type. + private static void ResolzeLazyMember(ExpressionScope scope, IDictionary parameterTypes, string parameterName, Type memberType) + { + if (Type.GetTypeCode(memberType) == TypeCode.Object) + { + var parameterProperties = memberType.GetProperties().Where(x => !x.GetIndexParameters().Any()).ToArray(); + var parameterFields = memberType.GetFields(); + + foreach (var propertyInfo in parameterProperties) + { + parameterTypes.Add(propertyInfo.Name, propertyInfo.PropertyType); + + scope.CreateLazyVariable(propertyInfo.Name, new LazySingleThread(() => + { + var innerParameter = scope.CreateVariable(propertyInfo.PropertyType, propertyInfo.Name); + var innerExpression = Expression.Assign(innerParameter, Expression.Property(scope.GetValueExpressionOrNull(parameterName), propertyInfo)); + scope.Expressions.Add(innerExpression); + + return innerParameter; + })); + } + + foreach (var fieldInfo in parameterFields) + { + parameterTypes.Add(fieldInfo.Name, fieldInfo.FieldType); + + scope.CreateLazyVariable(fieldInfo.Name, new LazySingleThread(() => + { + var innerParameter = scope.CreateVariable(fieldInfo.FieldType, fieldInfo.Name); + var innerExpression = Expression.Assign(innerParameter, Expression.Field(scope.GetValueExpressionOrNull(parameterName), fieldInfo)); + scope.Expressions.Add(innerExpression); + + return innerParameter; + })); + } + } + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameter.cs b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameter.cs index d3b4e32..c69f1e2 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameter.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameter.cs @@ -1,12 +1,11 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; -using System.Collections; using System.Collections.Generic; using System.Linq.Expressions; using Z.Expressions.CodeCompiler.CSharp; @@ -17,38 +16,38 @@ internal static partial class EvalCompiler { /// Resolve parameters used for the code or expression. /// The expression scope for the code or expression to compile. - /// The dictionary of parameters (name / type) used in the code or expression to compile. + /// The parameter kind for the code or expression to compile. + /// The dictionary of parameter (name / type) used in the code or expression to compile. /// A ParameterExpression list used in code or expression to compile. - private static List ResolveParameter(ExpressionScope scope, IDictionary parameterTypes) + private static List ResolveParameter(ExpressionScope scope, EvalCompilerParameterKind parameterKind, IDictionary parameterTypes) { - var parameters = new List(); + if (parameterTypes == null) return null; - var parameterDictionary = scope.CreateParameter(typeof (IDictionary)); - parameters.Add(parameterDictionary); + List parameterExpressions; - foreach (var parameter in parameterTypes) + switch (parameterKind) { -#if SQLNET - scope.CreateLazyVariable(parameter.Key, new LazySingleThread(() => -#else - scope.CreateLazyVariable(parameter.Key, new Lazy(() => -#endif - { - var innerParameter = scope.CreateVariable(parameter.Value, parameter.Key); - - Expression innerExpression = Expression.Property(parameterDictionary, DictionaryItemPropertyInfo, Expression.Constant(parameter.Key)); - - innerExpression = innerExpression.Type != parameter.Value ? - Expression.Assign(innerParameter, Expression.Convert(innerExpression, parameter.Value)) : - Expression.Assign(innerParameter, innerExpression); - - scope.Expressions.Add(Expression.Assign(innerParameter, innerExpression)); - - return innerParameter; - })); + case EvalCompilerParameterKind.Dictionary: + parameterExpressions = ResolveParameterDictionary(scope, parameterTypes); + break; + case EvalCompilerParameterKind.Enumerable: + parameterExpressions = ResolveParameterEnumerable(scope, parameterTypes); + break; + case EvalCompilerParameterKind.SingleDictionary: + parameterExpressions = ResolveParameterSingleDictionary(scope, parameterTypes); + break; + case EvalCompilerParameterKind.Typed: + parameterExpressions = ResolveParameterTyped(scope, parameterTypes); + break; + case EvalCompilerParameterKind.Untyped: + parameterExpressions = ResolveParameterUntyped(scope, parameterTypes); + break; + default: + parameterExpressions = new List(); + break; } - return parameters; + return parameterExpressions; } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterDictionary.cs b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterDictionary.cs new file mode 100644 index 0000000..1a4506c --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterDictionary.cs @@ -0,0 +1,50 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq.Expressions; +using Z.Expressions.CodeCompiler.CSharp; + +namespace Z.Expressions +{ + internal static partial class EvalCompiler + { + /// Resolve dictionary parameters used for the code or expression. + /// The expression scope for the code or expression to compile. + /// The dictionary of parameter (name / type) used in the code or expression to compile. + /// A ParameterExpression list used in code or expression to compile. + private static List ResolveParameterDictionary(ExpressionScope scope, IDictionary parameterTypes) + { + var parameters = new List(); + + var parameterDictionary = scope.CreateParameter(typeof (IDictionary)); + parameters.Add(parameterDictionary); + + foreach (var parameter in parameterTypes) + { + scope.CreateLazyVariable(parameter.Key, new LazySingleThread(() => + { + var innerParameter = scope.CreateVariable(parameter.Value, parameter.Key); + + Expression innerExpression = Expression.Property(parameterDictionary, DictionaryItemPropertyInfo, Expression.Constant(parameter.Key)); + + innerExpression = innerExpression.Type != parameter.Value ? + Expression.Assign(innerParameter, Expression.Convert(innerExpression, parameter.Value)) : + Expression.Assign(innerParameter, innerExpression); + + scope.Expressions.Add(Expression.Assign(innerParameter, innerExpression)); + + return innerParameter; + })); + } + + return parameters; + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterEnumerable.cs b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterEnumerable.cs new file mode 100644 index 0000000..8fd495a --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterEnumerable.cs @@ -0,0 +1,57 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Reflection; +using Z.Expressions.CodeCompiler.CSharp; + +namespace Z.Expressions +{ + internal static partial class EvalCompiler + { + /// Resolve enumerable parameters used for the code or expression. + /// The expression scope for the code or expression to compile. + /// The dictionary of parameter (name / type) used in the code or expression to compile. + /// A ParameterExpression list used in code or expression to compile. + private static List ResolveParameterEnumerable(ExpressionScope scope, IDictionary parameterTypes) + { + var parameters = new List(); + + var parameterEnumerable = scope.CreateParameter(typeof (IEnumerable)); + parameters.Add(parameterEnumerable); + + var dictParameter = scope.CreateVariable(typeof (Dictionary)); + var methodConvert = typeof (EvalCompiler).GetMethod("ResolveToParameterDictionary", BindingFlags.NonPublic | BindingFlags.Static); + var expressionConvert = Expression.Call(methodConvert, new Expression[] {parameterEnumerable}); + var expressionAssign = Expression.Assign(dictParameter, expressionConvert); + scope.Expressions.Add(expressionAssign); + + foreach (var parameter in parameterTypes) + { + scope.CreateLazyVariable(parameter.Key, new LazySingleThread(() => + { + var innerParameter = scope.CreateVariable(parameter.Value, parameter.Key); + + Expression innerExpression = Expression.Property(dictParameter, DictionaryItemPropertyInfo, Expression.Constant(parameter.Key)); + + innerExpression = innerExpression.Type != parameter.Value ? + Expression.Assign(innerParameter, Expression.Convert(innerExpression, parameter.Value)) : + Expression.Assign(innerParameter, innerExpression); + + scope.Expressions.Add(Expression.Assign(innerParameter, innerExpression)); + + return innerParameter; + })); + } + + return parameters; + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterSingleDictionary.cs b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterSingleDictionary.cs new file mode 100644 index 0000000..33f58da --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterSingleDictionary.cs @@ -0,0 +1,50 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq.Expressions; +using Z.Expressions.CodeCompiler.CSharp; + +namespace Z.Expressions +{ + internal static partial class EvalCompiler + { + /// Resolve single dictionary parameters used for the code or expression. + /// The expression scope for the code or expression to compile. + /// The dictionary of parameter (name / type) used in the code or expression to compile. + /// A ParameterExpression list used in code or expression to compile. + private static List ResolveParameterSingleDictionary(ExpressionScope scope, IDictionary parameterTypes) + { + var parameters = new List(); + + var parameterDictionary = scope.CreateParameter(typeof (IDictionary), "{0}"); + parameters.Add(parameterDictionary); + + foreach (var parameter in parameterTypes) + { + scope.CreateLazyVariable(parameter.Key, new LazySingleThread(() => + { + var innerParameter = scope.CreateVariable(parameter.Value, parameter.Key); + + Expression innerExpression = Expression.Property(parameterDictionary, DictionaryItemPropertyInfo, Expression.Constant(parameter.Key)); + + innerExpression = innerExpression.Type != parameter.Value ? + Expression.Assign(innerParameter, Expression.Convert(innerExpression, parameter.Value)) : + Expression.Assign(innerParameter, innerExpression); + + scope.Expressions.Add(Expression.Assign(innerParameter, innerExpression)); + + return innerParameter; + })); + } + + return parameters; + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterTyped.cs b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterTyped.cs new file mode 100644 index 0000000..5592d8b --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterTyped.cs @@ -0,0 +1,43 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using Z.Expressions.CodeCompiler.CSharp; + +namespace Z.Expressions +{ + internal static partial class EvalCompiler + { + /// Resolve typed parameters used for the code or expression. + /// The expression scope for the code or expression to compile. + /// The dictionary of parameter (name / type) used in the code or expression to compile. + /// A ParameterExpression list used in code or expression to compile. + private static List ResolveParameterTyped(ExpressionScope scope, IDictionary parameterTypes) + { + var parameters = new List(); + + foreach (var parameter in parameterTypes) + { + parameters.Add(scope.CreateParameter(parameter.Value, parameter.Key)); + } + + if (parameterTypes.Count == 1) + { + var keyValue = parameterTypes.First(); + if (Type.GetTypeCode(keyValue.Value) == TypeCode.Object) + { + ResolzeLazyMember(scope, parameterTypes, keyValue.Key, keyValue.Value); + } + } + + return parameters; + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterUntyped.cs b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterUntyped.cs new file mode 100644 index 0000000..570fefc --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/EvalCompiler/Parameter/ResolveParameterUntyped.cs @@ -0,0 +1,57 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using Z.Expressions.CodeCompiler.CSharp; + +namespace Z.Expressions +{ + internal static partial class EvalCompiler + { + /// Resolve untyped parameters used for the code or expression. + /// The expression scope for the code or expression to compile. + /// The dictionary of parameter (name / type) used in the code or expression to compile. + /// A ParameterExpression list used in code or expression to compile. + private static List ResolveParameterUntyped(ExpressionScope scope, IDictionary parameterTypes) + { + var parameters = new List(); + + foreach (var parameter in parameterTypes) + { + var parameterExpression = scope.CreateParameter(typeof (object)); + parameters.Add(parameterExpression); + + scope.CreateLazyVariable(parameter.Key, new LazySingleThread(() => + { + var innerParameter = scope.CreateVariable(parameter.Value, parameter.Key); + + var innerExpression = parameterExpression.Type != parameter.Value ? + Expression.Assign(innerParameter, Expression.Convert(parameterExpression, parameter.Value)) : + Expression.Assign(innerParameter, parameterExpression); + + scope.Expressions.Insert(0, innerExpression); + + return innerParameter; + })); + } + + if (parameterTypes.Count == 1) + { + var keyValue = parameterTypes.First(); + if (Type.GetTypeCode(keyValue.Value) == TypeCode.Object) + { + ResolzeLazyMember(scope, parameterTypes, keyValue.Key, keyValue.Value); + } + } + + return parameters; + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalCompilerParameterKind.cs b/src/Z.Expressions.SqlServer.Eval/EvalCompilerParameterKind.cs new file mode 100644 index 0000000..1a1633f --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/EvalCompilerParameterKind.cs @@ -0,0 +1,31 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +namespace Z.Expressions +{ + /// Values that represent the ParameterKind for the EvalCompiler. + public enum EvalCompilerParameterKind + { + /// An enum constant representing the option when no parameter is specified. + None, + + /// An enum constant representing the option when a dictionary parameter is specified. + Dictionary, + + /// An enum constant representing the option when an enumerable parable is specified. + Enumerable, + + /// An enum constant representing the option when a single dictionary parameter is specified. + SingleDictionary, + + /// An enum constant representing the option when parameter are typed. + Typed, + + /// An enum constant representing the option when parameter are untyped. + Untyped + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Compile/EvalContext.Compile.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Compile/EvalContext.Compile.cs index 0a8527b..74a9e75 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Compile/EvalContext.Compile.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Compile/EvalContext.Compile.cs @@ -1,12 +1,14 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +using System.Collections; using System.Collections.Generic; +using System.Linq; namespace Z.Expressions { @@ -16,9 +18,231 @@ public partial class EvalContext /// The code or expression to compile. /// Parameter types used to compile the code or expression. /// A delegate of type Func that represents the compiled code or expression. - public EvalDelegate Compile(string code, ListDictionary parameterTypes) + public EvalDelegate CompileSQLNET(string code, IDictionary parameterTypes) { - return EvalCompiler.Compile(this, code, parameterTypes, typeof (object)); + return EvalCompiler.CompileSQLNET(this, code, parameterTypes, typeof (object)); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code) + { + return EvalCompiler.Compile>(this, code, null, typeof(object), EvalCompilerParameterKind.None); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// Parameter types used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code, IEnumerable parameterTypes) + { + return Compile(code, parameterTypes.ToArray()); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// Parameter types used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code, params Type[] parameterTypes) + { + var dict = new Dictionary(); + + for (var i = 0; i < parameterTypes.Length; i++) + { + dict.Add(string.Concat("{", i, "}"), parameterTypes[i]); + } + + return EvalCompiler.Compile>(this, code, dict, typeof(object), EvalCompilerParameterKind.Enumerable); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// Parameter types used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code, IDictionary parameterTypes) + { + return EvalCompiler.Compile>(this, code, parameterTypes, typeof(object), EvalCompilerParameterKind.Dictionary); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code, Type type1) + { + return EvalCompiler.Compile>(this, code, new Dictionary + { + {"{0}", type1} + }, typeof(object), EvalCompilerParameterKind.Untyped); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code, Type type1, Type type2) + { + return EvalCompiler.Compile>(this, code, new Dictionary + { + {"{0}", type1}, + {"{1}", type2} + }, typeof(object), EvalCompilerParameterKind.Untyped); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code, Type type1, Type type2, Type type3) + { + return EvalCompiler.Compile>(this, code, new Dictionary + { + {"{0}", type1}, + {"{1}", type2}, + {"{2}", type3} + }, typeof(object), EvalCompilerParameterKind.Untyped); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// The fourth type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code, Type type1, Type type2, Type type3, Type type4) + { + return EvalCompiler.Compile>(this, code, new Dictionary + { + {"{0}", type1}, + {"{1}", type2}, + {"{2}", type3}, + {"{3}", type4} + }, typeof(object), EvalCompilerParameterKind.Untyped); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// The fourth type used to compile the code or expression. + /// The fifth type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5) + { + return EvalCompiler.Compile>(this, code, new Dictionary + { + {"{0}", type1}, + {"{1}", type2}, + {"{2}", type3}, + {"{3}", type4}, + {"{4}", type5} + }, typeof(object), EvalCompilerParameterKind.Untyped); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// The fourth type used to compile the code or expression. + /// The fifth type used to compile the code or expression. + /// The sixth type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5, Type type6) + { + return EvalCompiler.Compile>(this, code, new Dictionary + { + {"{0}", type1}, + {"{1}", type2}, + {"{2}", type3}, + {"{3}", type4}, + {"{4}", type5}, + {"{5}", type6} + }, typeof(object), EvalCompilerParameterKind.Untyped); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// The fourth type used to compile the code or expression. + /// The fifth type used to compile the code or expression. + /// The sixth type used to compile the code or expression. + /// The seventh type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7) + { + return EvalCompiler.Compile>(this, code, new Dictionary + { + {"{0}", type1}, + {"{1}", type2}, + {"{2}", type3}, + {"{3}", type4}, + {"{4}", type5}, + {"{5}", type6}, + {"{6}", type7} + }, typeof(object), EvalCompilerParameterKind.Untyped); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// The fourth type used to compile the code or expression. + /// The fifth type used to compile the code or expression. + /// The sixth type used to compile the code or expression. + /// The seventh type used to compile the code or expression. + /// The eighth type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7, Type type8) + { + return EvalCompiler.Compile>(this, code, new Dictionary + { + {"{0}", type1}, + {"{1}", type2}, + {"{2}", type3}, + {"{3}", type4}, + {"{4}", type5}, + {"{5}", type6}, + {"{6}", type7}, + {"{7}", type8} + }, typeof(object), EvalCompilerParameterKind.Untyped); + } + + /// Compile the code or expression and return a delegate of type Func to execute. + /// The code or expression to compile. + /// The first type used to compile the code or expression. + /// The second type used to compile the code or expression. + /// The third type used to compile the code or expression. + /// The fourth type used to compile the code or expression. + /// The fifth type used to compile the code or expression. + /// The sixth type used to compile the code or expression. + /// The seventh type used to compile the code or expression. + /// The eighth type used to compile the code or expression. + /// The ninth type used to compile the code or expression. + /// A delegate of type Func that represents the compiled code or expression. + public Func Compile(string code, Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7, Type type8, Type type9) + { + return EvalCompiler.Compile>(this, code, new Dictionary + { + {"{0}", type1}, + {"{1}", type2}, + {"{2}", type3}, + {"{3}", type4}, + {"{4}", type5}, + {"{5}", type6}, + {"{6}", type7}, + {"{7}", type8}, + {"{8}", type9} + }, typeof(object), EvalCompilerParameterKind.Untyped); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Compile/EvalContext.Compile`.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Compile/EvalContext.Compile`.cs new file mode 100644 index 0000000..31626f1 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Compile/EvalContext.Compile`.cs @@ -0,0 +1,66 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Z.Expressions +{ + public partial class EvalContext + { + /// Compile the code or expression and return a TDelegate of type Func or Action to execute. + /// Type of the delegate (Func or Action) to use to compile the code or expression. + /// The code or expression to compile. + /// A TDelegate of type Func or Action that represents the compiled code or expression. + public TDelegate Compile(string code) + { + return Compile(code, null); + } + + /// Compile the code or expression and return a TDelegate of type Func or Action to execute. + /// Type of the delegate (Func or Action) to use to compile the code or expression. + /// The code or expression to compile. + /// Parameter names used to compile the code or expressions. + /// A TDelegate of type Func or Action that represents the compiled code or expression. + public TDelegate Compile(string code, IEnumerable parameterNames) + { + return Compile(code, parameterNames.ToArray()); + } + + /// Compile the code or expression and return a TDelegate of type Func or Action to execute. + /// Type of the delegate (Func or Action) to use to compile the code or expression. + /// The code or expression to compile. + /// Parameter names used to compile the code or expressions. + /// A TDelegate of type Func or Action that represents the compiled code or expression. + public TDelegate Compile(string code, params string[] parameterNames) + { + var parameterTypes = new Dictionary(); + + var tDelegate = typeof (TDelegate); + var arguments = tDelegate.GetGenericArguments(); + var isAction = tDelegate.FullName.StartsWith("System.Action"); + + var tReturn = isAction ? null : arguments.Last(); + var lastArgumentPosition = isAction ? arguments.Length : arguments.Length - 1; + + for (var i = 0; i < lastArgumentPosition; i++) + { + if (parameterNames != null && i <= parameterNames.Length) + { + parameterTypes.Add(parameterNames[i], arguments[i]); + } + else + { + parameterTypes.Add(string.Concat("{", i, "}"), arguments[i]); + } + } + + return EvalCompiler.Compile(this, code, parameterTypes, tReturn, EvalCompilerParameterKind.Typed); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/EvalContext.RegisterDefaultAlias.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/EvalContext.RegisterDefaultAlias.cs index 920bd66..f4f9d2c 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/EvalContext.RegisterDefaultAlias.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/EvalContext.RegisterDefaultAlias.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Collections; @@ -59,6 +59,7 @@ public void RegisterDefaultAlias() { // Extension Methods RegisterExtensionMethod(typeof (Enumerable)); + RegisterExtensionMethod(typeof (Queryable)); // Static Members RegisterStaticMember(typeof (Math)); @@ -344,12 +345,18 @@ public void RegisterDefaultAlias() RegisterType(typeof (Tuple<,,,,,,,>)); } + // Library + RegisterType(typeof (EvalManager)); + RegisterType(typeof (Eval)); + // New RegisterType(typeof (CommandType)); - RegisterType(typeof(Match)); + RegisterType(typeof (Match)); + RegisterType(typeof (SqlCommandBuilder)); + RegisterExtensionMethod(typeof (Extensions)); - // Library - RegisterType(typeof (EvalManager)); + // Static Members + RegisterStaticMember(typeof (Regex)); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Execute/EvalContext.Execute.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Execute/EvalContext.Execute.cs new file mode 100644 index 0000000..b2c0554 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Execute/EvalContext.Execute.cs @@ -0,0 +1,38 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +namespace Z.Expressions +{ + public partial class EvalContext + { + /// Compile and evaluate the code or expression and return the result. + /// The code or expression to evaluate. + /// The evaluated result or null that represents the evaluted code or expression. + public object Execute(string code) + { + return Execute(code); + } + + /// Compile and evaluate the code or expression and return the result. + /// The code or expression to evaluate. + /// The parameter values used to evaluates the code or expression. + /// The evaluated result or null that represents the evaluted code or expression. + public object Execute(string code, object parameters) + { + return Execute(code, parameters); + } + + /// Compile and evaluate the code or expression and return the result. + /// The code or expression to evaluate. + /// The parameter values used to evaluates the code or expression. + /// The evaluated result or null that represents the evaluted code or expression. + public object Execute(string code, params object[] parameters) + { + return Execute(code, parameters); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Execute/EvalContext.Execute`.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Execute/EvalContext.Execute`.cs new file mode 100644 index 0000000..4757613 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Execute/EvalContext.Execute`.cs @@ -0,0 +1,67 @@ +// Description: C# Expression Evaluator | Evaluate, Compile and Execute C# code and expression at runtime. +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Z.Expressions +{ + public partial class EvalContext + { + /// Compile and evaluate the code or expression and return the result of type TResult. + /// Type of the result of the evaluted code or expression. + /// The code or expression to evaluate. + /// The evaluated result of type TResult or null that represents the evaluted code or expression. + public TResult Execute(string code) + { + return EvalCompiler.Compile>(this, code, null, typeof (TResult), EvalCompilerParameterKind.None)(); + } + + /// Compile and evaluate the code or expression and return the result of type TResult. + /// Type of the result of the evaluted code or expression. + /// The code or expression to evaluate. + /// The parameter values used to evaluates the code or expression. + /// The evaluated result of type TResult or null that represents the evaluted code or expression. + public TResult Execute(string code, object parameters) + { + var parameterTypes = new Dictionary {{"{0}", parameters.GetType()}}; + + if (parameters is IDictionary) + { + foreach (DictionaryEntry entry in (IDictionary) parameters) + { + parameterTypes.Add(entry.Key.ToString(), entry.Value.GetType()); + } + + return EvalCompiler.Compile>(this, code, parameterTypes, typeof (TResult), EvalCompilerParameterKind.SingleDictionary)((IDictionary) parameters); + } + + return EvalCompiler.Compile>(this, code, parameterTypes, typeof (TResult), EvalCompilerParameterKind.Untyped)(parameters); + } + + /// Compile and evaluate the code or expression and return the result of type TResult. + /// Type of the result of the evaluted code or expression. + /// The code or expression to evaluate. + /// The parameter values used to evaluates the code or expression. + /// The evaluated result of type TResult or null that represents the evaluted code or expression. + public TResult Execute(string code, params object[] parameters) + { + var dictValues = new Dictionary(); + var dictTypes = new Dictionary(); + + for (var i = 0; i < parameters.Length; i++) + { + var key = string.Concat("{", i, "}"); + dictValues.Add(key, parameters[i]); + dictTypes.Add(key, parameters[i].GetType()); + } + + return EvalCompiler.Compile>(this, code, dictTypes, typeof (TResult), EvalCompilerParameterKind.Dictionary)(dictValues); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterAlias.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterAlias.cs index 75fa268..ea72b74 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterAlias.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterAlias.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using Z.Expressions.SqlServer.Eval; diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterAssembly.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterAssembly.cs index 9ae3fd2..a540d0b 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterAssembly.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterAssembly.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System.Linq; using System.Reflection; diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterDomainAssemblies.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterDomainAssemblies.cs index 850b4df..f39c0d7 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterDomainAssemblies.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterDomainAssemblies.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Linq; diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterExtensionMethod.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterExtensionMethod.cs index eff5576..e0b9649 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterExtensionMethod.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterExtensionMethod.cs @@ -1,12 +1,11 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -25,7 +24,7 @@ public EvalContext RegisterExtensionMethod(params Type[] types) foreach (var type in types) { var extensionMethods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) - .Where(x => x.IsDefined(typeof(ExtensionAttribute), false)).ToArray(); + .Where(x => x.IsDefined(typeof (ExtensionAttribute), false)).ToArray(); RegisterExtensionMethod(extensionMethods); } @@ -47,11 +46,11 @@ public EvalContext RegisterExtensionMethod(params MethodInfo[] extensionMethods) #else var dict = new ConcurrentDictionary(); #endif - dict.TryAdd(method, (byte)1); + dict.TryAdd(method, (byte) 1); return dict; }, (s, list) => { - list.TryAdd(method, (byte)1); + list.TryAdd(method, (byte) 1); return list; }); } diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterGlobalConstant.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterGlobalConstant.cs index 408c54a..aeda072 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterGlobalConstant.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterGlobalConstant.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Linq.Expressions; diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterGlobalVariable.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterGlobalVariable.cs index 2dbf6ab..f88cd0d 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterGlobalVariable.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterGlobalVariable.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using Z.Expressions.SqlServer.Eval; diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterStaticMember.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterStaticMember.cs index a9517e0..699a42e 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterStaticMember.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterStaticMember.cs @@ -1,12 +1,11 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Reflection; using Z.Expressions.SqlServer.Eval; @@ -48,11 +47,11 @@ public EvalContext RegisterStaticMember(params MemberInfo[] members) #else var dict = new ConcurrentDictionary(); #endif - dict.TryAdd(member, (byte)1); + dict.TryAdd(member, (byte) 1); return dict; }, (s, list) => { - list.TryAdd(member, (byte)1); + list.TryAdd(member, (byte) 1); return list; }); } diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterType.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterType.cs index 2d65c12..f609146 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterType.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Register/EvalContext.RegisterType.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using Z.Expressions.SqlServer.Eval; diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterAlias.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterAlias.cs index 8405e6c..1c7868b 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterAlias.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterAlias.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using Z.Expressions.SqlServer.Eval; diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterAll.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterAll.cs index 592a26d..0c9079c 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterAll.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterAll.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. namespace Z.Expressions { diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterAssembly.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterAssembly.cs index fb694e6..80d7bc3 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterAssembly.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterAssembly.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System.Reflection; diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterExtensionMethod.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterExtensionMethod.cs index cf34ddd..75e1930 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterExtensionMethod.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterExtensionMethod.cs @@ -1,12 +1,11 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -25,7 +24,7 @@ public EvalContext UnregisterExtensionMethod(params Type[] types) foreach (var type in types) { var extensionMethods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) - .Where(x => x.IsDefined(typeof(ExtensionAttribute), false)).ToArray(); + .Where(x => x.IsDefined(typeof (ExtensionAttribute), false)).ToArray(); UnregisterExtensionMethod(extensionMethods); } diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterGlobalConstant.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterGlobalConstant.cs index 776563d..fde42a4 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterGlobalConstant.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterGlobalConstant.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System.Linq.Expressions; using Z.Expressions.SqlServer.Eval; diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterGlobalVariable.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterGlobalVariable.cs index eded0d5..b40ba02 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterGlobalVariable.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterGlobalVariable.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using Z.Expressions.SqlServer.Eval; diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterStaticMember.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterStaticMember.cs index 1b025b4..714ac1f 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterStaticMember.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterStaticMember.cs @@ -1,12 +1,11 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Reflection; using Z.Expressions.SqlServer.Eval; diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterType.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterType.cs index 0637e89..d297aae 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterType.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/Unregister/EvalContext.UnregisterType.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using Z.Expressions.SqlServer.Eval; diff --git a/src/Z.Expressions.SqlServer.Eval/EvalContext/_EvalContext.cs b/src/Z.Expressions.SqlServer.Eval/EvalContext/_EvalContext.cs index 283b804..be0e700 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalContext/_EvalContext.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalContext/_EvalContext.cs @@ -1,14 +1,15 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; +using Z.Expressions.SqlServer.Eval; namespace Z.Expressions { @@ -27,12 +28,14 @@ public EvalContext() BindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; CacheKeyPrefix = GetType().FullName; UseCaretForExponent = false; - RegisterDefaultAlias(); ExpireCacheNextScheduled = DateTime.Now.Add(ExpireCacheDelay); } + /// The cache item counter. + public int CacheItemCounter = int.MinValue; + /// The delay between expire cache call. public TimeSpan ExpireCacheDelay = TimeSpan.FromMinutes(5); @@ -123,5 +126,21 @@ public EvalContext() /// /// true if the caret should be used for exponent, false if not. public bool UseCaretForExponent { get; set; } + + /// Gets the next cache item counter. + /// The next cache item counter. + public int GetNextCacheItemCounter() + { + try + { + SharedLock.AcquireLock(ref EvalManager.SharedLock.CacheItemLock); + CacheItemCounter++; + return CacheItemCounter; + } + finally + { + SharedLock.ReleaseLock(ref EvalManager.SharedLock.CacheItemLock); + } + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/EvalDelegate/EvalDelegate.cs b/src/Z.Expressions.SqlServer.Eval/EvalDelegate/EvalDelegate.cs index 9c51f7d..8211463 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalDelegate/EvalDelegate.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalDelegate/EvalDelegate.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Collections; @@ -19,16 +19,19 @@ public class EvalDelegate /// The delegate to cache. public Func Delegate; + /// The inner delegate. + public object InnerDelegate; + /// The last access Date/Time of the delegate. public DateTime LastAccess; /// Constructor. /// The key used to cache the EvalDelegate. - /// The delegate to cache. - public EvalDelegate(string cacheKey, Func @delegate) + /// The delegate to cache. + public EvalDelegate(string cacheKey, Func delegateAction) { CacheKey = cacheKey; - Delegate = @delegate; + Delegate = delegateAction; LastAccess = DateTime.Now; } } diff --git a/src/Z.Expressions.SqlServer.Eval/EvalManager/EvalManager.cs b/src/Z.Expressions.SqlServer.Eval/EvalManager/EvalManager.cs index 58757ef..f152450 100644 --- a/src/Z.Expressions.SqlServer.Eval/EvalManager/EvalManager.cs +++ b/src/Z.Expressions.SqlServer.Eval/EvalManager/EvalManager.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Collections.Generic; @@ -15,14 +15,17 @@ namespace Z.Expressions public static class EvalManager { /// The cache for EvalDelegate. - public static readonly SharedCache CacheDelegate = new SharedCache(); + public static readonly SharedBuckedCache CacheDelegate = new SharedBuckedCache(); /// The cache for SQLNETItem. - public static readonly SharedCache CacheItem = new SharedCache(); + public static readonly SharedBuckedCache CacheItem = new SharedBuckedCache(); /// The default context used to compile the code or expression. public static readonly EvalContext Configuration; + /// The default context. + internal static readonly EvalContext DefaultContext; + /// The shared lock. public static readonly SharedLock SharedLock; @@ -31,9 +34,12 @@ static EvalManager() // ENSURE to create lock first SharedLock = new SharedLock(); Configuration = new EvalContext(); + DefaultContext = Configuration; SQLNET.LoadConfiguration(); } + /// Determines if we can expire cache. + /// true if it succeeds, false if it fails. public static bool ExpireCache() { try @@ -48,57 +54,63 @@ public static bool ExpireCache() var expireDateDelegate = DateTime.Now.Subtract(Configuration.SlidingExpirationDelegate); var keyToRemoves = new List(); - try + foreach (var bucket in CacheDelegate.Buckets) { - CacheDelegate.AcquireLock(); - - foreach (var keyvalue in CacheDelegate.InnerDictionary) + try { - if (keyvalue.Value.LastAccess < expireDateDelegate) + bucket.AcquireLock(); + + foreach (var keyvalue in bucket.InnerDictionary) { - keyToRemoves.Add(keyvalue.Key); + if (keyvalue.Value.LastAccess < expireDateDelegate) + { + keyToRemoves.Add(keyvalue.Key); + } } - } - foreach (var key in keyToRemoves) + foreach (var key in keyToRemoves) + { + bucket.InnerDictionary.Remove(key); + } + } + finally { - CacheDelegate.InnerDictionary.Remove(key); + bucket.ReleaseLock(); } } - finally - { - CacheDelegate.ReleaseLock(); - } } // EXPIRE item cache { var expireDateItem = DateTime.Now.Subtract(Configuration.SlidingExpirationItem); - var keyToRemoves = new List(); + var keyToRemoves = new List(); - try + foreach (var bucket in CacheItem.Buckets) { - CacheItem.AcquireLock(); - - foreach (var keyvalue in CacheItem.InnerDictionary) + try { - if (keyvalue.Value.LastAccess < expireDateItem) + bucket.AcquireLock(); + + foreach (var keyvalue in bucket.InnerDictionary) { - keyvalue.Value.IsCached = false; - keyToRemoves.Add(keyvalue.Key); + if (keyvalue.Value.LastAccess < expireDateItem) + { + keyvalue.Value.IsCached = false; + keyToRemoves.Add(keyvalue.Key); + } } - } - foreach (var key in keyToRemoves) + foreach (var key in keyToRemoves) + { + bucket.InnerDictionary.Remove(key); + } + } + finally { - CacheItem.InnerDictionary.Remove(key); + bucket.ReleaseLock(); } } - finally - { - CacheItem.ReleaseLock(); - } } return true; diff --git a/src/Z.Expressions.SqlServer.Eval/ExceptionMessage.cs b/src/Z.Expressions.SqlServer.Eval/ExceptionMessage.cs index 2ace097..b61c614 100644 --- a/src/Z.Expressions.SqlServer.Eval/ExceptionMessage.cs +++ b/src/Z.Expressions.SqlServer.Eval/ExceptionMessage.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System.Diagnostics.CodeAnalysis; diff --git a/src/Z.Expressions.SqlServer.Eval/ExtensionMethods/SqlCommand/ExecuteDataTable.cs b/src/Z.Expressions.SqlServer.Eval/ExtensionMethods/SqlCommand/ExecuteDataTable.cs new file mode 100644 index 0000000..9bee78d --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/ExtensionMethods/SqlCommand/ExecuteDataTable.cs @@ -0,0 +1,17 @@ +using System.Data; +using System.Data.SqlClient; + +public static partial class Extensions +{ + public static DataTable ExecuteDataTable(this SqlCommand @this) + { + var dt = new DataTable(); + + using (var dataAdapter = new SqlDataAdapter(@this)) + { + dataAdapter.Fill(dt); + } + + return dt; + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/ExtensionMethods/String/String.Split.cs b/src/Z.Expressions.SqlServer.Eval/ExtensionMethods/String/String.Split.cs new file mode 100644 index 0000000..8d0c758 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/ExtensionMethods/String/String.Split.cs @@ -0,0 +1,14 @@ +using System; + +public static partial class Extensions +{ + public static string[] Split(this string @this, string separator, StringSplitOptions option = StringSplitOptions.None) + { + return @this.Split(new[] {separator}, option); + } + + public static string[] Split(this string @this, params string[] separators) + { + return @this.Split(separators, StringSplitOptions.None); + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/ExtensionMethods/System.Data/AsEnumerable.cs b/src/Z.Expressions.SqlServer.Eval/ExtensionMethods/System.Data/AsEnumerable.cs new file mode 100644 index 0000000..f5d7b36 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/ExtensionMethods/System.Data/AsEnumerable.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Data; + +public static partial class Extensions +{ + public static List AsEnumerable(this DataTable @this) + { + var drs = new List(); + + foreach (DataRow row in @this.Rows) + { + drs.Add(row); + } + + return drs; + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/ExtensionMethods/System.Data/SaveChanges.cs b/src/Z.Expressions.SqlServer.Eval/ExtensionMethods/System.Data/SaveChanges.cs new file mode 100644 index 0000000..2a7dd78 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/ExtensionMethods/System.Data/SaveChanges.cs @@ -0,0 +1,21 @@ +using System.Data; +using System.Data.SqlClient; + +public static partial class Extensions +{ + public static void SaveChanges(this DataTable @this) + { + var sql = @this.ExtendedProperties["ZZZ_Select"].ToString(); + using (var connection = new SqlConnection("context connection = true")) + { + using (var adapter = new SqlDataAdapter(sql, connection)) + { + // ReSharper disable once UnusedVariable + var cmdBuilder = new SqlCommandBuilder(adapter); + connection.Open(); + + adapter.Update(@this); + } + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/Extensions/Dictionary`2/AddOrUpdate.cs b/src/Z.Expressions.SqlServer.Eval/Extensions/Dictionary`2/AddOrUpdate.cs index 513b5e5..8e8e5ca 100644 --- a/src/Z.Expressions.SqlServer.Eval/Extensions/Dictionary`2/AddOrUpdate.cs +++ b/src/Z.Expressions.SqlServer.Eval/Extensions/Dictionary`2/AddOrUpdate.cs @@ -1,3 +1,10 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + using System; using System.Collections.Generic; diff --git a/src/Z.Expressions.SqlServer.Eval/Extensions/Dictionary`2/TryAdd.cs b/src/Z.Expressions.SqlServer.Eval/Extensions/Dictionary`2/TryAdd.cs index dd594c2..29dbe6c 100644 --- a/src/Z.Expressions.SqlServer.Eval/Extensions/Dictionary`2/TryAdd.cs +++ b/src/Z.Expressions.SqlServer.Eval/Extensions/Dictionary`2/TryAdd.cs @@ -1,3 +1,10 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + using System.Collections.Generic; namespace Z.Expressions.SqlServer.Eval diff --git a/src/Z.Expressions.SqlServer.Eval/Extensions/Dictionary`2/TryRemove.cs b/src/Z.Expressions.SqlServer.Eval/Extensions/Dictionary`2/TryRemove.cs index d149712..4db867c 100644 --- a/src/Z.Expressions.SqlServer.Eval/Extensions/Dictionary`2/TryRemove.cs +++ b/src/Z.Expressions.SqlServer.Eval/Extensions/Dictionary`2/TryRemove.cs @@ -1,3 +1,10 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + using System.Collections.Generic; namespace Z.Expressions.SqlServer.Eval diff --git a/src/Z.Expressions.SqlServer.Eval/Helper/DataTableHelper.cs b/src/Z.Expressions.SqlServer.Eval/Helper/DataTableHelper.cs index 3b0586f..956a067 100644 --- a/src/Z.Expressions.SqlServer.Eval/Helper/DataTableHelper.cs +++ b/src/Z.Expressions.SqlServer.Eval/Helper/DataTableHelper.cs @@ -1,7 +1,17 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + using System; using System.Collections; using System.Collections.Generic; using System.Data; +using System.Runtime.InteropServices; +using System.Text.RegularExpressions; +using Z.Expressions.CodeCompiler; namespace Z.Expressions.SqlServer.Eval { @@ -22,23 +32,69 @@ public static DataTable GetDataTable(object value) { dt = (DataTable) value; } + else if (value is IEnumerable) + { + var drs = (IEnumerable) value; + dt = new DataTable(); + + bool isFirst = true; + + foreach (var dr in drs) + { + if (isFirst) + { + var ownerTable = dr.Table; + dt = ownerTable.Clone(); + isFirst = false; + } + + dt.ImportRow(dr); + } + } + else if (value is IEnumerable) + { + var list = (IEnumerable)value; + + bool isFirst = true; + + dt = new DataTable(); + + foreach (var item in list) + { + if (isFirst) + { + foreach (var property in item.Properties) + { + dt.Columns.Add(property.Key); + } + isFirst = false; + } + + var row = dt.NewRow(); + dt.Rows.Add(row); + foreach (var property in item.Properties) + { + row[property.Key] = property.Value; + } + } + } else if (value is IEnumerable && value.GetType().IsGenericType && value.GetType().GetGenericArguments().Length == 1) { var genericType = value.GetType().GetGenericArguments()[0]; if (genericType.IsGenericType && ( - genericType.GetGenericTypeDefinition() == typeof(Tuple) - ||genericType.GetGenericTypeDefinition() == typeof (Tuple<>) - || genericType.GetGenericTypeDefinition() == typeof(Tuple<,>) - || genericType.GetGenericTypeDefinition() == typeof(Tuple<,,>) - || genericType.GetGenericTypeDefinition() == typeof(Tuple<,,,>) - || genericType.GetGenericTypeDefinition() == typeof(Tuple<,,,,>) - || genericType.GetGenericTypeDefinition() == typeof(Tuple<,,,,,>) - || genericType.GetGenericTypeDefinition() == typeof(Tuple<,,,,,,>) - || genericType.GetGenericTypeDefinition() == typeof(Tuple<,,,,,,,>) + genericType.GetGenericTypeDefinition() == typeof (Tuple) + || genericType.GetGenericTypeDefinition() == typeof (Tuple<>) + || genericType.GetGenericTypeDefinition() == typeof (Tuple<,>) + || genericType.GetGenericTypeDefinition() == typeof (Tuple<,,>) + || genericType.GetGenericTypeDefinition() == typeof (Tuple<,,,>) + || genericType.GetGenericTypeDefinition() == typeof (Tuple<,,,,>) + || genericType.GetGenericTypeDefinition() == typeof (Tuple<,,,,,>) + || genericType.GetGenericTypeDefinition() == typeof (Tuple<,,,,,,>) + || genericType.GetGenericTypeDefinition() == typeof (Tuple<,,,,,,,>) )) { - var list = (IEnumerable)value; + var list = (IEnumerable) value; var properties = genericType.GetProperties(); dt = new DataTable(); @@ -59,29 +115,78 @@ public static DataTable GetDataTable(object value) } } } + else if (genericType.IsArray) + { + var list = (IEnumerable) value; + + dt = new DataTable(); + + foreach (var item in list) + { + var itemArray = (object[]) item; + + if (itemArray.Length > dt.Columns.Count) + { + for (var i = dt.Columns.Count; i < itemArray.Length; i++) + { + dt.Columns.Add("Value_" + (i + 1)); + } + } + + var dr = dt.NewRow(); + dt.Rows.Add(dr); + + for (var i = 0; i < itemArray.Length; i++) + { + dr[i] = itemArray[i]; + } + } + } else { - var list = (IEnumerable)value; + var list = (IEnumerable) value; dt = new DataTable(); - dt.Columns.Add("value1"); + dt.Columns.Add("Value_1"); foreach (var item in list) { dt.Rows.Add(item); } } } + else if (value is IEnumerable && value.GetType().IsGenericType && value.GetType().GetGenericArguments().Length > 1) + { + var list = (IEnumerable)value; + + bool isFirst = false; + + dt = new DataTable(); + dt.Columns.Add("Value_1"); + foreach (var item in list) + { + dt.Rows.Add(item); + } + } else if (value is IEnumerable && value.GetType().HasElementType) { var list = (IEnumerable) value; dt = new DataTable(); - dt.Columns.Add("value1"); + dt.Columns.Add("Value_1"); foreach (var item in list) { dt.Rows.Add(item); } } + else if (value is MatchCollection) + { + dt = new DataTable(); + dt.Columns.Add("Value_1"); + foreach (Match item in (MatchCollection)value) + { + dt.Rows.Add(item.Value); + } + } else { throw new Exception(string.Format(ExceptionMessage.Unsupported_DataTable_ResultSet, value.GetType())); diff --git a/src/Z.Expressions.SqlServer.Eval/Helper/SqlContextHelper.cs b/src/Z.Expressions.SqlServer.Eval/Helper/SqlContextHelper.cs index acc17df..cced22c 100644 --- a/src/Z.Expressions.SqlServer.Eval/Helper/SqlContextHelper.cs +++ b/src/Z.Expressions.SqlServer.Eval/Helper/SqlContextHelper.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Data; diff --git a/src/Z.Expressions.SqlServer.Eval/Helper/SqlTypeHelper.cs b/src/Z.Expressions.SqlServer.Eval/Helper/SqlTypeHelper.cs index 796b8c3..edefd39 100644 --- a/src/Z.Expressions.SqlServer.Eval/Helper/SqlTypeHelper.cs +++ b/src/Z.Expressions.SqlServer.Eval/Helper/SqlTypeHelper.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Data.SqlTypes; @@ -47,7 +47,7 @@ public static object ConvertToType(object value) return valueDouble.IsNull ? (double?) null : valueDouble.Value; case "SqlGuid": var valueGuid = (SqlGuid) value; - return valueGuid.IsNull ? Guid.Empty : valueGuid.Value; + return valueGuid.IsNull ? (Guid?) null : valueGuid.Value; case "SqlInt16": var valueInt16 = (SqlInt16) value; return valueInt16.IsNull ? (short?) null : valueInt16.Value; @@ -75,5 +75,48 @@ public static object ConvertToType(object value) return rValue; } + + public static Type GetNullableType(object value) + { + switch (value.GetType().Name) + { + case "SqlBinary": + return typeof (byte[]); + case "SqlBoolean": + return typeof (bool?); + case "SqlByte": + return typeof (byte?); + case "SqlBytes": + return typeof (byte[]); + case "SqlChars": + return typeof (char[]); + case "SqlDateTime": + return typeof (DateTime?); + case "SqlDecimal": + return typeof (decimal?); + case "SqlDouble": + return typeof (double?); + case "SqlGuid": + return typeof (Guid?); + case "SqlInt16": + return typeof (short?); + case "SqlInt32": + return typeof (int?); + case "SqlInt64": + return typeof (long?); + case "SqlMoney": + return typeof (decimal?); + case "SqlSingle": + return typeof (float?); + case "SqlString": + return typeof (string); + case "SqlXml": + return typeof (string); + case "DBNull": + return null; + } + + return typeof (object); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/Helper/TypeHelper.cs b/src/Z.Expressions.SqlServer.Eval/Helper/TypeHelper.cs index 5a5c291..ed028bb 100644 --- a/src/Z.Expressions.SqlServer.Eval/Helper/TypeHelper.cs +++ b/src/Z.Expressions.SqlServer.Eval/Helper/TypeHelper.cs @@ -1,11 +1,12 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +using System.Data; namespace Z.Expressions.SqlServer.Eval { @@ -56,6 +57,9 @@ public static Type GetTypeFromName(string name) case "DateTime?": type = typeof (DateTime?); break; + case "DataTable": + type = typeof (DataTable); + break; default: throw new Exception("Unsupported"); } diff --git a/src/Z.Expressions.SqlServer.Eval/ListDictionary.cs b/src/Z.Expressions.SqlServer.Eval/ListDictionary.cs index 9023ea7..68f6a63 100644 --- a/src/Z.Expressions.SqlServer.Eval/ListDictionary.cs +++ b/src/Z.Expressions.SqlServer.Eval/ListDictionary.cs @@ -1,81 +1,48 @@ -//------------------------------------------------------------------------------ -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -//------------------------------------------------------------------------------ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Collections; +using System.Threading; namespace Z.Expressions { /// - /// - /// This is a simple implementation of IDictionary using a singly linked list. This - /// will be smaller and faster than a Hashtable if the number of elements is 10 or less. - /// This should not be used if performance is important for large numbers of elements. - /// + /// + /// This is a simple implementation of IDictionary using a singly linked list. This + /// will be smaller and faster than a Hashtable if the number of elements is 10 or less. + /// This should not be used if performance is important for large numbers of elements. + /// /// [Serializable] public class ListDictionary : IDictionary { - public bool TryGetValue(object key, out object value) - { - if (key == null) - { - throw new ArgumentNullException("key", "error"); - } - DictionaryNode node = head; - if (comparer == null) - { - while (node != null) - { - object oldKey = node.key; - if (oldKey != null && oldKey.Equals(key)) - { - value = node.value; - return true; - } - node = node.next; - } - } - else - { - while (node != null) - { - object oldKey = node.key; - if (oldKey != null && comparer.Compare(oldKey, key) == 0) - { - value = node.value; - return true; - } - node = node.next; - } - } + // todo: Do we still really need a list dictionary? + private readonly IComparer comparer; - value = null; - return false; - } + [NonSerialized] private object _syncRoot; + private DictionaryNode head; + /// The lock value. + public int LockValue; - DictionaryNode head; - int version; - int count; - IComparer comparer; - [NonSerialized] - private Object _syncRoot; + private int version; /// - /// [To be supplied.] + /// [To be supplied.] /// public ListDictionary() { } /// - /// [To be supplied.] + /// [To be supplied.] /// public ListDictionary(IComparer comparer) { @@ -83,7 +50,7 @@ public ListDictionary(IComparer comparer) } /// - /// [To be supplied.] + /// [To be supplied.] /// public object this[object key] { @@ -93,12 +60,12 @@ public object this[object key] { throw new ArgumentNullException("key", "error"); } - DictionaryNode node = head; + var node = head; if (comparer == null) { while (node != null) { - object oldKey = node.key; + var oldKey = node.key; if (oldKey != null && oldKey.Equals(key)) { return node.value; @@ -110,7 +77,7 @@ public object this[object key] { while (node != null) { - object oldKey = node.key; + var oldKey = node.key; if (oldKey != null && comparer.Compare(oldKey, key) == 0) { return node.value; @@ -131,7 +98,7 @@ public object this[object key] DictionaryNode node; for (node = head; node != null; node = node.next) { - object oldKey = node.key; + var oldKey = node.key; if ((comparer == null) ? oldKey.Equals(key) : comparer.Compare(oldKey, key) == 0) { break; @@ -145,7 +112,7 @@ public object this[object key] return; } // Not found, so add a new one - DictionaryNode newNode = new DictionaryNode(); + var newNode = new DictionaryNode(); newNode.key = key; newNode.value = value; if (last != null) @@ -156,67 +123,49 @@ public object this[object key] { head = newNode; } - count++; + Count++; } } /// - /// [To be supplied.] + /// [To be supplied.] /// - public int Count - { - get - { - return count; - } - } + public int Count { get; private set; } /// - /// [To be supplied.] + /// [To be supplied.] /// public ICollection Keys { - get - { - return new NodeKeyValueCollection(this, true); - } + get { return new NodeKeyValueCollection(this, true); } } /// - /// [To be supplied.] + /// [To be supplied.] /// public bool IsReadOnly { - get - { - return false; - } + get { return false; } } /// - /// [To be supplied.] + /// [To be supplied.] /// public bool IsFixedSize { - get - { - return false; - } + get { return false; } } /// - /// [To be supplied.] + /// [To be supplied.] /// public bool IsSynchronized { - get - { - return false; - } + get { return false; } } /// - /// [To be supplied.] + /// [To be supplied.] /// public object SyncRoot { @@ -224,46 +173,44 @@ public object SyncRoot { if (_syncRoot == null) { - System.Threading.Interlocked.CompareExchange(ref _syncRoot, new Object(), null); + Interlocked.CompareExchange(ref _syncRoot, new object(), null); } return _syncRoot; } } /// - /// [To be supplied.] + /// [To be supplied.] /// public ICollection Values { - get - { - return new NodeKeyValueCollection(this, false); - } + get { return new NodeKeyValueCollection(this, false); } } /// - /// [To be supplied.] + /// [To be supplied.] /// public void Add(object key, object value) { if (key == null) { - throw new ArgumentNullException("key", "error"); + throw new ArgumentNullException("Argument cannot be null", "key"); } version++; DictionaryNode last = null; DictionaryNode node; for (node = head; node != null; node = node.next) { - object oldKey = node.key; + var oldKey = node.key; if ((comparer == null) ? oldKey.Equals(key) : comparer.Compare(oldKey, key) == 0) { - throw new ArgumentException("error"); + throw new ArgumentException(string.Format("Duplicate keys: new key: {0}, old value: {1}, new value: {2}", key, this[oldKey], value)); } last = node; } + // Not found, so add a new one - DictionaryNode newNode = new DictionaryNode(); + var newNode = new DictionaryNode(); newNode.key = key; newNode.value = value; if (last != null) @@ -274,21 +221,21 @@ public void Add(object key, object value) { head = newNode; } - count++; + Count++; } /// - /// [To be supplied.] + /// [To be supplied.] /// public void Clear() { - count = 0; + Count = 0; head = null; version++; } /// - /// [To be supplied.] + /// [To be supplied.] /// public bool Contains(object key) { @@ -296,9 +243,9 @@ public bool Contains(object key) { throw new ArgumentNullException("key", "error"); } - for (DictionaryNode node = head; node != null; node = node.next) + for (var node = head; node != null; node = node.next) { - object oldKey = node.key; + var oldKey = node.key; if ((comparer == null) ? oldKey.Equals(key) : comparer.Compare(oldKey, key) == 0) { return true; @@ -308,7 +255,7 @@ public bool Contains(object key) } /// - /// [To be supplied.] + /// [To be supplied.] /// public void CopyTo(Array array, int index) { @@ -317,10 +264,10 @@ public void CopyTo(Array array, int index) if (index < 0) throw new ArgumentOutOfRangeException("index", "error"); - if (array.Length - index < count) + if (array.Length - index < Count) throw new ArgumentException("error"); - for (DictionaryNode node = head; node != null; node = node.next) + for (var node = head; node != null; node = node.next) { array.SetValue(new DictionaryEntry(node.key, node.value), index); index++; @@ -328,7 +275,7 @@ public void CopyTo(Array array, int index) } /// - /// [To be supplied.] + /// [To be supplied.] /// public IDictionaryEnumerator GetEnumerator() { @@ -341,7 +288,7 @@ IEnumerator IEnumerable.GetEnumerator() } /// - /// [To be supplied.] + /// [To be supplied.] /// public void Remove(object key) { @@ -354,7 +301,7 @@ public void Remove(object key) DictionaryNode node; for (node = head; node != null; node = node.next) { - object oldKey = node.key; + var oldKey = node.key; if ((comparer == null) ? oldKey.Equals(key) : comparer.Compare(oldKey, key) == 0) { break; @@ -373,15 +320,53 @@ public void Remove(object key) { last.next = node.next; } - count--; + Count--; + } + + public bool TryGetValue(object key, out object value) + { + if (key == null) + { + throw new ArgumentNullException("key", "error"); + } + var node = head; + if (comparer == null) + { + while (node != null) + { + var oldKey = node.key; + if (oldKey != null && oldKey.Equals(key)) + { + value = node.value; + return true; + } + node = node.next; + } + } + else + { + while (node != null) + { + var oldKey = node.key; + if (oldKey != null && comparer.Compare(oldKey, key) == 0) + { + value = node.value; + return true; + } + node = node.next; + } + } + + value = null; + return false; } private class NodeEnumerator : IDictionaryEnumerator { - ListDictionary list; - DictionaryNode current; - int version; - bool start; + private readonly ListDictionary list; + private readonly int version; + private DictionaryNode current; + private bool start; public NodeEnumerator(ListDictionary list) @@ -394,10 +379,7 @@ public NodeEnumerator(ListDictionary list) public object Current { - get - { - return Entry; - } + get { return Entry; } } public DictionaryEntry Entry @@ -463,14 +445,13 @@ public void Reset() start = true; current = null; } - } private class NodeKeyValueCollection : ICollection { - ListDictionary list; - bool isKeys; + private readonly bool isKeys; + private readonly ListDictionary list; public NodeKeyValueCollection(ListDictionary list, bool isKeys) { @@ -484,7 +465,7 @@ void ICollection.CopyTo(Array array, int index) throw new ArgumentNullException("array"); if (index < 0) throw new ArgumentOutOfRangeException("index", "error"); - for (DictionaryNode node = list.head; node != null; node = node.next) + for (var node = list.head; node != null; node = node.next) { array.SetValue(isKeys ? node.key : node.value, index); index++; @@ -495,8 +476,8 @@ int ICollection.Count { get { - int count = 0; - for (DictionaryNode node = list.head; node != null; node = node.next) + var count = 0; + for (var node = list.head; node != null; node = node.next) { count++; } @@ -506,18 +487,12 @@ int ICollection.Count bool ICollection.IsSynchronized { - get - { - return false; - } + get { return false; } } object ICollection.SyncRoot { - get - { - return list.SyncRoot; - } + get { return list.SyncRoot; } } IEnumerator IEnumerable.GetEnumerator() @@ -528,19 +503,19 @@ IEnumerator IEnumerable.GetEnumerator() private class NodeKeyValueEnumerator : IEnumerator { - ListDictionary list; - DictionaryNode current; - int version; - bool isKeys; - bool start; + private readonly bool isKeys; + private readonly ListDictionary list; + private readonly int version; + private DictionaryNode current; + private bool start; public NodeKeyValueEnumerator(ListDictionary list, bool isKeys) { this.list = list; this.isKeys = isKeys; - this.version = list.version; - this.start = true; - this.current = null; + version = list.version; + start = true; + current = null; } public object Current @@ -589,8 +564,8 @@ public void Reset() private class DictionaryNode { public object key; - public object value; public DictionaryNode next; + public object value; } } -} +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/Properties/AssemblyInfo.cs b/src/Z.Expressions.SqlServer.Eval/Properties/AssemblyInfo.cs index d277dd0..294a286 100644 --- a/src/Z.Expressions.SqlServer.Eval/Properties/AssemblyInfo.cs +++ b/src/Z.Expressions.SqlServer.Eval/Properties/AssemblyInfo.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System.Reflection; @@ -12,7 +12,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("ZZZ Projects Inc.")] [assembly: AssemblyProduct("Eval SQL.NET")] -[assembly: AssemblyCopyright("ZZZ Projects Inc. Copyright © 2016")] +[assembly: AssemblyCopyright("Copyright © ZZZ Projects Inc. 2014 - 2016")] [assembly: AssemblyTrademark("SQL & .NET Tools")] [assembly: AssemblyCulture("")] [assembly: AssemblyVersion("1.0.0")] diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Configuration/Configuration.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Configuration/Configuration.cs index 18657f0..acdbd06 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Configuration/Configuration.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Configuration/Configuration.cs @@ -1,11 +1,10 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. -using System; using System.Data; using System.Data.SqlClient; using Microsoft.SqlServer.Server; diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/Eval.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/Eval.cs index a107066..3117ff3 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/Eval.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/Eval.cs @@ -1,82 +1,41 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. -using System; -using System.Security.Principal; using Microsoft.SqlServer.Server; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { /// Eval the code or expression and return an object value. /// The object value from the evaluated code or expression. - [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] public object Eval() { - var now = DateTime.Now; - - // Overwrite last access - Item.LastAccess = now; - if (Item.Delegate != null) - { - Item.Delegate.LastAccess = now; - } - - if (now > EvalManager.Configuration.ExpireCacheNextScheduled) - { - EvalManager.ExpireCache(); - } - - object result; - - if (Item.IsImpersonate) - { - WindowsImpersonationContext impersonatedIdentity = null; - - if (SqlContext.WindowsIdentity != null) - { - var currentIdentity = SqlContext.WindowsIdentity; - impersonatedIdentity = currentIdentity.Impersonate(); - } - - try - { - if (Item.Delegate == null) - { - Item.Delegate = EvalManager.Configuration.Compile(Item.Code, Item.ParameterTypes); - } - - result = Item.Delegate.Delegate(Item.ParameterValues); - } - finally - { - if (impersonatedIdentity != null) - { - impersonatedIdentity.Undo(); - } - } - } - else - { - if (Item.Delegate == null) - { - Item.Delegate = EvalManager.Configuration.Compile(Item.Code, Item.ParameterTypes); - } + return InternalEval(); + } - result = Item.Delegate.Delegate(Item.ParameterValues); - } + /// Eval the code or expression and return an object value. + /// The object value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public object eval() + { + return Eval(); + } - if (Item.IsAutoDispose) - { - Dispose(); - } + /// Eval the code or expression and return an object value. + /// The object value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public object EVAL() - return result; + { + return Eval(); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalBigInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalBigInt.cs index 785b71d..39ab7ba 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalBigInt.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalBigInt.cs @@ -1,25 +1,44 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +using System.Data.SqlTypes; using Microsoft.SqlServer.Server; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { /// Eval the code or expression and return a big int value. /// The big int value from the evaluated code or expression. - [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] - public long? EvalBigInt() + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlInt64 EvalBigInt() { - var value = Eval(); + var value = InternalEval(); + return value == null || value == DBNull.Value ? SqlInt64.Null : new SqlInt64(Convert.ToInt64(value)); + } + + /// Eval the code or expression and return a big int value. + /// The big int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlInt64 evalbigint() - return value == null || value == DBNull.Value ? (long?) null : Convert.ToInt64(value); + { + return EvalBigInt(); + } + + /// Eval the code or expression and return a big int value. + /// The big int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlInt64 EVALBIGINT() + { + return EvalBigInt(); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalBinary.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalBinary.cs new file mode 100644 index 0000000..3e10dc9 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalBinary.cs @@ -0,0 +1,44 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a binary value. + /// The binary value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlBytes EvalBinary() + { + var value = InternalEval(); + return value == null || value == DBNull.Value ? SqlBytes.Null : new SqlBytes((byte[]) value); + } + + /// Eval the code or expression and return a binary value. + /// The binary value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlBytes evalbinary() + + { + return EvalBinary(); + } + + /// Eval the code or expression and return a binary value. + /// The binary value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlBytes EVALBINARY() + { + return EvalBinary(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalBit.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalBit.cs index d5b12c8..7b2b353 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalBit.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalBit.cs @@ -1,25 +1,44 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +using System.Data.SqlTypes; using Microsoft.SqlServer.Server; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { /// Eval the code or expression and return a bit value. /// The bit value from the evaluated code or expression. - [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] - public bool? EvalBit() + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlBoolean EvalBit() { - var value = Eval(); + var value = InternalEval(); + return value == null || value == DBNull.Value ? SqlBoolean.Null : new SqlBoolean(Convert.ToBoolean(value)); + } + + /// Eval the code or expression and return a bit value. + /// The bit value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlBoolean evalbit() - return value == null || value == DBNull.Value ? (bool?) null : Convert.ToBoolean(value); + { + return EvalBit(); + } + + /// Eval the code or expression and return a bit value. + /// The bit value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlBoolean EVALBIT() + { + return EvalBit(); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalChars.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalChars.cs new file mode 100644 index 0000000..77d65c0 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalChars.cs @@ -0,0 +1,42 @@ +//// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +//// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +//// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +//// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +//// More projects: http://www.zzzprojects.com/ +//// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +//using System.Data.SqlTypes; +//using Microsoft.SqlServer.Server; + +//// ReSharper disable InconsistentNaming + +//namespace Z.Expressions.SqlServer.Eval +//{ +// public partial struct SQLNET +// { +// /// Eval the code or expression and return a bit value. +// /// The bit value from the evaluated code or expression. +// [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] +// public SqlChars EvalChars() +// { +// return new SqlChars(InternalEval()); +// } + +// /// Eval the code or expression and return a bit value. +// /// The bit value from the evaluated code or expression. +// [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] +// public SqlChars evalchars() + +// { +// return EvalChars(); +// } + +// /// Eval the code or expression and return a bit value. +// /// The bit value from the evaluated code or expression. +// [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] +// public SqlChars EVALCHARS() +// { +// return EvalChars(); +// } +// } +//} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalDateTime.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalDateTime.cs new file mode 100644 index 0000000..145147c --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalDateTime.cs @@ -0,0 +1,44 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a DateTime value. + /// The DateTime value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlDateTime EvalDateTime() + { + var value = InternalEval(); + return value == null || value == DBNull.Value ? SqlDateTime.Null : new SqlDateTime(Convert.ToDateTime(value)); + } + + /// Eval the code or expression and return a DateTime value. + /// The DateTime value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlDateTime evaldatetime() + + { + return EvalDateTime(); + } + + /// Eval the code or expression and return a DateTime value. + /// The DateTime value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlDateTime EVALDATETIME() + { + return EvalDateTime(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalInt.cs index 982d941..2ff1222 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalInt.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalInt.cs @@ -1,25 +1,43 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +using System.Data.SqlTypes; using Microsoft.SqlServer.Server; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { /// Eval the code or expression and return an int value. /// The int value from the evaluated code or expression. - [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] - public int? EvalInt() + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlInt32 EvalInt() + { + var value = InternalEval(); + return value == null || value == DBNull.Value ? SqlInt32.Null : new SqlInt32(Convert.ToInt32(value)); + } + + /// Eval the code or expression and return an int value. + /// The int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlInt32 evalint() { - var value = Eval(); + return EvalInt(); + } - return value == null || value == DBNull.Value ? (int?) null : Convert.ToInt32(value); + /// Eval the code or expression and return an int value. + /// The int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlInt32 EVALINT() + { + return EvalInt(); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalSQLNET.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalSQLNET.cs index 9dda765..11b16e1 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalSQLNET.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalSQLNET.cs @@ -1,28 +1,46 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using Microsoft.SqlServer.Server; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { /// Eval the code or expression and return a SQLNET object value. /// The SQLNET object value from the evaluated code or expression. - [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] public SQLNET EvalSQLNET() { var value = Eval(); var sqlnet = New(InternalValueName); - sqlnet.Item = new SQLNETItem {IsImpersonate = Item.IsImpersonate}; + sqlnet.Item.IsImpersonate = Item.IsImpersonate; sqlnet.Val(InternalValueName, value); return sqlnet; } + + /// Eval the code or expression and return a SQLNET object value. + /// The SQLNET object value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SQLNET evalsqlnet() + { + return EvalSQLNET(); + } + + /// Eval the code or expression and return a SQLNET object value. + /// The SQLNET object value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SQLNET EVALSQLNET() + { + return EvalSQLNET(); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalSmallInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalSmallInt.cs index 4b8640c..12625c1 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalSmallInt.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalSmallInt.cs @@ -1,25 +1,43 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +using System.Data.SqlTypes; using Microsoft.SqlServer.Server; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { /// Eval the code or expression and return a small int value. /// The small int value from the evaluated code or expression. - [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] - public short? EvalSmallInt() + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlInt16 EvalSmallInt() + { + var value = InternalEval(); + return value == null || value == DBNull.Value ? SqlInt16.Null : new SqlInt16(Convert.ToInt16(value)); + } + + /// Eval the code or expression and return a small int value. + /// The small int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlInt16 evalsmallint() { - var value = Eval(); + return EvalSmallInt(); + } - return value == null || value == DBNull.Value ? (short?) null : Convert.ToInt16(value); + /// Eval the code or expression and return a small int value. + /// The small int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlInt16 EVALSMALLINT() + { + return EvalSmallInt(); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalString.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalString.cs index fe9bf94..3844025 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalString.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalString.cs @@ -1,27 +1,46 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { /// Eval the code or expression and return a string value. /// The string value from the evaluated code or expression. - [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] [return: SqlFacet(MaxSize = -1)] public SqlString EvalString() { - var value = Eval(); + var value = InternalEval(); + return value == null || value == DBNull.Value ? SqlString.Null : new SqlString(Convert.ToString(value)); + } + + /// Eval the code or expression and return a string value. + /// The string value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + [return: SqlFacet(MaxSize = -1)] + public SqlString evalstring() + { + return EvalString(); + } - return value == null || value == DBNull.Value ? SqlString.Null : new SqlString(value.ToString()); + /// Eval the code or expression and return a string value. + /// The string value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + [return: SqlFacet(MaxSize = -1)] + public SqlString EVALSTRING() + { + return EvalString(); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalTinyInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalTinyInt.cs index c21de65..e0babdd 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalTinyInt.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalTinyInt.cs @@ -1,25 +1,43 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +using System.Data.SqlTypes; using Microsoft.SqlServer.Server; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { /// Eval the code or expression and return a tiny int value. /// The tiny int value from the evaluated code or expression. - [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] - public byte? EvalTinyInt() + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlByte EvalTinyInt() + { + var value = InternalEval(); + return value == null || value == DBNull.Value ? SqlByte.Null : new SqlByte(Convert.ToByte(value)); + } + + /// Eval the code or expression and return a tiny int value. + /// The tiny int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlByte evaltinyint() { - var value = Eval(); + return EvalTinyInt(); + } - return value == null || value == DBNull.Value ? (byte?) null : Convert.ToByte(value); + /// Eval the code or expression and return a tiny int value. + /// The tiny int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlByte EVALTINYINT() + { + return EvalTinyInt(); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalUniqueIdentifier.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalUniqueIdentifier.cs new file mode 100644 index 0000000..c8c6880 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalUniqueIdentifier.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a unique identifier value. + /// The unique identifier value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlGuid EvalUniqueIdentifier() + { + var value = InternalEval(); + return value == null || value == DBNull.Value ? SqlGuid.Null : new SqlGuid((Guid) value); + } + + /// Eval the code or expression and return a unique identifier value. + /// The unique identifier value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlGuid evaluniqueidentifier() + { + return EvalUniqueIdentifier(); + } + + /// Eval the code or expression and return a unique identifier value. + /// The unique identifier value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlGuid EVALUNIQUEIDENTIFIER() + { + return EvalUniqueIdentifier(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalVarBinary.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalVarBinary.cs new file mode 100644 index 0000000..de73b76 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalVarBinary.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a varbinary value. + /// The varbinary value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlBinary EvalVarBinary() + { + var value = InternalEval(); + return value == null || value == DBNull.Value ? SqlBinary.Null : new SqlBinary((byte[]) value); + } + + /// Eval the code or expression and return a varbinary value. + /// The varbinary value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlBinary evalvarbinary() + { + return EvalVarBinary(); + } + + /// Eval the code or expression and return a varbinary value. + /// The varbinary value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] + public SqlBinary EVALVARBINARY() + { + return EvalVarBinary(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalXml.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalXml.cs new file mode 100644 index 0000000..1907bd2 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Eval/EvalXml.cs @@ -0,0 +1,43 @@ +//// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +//// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +//// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +//// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +//// More projects: http://www.zzzprojects.com/ +//// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +//using System; +//using System.Data.SqlTypes; +//using Microsoft.SqlServer.Server; + +//// ReSharper disable InconsistentNaming + +//namespace Z.Expressions.SqlServer.Eval +//{ +// public partial struct SQLNET +// { +// /// Eval the code or expression and return a tiny int value. +// /// The tiny int value from the evaluated code or expression. +// [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] +// public SqlXml EvalXml() +// { +// return new SqlXml(InternalEval()); +// } + +// /// Eval the code or expression and return a tiny int value. +// /// The tiny int value from the evaluated code or expression. +// [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] +// public SqlXml evalxml() +// { +// return EvalXml(); +// } + +// /// Eval the code or expression and return a tiny int value. +// /// The tiny int value from the evaluated code or expression. +// [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] +// public SqlXml EVALXML() +// { +// return EvalXml(); +// } +// } +//} + diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccess.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccess.cs new file mode 100644 index 0000000..dd986fd --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccess.cs @@ -0,0 +1,41 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return an object value. + /// The object value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public object EvalReadAccess() + { + return Eval(); + } + + /// Eval the code or expression and return an object value. + /// The object value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public object evalreadaccess() + { + return EvalReadAccess(); + } + + /// Eval the code or expression and return an object value. + /// The object value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public object EVALREADACCESS() + + { + return EvalReadAccess(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessBigInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessBigInt.cs new file mode 100644 index 0000000..2362186 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessBigInt.cs @@ -0,0 +1,42 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a big int value. + /// The big int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlInt64 EvalReadAccessBigInt() + { + return EvalBigInt(); + } + + /// Eval the code or expression and return a big int value. + /// The big int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlInt64 evalreadaccessbigint() + + { + return EvalReadAccessBigInt(); + } + + /// Eval the code or expression and return a big int value. + /// The big int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlInt64 EVALREADACCESSBIGINT() + { + return EvalReadAccessBigInt(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessBinary.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessBinary.cs new file mode 100644 index 0000000..8bc3558 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessBinary.cs @@ -0,0 +1,42 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a binary value. + /// The binary value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlBytes EvalReadAccessBinary() + { + return EvalBinary(); + } + + /// Eval the code or expression and return a binary value. + /// The binary value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlBytes evalreadaccessbinary() + + { + return EvalReadAccessBinary(); + } + + /// Eval the code or expression and return a binary value. + /// The binary value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlBytes EVALREADACCESSBINARY() + { + return EvalReadAccessBinary(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessBit.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessBit.cs new file mode 100644 index 0000000..38f0fcb --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessBit.cs @@ -0,0 +1,42 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a bit value. + /// The bit value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlBoolean EvalReadAccessBit() + { + return EvalBit(); + } + + /// Eval the code or expression and return a bit value. + /// The bit value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlBoolean evalreadaccessbit() + + { + return EvalReadAccessBit(); + } + + /// Eval the code or expression and return a bit value. + /// The bit value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlBoolean EVALREADACCESSBIT() + { + return EvalReadAccessBit(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessChars.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessChars.cs new file mode 100644 index 0000000..77d65c0 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessChars.cs @@ -0,0 +1,42 @@ +//// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +//// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +//// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +//// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +//// More projects: http://www.zzzprojects.com/ +//// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +//using System.Data.SqlTypes; +//using Microsoft.SqlServer.Server; + +//// ReSharper disable InconsistentNaming + +//namespace Z.Expressions.SqlServer.Eval +//{ +// public partial struct SQLNET +// { +// /// Eval the code or expression and return a bit value. +// /// The bit value from the evaluated code or expression. +// [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] +// public SqlChars EvalChars() +// { +// return new SqlChars(InternalEval()); +// } + +// /// Eval the code or expression and return a bit value. +// /// The bit value from the evaluated code or expression. +// [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] +// public SqlChars evalchars() + +// { +// return EvalChars(); +// } + +// /// Eval the code or expression and return a bit value. +// /// The bit value from the evaluated code or expression. +// [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] +// public SqlChars EVALCHARS() +// { +// return EvalChars(); +// } +// } +//} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessDateTime.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessDateTime.cs new file mode 100644 index 0000000..235f0e5 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessDateTime.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a DateTime value. + /// The DateTime value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlDateTime EvalReadAccessDateTime() + { + return EvalDateTime(); + } + + /// Eval the code or expression and return a DateTime value. + /// The DateTime value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlDateTime evalreadaccessdatetime() + + { + return EvalReadAccessDateTime(); + } + + /// Eval the code or expression and return a DateTime value. + /// The DateTime value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlDateTime EVALREADACCESSDATETIME() + { + return EvalReadAccessDateTime(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessInt.cs new file mode 100644 index 0000000..5326c99 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessInt.cs @@ -0,0 +1,42 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return an int value. + /// The int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlInt32 EvalReadAccessInt() + { + return EvalInt(); + } + + /// Eval the code or expression and return an int value. + /// The int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlInt32 evalreadaccessint() + { + return EvalReadAccessInt(); + } + + /// Eval the code or expression and return an int value. + /// The int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlInt32 EVALREADACCESSINT() + { + return EvalReadAccessInt(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessSQLNET.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessSQLNET.cs new file mode 100644 index 0000000..0d08e41 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessSQLNET.cs @@ -0,0 +1,40 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a SQLNET object value. + /// The SQLNET object value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SQLNET EvalReadAccessSQLNET() + { + return EvalSQLNET(); + } + + /// Eval the code or expression and return a SQLNET object value. + /// The SQLNET object value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SQLNET evalreadaccesssqlnet() + { + return EvalReadAccessSQLNET(); + } + + /// Eval the code or expression and return a SQLNET object value. + /// The SQLNET object value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SQLNET EVALREADACCESSSQLNET() + { + return EvalReadAccessSQLNET(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessSmallInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessSmallInt.cs new file mode 100644 index 0000000..ac814c3 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessSmallInt.cs @@ -0,0 +1,42 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a small int value. + /// The small int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlInt16 EvalReadAccessSmallInt() + { + return EvalSmallInt(); + } + + /// Eval the code or expression and return a small int value. + /// The small int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlInt16 evalreadaccesssmallint() + { + return EvalReadAccessSmallInt(); + } + + /// Eval the code or expression and return a small int value. + /// The small int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlInt16 EVALREADACCESSSMALLINT() + { + return EvalReadAccessSmallInt(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessString.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessString.cs new file mode 100644 index 0000000..988261e --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessString.cs @@ -0,0 +1,44 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a string value. + /// The string value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + [return: SqlFacet(MaxSize = -1)] + public SqlString EvalReadAccessString() + { + return EvalString(); + } + + /// Eval the code or expression and return a string value. + /// The string value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + [return: SqlFacet(MaxSize = -1)] + public SqlString evalreadaccessstring() + { + return EvalReadAccessString(); + } + + /// Eval the code or expression and return a string value. + /// The string value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + [return: SqlFacet(MaxSize = -1)] + public SqlString EVALREADACCESSSTRING() + { + return EvalReadAccessString(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessTinyInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessTinyInt.cs new file mode 100644 index 0000000..4883fcd --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessTinyInt.cs @@ -0,0 +1,42 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a tiny int value. + /// The tiny int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlByte EvalReadAccessTinyInt() + { + return EvalTinyInt(); + } + + /// Eval the code or expression and return a tiny int value. + /// The tiny int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlByte evalreadaccesstinyint() + { + return EvalReadAccessTinyInt(); + } + + /// Eval the code or expression and return a tiny int value. + /// The tiny int value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlByte EVALREADACCESSTINYINT() + { + return EvalReadAccessTinyInt(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessUniqueIdentifier.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessUniqueIdentifier.cs new file mode 100644 index 0000000..259c0aa --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessUniqueIdentifier.cs @@ -0,0 +1,42 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a unique identifier value. + /// The unique identifier value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlGuid EvalReadAccessUniqueIdentifier() + { + return EvalUniqueIdentifier(); + } + + /// Eval the code or expression and return a unique identifier value. + /// The unique identifier value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlGuid evalreadaccessuniqueidentifier() + { + return EvalReadAccessUniqueIdentifier(); + } + + /// Eval the code or expression and return a unique identifier value. + /// The unique identifier value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlGuid EVALREADACCESSUNIQUEIDENTIFIER() + { + return EvalReadAccessUniqueIdentifier(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessVarBinary.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessVarBinary.cs new file mode 100644 index 0000000..adf457d --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessVarBinary.cs @@ -0,0 +1,42 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Eval the code or expression and return a varbinary value. + /// The varbinary value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlBinary EvalReadAccessVarBinary() + { + return EvalVarBinary(); + } + + /// Eval the code or expression and return a varbinary value. + /// The varbinary value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlBinary evalreadaccessvarbinary() + { + return EvalReadAccessVarBinary(); + } + + /// Eval the code or expression and return a varbinary value. + /// The varbinary value from the evaluated code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] + public SqlBinary EVALREADACCESSVARBINARY() + { + return EvalReadAccessVarBinary(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessXml.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessXml.cs new file mode 100644 index 0000000..1907bd2 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalReadAccess/EvalReadAccessXml.cs @@ -0,0 +1,43 @@ +//// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +//// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +//// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +//// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +//// More projects: http://www.zzzprojects.com/ +//// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +//using System; +//using System.Data.SqlTypes; +//using Microsoft.SqlServer.Server; + +//// ReSharper disable InconsistentNaming + +//namespace Z.Expressions.SqlServer.Eval +//{ +// public partial struct SQLNET +// { +// /// Eval the code or expression and return a tiny int value. +// /// The tiny int value from the evaluated code or expression. +// [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] +// public SqlXml EvalXml() +// { +// return new SqlXml(InternalEval()); +// } + +// /// Eval the code or expression and return a tiny int value. +// /// The tiny int value from the evaluated code or expression. +// [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] +// public SqlXml evalxml() +// { +// return EvalXml(); +// } + +// /// Eval the code or expression and return a tiny int value. +// /// The tiny int value from the evaluated code or expression. +// [SqlMethod(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None)] +// public SqlXml EVALXML() +// { +// return EvalXml(); +// } +// } +//} + diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalResultSet/SQLNET_EvalResultSet.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalResultSet/SQLNET_EvalResultSet.cs index 3e1b85e..28ebf24 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalResultSet/SQLNET_EvalResultSet.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalResultSet/SQLNET_EvalResultSet.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Data; @@ -21,9 +21,14 @@ public static void SQLNET_EvalResultSet(SQLNET sqlnet) { var value = sqlnet.Eval(); + if (value == null || value == DBNull.Value) + { + return; + } + if (value is DataTable) { - SqlContextHelper.SendDataTable((DataTable)value); + SqlContextHelper.SendDataTable((DataTable) value); return; } diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_1.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_1.cs index f812e3e..430ba52 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_1.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_1.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System.Collections; using System.Data; @@ -13,7 +13,7 @@ namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { - [SqlFunction(DataAccess = DataAccessKind.Read, FillRowMethodName = "Fill_SQLNET_EvalTVF_1", TableDefinition = "Value_1 sql_variant")] + [SqlFunction(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None, FillRowMethodName = "Fill_SQLNET_EvalTVF_1", TableDefinition = "Value_1 sql_variant")] public static IEnumerable SQLNET_EvalTVF_1(SQLNET sqlnet) { var obj = sqlnet.Eval(); diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_2.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_2.cs index edbb51a..244f8b2 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_2.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_2.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System.Collections; using System.Data; @@ -13,7 +13,7 @@ namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { - [SqlFunction(DataAccess = DataAccessKind.Read, FillRowMethodName = "Fill_SQLNET_EvalTVF_2", TableDefinition = "Value_1 sql_variant, Value_2 sql_variant")] + [SqlFunction(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None, FillRowMethodName = "Fill_SQLNET_EvalTVF_2", TableDefinition = "Value_1 sql_variant, Value_2 sql_variant")] public static IEnumerable SQLNET_EvalTVF_2(SQLNET sqlnet) { var obj = sqlnet.Eval(); @@ -22,7 +22,7 @@ public static IEnumerable SQLNET_EvalTVF_2(SQLNET sqlnet) public static void Fill_SQLNET_EvalTVF_2(object obj, out object value1, out object value2) { - var row = (DataRow)obj; + var row = (DataRow) obj; value1 = row[0]; value2 = row[1]; } diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_3.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_3.cs index bbf8d13..9e91df8 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_3.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_3.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System.Collections; using System.Data; @@ -13,7 +13,7 @@ namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { - [SqlFunction(DataAccess = DataAccessKind.Read, FillRowMethodName = "Fill_SQLNET_EvalTVF_3", TableDefinition = "Value_1 sql_variant, Value_2 sql_variant, Value_3 sql_variant")] + [SqlFunction(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None, FillRowMethodName = "Fill_SQLNET_EvalTVF_3", TableDefinition = "Value_1 sql_variant, Value_2 sql_variant, Value_3 sql_variant")] public static IEnumerable SQLNET_EvalTVF_3(SQLNET sqlnet) { var obj = sqlnet.Eval(); @@ -22,7 +22,7 @@ public static IEnumerable SQLNET_EvalTVF_3(SQLNET sqlnet) public static void Fill_SQLNET_EvalTVF_3(object obj, out object value1, out object value2, out object value3) { - var row = (DataRow)obj; + var row = (DataRow) obj; value1 = row[0]; value2 = row[1]; value3 = row[2]; diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_4.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_4.cs index 6075e23..d4c8e48 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_4.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_4.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System.Collections; using System.Data; @@ -13,7 +13,7 @@ namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { - [SqlFunction(DataAccess = DataAccessKind.Read, FillRowMethodName = "Fill_SQLNET_EvalTVF_4", TableDefinition = "Value_1 sql_variant, Value_2 sql_variant, Value_3 sql_variant, Value_4 sql_variant")] + [SqlFunction(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None, FillRowMethodName = "Fill_SQLNET_EvalTVF_4", TableDefinition = "Value_1 sql_variant, Value_2 sql_variant, Value_3 sql_variant, Value_4 sql_variant")] public static IEnumerable SQLNET_EvalTVF_4(SQLNET sqlnet) { var obj = sqlnet.Eval(); @@ -22,7 +22,7 @@ public static IEnumerable SQLNET_EvalTVF_4(SQLNET sqlnet) public static void Fill_SQLNET_EvalTVF_4(object obj, out object value1, out object value2, out object value3, out object value4) { - var row = (DataRow)obj; + var row = (DataRow) obj; value1 = row[0]; value2 = row[1]; value3 = row[2]; diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_5.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_5.cs index 011a35a..ecb0401 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_5.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_5.cs @@ -1,9 +1,9 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System.Collections; using System.Data; @@ -13,7 +13,7 @@ namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET { - [SqlFunction(DataAccess = DataAccessKind.Read, FillRowMethodName = "Fill_SQLNET_EvalTVF_5", TableDefinition = "Value_1 sql_variant, Value_2 sql_variant, Value_3 sql_variant, Value_4 sql_variant, Value_5 sql_variant")] + [SqlFunction(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None, FillRowMethodName = "Fill_SQLNET_EvalTVF_5", TableDefinition = "Value_1 sql_variant, Value_2 sql_variant, Value_3 sql_variant, Value_4 sql_variant, Value_5 sql_variant")] public static IEnumerable SQLNET_EvalTVF_5(SQLNET sqlnet) { var obj = sqlnet.Eval(); diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_String.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_String.cs new file mode 100644 index 0000000..01ca6f8 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/EvalTVF/SQLNET_EvalTVF_String.cs @@ -0,0 +1,30 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System.Collections; +using System.Data; +using System.Data.SqlTypes; +using Microsoft.SqlServer.Server; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + [SqlFunction(DataAccess = DataAccessKind.None, SystemDataAccess = SystemDataAccessKind.None, FillRowMethodName = "Fill_SQLNET_EvalTVF_String", TableDefinition = "Value_1 NVARCHAR(MAX)")] + public static IEnumerable SQLNET_EvalTVF_String(SQLNET sqlnet) + { + var obj = sqlnet.Eval(); + return DataTableHelper.GetDataRows(obj); + } + + public static void Fill_SQLNET_EvalTVF_String(object obj, out SqlString value1) + { + var row = (DataRow) obj; + value1 = new SqlString((string)row[0]); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetAutoDispose.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetAutoDispose.cs index 3611343..8ca2f9e 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetAutoDispose.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetAutoDispose.cs @@ -1,9 +1,11 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming namespace Z.Expressions.SqlServer.Eval { @@ -15,5 +17,19 @@ public bool GetAutoDispose() { return Item.IsAutoDispose; } + + /// Gets the value if the object should AutoDispose once it has been evaluated. + /// true if the object AutoDispose, otherwise false. + public bool getautodispose() + { + return Item.IsAutoDispose; + } + + /// Gets the value if the object should AutoDispose once it has been evaluated. + /// true if the object AutoDispose, otherwise false. + public bool GETAUTODISPOSE() + { + return Item.IsAutoDispose; + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetCode.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetCode.cs index 51455b2..2666539 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetCode.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetCode.cs @@ -1,9 +1,11 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming namespace Z.Expressions.SqlServer.Eval { @@ -15,5 +17,19 @@ public string GetCode() { return Item.Code; } + + /// Gets the code or expression to evaluate. + /// The code or expression to evaluate. + public string getcode() + { + return Item.Code; + } + + /// Gets the code or expression to evaluate. + /// The code or expression to evaluate. + public string GETCODE() + { + return Item.Code; + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetImpersonate.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetImpersonate.cs index d044f46..6a15b62 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetImpersonate.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetImpersonate.cs @@ -1,9 +1,11 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming namespace Z.Expressions.SqlServer.Eval { @@ -15,5 +17,19 @@ public bool GetImpersonate() { return Item.IsImpersonate; } + + /// Gets the value if the context should use an impersonate context to evaluate the code or expression. + /// true if the context should use an impersonate context to evaluate the code or expressions, otherwise false. + public bool getimpersonate() + { + return Item.IsImpersonate; + } + + /// Gets the value if the context should use an impersonate context to evaluate the code or expression. + /// true if the context should use an impersonate context to evaluate the code or expressions, otherwise false. + public bool GETIMPERSONATE() + { + return Item.IsImpersonate; + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValue.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValue.cs index dde4dde..2ed8f6e 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValue.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValue.cs @@ -1,12 +1,14 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET @@ -26,5 +28,23 @@ public object GetValue(string key) throw new Exception(string.Format(ExceptionMessage.Unexpected_ParameterKeyNotFound, key)); } + + /// Gets the value associated with the specified key. + /// Throws an exception if no value is associated with the specified key. + /// The key of the value to get. + /// The value associated with the specified key. + public object getvalue(string key) + { + return GetValue(key); + } + + /// Gets the value associated with the specified key. + /// Throws an exception if no value is associated with the specified key. + /// The key of the value to get. + /// The value associated with the specified key. + public object GETVALUE(string key) + { + return GetValue(key); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueBigInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueBigInt.cs index eb275f3..97ab63c 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueBigInt.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueBigInt.cs @@ -1,12 +1,14 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET @@ -19,5 +21,21 @@ public partial struct SQLNET var value = GetValue(key); return value == DBNull.Value ? (long?) null : Convert.ToInt64(value); } + + /// Gets the big int value associated with the specified key. + /// The key of the value to get. + /// The big int value associated with the specified key. + public long? getvaluebigint(string key) + { + return GetValueBigInt(key); + } + + /// Gets the big int value associated with the specified key. + /// The key of the value to get. + /// The big int value associated with the specified key. + public long? GETVALUEBIGINT(string key) + { + return GetValueBigInt(key); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueBit.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueBit.cs index 8956d86..9f8946c 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueBit.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueBit.cs @@ -1,12 +1,14 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET @@ -19,5 +21,21 @@ public partial struct SQLNET var value = GetValue(key); return value == DBNull.Value ? (bool?) null : Convert.ToBoolean(value); } + + /// Gets the bit value associated with the specified key. + /// The key of the value to get. + /// The bit value associated with the specified key. + public bool? getvaluebit(string key) + { + return GetValueBit(key); + } + + /// Gets the bit value associated with the specified key. + /// The key of the value to get. + /// The bit value associated with the specified key. + public bool? GETVALUEBIT(string key) + { + return GetValueBit(key); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueInt.cs index c9a79e0..e639194 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueInt.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueInt.cs @@ -1,12 +1,14 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET @@ -19,5 +21,21 @@ public partial struct SQLNET var value = GetValue(key); return value == DBNull.Value ? (int?) null : Convert.ToInt32(value); } + + /// Gets the int value associated with the specified key. + /// The key of the value to get. + /// The int value associated with the specified key. + public int? getvalueint(string key) + { + return GetValueInt(key); + } + + /// Gets the int value associated with the specified key. + /// The key of the value to get. + /// The int value associated with the specified key. + public int? GETVALUEINT(string key) + { + return GetValueInt(key); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueSmallInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueSmallInt.cs index d3395ef..222ec91 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueSmallInt.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueSmallInt.cs @@ -1,12 +1,14 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET @@ -19,5 +21,21 @@ public partial struct SQLNET var value = GetValue(key); return value == DBNull.Value ? (short?) null : Convert.ToInt16(value); } + + /// Gets the small int value associated with the specified key. + /// The key of the value to get. + /// The small int value associated with the specified key. + public short? getvaluesmallint(string key) + { + return GetValueSmallInt(key); + } + + /// Gets the small int value associated with the specified key. + /// The key of the value to get. + /// The small int value associated with the specified key. + public short? GETVALUESMALLINT(string key) + { + return GetValueSmallInt(key); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueString.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueString.cs index c4d5c0a..18a3883 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueString.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueString.cs @@ -1,14 +1,16 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET @@ -22,5 +24,23 @@ public SqlString GetValueString(string key) var value = GetValue(key); return value == DBNull.Value ? null : new SqlString(value.ToString()); } + + /// Gets the string value associated with the specified key. + /// The key of the value to get. + /// The string value associated with the specified key. + [return: SqlFacet(MaxSize = -1)] + public SqlString getvaluestring(string key) + { + return GetValueString(key); + } + + /// Gets the string value associated with the specified key. + /// The key of the value to get. + /// The string value associated with the specified key. + [return: SqlFacet(MaxSize = -1)] + public SqlString GETVALUESTRING(string key) + { + return GetValueString(key); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueTinyInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueTinyInt.cs index 4667ec6..6da0d7f 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueTinyInt.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Getter/GetValueTinyInt.cs @@ -1,12 +1,14 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { public partial struct SQLNET @@ -19,5 +21,21 @@ public partial struct SQLNET var value = GetValue(key); return value == DBNull.Value ? (byte?) null : Convert.ToByte(value); } + + /// Gets the tiny int value associated with the specified key. + /// The key of the value to get. + /// The tiny int value associated with the specified key. + public byte? getvaluetinyint(string key) + { + return GetValueTinyInt(key); + } + + /// Gets the tiny int value associated with the specified key. + /// The key of the value to get. + /// The tiny int value associated with the specified key. + public byte? GETVALUETINYINT(string key) + { + return GetValueTinyInt(key); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Internal/InternalEval.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Internal/InternalEval.cs new file mode 100644 index 0000000..a6ceab9 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Internal/InternalEval.cs @@ -0,0 +1,132 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System; +using System.Security.Principal; +using Microsoft.SqlServer.Server; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + public object InternalEval() + { + var item = Item; + var lastAccess = DateTime.Now; + + // Overwrite last access + item.LastAccess = lastAccess; + if (item.Delegate != null) + { + item.Delegate.LastAccess = lastAccess; + } + + // CHECK if the garbage collection should be invoked + if (lastAccess > EvalManager.Configuration.ExpireCacheNextScheduled) + { + EvalManager.ExpireCache(); + } + + var code = item.Code; + + SQLNETParallelItem parallelValue; + if (ValueParallel != 0) + { + parallelValue = item.GetParallelValue(ValueParallel); + } + else + { + parallelValue = new SQLNETParallelItem(); + } + + //var parallelValue = item; + object result; + + if (item.IsImpersonate) + { + WindowsImpersonationContext impersonatedIdentity = null; + + if (SqlContext.WindowsIdentity != null) + { + var currentIdentity = SqlContext.WindowsIdentity; + impersonatedIdentity = currentIdentity.Impersonate(); + } + + try + { + if (item.Delegate == null) + { + item.Delegate = EvalManager.Configuration.CompileSQLNET(code, item.ParameterTypes.InnerDictionary); + item.IsCompiled = true; + } + + result = item.Delegate.Delegate(parallelValue.ParameterValues); + } + finally + { + if (impersonatedIdentity != null) + { + impersonatedIdentity.Undo(); + } + } + } + else + { + if (item.Delegate == null) + { + item.Delegate = EvalManager.Configuration.CompileSQLNET(code, item.ParameterTypes.InnerDictionary); + item.IsCompiled = true; + } + + result = item.Delegate.Delegate(parallelValue.ParameterValues); + } + + // RELEASE parallel item once resolved + if (ValueParallel != 0) + { + Item.ParallelItems.TryRemove(parallelValue); + } + + + if (Item.IsAutoDispose) + { + Dispose(); + } + + return result; + + + // if (item.ParameterTables.Count > 0) + // { + // var s = @" + //using (SqlConnection connection = new SqlConnection(""context connection = true"")) + //{ + // using (SqlCommand command = new SqlCommand()) + // { + // command.Connection = connection; + // connection.Open(); + // [SQLNET_Code] + // } + //} + //"; + // //var list = new List(); + // //foreach (DictionaryEntry parameterTable in item.ParameterTables) + // //{ + // // list.Add(string.Concat("command.CommandText = 'SELECT * FROM ", parameterTable.Value, "';")); + // // list.Add(string.Concat(parameterTable.Key, " = command.ExecuteDataTable();")); + // // list.Add(parameterTable.Key + ".ExtendedProperties['ZZZ_Select'] = command.CommandText"); + // //} + + // //code = s.Replace("[SQLNET_Code]", string.Join(Environment.NewLine, list)) + code; + + // //throw new Exception(code); + // } + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Internal/InternalValue.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Internal/InternalValue.cs new file mode 100644 index 0000000..b6571f8 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Internal/InternalValue.cs @@ -0,0 +1,53 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System; +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + public SQLNET InternalValue(SqlString keyString, Type type, object value) + { + var key = keyString.Value; + var item = Item; + var sqlnet = this; + + SQLNETParallelItem parallelValue; + + // CREATE a new SQLNET from the root + if (ValueParallel == 0) + { + sqlnet = new SQLNET {ValueSerializable = ValueSerializable, ValueParallel = item.GetNextCountAndAddParallel()}; + parallelValue = item.AddParallelValue(sqlnet.ValueParallel); + } + else + { + parallelValue = item.GetParallelValue(sqlnet.ValueParallel); + } + + if (!item.IsCompiled) + { + //parallelValue.ParameterValues[key] = value; + parallelValue.ParameterValues.Add(key, value); + + // Try to add type only if it's not compiled yet + item.ParameterTypes.TryAdd(key, type); + } + else + { + // AddOrUpdate value + parallelValue.ParameterValues[key] = value; + } + + return sqlnet; + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/License/AddLicense.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/License/AddLicense.cs index 84688fa..8cc23b5 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/License/AddLicense.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/License/AddLicense.cs @@ -1,9 +1,11 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming namespace Z.Expressions.SqlServer.Eval { @@ -17,5 +19,21 @@ public static bool AddLicense(string licenseName, string licenseKey) CompilerManager.AddLicense(licenseName, licenseKey); return true; } + + /// Add the PRO license purchased from ZZZ Projects Inc. (http://eval-sql.net/). + /// The license name. + /// The license key. + public static bool addlicense(string licenseName, string licenseKey) + { + return AddLicense(licenseName, licenseKey); + } + + /// Add the PRO license purchased from ZZZ Projects Inc. (http://eval-sql.net/). + /// The license name. + /// The license key. + public static bool ADDLICENSE(string licenseName, string licenseKey) + { + return AddLicense(licenseName, licenseKey); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Options/AutoDispose.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Options/AutoDispose.cs index e332980..1b60db0 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Options/AutoDispose.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Options/AutoDispose.cs @@ -1,9 +1,11 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming namespace Z.Expressions.SqlServer.Eval { @@ -16,5 +18,19 @@ public SQLNET AutoDispose() Item.IsAutoDispose = true; return this; } + + /// Set the IsAutoDispose value to true. + /// A fluent SQLNET object. + public SQLNET autodispose() + { + return AutoDispose(); + } + + /// Set the IsAutoDispose value to true. + /// A fluent SQLNET object. + public SQLNET AUTODISPOSE() + { + return AutoDispose(); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Options/Code.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Options/Code.cs index 66129f4..42a837c 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Options/Code.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Options/Code.cs @@ -1,9 +1,11 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming namespace Z.Expressions.SqlServer.Eval { @@ -19,9 +21,29 @@ public SQLNET Code(string code) code = TemplateConnection.Replace("[SQLNET_Code]", code); } - Item.Delegate = null; - Item.Code = code; + if (code != Item.Code) + { + Item.Delegate = null; + Item.Code = code; + } + return this; } + + /// Set the code or expression to evaluate. + /// The code or expression to evaluate. + /// A fluent SQLNET object. + public SQLNET code(string code) + { + return Code(code); + } + + /// Set the code or expression to evaluate. + /// The code or expression to evaluate. + /// A fluent SQLNET object. + public SQLNET CODE(string code) + { + return Code(code); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Options/Impersonate.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Options/Impersonate.cs index 72016a7..117c1a1 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Options/Impersonate.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Options/Impersonate.cs @@ -1,9 +1,11 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming namespace Z.Expressions.SqlServer.Eval { @@ -16,5 +18,19 @@ public SQLNET Impersonate() Item.IsImpersonate = true; return this; } + + /// Set the IsImpersonate value to true. + /// A fluent SQLNET object. + public SQLNET impersonate() + { + return Impersonate(); + } + + /// Set the IsImpersonate value to true. + /// A fluent SQLNET object. + public SQLNET IMPERSONATE() + { + return Impersonate(); + } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/SQLNET.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/SQLNET.cs index 3ebad15..4e841d4 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/SQLNET.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/SQLNET.cs @@ -1,26 +1,54 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; using System.Data.SqlTypes; -using System.IO; +using System.Linq; using Microsoft.SqlServer.Server; +// ReSharper disable InconsistentNaming + namespace Z.Expressions.SqlServer.Eval { /// A SQLNET used to compile the code or expression. - [SqlUserDefinedType(Format.UserDefined, MaxByteSize = -1)] - public partial struct SQLNET : INullable, IBinarySerialize + [SqlUserDefinedType(Format.Native, IsByteOrdered = true)] + public partial struct SQLNET : INullable { + public static int AddValue(int x, int y) + { + return x + y; + } + //public static bool IsMatch(SqlString value) + //{ + // return Regex.IsMatch(value.Value, "toto"); + //} + + /// The value serializable. + public int ValueSerializable; + + public int ValueParallel; + /// Name of internal value. public static readonly string InternalValueName = "value"; /// The SQLNETItem used to compile the code or expression. - public SQLNETItem Item; + public SQLNETItem Item + { + get + { + SQLNETItem item; + if (!EvalManager.CacheItem.TryGetValue(ValueSerializable, out item)) + { + throw new Exception(ExceptionMessage.GeneralException); + } + + return item; + } + } /// The template connection when SqlClrCommand is used. private static readonly string TemplateConnection = @" @@ -56,6 +84,20 @@ public static int CacheDelegateCount() return EvalManager.CacheDelegate.Count; } + /// Get the cache delegate count. + /// The number of items in the cache delegate. + public static int cachedelegatecount() + { + return CacheDelegateCount(); + } + + /// Get the cache delegate count. + /// The number of items in the cache delegate. + public static int CACHEDELEGATECOUNT() + { + return CacheDelegateCount(); + } + /// Get the cache item count. /// The number of items in the cache item. public static int CacheItemCount() @@ -63,6 +105,37 @@ public static int CacheItemCount() return EvalManager.CacheItem.Count; } + public SQLNET Compile() + { + var item = Item; + + item.Delegate = EvalManager.Configuration.CompileSQLNET(item.Code, item.ParameterTypes.InnerDictionary); + item.IsCompiled = true; + Root(); + + return this; + } + + public SQLNET compile() + { + return Compile(); + } + + public SQLNET COMPILE() + { + return Compile(); + } + + public static int Counter() + { + return EvalManager.DefaultContext.CacheItemCounter; + } + + public int InstanceCounter() + { + return ValueSerializable; + } + /// Expire caching item. /// true if it succeeds, false if it fails which usually means another process is already cleaning it. public static bool ExpireCache() @@ -70,6 +143,20 @@ public static bool ExpireCache() return EvalManager.ExpireCache(); } + /// Expire caching item. + /// true if it succeeds, false if it fails which usually means another process is already cleaning it. + public static bool expirecache() + { + return ExpireCache(); + } + + /// Expire caching item. + /// true if it succeeds, false if it fails which usually means another process is already cleaning it. + public static bool EXPIRECACHE() + { + return ExpireCache(); + } + /// News. /// The code. /// A SQLNET to evaluate the code or expression. @@ -81,28 +168,52 @@ public static SQLNET New(string code) code = TemplateConnection.Replace("[SQLNET_Code]", code); } - var sqlnet = new SQLNET {Item = new SQLNETItem()}; - sqlnet.Item.Code = code; + var sqlnet = new SQLNET {ValueSerializable = EvalManager.DefaultContext.GetNextCacheItemCounter()}; + var sqlnetitem = new SQLNETItem {Code = code}; + EvalManager.CacheItem.TryAdd(sqlnet.ValueSerializable, sqlnetitem); return sqlnet; } + /// News. + /// The code. + /// A SQLNET to evaluate the code or expression. + [SqlMethod(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)] // Required for static constructor + public static SQLNET NEW(string code) + { + return New(code); + } + /// Releases all locks. /// true if it succeeds, false if it fails. public static bool ReleaseLocks() { - EvalManager.CacheDelegate.ReleaseLock(); - EvalManager.CacheItem.ReleaseLock(); + EvalManager.CacheDelegate.Buckets.ToList().ForEach(x => x.ReleaseLock()); + EvalManager.CacheItem.Buckets.ToList().ForEach(x => x.ReleaseLock()); SharedLock.ReleaseLock(ref EvalManager.SharedLock.ExpireCacheLock); return true; } + /// Releases all locks. + /// true if it succeeds, false if it fails. + public static bool releaselock() + { + return ReleaseLocks(); + } + + /// Releases all locks. + /// true if it succeeds, false if it fails. + public static bool RELEASELOCK() + { + return ReleaseLocks(); + } + /// /// Performs application-defined tasks associated with freeing, releasing, or resetting /// unmanaged resources. /// - public void Dispose() + public bool Dispose() { if (Item.Delegate != null) { @@ -110,54 +221,68 @@ public void Dispose() EvalManager.CacheDelegate.TryRemove(Item.Delegate.CacheKey, out evalDelegate); } - EvalManager.CacheItem.TryRemove(Item.CacheKey, out Item); + SQLNETItem item; + EvalManager.CacheItem.TryRemove(ValueSerializable, out item); + return true; + } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting + /// unmanaged resources. + /// + public bool dispose() + { + return Dispose(); } + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting + /// unmanaged resources. + /// + public bool DISPOSE() + { + return Dispose(); + } + + /// Parses the given value to a SQLNET object from the string representation. /// The value that reprensent a SQLNET object. /// A SQLNET object parsed from the string representation. [SqlMethod(OnNullCall = false)] public static SQLNET Parse(SqlString value) { - return new SQLNET(); + throw new Exception(ExceptionMessage.GeneralException); } - /// Reads the given reader to retrieve the SQLNETItem from the cache. - /// The reader to read. - public void Read(BinaryReader reader) + public SQLNET Root() { - if (reader.BaseStream.Length > 0) + if (ValueParallel != 0) { - var cacheKey = reader.ReadString(); - - if (!EvalManager.CacheItem.TryGetValue(cacheKey, out Item)) - { - throw new Exception(ExceptionMessage.Unexpected_CacheItemExpired); - } + var item = Item; + var parallelValue = item.GetParallelValue(ValueParallel); + item.ParameterValues = parallelValue.ParameterValues; + Item.ParallelItems.TryRemove(parallelValue); + ValueParallel = 0; } + + return this; } - /// Convert the SQLNET object into a string representation. - /// A string that represents a SQLNET object. - public override string ToString() + public SQLNET root() { - return Item.Code; + return Root(); } - /// Writes the given writer to store the SQLNETItem in the cache. - /// The writer to write. - public void Write(BinaryWriter writer) + public SQLNET ROOT() { - if (Item != null) - { - if (!Item.IsCached) - { - EvalManager.CacheItem.TryAdd(Item.CacheKey, Item); - Item.IsCached = true; - } + return Root(); + } - writer.Write(Item.CacheKey); - } + /// Convert the SQLNET object into a string representation. + /// A string that represents a SQLNET object. + public override string ToString() + { + throw new Exception(ExceptionMessage.GeneralException); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Type/Type.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Type/Type.cs deleted file mode 100644 index 250fe62..0000000 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Type/Type.cs +++ /dev/null @@ -1,32 +0,0 @@ -//// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. -//// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -//// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -//// License: http://www.zzzprojects.com/license-agreement/ -//// More projects: http://www.zzzprojects.com/ -//// Copyright (c) 2015 ZZZ Projects. All rights reserved. - -//namespace Z.Expressions.SqlServer.Eval -//{ -// public partial struct SQLNET -// { -// public SQLNET Type(string key, string typeName) -// { -// var type = TypeHelper.GetTypeFromName(typeName); - -// object oldType; -// if (Item.ParameterTypes.TryGetValue(key, out oldType)) -// { -// if (!Equals(oldType, type)) -// { -// Item.ParameterTypes[key] = type; -// } -// } -// else -// { -// Item.ParameterTypes.Add(key, type); -// } - -// return this; -// } -// } -//} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/Val.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/Val.cs index 8860fab..a89a75b 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/Val.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/Val.cs @@ -1,11 +1,13 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. -using System; +using System.Data.SqlTypes; + +// ReSharper disable InconsistentNaming namespace Z.Expressions.SqlServer.Eval { @@ -15,54 +17,28 @@ public partial struct SQLNET /// The key of the value to add or update. /// The value to add or update associated with the specified key. /// A fluent SQLNET object. - public SQLNET Val(string key, object value) + public SQLNET Val(SqlString key, object value) { value = SqlTypeHelper.ConvertToType(value); - Type type; - - // CHECK for key containing type: int? x - if (key.Contains(" ")) - { - var split = key.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); - - if (split.Length == 1) - { - type = value.GetType(); - key = key.Trim(); - } - else if (split.Length == 2) - { - type = TypeHelper.GetTypeFromName(split[0]); - key = split[1]; - } - else - { - throw new Exception(string.Format(ExceptionMessage.Invalid_ValueKey, key)); - } - } - else - { - type = value.GetType(); - } - - object oldType; - if (Item.ParameterTypes.TryGetValue(key, out oldType)) - { - if (!Equals(oldType, type)) - { - Item.ParameterTypes[key] = type; - Item.Delegate = null; - } + return InternalValue(key, value.GetType(), value); + } - Item.ParameterValues[key] = value; - } - else - { - Item.ParameterTypes.Add(key, type); - Item.ParameterValues.Add(key, value); - } + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET val(SqlString key, object value) + { + return Val(key, value); + } - return this; + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VAL(SqlString key, object value) + { + return Val(key, value); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/Value.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/Value.cs index 907cb15..a47ac91 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/Value.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/Value.cs @@ -1,9 +1,13 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; namespace Z.Expressions.SqlServer.Eval { @@ -13,10 +17,27 @@ public partial struct SQLNET /// The key of the value to add or update. /// The value to add or update associated with the specified key. /// A fluent SQLNET object. - public SQLNET Value(string key, object value) + public SQLNET Value(SqlString key, object value) + { + return Val(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET value(SqlString key, object value) + { + return Value(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUE(SqlString key, object value) { - Val(key, value); - return this; + return Value(key, value); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueBigInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueBigInt.cs new file mode 100644 index 0000000..ed14103 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueBigInt.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueBigInt(SqlString key, SqlInt64 value) + { + return InternalValue(key, typeof (long), value.Value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuebigint(SqlString key, SqlInt64 value) + { + return ValueBigInt(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUEBIGINT(SqlString key, SqlInt64 value) + { + return ValueBigInt(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueBinary.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueBinary.cs index af735e8..d4445b8 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueBinary.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueBinary.cs @@ -1,9 +1,14 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System; +using System.Data.SqlTypes; namespace Z.Expressions.SqlServer.Eval { @@ -13,10 +18,27 @@ public partial struct SQLNET /// The key of the value to add or update. /// The binary value to add or update associated with the specified key. /// A fluent SQLNET object. - public SQLNET ValueBinary(string key, byte[] value) + public SQLNET ValueBinary(SqlString key, SqlBinary value) + { + return InternalValue(key, typeof(byte[]), value.Value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuebinary(SqlString key, SqlBinary value) + { + return ValueBinary(key.Value, value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUEBINARY(SqlString key, SqlBinary value) { - Val(key, value); - return this; + return ValueBinary(key.Value, value); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueBit.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueBit.cs new file mode 100644 index 0000000..20deada --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueBit.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueBit(SqlString key, SqlBoolean value) + { + return InternalValue(key, typeof (bool), value.Value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuebit(SqlString key, SqlBoolean value) + { + return ValueBit(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUEBIT(SqlString key, SqlBoolean value) + { + return ValueBit(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueChars.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueChars.cs new file mode 100644 index 0000000..8a49685 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueChars.cs @@ -0,0 +1,43 @@ +//// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +//// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +//// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +//// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +//// More projects: http://www.zzzprojects.com/ +//// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +//// ReSharper disable InconsistentNaming + +//using System.Data.SqlTypes; + +//namespace Z.Expressions.SqlServer.Eval +//{ +// public partial struct SQLNET +// { +// /// Add or update a binary value associated with the specified key. +// /// The key of the value to add or update. +// /// The binary value to add or update associated with the specified key. +// /// A fluent SQLNET object. +// public SQLNET ValueChars(SqlString key, SqlChars value) +// { +// return ValueInternal(key, typeof (char[]), value.Value); +// } + +// /// Add or update a binary value associated with the specified key. +// /// The key of the value to add or update. +// /// The binary value to add or update associated with the specified key. +// /// A fluent SQLNET object. +// public SQLNET valuechars(SqlString key, SqlChars value) +// { +// return ValueChars(key, value); +// } + +// /// Add or update a binary value associated with the specified key. +// /// The key of the value to add or update. +// /// The binary value to add or update associated with the specified key. +// /// A fluent SQLNET object. +// public SQLNET VALUECHARS(SqlString key, SqlChars value) +// { +// return ValueChars(key, value); +// } +// } +//} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueDateTime.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueDateTime.cs new file mode 100644 index 0000000..3bbad07 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueDateTime.cs @@ -0,0 +1,44 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System; +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueDateTime(SqlString key, SqlDateTime value) + { + return InternalValue(key, typeof (DateTime), value.Value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuedatetime(SqlString key, SqlDateTime value) + { + return ValueDateTime(key, value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUEDATETIME(SqlString key, SqlDateTime value) + { + return ValueDateTime(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueInt.cs new file mode 100644 index 0000000..232e773 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueInt.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueInt(SqlString key, SqlInt32 value) + { + return InternalValue(key, typeof (int), value.Value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valueint(SqlString key, SqlInt32 value) + { + return ValueInt(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUEINT(SqlString key, SqlInt32 value) + { + return ValueInt(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueSQLNET.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueSQLNET.cs index fc346eb..42c1cc4 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueSQLNET.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueSQLNET.cs @@ -1,9 +1,13 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; namespace Z.Expressions.SqlServer.Eval { @@ -13,10 +17,28 @@ public partial struct SQLNET /// The key of the value to add or update. /// The SQLNET value to add or update associated with the specified key. /// A fluent SQLNET object. - public SQLNET ValueSQLNET(string key, SQLNET value) + public SQLNET ValueSQLNET(SqlString key, SQLNET value) + { + var internalValue = value.GetValue(InternalValueName); + return InternalValue(key, internalValue.GetType(), internalValue); + } + + /// Add or update a SQLNET value associated with the specified key. + /// The key of the value to add or update. + /// The SQLNET value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuesqlnet(SqlString key, SQLNET value) + { + return ValueSQLNET(key, value); + } + + /// Add or update a SQLNET value associated with the specified key. + /// The key of the value to add or update. + /// The SQLNET value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUESQLNET(SqlString key, SQLNET value) { - Val(key, value.GetValue(InternalValueName)); - return this; + return ValueSQLNET(key, value); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueSmallInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueSmallInt.cs new file mode 100644 index 0000000..8c16a2e --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueSmallInt.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueSmallInt(SqlString key, SqlInt16 value) + { + return InternalValue(key, typeof (short), value.Value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuesmallint(SqlString key, SqlInt16 value) + { + return ValueSmallInt(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUESMALLINT(SqlString key, SqlInt16 value) + { + return ValueSmallInt(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueString.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueString.cs index 09f38ab..6f7ee6f 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueString.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueString.cs @@ -1,9 +1,14 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System; +using System.Data.SqlTypes; namespace Z.Expressions.SqlServer.Eval { @@ -13,10 +18,27 @@ public partial struct SQLNET /// The key of the value to add or update. /// The string value to add or update associated with the specified key. /// A fluent SQLNET object. - public SQLNET ValueString(string key, string value) + public SQLNET ValueString(SqlString key, SqlString value) + { + return InternalValue(key, typeof(string), value.Value); + } + + /// Add or update a string value associated with the specified key. + /// The key of the value to add or update. + /// The string value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuestring(SqlString key, SqlString value) + { + return ValueString(key, value); + } + + /// Add or update a string value associated with the specified key. + /// The key of the value to add or update. + /// The string value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUESTRING(SqlString key, SqlString value) { - Val(key, value); - return this; + return ValueString(key, value); } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueTable.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueTable.cs new file mode 100644 index 0000000..bdcd9f2 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueTable.cs @@ -0,0 +1,106 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data; +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a string value associated with the specified key. + /// The key of the value to add or update. + /// The string value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueTable(SqlString keyString, SqlString valueString) + { + //var key = keyString.Value; + //var value = valueString.Value; + //var type = typeof (DataTable); + + //object oldValue; + + //var item = Item; + + //if (item.ParameterTables.TryGetValue(key, out oldValue)) + //{ + // if (!oldValue.Equals(value)) + // { + // item.ParameterTables[key] = value; + // } + + // item.ParameterTypes[key] = type; + // item.ParameterValues[key] = new DataTable(); + //} + //else + //{ + // item.ParameterTables.Add(key, value); + // item.ParameterTypes.Add(key, type); + // item.ParameterValues.Add(key, new DataTable()); + //} + return this; + + + //// + //object oldType; + //if (Item.ParameterTypes.TryGetValue(key, out oldType)) + //{ + // if (!Equals(oldType, type)) + // { + // Item.ParameterTypes[key] = type; + // Item.Delegate = null; + // } + + // Item.ParameterValues[key] = value; + //} + //else + //{ + // Item.ParameterTypes.Add(key, type); + // Item.ParameterValues.Add(key, value); + //} + + //return this; + + + //Val("DataTable " + key, value); + + //object oldValue; + //if (Item.ParameterTables.TryGetValue(key, out oldValue)) + //{ + // if (!oldValue.Equals(value)) + // { + // Item.ParameterTables[key] = value; + // } + //} + //else + //{ + // Item.ParameterTables.Add(key, value); + //} + //return this; + } + + /// Add or update a string value associated with the specified key. + /// The key of the value to add or update. + /// The string value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuetable(SqlString key, string value) + { + return ValueTable(key, value); + } + + /// Add or update a string value associated with the specified key. + /// The key of the value to add or update. + /// The string value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUETABLE(SqlString key, string value) + { + return ValueTable(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueTinyInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueTinyInt.cs new file mode 100644 index 0000000..f976369 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueTinyInt.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueTinyInt(SqlString key, SqlByte value) + { + return InternalValue(key, typeof(byte), value.Value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuetinyint(SqlString key, SqlByte value) + { + return ValueTinyInt(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUETINYINT(SqlString key, SqlByte value) + { + return ValueTinyInt(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueUniqueIdentifier.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueUniqueIdentifier.cs new file mode 100644 index 0000000..3635959 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueUniqueIdentifier.cs @@ -0,0 +1,44 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System; +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueUniqueIdentifier(SqlString key, SqlGuid value) + { + return InternalValue(key, typeof (Guid), value.Value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valueuniqueidentifier(SqlString key, SqlGuid value) + { + return ValueUniqueIdentifier(key, value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUEUNIQUEIDENTIFIER(SqlString key, SqlGuid value) + { + return ValueUniqueIdentifier(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueVarBinary.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueVarBinary.cs new file mode 100644 index 0000000..7f74168 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueVarBinary.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueVarBinary(SqlString key, SqlBytes value) + { + return InternalValue(key, typeof (byte[]), value.Value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuevarbinary(SqlString key, SqlBytes value) + { + return ValueVarBinary(key, value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUEVARBINARY(SqlString key, SqlBytes value) + { + return ValueVarBinary(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueXml.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueXml.cs index b5eeb04..7ca1fa5 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueXml.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/Value/ValueXml.cs @@ -1,24 +1,43 @@ -// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. -// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ -// More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +//// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +//// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +//// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +//// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +//// More projects: http://www.zzzprojects.com/ +//// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. -using System.Data.SqlTypes; +//using System.Data.SqlTypes; -namespace Z.Expressions.SqlServer.Eval -{ - public partial struct SQLNET - { - /// Add or update a xml value associated with the specified key. - /// The key of the value to add or update. - /// The xml value to add or update associated with the specified key. - /// A fluent SQLNET object. - public SQLNET ValueXml(string key, SqlXml value) - { - Val(key, value); - return this; - } - } -} \ No newline at end of file +//// ReSharper disable InconsistentNaming + +//namespace Z.Expressions.SqlServer.Eval +//{ +// public partial struct SQLNET +// { +// /// Add or update a xml value associated with the specified key. +// /// The key of the value to add or update. +// /// The xml value to add or update associated with the specified key. +// /// A fluent SQLNET object. +// public SQLNET ValueXml(SqlString key, SqlXml value) +// { +// return ValueInternal(key, typeof (string), value.Value); +// } + +// /// Add or update a xml value associated with the specified key. +// /// The key of the value to add or update. +// /// The xml value to add or update associated with the specified key. +// /// A fluent SQLNET object. +// public SQLNET valuexml(SqlString key, SqlXml value) +// { +// return ValueXml(key, value); +// } + +// /// Add or update a xml value associated with the specified key. +// /// The key of the value to add or update. +// /// The xml value to add or update associated with the specified key. +// /// A fluent SQLNET object. +// public SQLNET VALUEXML(SqlString key, SqlXml value) +// { +// return ValueXml(key, value); +// } +// } +//} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValNullable.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValNullable.cs new file mode 100644 index 0000000..666752d --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValNullable.cs @@ -0,0 +1,72 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Data.SqlTypes; + +// ReSharper disable InconsistentNaming + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValNullable(SqlString key, object value) + { + Type type; + value = SqlTypeHelper.ConvertToType(value); + + // CHECK for key containing type: int? x + if (key.Value.Contains(" ")) + { + var split = key.Value.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); + + if (split.Length == 1) + { + type = value.GetType(); + key = key.Value.Trim(); + } + else if (split.Length == 2) + { + type = TypeHelper.GetTypeFromName(split[0]); + key = split[1]; + } + else + { + throw new Exception(string.Format(ExceptionMessage.Invalid_ValueKey, key)); + } + } + else + { + type = value.GetType(); + } + + return InternalValue(key, type, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valnullable(SqlString key, object value) + { + return ValNullable(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALNULLABLE(SqlString key, object value) + { + return ValNullable(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullable.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullable.cs new file mode 100644 index 0000000..9d1e3df --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullable.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueNullable(SqlString key, object value) + { + return ValNullable(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuenullable(SqlString key, object value) + { + return ValueNullable(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUENULLABLE(SqlString key, object value) + { + return ValueNullable(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableBigInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableBigInt.cs new file mode 100644 index 0000000..d6d0678 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableBigInt.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueNullableBigInt(SqlString key, SqlInt64 value) + { + return InternalValue(key, typeof (long?), value.IsNull ? (long?) null : value.Value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuenullablebigint(SqlString key, SqlInt64 value) + { + return ValueNullableBigInt(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUENULLABLEBIGINT(SqlString key, SqlInt64 value) + { + return ValueNullableBigInt(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableBinary.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableBinary.cs new file mode 100644 index 0000000..2c48757 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableBinary.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueNullableBinary(SqlString key, SqlBinary value) + { + return InternalValue(key, typeof (byte[]), value.Value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuenullablebinary(SqlString key, SqlBinary value) + { + return ValueNullableBinary(key.Value, value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUENULLABLEBINARY(SqlString key, SqlBinary value) + { + return ValueNullableBinary(key.Value, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableBit.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableBit.cs new file mode 100644 index 0000000..80785f6 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableBit.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueNullableBit(SqlString key, SqlBoolean value) + { + return InternalValue(key, typeof (bool), value.Value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuenullablebit(SqlString key, SqlBoolean value) + { + return ValueNullableBit(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUENULLABLEBIT(SqlString key, SqlBoolean value) + { + return ValueNullableBit(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableChars.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableChars.cs new file mode 100644 index 0000000..8a49685 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableChars.cs @@ -0,0 +1,43 @@ +//// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +//// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +//// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +//// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +//// More projects: http://www.zzzprojects.com/ +//// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +//// ReSharper disable InconsistentNaming + +//using System.Data.SqlTypes; + +//namespace Z.Expressions.SqlServer.Eval +//{ +// public partial struct SQLNET +// { +// /// Add or update a binary value associated with the specified key. +// /// The key of the value to add or update. +// /// The binary value to add or update associated with the specified key. +// /// A fluent SQLNET object. +// public SQLNET ValueChars(SqlString key, SqlChars value) +// { +// return ValueInternal(key, typeof (char[]), value.Value); +// } + +// /// Add or update a binary value associated with the specified key. +// /// The key of the value to add or update. +// /// The binary value to add or update associated with the specified key. +// /// A fluent SQLNET object. +// public SQLNET valuechars(SqlString key, SqlChars value) +// { +// return ValueChars(key, value); +// } + +// /// Add or update a binary value associated with the specified key. +// /// The key of the value to add or update. +// /// The binary value to add or update associated with the specified key. +// /// A fluent SQLNET object. +// public SQLNET VALUECHARS(SqlString key, SqlChars value) +// { +// return ValueChars(key, value); +// } +// } +//} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableDateTime.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableDateTime.cs new file mode 100644 index 0000000..37e3001 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableDateTime.cs @@ -0,0 +1,44 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System; +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueNullableDateTime(SqlString key, SqlDateTime value) + { + return InternalValue(key, typeof (DateTime?), value.IsNull ? (DateTime?) null : value.Value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuenullabledatetime(SqlString key, SqlDateTime value) + { + return ValueNullableDateTime(key, value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUENULLABLEDATETIME(SqlString key, SqlDateTime value) + { + return ValueNullableDateTime(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableInt.cs new file mode 100644 index 0000000..a249b86 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableInt.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueNullableInt(SqlString key, SqlInt32 value) + { + return InternalValue(key, typeof (int?), value.IsNull ? (int?) null : value.Value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuenullableint(SqlString key, SqlInt32 value) + { + return ValueNullableInt(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUENULLABLEINT(SqlString key, SqlInt32 value) + { + return ValueNullableInt(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableSmallInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableSmallInt.cs new file mode 100644 index 0000000..59f4910 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableSmallInt.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueNullableSmallInt(SqlString key, SqlInt16 value) + { + return InternalValue(key, typeof(short?), value.IsNull ? (short?)null : value.Value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuenullablesmallint(SqlString key, SqlInt16 value) + { + return ValueNullableSmallInt(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUENULLABLESMALLINT(SqlString key, SqlInt16 value) + { + return ValueNullableSmallInt(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableString.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableString.cs new file mode 100644 index 0000000..5afe153 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableString.cs @@ -0,0 +1,44 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System; +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a string value associated with the specified key. + /// The key of the value to add or update. + /// The string value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueNullableString(SqlString key, SqlString value) + { + return InternalValue(key, typeof(string), value.Value); + } + + /// Add or update a string value associated with the specified key. + /// The key of the value to add or update. + /// The string value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuenullablestring(SqlString key, SqlString value) + { + return ValueNullableString(key, value); + } + + /// Add or update a string value associated with the specified key. + /// The key of the value to add or update. + /// The string value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUENULLABLESTRING(SqlString key, SqlString value) + { + return ValueNullableString(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableTinyInt.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableTinyInt.cs new file mode 100644 index 0000000..94a1a58 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableTinyInt.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueNullableTinyInt(SqlString key, SqlByte value) + { + return InternalValue(key, typeof(byte?), value.IsNull ? (byte?)null : value.Value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuenullabletinyint(SqlString key, SqlByte value) + { + return ValueNullableTinyInt(key, value); + } + + /// Add or update a value associated with the specified key. + /// The key of the value to add or update. + /// The value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUENULLABLETINYINT(SqlString key, SqlByte value) + { + return ValueNullableTinyInt(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableUniqueIdentifier.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableUniqueIdentifier.cs new file mode 100644 index 0000000..df9303a --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableUniqueIdentifier.cs @@ -0,0 +1,44 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System; +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueNullableUniqueIdentifier(SqlString key, SqlGuid value) + { + return InternalValue(key, typeof (Guid?), value.IsNull ? (Guid?) null : value.Value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuenullableuniqueidentifier(SqlString key, SqlGuid value) + { + return ValueNullableUniqueIdentifier(key, value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUENULLABLEUNIQUEIDENTIFIER(SqlString key, SqlGuid value) + { + return ValueNullableUniqueIdentifier(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableVarBinary.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableVarBinary.cs new file mode 100644 index 0000000..8cecf13 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableVarBinary.cs @@ -0,0 +1,43 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +// ReSharper disable InconsistentNaming + +using System.Data.SqlTypes; + +namespace Z.Expressions.SqlServer.Eval +{ + public partial struct SQLNET + { + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET ValueNullableVarBinary(SqlString key, SqlBytes value) + { + return InternalValue(key, typeof (byte[]), value.Value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET valuenullablevarbinary(SqlString key, SqlBytes value) + { + return ValueNullableVarBinary(key, value); + } + + /// Add or update a binary value associated with the specified key. + /// The key of the value to add or update. + /// The binary value to add or update associated with the specified key. + /// A fluent SQLNET object. + public SQLNET VALUENULLABLEVARBINARY(SqlString key, SqlBytes value) + { + return ValueNullableVarBinary(key, value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableXml.cs b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableXml.cs new file mode 100644 index 0000000..7ca1fa5 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNET/ValueNullable/ValueNullableXml.cs @@ -0,0 +1,43 @@ +//// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +//// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +//// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +//// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +//// More projects: http://www.zzzprojects.com/ +//// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +//using System.Data.SqlTypes; + +//// ReSharper disable InconsistentNaming + +//namespace Z.Expressions.SqlServer.Eval +//{ +// public partial struct SQLNET +// { +// /// Add or update a xml value associated with the specified key. +// /// The key of the value to add or update. +// /// The xml value to add or update associated with the specified key. +// /// A fluent SQLNET object. +// public SQLNET ValueXml(SqlString key, SqlXml value) +// { +// return ValueInternal(key, typeof (string), value.Value); +// } + +// /// Add or update a xml value associated with the specified key. +// /// The key of the value to add or update. +// /// The xml value to add or update associated with the specified key. +// /// A fluent SQLNET object. +// public SQLNET valuexml(SqlString key, SqlXml value) +// { +// return ValueXml(key, value); +// } + +// /// Add or update a xml value associated with the specified key. +// /// The key of the value to add or update. +// /// The xml value to add or update associated with the specified key. +// /// A fluent SQLNET object. +// public SQLNET VALUEXML(SqlString key, SqlXml value) +// { +// return ValueXml(key, value); +// } +// } +//} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNETItem/SQLNETItem.cs b/src/Z.Expressions.SqlServer.Eval/SQLNETItem/SQLNETItem.cs index 1cdf41b..d249345 100644 --- a/src/Z.Expressions.SqlServer.Eval/SQLNETItem/SQLNETItem.cs +++ b/src/Z.Expressions.SqlServer.Eval/SQLNETItem/SQLNETItem.cs @@ -1,16 +1,16 @@ // Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. // Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET -// Forum: https://zzzprojects.uservoice.com/forums/328452-eval-sql-net -// License: http://www.zzzprojects.com/license-agreement/ +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE // More projects: http://www.zzzprojects.com/ -// Copyright (c) 2015 ZZZ Projects. All rights reserved. +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. using System; +using System.Collections; namespace Z.Expressions.SqlServer.Eval { /// A SQLNETItem used to compile the code or expression. - [Serializable] public class SQLNETItem { /// Gets or sets the cache key used to cache the SQLNETItem. @@ -19,6 +19,9 @@ public class SQLNETItem /// Gets or sets the code or expression to evaluate. public string Code; + /// The counter. + public int Counter = int.MinValue; + /// Gets or sets the compiled code or expression. public EvalDelegate Delegate; @@ -28,24 +31,90 @@ public class SQLNETItem /// Gets or sets if this object is cached. public bool IsCached; + /// true if this object is root. + public bool IsCompiled; + /// Gets or sets if an impersonate context should be used to evaluate the code or expression. public bool IsImpersonate; /// Gets or sets the last access Date/Time from the cache. public DateTime LastAccess; + /// The parallel values. + public SharedBucketList ParallelItems; + + /// Gets or sets the parameter table used to evaluate the code or expression. + public ListDictionary ParameterTables; + /// Gets or sets the parameter types used to evaluate the code or expression. - public ListDictionary ParameterTypes; + public SharedCache ParameterTypes; /// Gets or sets the parameter values used to evaluate the code or expression. public ListDictionary ParameterValues; + public bool IsFirstCounter = true; + /// Default constructor. public SQLNETItem() { CacheKey = Guid.NewGuid().ToString(); - ParameterTypes = new ListDictionary(); + ParameterTables = new ListDictionary(); + ParameterTypes = new SharedCache(); ParameterValues = new ListDictionary(); + ParallelItems = new SharedBucketList(); + } + + /// Gets the next counter. + /// The next counter. + public int GetNextCountAndAddParallel() + { + try + { + SharedLock.AcquireLock(ref EvalManager.SharedLock.CacheItemLock); + Counter++; + + if (Counter == 0) + { + Counter++; + } + + return Counter; + } + finally + { + SharedLock.ReleaseLock(ref EvalManager.SharedLock.CacheItemLock); + } + } + + public SQLNETParallelItem AddParallelValue(int parallelId) + { + var value = new SQLNETParallelItem + { + ParallelId = parallelId + }; + + ParallelItems.TryAdd(value); + + if (ParameterValues.Count > 0) + { + foreach (DictionaryEntry entry in ParameterValues) + { + value.ParameterValues.Add(entry.Key, entry.Value); + } + } + + return value; + } + + public SQLNETParallelItem GetParallelValue(int parallelId) + { + SQLNETParallelItem value; + if (!ParallelItems.TryGetValue(parallelId, out value)) + { + throw new Exception(ExceptionMessage.GeneralException); + } + + return value; } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/SQLNETItem/SQLNETParallelItem.cs b/src/Z.Expressions.SqlServer.Eval/SQLNETItem/SQLNETParallelItem.cs new file mode 100644 index 0000000..e5130be --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/SQLNETItem/SQLNETParallelItem.cs @@ -0,0 +1,17 @@ +namespace Z.Expressions.SqlServer.Eval +{ + /// A sqlnet parallel item. + public class SQLNETParallelItem + { + public int ParallelId; + + /// Gets or sets the parameter values used to evaluate the code or expression. + public ListDictionary ParameterValues; + + /// Default constructor. + public SQLNETParallelItem() + { + ParameterValues = new ListDictionary(); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/Shared/SharedBucketCache.cs b/src/Z.Expressions.SqlServer.Eval/Shared/SharedBucketCache.cs new file mode 100644 index 0000000..2a2d717 --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/Shared/SharedBucketCache.cs @@ -0,0 +1,97 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Linq; + +namespace Z.Expressions.SqlServer.Eval +{ + // todo: Improve this cache by using the dictionary bucket instead? or at least an algorith based on the length. + public class SharedBuckedCache + { + public SharedCache[] Buckets; + + public SharedBuckedCache(int bucketSize = 100) + { + Buckets = new SharedCache[bucketSize]; + + for (var i = 0; i < bucketSize; i++) + { + Buckets[i] = new SharedCache(); + } + } + + /// Gets the number of items cached. + /// The number of items cached. + public int Count + { + get { return Buckets.Sum(x => x.Count); } + } + + /// Adds or updates a cache value for the specified key. + /// The cache key. + /// The cache value used to add. + /// The cache value factory used to update. + /// The value added or updated in the cache for the specified key. + public TValue AddOrUpdate(TKey key, TValue value, Func updateValueFactory) + { + var bucket = key.GetHashCode()%Buckets.Length; + bucket = bucket < 0 ? -bucket : bucket; + + return Buckets[bucket].AddOrUpdate(key, value, updateValueFactory); + } + + /// Adds or update a cache value for the specified key. + /// The cache key. + /// The cache value factory used to add. + /// The cache value factory used to update. + /// The value added or updated in the cache for the specified key. + public TValue AddOrUpdate(TKey key, Func addValueFactory, Func updateValueFactory) + { + var bucket = key.GetHashCode()%Buckets.Length; + bucket = bucket < 0 ? -bucket : bucket; + + return Buckets[bucket].AddOrUpdate(key, addValueFactory, updateValueFactory); + } + + /// Attempts to add a value in the shared cache for the specified key. + /// The key. + /// The value. + /// true if it succeeds, false if it fails. + public bool TryAdd(TKey key, TValue value) + { + var bucket = key.GetHashCode()%Buckets.Length; + bucket = bucket < 0 ? -bucket : bucket; + + return Buckets[bucket].TryAdd(key, value); + } + + /// Attempts to remove a key from the shared cache. + /// The key. + /// [out] The value. + /// true if it succeeds, false if it fails. + public bool TryRemove(TKey key, out TValue value) + { + var bucket = key.GetHashCode()%Buckets.Length; + bucket = bucket < 0 ? -bucket : bucket; + + return Buckets[bucket].TryRemove(key, out value); + } + + /// Attempts to get value from the shared cache for the specified key. + /// The key. + /// [out] The value. + /// true if it succeeds, false if it fails. + public bool TryGetValue(TKey key, out TValue value) + { + var bucket = key.GetHashCode()%Buckets.Length; + bucket = bucket < 0 ? -bucket : bucket; + + return Buckets[bucket].TryGetValue(key, out value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/Shared/SharedBucketList.cs b/src/Z.Expressions.SqlServer.Eval/Shared/SharedBucketList.cs new file mode 100644 index 0000000..5c3786b --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/Shared/SharedBucketList.cs @@ -0,0 +1,45 @@ +namespace Z.Expressions.SqlServer.Eval +{ + public class SharedBucketList + { + public SharedList[] Buckets; + + public SharedBucketList(int bucketSize = 16) + { + Buckets = new SharedList[bucketSize]; + + for (var i = 0; i < bucketSize; i++) + { + Buckets[i] = new SharedList(); + } + } + + /// Attempts to add a value in the shared cache for the specified key. + /// The value. + /// true if it succeeds, false if it fails. + public bool TryAdd(SQLNETParallelItem value) + { + var bucket = value.ParallelId%Buckets.Length; + bucket = bucket < 0 ? -bucket : bucket; + return Buckets[bucket].TryAdd(value); + } + + public void TryRemove(SQLNETParallelItem value) + { + var bucket = value.ParallelId%Buckets.Length; + bucket = bucket < 0 ? -bucket : bucket; + Buckets[bucket].TryRemove(value); + } + + /// Attempts to get value from the shared cache for the specified key. + /// The key. + /// [out] The value. + /// true if it succeeds, false if it fails. + public bool TryGetValue(int key, out SQLNETParallelItem value) + { + var bucket = key%Buckets.Length; + bucket = bucket < 0 ? -bucket : bucket; + return Buckets[bucket].TryGetValue(key, out value); + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/Shared/SharedCache.cs b/src/Z.Expressions.SqlServer.Eval/Shared/SharedCache.cs index 62dd2ba..1f4bdd4 100644 --- a/src/Z.Expressions.SqlServer.Eval/Shared/SharedCache.cs +++ b/src/Z.Expressions.SqlServer.Eval/Shared/SharedCache.cs @@ -1,3 +1,10 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + using System; using System.Collections.Generic; @@ -172,15 +179,38 @@ public bool TryRemove(TKey key, out TValue value) /// true if it succeeds, false if it fails. public bool TryGetValue(TKey key, out TValue value) { + bool found; try { - return InnerDictionary.TryGetValue(key, out value); + found = InnerDictionary.TryGetValue(key, out value); } - catch (Exception) + catch { value = default(TValue); - return false; + found = false; } + + if (!found) + { + // May happen rarely in concurrency scenario + // We try again but with a lock + try + { + AcquireLock(); + return InnerDictionary.TryGetValue(key, out value); + } + catch (Exception) + { + value = default(TValue); + return false; + } + finally + { + ReleaseLock(); + } + } + + return true; } } } \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/Shared/SharedList.cs b/src/Z.Expressions.SqlServer.Eval/Shared/SharedList.cs new file mode 100644 index 0000000..4f2a98d --- /dev/null +++ b/src/Z.Expressions.SqlServer.Eval/Shared/SharedList.cs @@ -0,0 +1,138 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + +using System; +using System.Collections.Generic; + +namespace Z.Expressions.SqlServer.Eval +{ + public class SharedList + { + /// The lock value. + public int LockValue; + + /// Default constructor. + public SharedList() + { + InnerList = new List(); + } + + /// Gets the number of items cached. + /// The number of items cached. + public int Count + { + get { return InnerList.Count; } + } + + /// Gets or sets the inner dictionary used to cache items. + /// The inner dictionary used to cache items. + public List InnerList; + + /// Acquires the lock on the shared cache. + public void AcquireLock() + { + SharedLock.AcquireLock(ref LockValue); + } + + /// Releases the lock on the shared cache. + public void ReleaseLock() + { + SharedLock.ReleaseLock(ref LockValue); + } + + /// Attempts to add a value in the shared cache for the specified key. + /// The value. + /// true if it succeeds, false if it fails. + public bool TryAdd(SQLNETParallelItem value) + { + try + { + AcquireLock(); + + InnerList.Add(value); + + return true; + } + finally + { + ReleaseLock(); + } + } + + public void TryRemove(SQLNETParallelItem value) + { + try + { + AcquireLock(); + InnerList.Remove(value); + } + finally + { + ReleaseLock(); + } + } + + /// Attempts to get value from the shared cache for the specified key. + /// The key. + /// [out] The value. + /// true if it succeeds, false if it fails. + public bool TryGetValue(int key, out SQLNETParallelItem value) + { + bool found; + + try + { + var count = InnerList.Count; + + for (int i = 0; i < count; i++) + { + if (i < InnerList.Count) + { + value = InnerList[i]; + if (value.ParallelId == key) + { + return true; + } + } + } + + found = false; + value = default(SQLNETParallelItem); + + } + catch + { + // Happen with concurrent remove + value = default(SQLNETParallelItem); + found = false; + } + + if (!found) + { + // May happen rarely in concurrency scenario + // We try again but with a lock + try + { + AcquireLock(); + value = InnerList.Find(x => x.ParallelId == key); + return true; + } + catch (Exception) + { + value = default(SQLNETParallelItem); + return false; + } + finally + { + ReleaseLock(); + } + } + + return true; + } + } +} \ No newline at end of file diff --git a/src/Z.Expressions.SqlServer.Eval/Shared/SharedLock.cs b/src/Z.Expressions.SqlServer.Eval/Shared/SharedLock.cs index 7e6ea7f..61344fb 100644 --- a/src/Z.Expressions.SqlServer.Eval/Shared/SharedLock.cs +++ b/src/Z.Expressions.SqlServer.Eval/Shared/SharedLock.cs @@ -1,3 +1,10 @@ +// Description: Evaluate C# code and expression in T-SQL stored procedure, function and trigger. +// Website & Documentation: https://github.com/zzzprojects/Eval-SQL.NET +// Forum & Issues: https://github.com/zzzprojects/Eval-SQL.NET/issues +// License: https://github.com/zzzprojects/Eval-SQL.NET/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright ZZZ Projects Inc. 2014 - 2016. All rights reserved. + using System.Threading; namespace Z.Expressions.SqlServer.Eval @@ -5,6 +12,9 @@ namespace Z.Expressions.SqlServer.Eval /// A shared lock. public class SharedLock { + /// The counter lock. + public int CacheItemLock = 0; + /// The expire cache lock. public int ExpireCacheLock = 0; diff --git a/src/Z.Expressions.SqlServer.Eval/Z.Expressions.SqlServer.Eval.sqlproj b/src/Z.Expressions.SqlServer.Eval/Z.Expressions.SqlServer.Eval.sqlproj index 2f80a6b..2bbfea1 100644 --- a/src/Z.Expressions.SqlServer.Eval/Z.Expressions.SqlServer.Eval.sqlproj +++ b/src/Z.Expressions.SqlServer.Eval/Z.Expressions.SqlServer.Eval.sqlproj @@ -30,6 +30,8 @@ SAK SAK True + True + True bin\Release\ @@ -88,7 +90,15 @@ - + + + + + + + + + @@ -96,11 +106,10 @@ - + ..\..\..\..\..\OneDrive\Documents\Release\Z.Expressions.Compiler\Z.Expressions.Compiler.dll True True - True @@ -177,6 +186,74 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/version.txt b/src/version.txt new file mode 100644 index 0000000..be38891 --- /dev/null +++ b/src/version.txt @@ -0,0 +1 @@ +v1.1.8