├── .gitignore ├── LICENSE ├── NugetIcon.png ├── Project ├── .nuget │ ├── LambdicSql.nuspec │ └── NuGet.exe ├── LambdicSql.NETStandard │ ├── LambdicSql.NETStandard.csproj │ ├── LambdicSql.NETStandard.snk │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── feat │ │ ├── Dapper │ │ │ └── DapperAdapter.partial.cs │ │ └── EntityFramework │ │ │ ├── EFAdapter.cs │ │ │ └── EFWrapper.cs │ └── project.json ├── LambdicSql.NetFramework.3.5 │ ├── LambdicSql.NetFramework.3.5.csproj │ ├── LambdicSql.snk │ ├── MultiplatformCompatibe │ │ ├── MetaId.cs │ │ └── ReflectionAdapter.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── feat │ │ ├── Dapper │ │ └── DapperAdapter.partial.cs │ │ └── EntityFramework │ │ ├── EFAdapter.cs │ │ └── EFWrapper.cs ├── LambdicSql.NetFramework.4.6 │ ├── LambdicSql.NetFramework.4.6.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ └── StringInterpolator.cs ├── LambdicSql.PCL │ ├── LambdicSql.PCL.csproj │ ├── LambdicSql.PCL.snk │ ├── MultiplatformCompatibe │ │ ├── BuildedSqlExtensionsPCL.cs │ │ ├── MetaId.cs │ │ └── ReflectionAdapter.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── feat │ │ └── SqLiteNetPcl │ │ ├── SqLiteNetPclAdapter.cs │ │ └── SqLiteNetPclWrapper.cs ├── LambdicSql.Shared │ ├── BuildedSql.cs │ ├── BuilderServices │ │ ├── BasicCode │ │ │ ├── Code.cs │ │ │ ├── HCode.cs │ │ │ ├── ICodeCustomizer.cs │ │ │ ├── SingleTextCode.cs │ │ │ ├── StringFormatText.cs │ │ │ └── VCode.cs │ │ ├── BuildingContext.cs │ │ ├── CodeParts │ │ │ ├── AroundCode.cs │ │ │ ├── HCode.cs │ │ │ ├── ICode.cs │ │ │ ├── ICodeCustomizer.cs │ │ │ ├── ITopQueryCode.cs │ │ │ ├── SingleTextCode.cs │ │ │ ├── StringFormatText.cs │ │ │ └── VCode.cs │ │ ├── CustomizeColumnOnly.cs │ │ ├── CustomizeObjectToParameter.cs │ │ ├── CustomizeParameterToDefineName.cs │ │ ├── CustomizeParameterToObject.cs │ │ ├── CustomizeParameterToVariableName.cs │ │ ├── DialectOption.cs │ │ ├── Inside │ │ │ ├── CustomizeParameterValue.cs │ │ │ ├── DialectResolver.cs │ │ │ └── PartsUtils.cs │ │ ├── ParameterInfo.cs │ │ └── TextParts │ │ │ ├── HText.cs │ │ │ ├── ISyntaxCustomizer.cs │ │ │ ├── Inside │ │ │ ├── AliasSyntax.cs │ │ │ ├── CustomizeColumnOnly.cs │ │ │ ├── CustomizeParameterToObject.cs │ │ │ ├── DbColumnSyntax.cs │ │ │ ├── DbTableSyntax.cs │ │ │ ├── ParameterSyntax.cs │ │ │ ├── QuerySyntax.cs │ │ │ ├── SelectClauseSyntax.cs │ │ │ ├── SelectQuerySyntax.cs │ │ │ ├── StringAddOperatorSyntax.cs │ │ │ ├── StringFormatSyntax.cs │ │ │ ├── SyntaxFactoryUtils.cs │ │ │ └── SyntaxUtils.cs │ │ │ ├── SingleTextSyntax.cs │ │ │ ├── StringFormatText.cs │ │ │ ├── TextPartsBase.cs │ │ │ └── VText.cs │ ├── Clause.cs │ ├── Condition.cs │ ├── ConverterServices │ │ ├── ExpressionConverter.cs │ │ ├── Inside │ │ │ ├── CodeParts │ │ │ │ ├── BinaryExpressionCode.cs │ │ │ │ ├── DbColumnCode.cs │ │ │ │ ├── DbSchemaCode.cs │ │ │ │ ├── DbTableCode.cs │ │ │ │ ├── ISqlCode.cs │ │ │ │ ├── ParameterCode.cs │ │ │ │ ├── QueryCode.cs │ │ │ │ ├── SqlCode.cs │ │ │ │ ├── StringAddOperatorCode.cs │ │ │ │ └── TopQuerySqlCode.cs │ │ │ ├── ColumnInfo.cs │ │ │ ├── DBDefineAnalyzer.cs │ │ │ ├── DbInfo.cs │ │ │ ├── DbParamValueOnly.cs │ │ │ ├── ExpressionToObject.CreateGetter.cs │ │ │ ├── ExpressionToObject.Getter.cs │ │ │ ├── ExpressionToObject.cs │ │ │ ├── FormatConverterCore.cs │ │ │ ├── GeneralStyleConverterCore.cs │ │ │ ├── OperatorCode.cs │ │ │ ├── SupportedTypeSpec.cs │ │ │ ├── SymbolHelper.cs │ │ │ ├── TableInfo.cs │ │ │ └── TowWaySqlSpec.cs │ │ ├── InvalitContextException.cs │ │ ├── ObjectCreateAnalyzer.cs │ │ ├── ObjectCreateInfo.cs │ │ ├── ObjectCreateMemberInfo.cs │ │ └── SymbolConverters │ │ │ ├── ClauseStyleConverterAttribute.cs │ │ │ ├── EnumToStringConverterAttribute.cs │ │ │ ├── FieldSqlNameAttribute.cs │ │ │ ├── FormatDirection.cs │ │ │ ├── FuncStyleConverterAttribute.cs │ │ │ ├── MemberConverterAttribute.cs │ │ │ ├── MemberTableConverterAttribute.cs │ │ │ ├── MethodConverterAttribute.cs │ │ │ ├── MethodFormatConverterAttribute.cs │ │ │ ├── NewConverterAttribute.cs │ │ │ ├── NewFormatConverterAttribute.cs │ │ │ └── ObjectConverterAttribute.cs │ ├── Db.cs │ ├── DbDefinitionCustomizerDelegate.cs │ ├── IDbParam.cs │ ├── Inside │ │ └── SqlBuilder.cs │ ├── LambdicSql.Shared.projitems │ ├── LambdicSql.Shared.shproj │ ├── Non.cs │ ├── Specialized │ │ ├── Inside │ │ │ └── CodeParts │ │ │ │ └── StringFormatCode.cs │ │ └── SymbolConverters │ │ │ ├── ConditionConverterAttribute.cs │ │ │ ├── ToSqlConverterAttribute.cs │ │ │ └── TwoWaySqlConverterAttribute.cs │ ├── Sql.cs │ ├── SqlExpression.cs │ ├── UtilitySymbolExtensions.cs │ └── feat │ │ └── NotInitializedException.cs ├── LambdicSql.System.Data.Shared │ ├── DbParam.cs │ ├── LambdicSql.System.Data.Shared.projitems │ ├── LambdicSql.System.Data.Shared.shproj │ ├── MultiplatformCompatibe │ │ └── BuildedSqlExtensions.cs │ └── feat │ │ └── Dapper │ │ ├── DapperAdapter.cs │ │ └── DapperWrapper.cs ├── LambdicSql.sln ├── Performance │ ├── App.config │ ├── Performance.csproj │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── binsample3.db │ └── packages.config ├── Test.NET35 │ ├── Helper │ │ ├── AssertHelper.cs │ │ ├── DB.cs │ │ ├── DBProviderInfo.cs │ │ ├── DataType.cs │ │ ├── HelperForTest.cs │ │ ├── Program.cs │ │ ├── ReflectionAdapter.cs │ │ ├── Symbol.Clauses.cs │ │ ├── Symbol.Etc.cs │ │ ├── Symbol.Funcs.cs │ │ └── TestEnvironment.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Test.NET35.csproj │ ├── TestBrankets.cs │ ├── TestDbDefine.cs │ ├── TestDbParam.cs │ ├── TestExpression.cs │ ├── TestMethodFormatConverter.cs │ ├── TestOperator.cs │ ├── TestParameterName.cs │ ├── TestSymbolSub.cs │ ├── TestUtilitySymbolExtensions.cs │ ├── app.config │ ├── db.txt │ └── packages.config ├── Test.NetCore │ ├── BaseClassTest.cs │ ├── ReflectionAdapter.cs │ ├── Test.NetCore.csproj │ └── TestDbDefineCustomizer.cs ├── Test.PCL │ ├── Helper │ │ ├── DB.cs │ │ ├── HelperForTest.cs │ │ └── TestEnvironment.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Test.PCL.csproj │ ├── Test.cs │ ├── app.config │ └── packages.config └── Test │ ├── App.config │ ├── Helper │ ├── CodeGenerate.cs │ ├── DBProviderInfo.cs │ ├── ReflectionAdapter.cs │ └── TestEnvironment.cs │ ├── Model │ ├── ModelLambdicSqlTestDB.cs │ ├── tbl_data.cs │ ├── tbl_remuneration.cs │ └── tbl_staff.cs │ ├── Params.xlsx │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx │ ├── Resources │ ├── CreateTableDataChange.txt │ ├── CreateTableRemuneration.txt │ ├── CreateTableStaff.txt │ ├── InsertTableRemuneration.txt │ └── InsertTableStaff.sql │ ├── Test.csproj │ ├── Test.csproj.qsx │ ├── TestCondition.cs │ ├── TestDbDefineAttribute.cs │ ├── TestDbDefineCustomizer.cs │ ├── TestEF.cs │ ├── TestInterpolateSql.cs │ ├── checkObj.json │ └── packages.config ├── README.md ├── SummaryCode.png └── lambdicSqlImage.png /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Codeer-Software 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NugetIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Codeer-Software/LambdicSql/99e964011f5848e448127fbc28af2c4bd892e66b/NugetIcon.png -------------------------------------------------------------------------------- /Project/.nuget/LambdicSql.nuspec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Codeer-Software/LambdicSql/99e964011f5848e448127fbc28af2c4bd892e66b/Project/.nuget/LambdicSql.nuspec -------------------------------------------------------------------------------- /Project/.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Codeer-Software/LambdicSql/99e964011f5848e448127fbc28af2c4bd892e66b/Project/.nuget/NuGet.exe -------------------------------------------------------------------------------- /Project/LambdicSql.NETStandard/LambdicSql.NETStandard.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 14.0 6 | Debug 7 | AnyCPU 8 | {5DA46552-0C9E-4692-9686-7B6B1BB5E18E} 9 | Library 10 | Properties 11 | LambdicSql.NETStandard 12 | LambdicSql.NETStandard 13 | ja-JP 14 | 512 15 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 16 | 17 | 18 | v5.0 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | bin\Release\LambdicSql.NETStandard.XML 37 | 38 | 39 | true 40 | 41 | 42 | LambdicSql.NETStandard.snk 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | {485b4c58-0b70-460b-aa20-b2b24af8f0d2} 58 | LambdicSql.PCL 59 | 60 | 61 | 62 | 63 | 70 | -------------------------------------------------------------------------------- /Project/LambdicSql.NETStandard/LambdicSql.NETStandard.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Codeer-Software/LambdicSql/99e964011f5848e448127fbc28af2c4bd892e66b/Project/LambdicSql.NETStandard/LambdicSql.NETStandard.snk -------------------------------------------------------------------------------- /Project/LambdicSql.NETStandard/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Resources; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | [assembly: AssemblyTitle("LambdicSql.NETStandard")] 7 | [assembly: AssemblyDescription("")] 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("LambdicSql.NETStandard")] 11 | [assembly: AssemblyCopyright("Copyright (C) 2017")] 12 | [assembly: AssemblyTrademark("")] 13 | [assembly: AssemblyCulture("")] 14 | [assembly: NeutralResourcesLanguage("ja")] 15 | 16 | [assembly: AssemblyVersion("0.69.0.0")] 17 | [assembly: AssemblyFileVersion("0.69.0.0")] 18 | -------------------------------------------------------------------------------- /Project/LambdicSql.NETStandard/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "supports": {}, 3 | "dependencies": { 4 | "Microsoft.NETCore.Portable.Compatibility": "1.0.1", 5 | "NETStandard.Library": "1.6.1", 6 | "System.Data.Common": "4.3.0" 7 | }, 8 | "frameworks": { 9 | "netstandard1.2": {} 10 | } 11 | } -------------------------------------------------------------------------------- /Project/LambdicSql.NetFramework.3.5/LambdicSql.NetFramework.3.5.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {9079C3C3-839D-4FF1-A774-B7F15DE9248D} 8 | Library 9 | Properties 10 | LambdicSql 11 | LambdicSql.NetFramework.3.5 12 | v3.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | bin\Debug\LambdicSql.NetFramework.3.5.xml 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | bin\Release\LambdicSql.NetFramework.3.5.xml 34 | 35 | 36 | true 37 | 38 | 39 | LambdicSql.snk 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 72 | -------------------------------------------------------------------------------- /Project/LambdicSql.NetFramework.3.5/LambdicSql.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Codeer-Software/LambdicSql/99e964011f5848e448127fbc28af2c4bd892e66b/Project/LambdicSql.NetFramework.3.5/LambdicSql.snk -------------------------------------------------------------------------------- /Project/LambdicSql.NetFramework.3.5/MultiplatformCompatibe/MetaId.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace LambdicSql.ConverterServices.Inside 5 | { 6 | class MetaId 7 | { 8 | MemberInfo _member; 9 | Type _declaringType; 10 | readonly int _memberToken; 11 | 12 | public MetaId(MemberInfo member) 13 | { 14 | _member = member; 15 | _declaringType = member.DeclaringType; 16 | _memberToken = member.MetadataToken; 17 | } 18 | 19 | public override bool Equals(object obj) 20 | { 21 | var target = obj as MetaId; 22 | if (target == null) return false; 23 | if (ReferenceEquals(_member, target._member)) return true; 24 | if (_memberToken != target._memberToken) return false; 25 | return _memberToken == target._memberToken && _declaringType == target._declaringType; 26 | } 27 | 28 | public override int GetHashCode() => _memberToken; 29 | 30 | public static bool operator == (MetaId lhs, MetaId rhs) 31 | { 32 | if (lhs is null && rhs is null) return true; 33 | if (lhs is null || rhs is null) return false; 34 | return lhs._memberToken == rhs._memberToken && lhs._declaringType == rhs._declaringType; 35 | } 36 | 37 | public static bool operator != (MetaId lhs, MetaId rhs) => !(lhs == rhs); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Project/LambdicSql.NetFramework.3.5/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyTitle("LambdicSql.NetFramework.3.5")] 5 | [assembly: AssemblyDescription("")] 6 | [assembly: AssemblyConfiguration("")] 7 | [assembly: AssemblyCompany("")] 8 | [assembly: AssemblyProduct("LambdicSql.NetFramework.3.5")] 9 | [assembly: AssemblyCopyright("Copyright © 2016")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | [assembly: ComVisible(false)] 14 | 15 | [assembly: Guid("9079c3c3-839d-4ff1-a774-b7f15de9248d")] 16 | 17 | [assembly: AssemblyVersion("0.69.0.0")] 18 | [assembly: AssemblyFileVersion("0.69.0.0")] 19 | [assembly: System.CLSCompliant(true)] -------------------------------------------------------------------------------- /Project/LambdicSql.NetFramework.3.5/feat/Dapper/DapperAdapter.partial.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.feat.Dapper 2 | { 3 | public static partial class DapperAdapter 4 | { 5 | const string AssemblyInitializeComment = "DapperAdapter.Assembly = typeof(Dapper.SqlMapper).Assembly;"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Project/LambdicSql.NetFramework.4.6/LambdicSql.NetFramework.4.6.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {59E0E08F-28B7-4093-8F44-78932707D8E8} 8 | Library 9 | Properties 10 | LambdicSql 11 | LambdicSql.NetFramework.4.6 12 | v4.6 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | bin\Release\LambdicSql.NetFramework.4.6.xml 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | {9079c3c3-839d-4ff1-a774-b7f15de9248d} 50 | LambdicSql.NetFramework.3.5 51 | 52 | 53 | 54 | 55 | if $(ConfigurationName) == Release "../../../.nuget/nuget" pack "../../../.nuget/LambdicSql.nuspec" 56 | 57 | 58 | -------------------------------------------------------------------------------- /Project/LambdicSql.NetFramework.4.6/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyTitle("LambdicSql.NetFramework.4.6")] 5 | [assembly: AssemblyDescription("")] 6 | [assembly: AssemblyConfiguration("")] 7 | [assembly: AssemblyCompany("")] 8 | [assembly: AssemblyProduct("LambdicSql.NetFramework.4.6")] 9 | [assembly: AssemblyCopyright("Copyright © 2017")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | [assembly: ComVisible(false)] 14 | 15 | [assembly: Guid("59e0e08f-28b7-4093-8f44-78932707d8e8")] 16 | 17 | [assembly: AssemblyVersion("0.69.0.0")] 18 | [assembly: AssemblyFileVersion("0.69.0.0")] 19 | [assembly: System.CLSCompliant(true)] 20 | -------------------------------------------------------------------------------- /Project/LambdicSql.NetFramework.4.6/StringInterpolator.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.ConverterServices; 3 | using LambdicSql.ConverterServices.Inside; 4 | using LambdicSql.ConverterServices.Inside.CodeParts; 5 | using LambdicSql.Inside.CodeParts; 6 | using System; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | 10 | namespace LambdicSql 11 | { 12 | /// 13 | /// StringInterpolator. 14 | /// 15 | /// DB's type. 16 | public class StringInterpolator where T : class 17 | { 18 | /// 19 | /// Create sql from FormattableString. 20 | /// 21 | /// Expression expressing Sql by lambda. 22 | /// Sql. 23 | public static Sql Sql(Expression> expression) 24 | => Inside.SqlBuilder.FromExpressionContainFormattableString(expression.Body); 25 | 26 | /// 27 | /// Create sql from FormattableString. 28 | /// 29 | /// The type represented by expression. 30 | /// Expression expressing Sql by lambda. 31 | /// Sql. 32 | public static Sql Sql(Expression> expression) 33 | => Inside.SqlBuilder.FromExpressionContainFormattableString(expression.Body); 34 | } 35 | 36 | /// 37 | /// StringInterpolator. 38 | /// 39 | public class StringInterpolator 40 | { 41 | /// 42 | /// Create sql from FormattableString. 43 | /// 44 | /// formattable string. 45 | /// Sql. 46 | public static Sql Sql(FormattableString formattableString) 47 | => Inside.SqlBuilder.FromFormattableString(formattableString.Format, formattableString.GetArguments()); 48 | 49 | /// 50 | /// Create sql from FormattableString. 51 | /// 52 | /// The type represented by expression. 53 | /// formattable string. 54 | /// Sql. 55 | public static Sql Sql(FormattableString formattableString) 56 | => Inside.SqlBuilder.FromFormattableString(formattableString.Format, formattableString.GetArguments()); 57 | 58 | /// 59 | /// Create sql from FormattableString. 60 | /// 61 | /// Expression expressing Sql by lambda. 62 | /// Sql. 63 | public static Sql Sql(Expression> expression) 64 | => Inside.SqlBuilder.FromExpressionContainFormattableString(expression.Body); 65 | 66 | /// 67 | /// Create sql from FormattableString. 68 | /// 69 | /// The type represented by expression. 70 | /// Expression expressing Sql by lambda. 71 | /// Sql. 72 | public static Sql Sql(Expression> expression) 73 | => Inside.SqlBuilder.FromExpressionContainFormattableString(expression.Body); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Project/LambdicSql.PCL/LambdicSql.PCL.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 10.0 6 | Debug 7 | AnyCPU 8 | {485B4C58-0B70-460B-AA20-B2B24AF8F0D2} 9 | Library 10 | Properties 11 | LambdicSql 12 | LambdicSql.PCL 13 | ja-JP 14 | 512 15 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 16 | Profile7 17 | v4.5 18 | 19 | 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | bin\Release\LambdicSql.PCL.XML 36 | 37 | 38 | true 39 | 40 | 41 | LambdicSql.PCL.snk 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /Project/LambdicSql.PCL/LambdicSql.PCL.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Codeer-Software/LambdicSql/99e964011f5848e448127fbc28af2c4bd892e66b/Project/LambdicSql.PCL/LambdicSql.PCL.snk -------------------------------------------------------------------------------- /Project/LambdicSql.PCL/MultiplatformCompatibe/BuildedSqlExtensionsPCL.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace LambdicSql 6 | { 7 | /// 8 | /// Extensions for BuildedSql. 9 | /// 10 | public static class BuildedSqlExtensionsPCL 11 | { 12 | /// 13 | /// Get parameters. 14 | /// 15 | /// BuildedSql. 16 | /// Parameters. 17 | public static object[] GetParamValues(this BuildedSql sql) 18 | { 19 | var tokens = sql.Text.Split(new char[] { ' ', ',', '(', ')', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToList(); 20 | return sql.GetParams(e => e.Value).Select(e => new { Index = tokens.IndexOfCheck(e.Key), Value = e.Value }).OrderBy(e => e.Index).Select(e => e.Value).ToArray(); 21 | } 22 | 23 | static int IndexOfCheck(this List target, string value) 24 | { 25 | var index = target.IndexOf(value); 26 | if (index == -1) throw new NotSupportedException(); 27 | return index; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Project/LambdicSql.PCL/MultiplatformCompatibe/MetaId.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace LambdicSql.ConverterServices.Inside 4 | { 5 | class MetaId 6 | { 7 | MemberInfo _member; 8 | int _hash; 9 | 10 | public MetaId(MemberInfo member) 11 | { 12 | _member = member; 13 | _hash = member.GetHashCode(); 14 | } 15 | 16 | public override bool Equals(object obj) 17 | { 18 | var target = obj as MetaId; 19 | if (target == null) return false; 20 | if (ReferenceEquals(_member, target._member)) return true; 21 | return _member.Equals(target._member); 22 | } 23 | 24 | public override int GetHashCode() => _hash; 25 | 26 | public static bool operator == (MetaId lhs, MetaId rhs) 27 | { 28 | if (ReferenceEquals(lhs, null) && ReferenceEquals(rhs, null)) return true; 29 | if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null)) return false; 30 | if (ReferenceEquals(lhs._member, rhs._member)) return true; 31 | return lhs._member.Equals(rhs._member); 32 | } 33 | 34 | public static bool operator != (MetaId lhs, MetaId rhs) => !(lhs == rhs); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Project/LambdicSql.PCL/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Resources; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | [assembly: AssemblyTitle("LambdicSql.PCL")] 7 | [assembly: AssemblyDescription("")] 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("LambdicSql.PCL")] 11 | [assembly: AssemblyCopyright("Copyright (C) 2017")] 12 | [assembly: AssemblyTrademark("")] 13 | [assembly: AssemblyCulture("")] 14 | [assembly: NeutralResourcesLanguage("ja")] 15 | 16 | [assembly: AssemblyVersion("0.69.0.0")] 17 | [assembly: AssemblyFileVersion("0.69.0.0")] 18 | -------------------------------------------------------------------------------- /Project/LambdicSql.PCL/feat/SqLiteNetPcl/SqLiteNetPclWrapper.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq.Expressions; 3 | 4 | namespace LambdicSql.feat.SQLiteNetPcl 5 | { 6 | static class SQLiteNetPclWrapper 7 | { 8 | internal static object _sync = new object(); 9 | internal delegate int ExecuteDelegate(object cnn, string sql, object[] arguments); 10 | static ExecuteDelegate Execute; 11 | 12 | internal static ExecuteDelegate GetExecute(object obj) 13 | { 14 | lock (_sync) 15 | { 16 | if (Execute != null) return Execute; 17 | 18 | var sqlLiteConnectionType = obj.GetType(); 19 | 20 | var cnn = Expression.Parameter(typeof(object), "cnn"); 21 | var sql = Expression.Parameter(typeof(string), "sql"); 22 | var arguments = Expression.Parameter(typeof(object[]), "arguments"); 23 | 24 | Execute = Expression.Lambda( 25 | Expression.Call(Expression.Convert(cnn, sqlLiteConnectionType), "Execute", null, new[] { sql, arguments }), 26 | new[] { cnn, sql, arguments } 27 | ).Compile(); 28 | 29 | return Execute; 30 | } 31 | } 32 | } 33 | 34 | static class SQLiteNetPclWrapper 35 | { 36 | internal static object _sync = new object(); 37 | internal delegate List QueryDelegate(object cnn, string query, params object[] args); 38 | internal static QueryDelegate Query; 39 | 40 | internal static QueryDelegate GetQuery(object obj) 41 | { 42 | lock (_sync) 43 | { 44 | if (Query != null) return Query; 45 | 46 | var sqlLiteConnectionType = obj.GetType(); 47 | 48 | var cnn = Expression.Parameter(typeof(object), "cnn"); 49 | var sql = Expression.Parameter(typeof(string), "sql"); 50 | var arguments = Expression.Parameter(typeof(object[]), "arguments"); 51 | 52 | Query = Expression.Lambda( 53 | Expression.Call(Expression.Convert(cnn, sqlLiteConnectionType), "Query", new[] { typeof(T) }, new[] { sql, arguments }), 54 | new[] { cnn, sql, arguments } 55 | ).Compile(); 56 | 57 | return Query; 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuildedSql.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace LambdicSql 6 | { 7 | /// 8 | /// SQL text and parameters. 9 | /// 10 | public class BuildedSql 11 | { 12 | //Don't change name. 13 | Dictionary DbParams { get; } 14 | 15 | /// 16 | /// Sql text. 17 | /// 18 | public string Text { get; } 19 | 20 | /// 21 | /// Get parameters. 22 | /// 23 | /// Converted type. 24 | /// Converter. 25 | /// Parameters. 26 | public Dictionary GetParams(Func converter) => DbParams.ToDictionary(e => e.Key, e => converter(e.Value)); 27 | 28 | /// 29 | /// Constructor. 30 | /// 31 | /// Sql text. 32 | /// Parameters. 33 | internal BuildedSql(string sqlText, Dictionary dbParams) 34 | { 35 | Text = sqlText; 36 | DbParams = dbParams; 37 | } 38 | 39 | /// 40 | /// Copy constructor. 41 | /// 42 | /// Source. 43 | internal BuildedSql(BuildedSql src) 44 | { 45 | Text = src.Text; 46 | DbParams = src.DbParams; 47 | } 48 | 49 | /// 50 | /// Change parameters. 51 | /// 52 | /// New values. 53 | /// BuildingSql after change. 54 | public BuildedSql ChangeParams(Dictionary values) 55 | => new BuildedSql(Text, DbParams.ToDictionary(e => e.Key, e => 56 | { 57 | object val; 58 | return values.TryGetValue(e.Key, out val) ? 59 | e.Value.ChangeValue(val) : e.Value; 60 | })); 61 | } 62 | 63 | /// 64 | /// SQL text and parameters. 65 | /// 66 | /// Type of selected at SELECT clause. 67 | public class BuildedSql : BuildedSql 68 | { 69 | /// 70 | /// Constructor. 71 | /// 72 | /// Sql text. 73 | /// Parameters. 74 | internal BuildedSql(string sqlText, Dictionary dbParams) 75 | : base(sqlText, dbParams) { } 76 | 77 | /// 78 | /// Constructor. 79 | /// 80 | /// Source. 81 | internal BuildedSql(BuildedSql src) : base(src) { } 82 | 83 | /// 84 | /// Change parameters. 85 | /// 86 | /// New values. 87 | /// BuildingSql after change. 88 | public new BuildedSql ChangeParams(Dictionary values) 89 | => new BuildedSql(base.ChangeParams(values)); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/BasicCode/Code.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.BasicCode 2 | { 3 | /// 4 | /// Sql code. 5 | /// 6 | public abstract class Code 7 | { 8 | /// 9 | /// Is empty. 10 | /// 11 | public abstract bool IsEmpty { get; } 12 | 13 | /// 14 | /// Is single line. 15 | /// 16 | public abstract bool IsSingleLine(BuildingContext context); 17 | 18 | /// 19 | /// To string. 20 | /// 21 | /// Is top level. 22 | /// Indent. 23 | /// Context. 24 | /// Text. 25 | public abstract string ToString(bool isTopLevel, int indent, BuildingContext context); 26 | 27 | /// 28 | /// Concat to front and back. 29 | /// 30 | /// Front. 31 | /// Back. 32 | /// Text. 33 | public abstract Code ConcatAround(string front, string back); 34 | 35 | /// 36 | /// Concat to front. 37 | /// 38 | /// Front. 39 | /// Text. 40 | public abstract Code ConcatToFront(string front); 41 | 42 | /// 43 | /// Concat to back. 44 | /// 45 | /// 46 | /// 47 | public abstract Code ConcatToBack(string back); 48 | 49 | /// 50 | /// Customize. 51 | /// 52 | /// Customizer. 53 | /// Customized SqlText. 54 | public abstract Code Customize(ICodeCustomizer customizer); 55 | 56 | /// 57 | /// Convert string to IText. 58 | /// 59 | /// string. 60 | public static implicit operator Code(string text) => new SingleTextCode(text); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/BasicCode/ICodeCustomizer.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.BasicCode 2 | { 3 | /// 4 | /// Customizer. 5 | /// 6 | public interface ICodeCustomizer 7 | { 8 | /// 9 | /// Coustom. 10 | /// 11 | /// Source. 12 | /// Result. 13 | Code Custom(Code src); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/BasicCode/SingleTextCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.Inside; 2 | 3 | namespace LambdicSql.BuilderServices.BasicCode 4 | { 5 | /// 6 | /// Single text. 7 | /// 8 | public class SingleTextCode : Code 9 | { 10 | string _text; 11 | int _indent; 12 | 13 | /// 14 | /// Constructor. 15 | /// 16 | /// Text. 17 | public SingleTextCode(string text) 18 | { 19 | _text = text; 20 | } 21 | 22 | /// 23 | /// Constructor. 24 | /// 25 | /// Text. 26 | /// Indent. 27 | public SingleTextCode(string text, int indent) 28 | { 29 | _text = text; 30 | _indent = indent; 31 | } 32 | 33 | /// 34 | /// Is single line. 35 | /// 36 | public override bool IsSingleLine(BuildingContext context) => true; 37 | 38 | /// 39 | /// Is empty. 40 | /// 41 | public override bool IsEmpty => string.IsNullOrEmpty(_text); 42 | 43 | /// 44 | /// To string. 45 | /// 46 | /// Is top level. 47 | /// Indent. 48 | /// Context. 49 | /// Text. 50 | public override string ToString(bool isTopLevel, int indent, BuildingContext context) => PartsUtils.GetIndent(_indent + indent) + _text; 51 | 52 | /// 53 | /// Concat to front and back. 54 | /// 55 | /// Front. 56 | /// Back. 57 | /// Text. 58 | public override Code ConcatAround(string front, string back) => new SingleTextCode(front + _text + back, _indent); 59 | 60 | /// 61 | /// Concat to front. 62 | /// 63 | /// Front. 64 | /// Text. 65 | public override Code ConcatToFront(string front) => new SingleTextCode(front + _text, _indent); 66 | 67 | /// 68 | /// Concat to back. 69 | /// 70 | /// 71 | /// 72 | public override Code ConcatToBack(string back) => new SingleTextCode(_text + back, _indent); 73 | 74 | /// 75 | /// Customize. 76 | /// 77 | /// Customizer. 78 | /// Customized SqlText. 79 | public override Code Customize(ICodeCustomizer customizer) => customizer.Custom(this); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/BasicCode/StringFormatText.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace LambdicSql.SqlBase.TextParts 7 | { 8 | class StringFormatText : ExpressionElement 9 | { 10 | string _formatText; 11 | ExpressionElement[] _args; 12 | string _front = string.Empty; 13 | string _back = string.Empty; 14 | 15 | 16 | internal StringFormatText(string formatText, ExpressionElement[] args) 17 | { 18 | _formatText = formatText; 19 | _args = args; 20 | } 21 | 22 | StringFormatText(string formatText, ExpressionElement[] args, string front, string back) 23 | { 24 | _formatText = formatText; 25 | _args = args; 26 | _front = front; 27 | _back = back; 28 | } 29 | 30 | public override bool IsSingleLine(ExpressionConvertingContext context) => true; 31 | 32 | public override bool IsEmpty => false; 33 | 34 | public override string ToString(bool isTopLevel, int indent, ExpressionConvertingContext context) 35 | => string.Join(string.Empty, Enumerable.Range(0, indent).Select(e => "\t").ToArray()) + 36 | _front + 37 | string.Format(_formatText, _args.Select(e => e.ToString(true, 0, context)).ToArray()) + 38 | _back; 39 | 40 | public override ExpressionElement ConcatAround(string front, string back) 41 | => new StringFormatText(_formatText, _args, front + _front, _back + back); 42 | 43 | public override ExpressionElement ConcatToFront(string front) 44 | => new StringFormatText(_formatText, _args, front + _front, _back); 45 | 46 | public override ExpressionElement ConcatToBack(string back) 47 | => new StringFormatText(_formatText, _args, _front, _back + back); 48 | 49 | public override ExpressionElement Customize(ISqlTextCustomizer customizer) 50 | => customizer.Custom(this); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/BuildingContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace LambdicSql.BuilderServices 5 | { 6 | /// 7 | /// Context of SQL building. 8 | /// 9 | public class BuildingContext 10 | { 11 | /// 12 | /// Is it a top-level query? 13 | /// 14 | public bool IsTopLevelQuery { get; } = true; 15 | 16 | /// 17 | /// Indent. 18 | /// 19 | public int Indent { get; } 20 | 21 | /// 22 | /// Options for resolving dialects per database. 23 | /// 24 | public DialectOption DialectOption { get; } 25 | 26 | /// 27 | /// Parameter info. 28 | /// 29 | public ParameterInfo ParameterInfo { get; } 30 | 31 | /// 32 | /// Data that users set up and use when building SQL. 33 | /// 34 | public Dictionary UserData { get; } = new Dictionary(); 35 | 36 | /// 37 | /// Generate clone with indent changed. 38 | /// 39 | /// 40 | /// 41 | public BuildingContext ChangeIndent(int indent) => new BuildingContext(IsTopLevelQuery, indent, DialectOption, ParameterInfo, UserData); 42 | 43 | /// 44 | /// Generate clone with changed top level flag. 45 | /// 46 | /// 47 | public BuildingContext ChangeTopLevelQuery(bool isTopLevelQuery) => new BuildingContext(isTopLevelQuery, Indent, DialectOption, ParameterInfo, UserData); 48 | 49 | internal BuildingContext(DialectOption dialectOption) 50 | { 51 | DialectOption = dialectOption; 52 | ParameterInfo = new ParameterInfo(dialectOption.ParameterPrefix); 53 | } 54 | 55 | BuildingContext(bool isTopLevel, int indent, DialectOption dialectOption, ParameterInfo parameterInfo, Dictionary userData) 56 | { 57 | IsTopLevelQuery = isTopLevel; 58 | Indent = indent; 59 | DialectOption = dialectOption; 60 | ParameterInfo = parameterInfo; 61 | UserData = userData; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/CodeParts/AroundCode.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.CodeParts 2 | { 3 | /// 4 | /// Enclose the central code. 5 | /// 6 | public class AroundCode : ICode 7 | { 8 | ICode _center; 9 | string _front = string.Empty; 10 | string _back = string.Empty; 11 | 12 | /// 13 | /// Constructor. 14 | /// 15 | /// Central code. 16 | /// Front code. 17 | /// Back code. 18 | public AroundCode(ICode center, string front, string back) 19 | { 20 | _center = center; 21 | _front = front; 22 | _back = back; 23 | } 24 | 25 | /// 26 | /// Is empty. 27 | /// 28 | public bool IsEmpty => _center.IsEmpty && string.IsNullOrEmpty(_front) && string.IsNullOrEmpty(_back); 29 | 30 | /// 31 | /// Is single line. 32 | /// 33 | /// Context. 34 | /// Is single line. 35 | public bool IsSingleLine(BuildingContext context) => _center.IsSingleLine(context); 36 | 37 | /// 38 | /// To string. 39 | /// 40 | /// Context. 41 | /// Text. 42 | public string ToString(BuildingContext context) 43 | { 44 | var conterText = _center.ToString(context); 45 | 46 | int index = FindNotEmptyIndex(conterText); 47 | 48 | if (index == 0) 49 | { 50 | return _front + conterText + _back; 51 | } 52 | return conterText.Substring(0, index) + _front + conterText.Substring(index) + _back; 53 | } 54 | 55 | /// 56 | /// Accept customizer. 57 | /// 58 | /// Customizer. 59 | /// Destination. 60 | public ICode Accept(ICodeCustomizer customizer) 61 | { 62 | var dst = customizer.Visit(this); 63 | if (!ReferenceEquals(this, dst)) return dst; 64 | return new AroundCode(_center.Accept(customizer), _front, _back); 65 | } 66 | 67 | static int FindNotEmptyIndex(string conterText) 68 | { 69 | int index = 0; 70 | for (index = 0; index < conterText.Length; index++) 71 | { 72 | switch (conterText[index]) 73 | { 74 | case ' ': 75 | case '\t': 76 | continue; 77 | default: 78 | break; 79 | } 80 | break; 81 | } 82 | return index; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/CodeParts/ICode.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.CodeParts 2 | { 3 | /// 4 | /// Sql code. 5 | /// 6 | public interface ICode 7 | { 8 | /// 9 | /// Is empty. 10 | /// 11 | bool IsEmpty { get; } 12 | 13 | /// 14 | /// Is single line. 15 | /// 16 | /// Context. 17 | /// Is single line. 18 | bool IsSingleLine(BuildingContext context); 19 | 20 | /// 21 | /// To string. 22 | /// 23 | /// Context. 24 | /// Text. 25 | string ToString(BuildingContext context); 26 | 27 | /// 28 | /// Accept customizer. 29 | /// 30 | /// Customizer. 31 | /// Customized SqlText. 32 | ICode Accept(ICodeCustomizer customizer); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/CodeParts/ICodeCustomizer.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.CodeParts 2 | { 3 | /// 4 | /// Customizer. 5 | /// 6 | public interface ICodeCustomizer 7 | { 8 | /// 9 | /// Visit and customize. 10 | /// 11 | /// Source. 12 | /// Destination. 13 | ICode Visit(ICode src); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/CodeParts/ITopQueryCode.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.CodeParts 2 | { 3 | /// 4 | /// Code with select clause at the beginning. The select clause is special and needs to be distinguished from others. 5 | /// 6 | public interface ITopQueryCode : ICode 7 | { 8 | /// 9 | /// Code. 10 | /// 11 | ICode Core { get; } 12 | 13 | /// 14 | /// Create ISelectQueryCode. 15 | /// 16 | /// Code. 17 | /// ISelectQueryCode. 18 | ITopQueryCode Create(ICode core); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/CodeParts/SingleTextCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.Inside; 2 | 3 | namespace LambdicSql.BuilderServices.CodeParts 4 | { 5 | /// 6 | /// Single text code. 7 | /// 8 | public class SingleTextCode : ICode 9 | { 10 | string _text; 11 | int _indent; 12 | 13 | /// 14 | /// Constructor. 15 | /// 16 | /// Text. 17 | public SingleTextCode(string text) 18 | { 19 | _text = text; 20 | } 21 | 22 | /// 23 | /// Constructor. 24 | /// 25 | /// Text. 26 | /// Indent. 27 | public SingleTextCode(string text, int indent) 28 | { 29 | _text = text; 30 | _indent = indent; 31 | } 32 | 33 | /// 34 | /// Is empty. 35 | /// 36 | public bool IsEmpty => string.IsNullOrEmpty(_text); 37 | 38 | /// 39 | /// To string. 40 | /// 41 | /// Context. 42 | /// Text. 43 | public string ToString(BuildingContext context) => PartsUtils.GetIndent(_indent + context.Indent) + _text; 44 | 45 | /// 46 | /// Accept customizer. 47 | /// 48 | /// Customizer. 49 | /// Destination. 50 | public ICode Accept(ICodeCustomizer customizer) => customizer.Visit(this); 51 | 52 | /// 53 | /// Is single line. 54 | /// 55 | public bool IsSingleLine(BuildingContext context) => true; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/CodeParts/StringFormatText.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace LambdicSql.SqlBase.TextParts 7 | { 8 | class StringFormatText : ExpressionElement 9 | { 10 | string _formatText; 11 | ExpressionElement[] _args; 12 | string _front = string.Empty; 13 | string _back = string.Empty; 14 | 15 | 16 | internal StringFormatText(string formatText, ExpressionElement[] args) 17 | { 18 | _formatText = formatText; 19 | _args = args; 20 | } 21 | 22 | StringFormatText(string formatText, ExpressionElement[] args, string front, string back) 23 | { 24 | _formatText = formatText; 25 | _args = args; 26 | _front = front; 27 | _back = back; 28 | } 29 | 30 | public override bool IsSingleLine(ExpressionConvertingContext context) => true; 31 | 32 | public override bool IsEmpty => false; 33 | 34 | public override string ToString(bool isTopLevel, int indent, ExpressionConvertingContext context) 35 | => string.Join(string.Empty, Enumerable.Range(0, indent).Select(e => "\t").ToArray()) + 36 | _front + 37 | string.Format(_formatText, _args.Select(e => e.ToString(true, 0, context)).ToArray()) + 38 | _back; 39 | 40 | public override ExpressionElement ConcatAround(string front, string back) 41 | => new StringFormatText(_formatText, _args, front + _front, _back + back); 42 | 43 | public override ExpressionElement ConcatToFront(string front) 44 | => new StringFormatText(_formatText, _args, front + _front, _back); 45 | 46 | public override ExpressionElement ConcatToBack(string back) 47 | => new StringFormatText(_formatText, _args, _front, _back + back); 48 | 49 | public override ExpressionElement Customize(ISqlTextCustomizer customizer) 50 | => customizer.Custom(this); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/CustomizeColumnOnly.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.ConverterServices.Inside.CodeParts; 3 | 4 | namespace LambdicSql.BuilderServices 5 | { 6 | /// 7 | /// Change only column name without table name. 8 | /// 9 | public class CustomizeColumnOnly : ICodeCustomizer 10 | { 11 | /// 12 | /// Visit and customize. 13 | /// 14 | /// Source. 15 | /// Destination. 16 | public ICode Visit(ICode src) 17 | { 18 | var col = src as DbColumnCode; 19 | return col == null ? src : col.ToColumnOnly(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/CustomizeObjectToParameter.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.ConverterServices.Inside.CodeParts; 3 | 4 | namespace LambdicSql.BuilderServices 5 | { 6 | /// 7 | /// Change object to paramter in SQL. 8 | /// 9 | public class CustomizeObjectToParameter : ICodeCustomizer 10 | { 11 | /// 12 | /// Visit and customize. 13 | /// 14 | /// Source. 15 | /// Destination. 16 | public ICode Visit(ICode src) 17 | { 18 | var schema = src as DbSchemaCode; 19 | if (schema != null) 20 | { 21 | return new ParameterCode(schema.Text); 22 | } 23 | 24 | var table = src as DbTableCode; 25 | if (table != null) 26 | { 27 | return new ParameterCode(table.Info.SqlFullName); 28 | } 29 | var col = src as DbColumnCode; 30 | if (col != null) 31 | { 32 | return new ParameterCode(col.ColumnName); 33 | } 34 | return src; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/CustomizeParameterToDefineName.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.BuilderServices.Inside; 3 | using LambdicSql.ConverterServices.Inside.CodeParts; 4 | 5 | namespace LambdicSql.BuilderServices 6 | { 7 | /// 8 | /// Change parameters to define name in SQL. 9 | /// 10 | public class CustomizeParameterToDefineName : ICodeCustomizer 11 | { 12 | class DefineNameCode : ICode 13 | { 14 | string _name; 15 | 16 | internal DefineNameCode(string name) 17 | { 18 | _name = name; 19 | } 20 | 21 | public bool IsEmpty { get; } 22 | public bool IsSingleLine(BuildingContext context) => true; 23 | public string ToString(BuildingContext context) => PartsUtils.GetIndent(context.Indent) + _name; 24 | public ICode Accept(ICodeCustomizer customizer) => customizer.Visit(this); 25 | } 26 | 27 | /// 28 | /// Visit and customize. 29 | /// 30 | /// Source. 31 | /// Destination. 32 | public ICode Visit(ICode src) 33 | { 34 | var param = src as ParameterCode; 35 | return param == null ? src : new DefineNameCode((string)param.Value); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/CustomizeParameterToObject.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.ConverterServices.Inside.CodeParts; 3 | 4 | namespace LambdicSql.BuilderServices 5 | { 6 | /// 7 | /// Change parameters to embed directly in SQL. 8 | /// 9 | public class CustomizeParameterToObject : ICodeCustomizer 10 | { 11 | /// 12 | /// Visit and customize. 13 | /// 14 | /// Source. 15 | /// Destination. 16 | public ICode Visit(ICode src) 17 | { 18 | var param = src as ParameterCode; 19 | return param == null ? src : param.ToDisplayValue(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/CustomizeParameterToVariableName.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.BuilderServices.Inside; 3 | using LambdicSql.ConverterServices.Inside.CodeParts; 4 | 5 | namespace LambdicSql.BuilderServices 6 | { 7 | /// 8 | /// Change parameters to define name in SQL. 9 | /// 10 | public class CustomizeParameterToVariableName : ICodeCustomizer 11 | { 12 | class VariableNameCode : ICode 13 | { 14 | string _name; 15 | 16 | internal VariableNameCode(string name) 17 | { 18 | _name = name; 19 | } 20 | 21 | public bool IsEmpty { get; } 22 | public bool IsSingleLine(BuildingContext context) => true; 23 | public string ToString(BuildingContext context) => PartsUtils.GetIndent(context.Indent) + _name; 24 | public ICode Accept(ICodeCustomizer customizer) => customizer.Visit(this); 25 | } 26 | 27 | /// 28 | /// Visit and customize. 29 | /// 30 | /// Source. 31 | /// Destination. 32 | public ICode Visit(ICode src) 33 | { 34 | var param = src as ParameterCode; 35 | if (param == null) return src; 36 | if (param.MetaId == null) return src; 37 | return new VariableNameCode((string)param.Name); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/DialectOption.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices 2 | { 3 | /// 4 | /// Option of to convert expression to sql text. 5 | /// 6 | public class DialectOption 7 | { 8 | string _stringAddOperator = " + "; 9 | 10 | /// 11 | /// Connection's type fullName. 12 | /// 13 | public string ConnectionTypeFullName { get; set; } 14 | 15 | /// 16 | /// String addtional operator. 17 | /// Default is +. 18 | /// 19 | public string StringAddOperator 20 | { 21 | get 22 | { 23 | return _stringAddOperator; 24 | } 25 | set 26 | { 27 | _stringAddOperator = " " + value.Trim() + " "; 28 | } 29 | } 30 | 31 | /// 32 | /// Parameter prefix. 33 | /// Defualt is @. 34 | /// 35 | public string ParameterPrefix { get; set; } = "@"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/Inside/CustomizeParameterValue.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.ConverterServices.Inside.CodeParts; 3 | using System.Collections.Generic; 4 | 5 | namespace LambdicSql.BuilderServices.Inside 6 | { 7 | class CustomizeParameterValue : ICodeCustomizer 8 | { 9 | Dictionary _values; 10 | 11 | internal CustomizeParameterValue(Dictionary values) 12 | { 13 | _values = values; 14 | } 15 | 16 | public ICode Visit(ICode src) 17 | { 18 | var param = src as ParameterCode; 19 | if (param == null) return src; 20 | 21 | object val; 22 | if (!_values.TryGetValue(param.Name, out val)) return src; 23 | 24 | return new ParameterCode(param.Name, param.MetaId, param.Param.ChangeValue(val)); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/Inside/DialectResolver.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.Inside 2 | { 3 | //TODO insert by ohter libs. 4 | static class DialectResolver 5 | { 6 | internal static DialectOption CreateCustomizer(string connectionTypeFullName) 7 | { 8 | switch (connectionTypeFullName) 9 | { 10 | case "Npgsql.NpgsqlConnection": 11 | return new DialectOption() { ConnectionTypeFullName = connectionTypeFullName, StringAddOperator = "||" }; 12 | case "SQLite.SQLiteConnection": 13 | case "System.Data.SQLite.SQLiteConnection": 14 | return new DialectOption() { ConnectionTypeFullName = connectionTypeFullName, StringAddOperator = "||" }; 15 | case "IBM.Data.DB2.DB2Connection": 16 | return new DialectOption() { ConnectionTypeFullName = connectionTypeFullName, StringAddOperator = "||" }; 17 | case "Oracle.ManagedDataAccess.Client.OracleConnection": 18 | return new DialectOption() { ConnectionTypeFullName = connectionTypeFullName, StringAddOperator = "||", ParameterPrefix = ":" }; 19 | default: 20 | return new DialectOption() { ConnectionTypeFullName = connectionTypeFullName }; 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/Inside/PartsUtils.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | 3 | namespace LambdicSql.BuilderServices.Inside 4 | { 5 | static class PartsUtils 6 | { 7 | internal static string GetIndent(int indent) 8 | { 9 | switch (indent) 10 | { 11 | case 0: return string.Empty; 12 | case 1: return "\t"; 13 | case 2: return "\t\t"; 14 | case 3: return "\t\t\t"; 15 | case 4: return "\t\t\t\t"; 16 | case 5: return "\t\t\t\t\t"; 17 | case 6: return "\t\t\t\t\t\t"; 18 | case 7: return "\t\t\t\t\t\t\t"; 19 | case 8: return "\t\t\t\t\t\t\t\t"; 20 | case 9: return "\t\t\t\t\t\t\t\t\t"; 21 | case 10: return "\t\t\t\t\t\t\t\t\t\t"; 22 | } 23 | 24 | var array = new char[indent]; 25 | for (int i = 0; i < indent; i++) 26 | { 27 | array[i] = '\t'; 28 | } 29 | return new string(array); 30 | } 31 | 32 | internal static HCode Line(params ICode[] args) 33 | => new HCode(args) { EnableChangeLine = false }; 34 | 35 | internal static SingleTextCode ToCode(this string src) 36 | => new SingleTextCode(src); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/ParameterInfo.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.ConverterServices.Inside; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace LambdicSql.BuilderServices 6 | { 7 | /// 8 | /// Parameter info. 9 | /// 10 | public class ParameterInfo 11 | { 12 | class DecodingParameterInfo 13 | { 14 | internal MetaId MetadataToken { get; set; } 15 | internal IDbParam Detail { get; set; } 16 | } 17 | 18 | int _count; 19 | Dictionary _parameters = new Dictionary(); 20 | string _prefix; 21 | 22 | internal ParameterInfo(string prefix) 23 | { 24 | _prefix = prefix; 25 | } 26 | 27 | /// 28 | /// Get parameters. 29 | /// It's dictionary of name and parameter. 30 | /// 31 | /// parameters. 32 | public Dictionary GetDbParams() 33 | => _parameters.ToDictionary(e => e.Key, e => e.Value.Detail); 34 | 35 | /// 36 | /// Add an object as a parameter. 37 | /// 38 | /// object. 39 | /// Parameter string. 40 | public string Push(object obj) => Push(obj, null, null, null); 41 | 42 | internal string Push(object obj, string nameSrc, MetaId metadataToken, IDbParam param) 43 | { 44 | if (string.IsNullOrEmpty(nameSrc)) nameSrc = "p_" + _count++; 45 | else nameSrc = nameSrc.Replace(".", "_"); 46 | 47 | var name = _prefix + nameSrc; 48 | 49 | DecodingParameterInfo val; 50 | if (_parameters.TryGetValue(name, out val)) 51 | { 52 | //find same metatoken object. 53 | if (metadataToken != null && metadataToken == val.MetadataToken && Equals(param?.Value, val.Detail?.Value)) return name; 54 | 55 | //make unique name. 56 | name = MakeUniqueName(nameSrc); 57 | } 58 | 59 | //register. 60 | if (param == null) param = new DbParamValueOnly() { Value = obj }; 61 | _parameters.Add(name, new DecodingParameterInfo() { MetadataToken = metadataToken, Detail = param }); 62 | 63 | return name; 64 | } 65 | 66 | string MakeUniqueName(string nameSrc) 67 | { 68 | while (true) 69 | { 70 | var nameCheck = _prefix + nameSrc; 71 | DecodingParameterInfo val; 72 | if (!_parameters.TryGetValue(nameCheck, out val)) 73 | { 74 | return nameCheck; 75 | } 76 | nameSrc += "_"; 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/ISyntaxCustomizer.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.Syntaxes 2 | { 3 | /// 4 | /// Customizer. 5 | /// 6 | public interface ISyntaxCustomizer 7 | { 8 | /// 9 | /// Coustom. 10 | /// 11 | /// Source. 12 | /// Result. 13 | TextPartsBase Custom(TextPartsBase src); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/AliasSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 2 | { 3 | class AliasSyntax : SingleTextSyntax 4 | { 5 | public AliasSyntax(string text) : base(text) { } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/CustomizeColumnOnly.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 2 | { 3 | class CustomizeColumnOnly : ISyntaxCustomizer 4 | { 5 | public TextPartsBase Custom(TextPartsBase src) 6 | { 7 | var col = src as DbColumnSyntax; 8 | return col == null ? src : col.ToColumnOnly(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/CustomizeParameterToObject.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 2 | { 3 | class CustomizeParameterToObject : ISyntaxCustomizer 4 | { 5 | public TextPartsBase Custom(TextPartsBase src) 6 | { 7 | var col = src as ParameterSyntax; 8 | return col == null ? src : col.ToDisplayValue(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/DbColumnSyntax.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.ConverterServices.Inside; 2 | 3 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 4 | { 5 | class DbColumnSyntax : TextPartsBase 6 | { 7 | ColumnInfo _col; 8 | string _front = string.Empty; 9 | string _back = string.Empty; 10 | bool _columnOnly; 11 | 12 | internal DbColumnSyntax(ColumnInfo col) 13 | { 14 | _col = col; 15 | } 16 | 17 | internal DbColumnSyntax(ColumnInfo col, bool columnOnly) 18 | { 19 | _col = col; 20 | _columnOnly = columnOnly; 21 | } 22 | 23 | DbColumnSyntax(ColumnInfo col, bool columnOnly, string front, string back) 24 | { 25 | _col = col; 26 | _front = front; 27 | _back = back; 28 | _columnOnly = columnOnly; 29 | } 30 | 31 | internal TextPartsBase ToColumnOnly() => new DbColumnSyntax(_col, true, _front, _back); 32 | 33 | string ColumnName => _columnOnly ? _col.SqlColumnName : _col.SqlFullName; 34 | 35 | public override bool IsEmpty => false; 36 | 37 | public override bool IsSingleLine(BuildingContext context) => true; 38 | 39 | public override string ToString(bool isTopLevel, int indent, BuildingContext context) => SyntaxUtils.GetIndent(indent) + _front + ColumnName + _back; 40 | 41 | public override TextPartsBase ConcatAround(string front, string back) => new DbColumnSyntax(_col, _columnOnly, front + _front, _back + back); 42 | 43 | public override TextPartsBase ConcatToFront(string front) => new DbColumnSyntax(_col, _columnOnly, front + _front, _back); 44 | 45 | public override TextPartsBase ConcatToBack(string back) => new DbColumnSyntax(_col, _columnOnly, _front, _back + back); 46 | 47 | public override TextPartsBase Customize(ISyntaxCustomizer customizer) => customizer.Custom(this); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/DbTableSyntax.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.ConverterServices.Inside; 2 | 3 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 4 | { 5 | class DbTableSyntax : TextPartsBase 6 | { 7 | string _front = string.Empty; 8 | string _back = string.Empty; 9 | 10 | internal DbTableSyntax(TableInfo info) 11 | { 12 | Info = info; 13 | } 14 | 15 | DbTableSyntax(TableInfo info, string front, string back) 16 | { 17 | Info = info; 18 | _front = front; 19 | _back = back; 20 | } 21 | 22 | internal TableInfo Info { get; private set; } 23 | 24 | public override bool IsEmpty => false; 25 | 26 | public override bool IsSingleLine(BuildingContext context) => true; 27 | 28 | public override string ToString(bool isTopLevel, int indent, BuildingContext context) => SyntaxUtils.GetIndent(indent) + _front + Info.SqlFullName + _back; 29 | 30 | public override TextPartsBase ConcatAround(string front, string back) => new DbTableSyntax(Info, front + _front, _back + back); 31 | 32 | public override TextPartsBase ConcatToFront(string front) => new DbTableSyntax(Info, front + _front, _back); 33 | 34 | public override TextPartsBase ConcatToBack(string back) => new DbTableSyntax(Info, _front, _back + back); 35 | 36 | public override TextPartsBase Customize(ISyntaxCustomizer customizer) => customizer.Custom(this); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/ParameterSyntax.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.ConverterServices.Inside; 2 | 3 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 4 | { 5 | class ParameterSyntax : TextPartsBase 6 | { 7 | internal string Name { get; private set; } 8 | internal MetaId MetaId { get; private set; } 9 | internal object Value => _param.Value; 10 | 11 | DbParam _param; 12 | string _front = string.Empty; 13 | string _back = string.Empty; 14 | bool _displayValue; 15 | 16 | internal ParameterSyntax(object value) 17 | { 18 | Name = null; 19 | MetaId = null; 20 | _param = new DbParam() {Value = value }; 21 | } 22 | 23 | internal ParameterSyntax(string name = null, MetaId metaId = null, DbParam param = null) 24 | { 25 | Name = name; 26 | MetaId = metaId; 27 | _param = param; 28 | } 29 | 30 | ParameterSyntax(string name, MetaId metaId, DbParam param, string front, string back, bool displayValue) 31 | { 32 | Name = name; 33 | MetaId = metaId; 34 | _param = param; 35 | _front = front; 36 | _back = back; 37 | _displayValue = displayValue; 38 | } 39 | 40 | public override bool IsEmpty => false; 41 | 42 | public override bool IsSingleLine(BuildingContext context) => true; 43 | 44 | public override string ToString(bool isTopLevel, int indent, BuildingContext context) => SyntaxUtils.GetIndent(indent) + _front + GetDisplayText(context) + _back; 45 | 46 | public override TextPartsBase ConcatAround(string front, string back) => new ParameterSyntax(Name, MetaId, _param, front + _front, _back + back, _displayValue); 47 | 48 | public override TextPartsBase ConcatToFront(string front) => new ParameterSyntax(Name, MetaId, _param, front + _front, _back, _displayValue); 49 | 50 | public override TextPartsBase ConcatToBack(string back) => new ParameterSyntax(Name, MetaId, _param, _front, _back + back, _displayValue); 51 | 52 | public override TextPartsBase Customize(ISyntaxCustomizer customizer) => customizer.Custom(this); 53 | 54 | internal TextPartsBase ToDisplayValue() => new ParameterSyntax(Name, MetaId, _param, _front, _back, true); 55 | 56 | string GetDisplayText(BuildingContext context) => _displayValue ? Value.ToString() : context.ParameterInfo.Push(_param.Value, Name, MetaId, _param); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/QuerySyntax.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 2 | { 3 | internal class QuerySyntax : TextPartsBase 4 | { 5 | TextPartsBase _core; 6 | 7 | internal QuerySyntax(TextPartsBase core) 8 | { 9 | _core = core; 10 | } 11 | 12 | public override bool IsEmpty => _core.IsEmpty; 13 | 14 | public override bool IsSingleLine(BuildingContext context) => _core.IsSingleLine(context); 15 | 16 | public override string ToString(bool isTopLevel, int indent, BuildingContext context) => _core.ToString(false, indent, context); 17 | 18 | public override TextPartsBase ConcatAround(string front, string back) => new QuerySyntax(_core.ConcatAround(front, back)); 19 | 20 | public override TextPartsBase ConcatToFront(string front) => new QuerySyntax(_core.ConcatToFront(front)); 21 | 22 | public override TextPartsBase ConcatToBack(string back) => new QuerySyntax(_core.ConcatToBack(back)); 23 | 24 | public override TextPartsBase Customize(ISyntaxCustomizer customizer) => customizer.Custom(this); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/SelectClauseSyntax.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.ConverterServices.Inside; 2 | 3 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 4 | { 5 | class SelectClauseSyntax : TextPartsBase 6 | { 7 | TextPartsBase _core; 8 | ObjectCreateInfo _createInfo; 9 | 10 | internal SelectClauseSyntax(ObjectCreateInfo createInfo, TextPartsBase core) 11 | { 12 | _core = core; 13 | _createInfo = createInfo; 14 | } 15 | 16 | public override bool IsEmpty => _core.IsEmpty; 17 | 18 | public override bool IsSingleLine(BuildingContext context) => _core.IsSingleLine(context); 19 | 20 | public override string ToString(bool isTopLevel, int indent, BuildingContext context) => _core.ToString(isTopLevel, indent, context); 21 | 22 | public override TextPartsBase ConcatAround(string front, string back) => new SelectClauseSyntax(_createInfo, _core.ConcatAround(front, back)); 23 | 24 | public override TextPartsBase ConcatToFront(string front) => new SelectClauseSyntax(_createInfo, _core.ConcatToFront(front)); 25 | 26 | public override TextPartsBase ConcatToBack(string back) => new SelectClauseSyntax(_createInfo, _core.ConcatToBack(back)); 27 | 28 | public override TextPartsBase Customize(ISyntaxCustomizer customizer) => customizer.Custom(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/SelectQuerySyntax.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 2 | { 3 | internal class SelectQuerySyntax : TextPartsBase 4 | { 5 | TextPartsBase _core; 6 | 7 | internal SelectQuerySyntax(TextPartsBase core) 8 | { 9 | _core = core; 10 | } 11 | 12 | public override bool IsEmpty => _core.IsEmpty; 13 | 14 | public override bool IsSingleLine(BuildingContext context) => _core.IsSingleLine(context); 15 | 16 | public override string ToString(bool isTopLevel, int indent, BuildingContext context) 17 | { 18 | var target = isTopLevel ? _core : _core.ConcatAround("(", ")"); 19 | return target.ToString(false, indent, context); 20 | } 21 | 22 | public override TextPartsBase ConcatAround(string front, string back) => new SelectQuerySyntax(_core.ConcatAround(front, back)); 23 | 24 | public override TextPartsBase ConcatToFront(string front) => new SelectQuerySyntax(_core.ConcatToFront(front)); 25 | 26 | public override TextPartsBase ConcatToBack(string back) => new SelectQuerySyntax(_core.ConcatToBack(back)); 27 | 28 | public override TextPartsBase Customize(ISyntaxCustomizer customizer) => customizer.Custom(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/StringAddOperatorSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 4 | { 5 | class StringAddOperatorSyntax : TextPartsBase 6 | { 7 | string _front = string.Empty; 8 | string _back = string.Empty; 9 | 10 | internal StringAddOperatorSyntax() { } 11 | 12 | StringAddOperatorSyntax(string front, string back) 13 | { 14 | _front = front; 15 | _back = back; 16 | } 17 | 18 | public override bool IsEmpty => false; 19 | 20 | public override bool IsSingleLine(BuildingContext context) => true; 21 | 22 | public override string ToString(bool isTopLevel, int indent, BuildingContext context) => SyntaxUtils.GetIndent(indent) + _front + context.Option.StringAddOperator + _back; 23 | 24 | public override TextPartsBase ConcatAround(string front, string back) => new StringAddOperatorSyntax(front + _front, _back + back); 25 | 26 | public override TextPartsBase ConcatToFront(string front) => new StringAddOperatorSyntax(front + _front, _back); 27 | 28 | public override TextPartsBase ConcatToBack(string back) => new StringAddOperatorSyntax(_front, _back + back); 29 | 30 | public override TextPartsBase Customize(ISyntaxCustomizer customizer) => customizer.Custom(this); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/StringFormatSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 4 | { 5 | class StringFormatSyntax : TextPartsBase 6 | { 7 | string _formatText; 8 | TextPartsBase[] _args; 9 | string _front = string.Empty; 10 | string _back = string.Empty; 11 | 12 | internal StringFormatSyntax(string formatText, TextPartsBase[] args) 13 | { 14 | _formatText = formatText; 15 | _args = args; 16 | } 17 | 18 | StringFormatSyntax(string formatText, TextPartsBase[] args, string front, string back) 19 | { 20 | _formatText = formatText; 21 | _args = args; 22 | _front = front; 23 | _back = back; 24 | } 25 | 26 | public override bool IsEmpty => false; 27 | 28 | public override bool IsSingleLine(BuildingContext context) => true; 29 | 30 | public override string ToString(bool isTopLevel, int indent, BuildingContext context) 31 | => SyntaxUtils.GetIndent(indent) + 32 | _front + 33 | string.Format(_formatText, _args.Select(e => e.ToString(true, 0, context)).ToArray()) + 34 | _back; 35 | 36 | public override TextPartsBase ConcatAround(string front, string back) => new StringFormatSyntax(_formatText, _args, front + _front, _back + back); 37 | 38 | public override TextPartsBase ConcatToFront(string front) => new StringFormatSyntax(_formatText, _args, front + _front, _back); 39 | 40 | public override TextPartsBase ConcatToBack(string back) => new StringFormatSyntax(_formatText, _args, _front, _back + back); 41 | 42 | public override TextPartsBase Customize(ISyntaxCustomizer customizer) => customizer.Custom(this); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/SyntaxFactoryUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 4 | { 5 | //TODO Symbolのリファクタリングが終わった段階で見直し 6 | static class SyntaxFactoryUtils 7 | { 8 | internal static HText Arguments(params TextPartsBase[] args) 9 | => new HText(args) { Separator = ", " }; 10 | 11 | internal static TextPartsBase Blanket(params TextPartsBase[] args) 12 | => Arguments(args).ConcatAround("(", ")"); 13 | 14 | internal static HText Func(TextPartsBase func, params TextPartsBase[] args) 15 | => Func(func, ", ", args); 16 | 17 | internal static HText FuncSpace(TextPartsBase func, params TextPartsBase[] args) 18 | => Func(func, " ", args); 19 | 20 | internal static HText Clause(TextPartsBase clause, params TextPartsBase[] args) 21 | => new HText(new TextPartsBase[] { clause }.Concat(args)) { IsFunctional = true, Separator = " " }; 22 | 23 | internal static HText SubClause(TextPartsBase clause, params TextPartsBase[] args) 24 | => new HText(new TextPartsBase[] { clause }.Concat(args)) { IsFunctional = true, Separator = " ", Indent = 1 }; 25 | 26 | internal static HText Line(params TextPartsBase[] args) 27 | => new HText(args) { EnableChangeLine = false }; 28 | 29 | internal static HText LineSpace(params TextPartsBase[] args) 30 | => new HText(args) { EnableChangeLine = false, Separator = " " }; 31 | 32 | static HText Func(TextPartsBase func, string separator, params TextPartsBase[] args) 33 | { 34 | var hArgs = new HText(args) { Separator = separator }.ConcatToBack(")"); 35 | return new HText(Line(func, "("), hArgs) { IsFunctional = true }; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/Inside/SyntaxUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace LambdicSql.BuilderServices.Syntaxes.Inside 4 | { 5 | static class SyntaxUtils 6 | { 7 | internal static string GetIndent(int indent) 8 | { 9 | switch (indent) 10 | { 11 | case 0: return string.Empty; 12 | case 1: return "\t"; 13 | case 2: return "\t\t"; 14 | case 3: return "\t\t\t"; 15 | case 4: return "\t\t\t\t"; 16 | case 5: return "\t\t\t\t\t"; 17 | case 6: return "\t\t\t\t\t\t"; 18 | case 7: return "\t\t\t\t\t\t\t"; 19 | case 8: return "\t\t\t\t\t\t\t\t"; 20 | case 9: return "\t\t\t\t\t\t\t\t\t"; 21 | case 10:return "\t\t\t\t\t\t\t\t\t\t"; 22 | } 23 | return string.Join(string.Empty, Enumerable.Range(0, indent).Select(e => "\t").ToArray()); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/SingleTextSyntax.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.Syntaxes.Inside; 2 | 3 | namespace LambdicSql.BuilderServices.Syntaxes 4 | { 5 | /// 6 | /// Single text. 7 | /// 8 | public class SingleTextSyntax : TextPartsBase 9 | { 10 | string _text; 11 | int _indent; 12 | 13 | /// 14 | /// Constructor. 15 | /// 16 | /// Text. 17 | public SingleTextSyntax(string text) 18 | { 19 | _text = text; 20 | } 21 | 22 | /// 23 | /// Constructor. 24 | /// 25 | /// Text. 26 | /// Indent. 27 | public SingleTextSyntax(string text, int indent) 28 | { 29 | _text = text; 30 | _indent = indent; 31 | } 32 | 33 | /// 34 | /// Is single line. 35 | /// 36 | public override bool IsSingleLine(BuildingContext context) => true; 37 | 38 | /// 39 | /// Is empty. 40 | /// 41 | public override bool IsEmpty => string.IsNullOrEmpty(_text.Trim()); 42 | 43 | /// 44 | /// To string. 45 | /// 46 | /// Is top level. 47 | /// Indent. 48 | /// Context. 49 | /// Text. 50 | public override string ToString(bool isTopLevel, int indent, BuildingContext context) => SyntaxUtils.GetIndent(_indent + indent) + _text; 51 | 52 | /// 53 | /// Concat to front and back. 54 | /// 55 | /// Front. 56 | /// Back. 57 | /// Text. 58 | public override TextPartsBase ConcatAround(string front, string back) => new SingleTextSyntax(front + _text + back, _indent); 59 | 60 | /// 61 | /// Concat to front. 62 | /// 63 | /// Front. 64 | /// Text. 65 | public override TextPartsBase ConcatToFront(string front) => new SingleTextSyntax(front + _text, _indent); 66 | 67 | /// 68 | /// Concat to back. 69 | /// 70 | /// 71 | /// 72 | public override TextPartsBase ConcatToBack(string back) => new SingleTextSyntax(_text + back, _indent); 73 | 74 | /// 75 | /// Customize. 76 | /// 77 | /// Customizer. 78 | /// Customized SqlText. 79 | public override TextPartsBase Customize(ISyntaxCustomizer customizer) => customizer.Custom(this); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/StringFormatText.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace LambdicSql.SqlBase.TextParts 7 | { 8 | class StringFormatText : ExpressionElement 9 | { 10 | string _formatText; 11 | ExpressionElement[] _args; 12 | string _front = string.Empty; 13 | string _back = string.Empty; 14 | 15 | 16 | internal StringFormatText(string formatText, ExpressionElement[] args) 17 | { 18 | _formatText = formatText; 19 | _args = args; 20 | } 21 | 22 | StringFormatText(string formatText, ExpressionElement[] args, string front, string back) 23 | { 24 | _formatText = formatText; 25 | _args = args; 26 | _front = front; 27 | _back = back; 28 | } 29 | 30 | public override bool IsSingleLine(ExpressionConvertingContext context) => true; 31 | 32 | public override bool IsEmpty => false; 33 | 34 | public override string ToString(bool isTopLevel, int indent, ExpressionConvertingContext context) 35 | => string.Join(string.Empty, Enumerable.Range(0, indent).Select(e => "\t").ToArray()) + 36 | _front + 37 | string.Format(_formatText, _args.Select(e => e.ToString(true, 0, context)).ToArray()) + 38 | _back; 39 | 40 | public override ExpressionElement ConcatAround(string front, string back) 41 | => new StringFormatText(_formatText, _args, front + _front, _back + back); 42 | 43 | public override ExpressionElement ConcatToFront(string front) 44 | => new StringFormatText(_formatText, _args, front + _front, _back); 45 | 46 | public override ExpressionElement ConcatToBack(string back) 47 | => new StringFormatText(_formatText, _args, _front, _back + back); 48 | 49 | public override ExpressionElement Customize(ISqlTextCustomizer customizer) 50 | => customizer.Custom(this); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/BuilderServices/TextParts/TextPartsBase.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.BuilderServices.Syntaxes 2 | { 3 | /// 4 | /// Text. 5 | /// 6 | public abstract class TextPartsBase 7 | { 8 | /// 9 | /// Is empty. 10 | /// 11 | public abstract bool IsEmpty { get; } 12 | 13 | /// 14 | /// Is single line. 15 | /// 16 | public abstract bool IsSingleLine(BuildingContext context); 17 | 18 | /// 19 | /// To string. 20 | /// 21 | /// Is top level. 22 | /// Indent. 23 | /// Context. 24 | /// Text. 25 | public abstract string ToString(bool isTopLevel, int indent, BuildingContext context); 26 | 27 | /// 28 | /// Concat to front and back. 29 | /// 30 | /// Front. 31 | /// Back. 32 | /// Text. 33 | public abstract TextPartsBase ConcatAround(string front, string back); 34 | 35 | /// 36 | /// Concat to front. 37 | /// 38 | /// Front. 39 | /// Text. 40 | public abstract TextPartsBase ConcatToFront(string front); 41 | 42 | /// 43 | /// Concat to back. 44 | /// 45 | /// 46 | /// 47 | public abstract TextPartsBase ConcatToBack(string back); 48 | 49 | /// 50 | /// Customize. 51 | /// 52 | /// Customizer. 53 | /// Customized SqlText. 54 | public abstract TextPartsBase Customize(ISyntaxCustomizer customizer); 55 | 56 | /// 57 | /// Convert string to IText. 58 | /// 59 | /// string. 60 | public static implicit operator TextPartsBase(string text) => new SingleTextSyntax(text); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/Clause.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.ConverterServices; 2 | 3 | namespace LambdicSql 4 | { 5 | /// 6 | /// Clause. 7 | /// 8 | public abstract class Clause : SqlExpression 9 | { 10 | /// 11 | /// Addition operator. 12 | /// 13 | /// clause. 14 | /// expression. 15 | /// Concatenated result. 16 | public static Clause operator +(Clause clause, SqlExpression exp) { throw new InvalitContextException("addition operator"); } 17 | } 18 | 19 | /// 20 | /// Clause. 21 | /// 22 | /// The type represented by clause. 23 | public abstract class Clause : Clause 24 | { 25 | /// 26 | /// Addition operator. 27 | /// 28 | /// clause. 29 | /// expression. 30 | /// Concatenated result. 31 | public static Clause operator +(Clause clause, SqlExpression exp) { throw new InvalitContextException("addition operator"); } 32 | 33 | /// 34 | /// Implicitly convert to the type represented by Clause. 35 | /// 36 | /// Clause chain. 37 | public static implicit operator TSelected(Clause src) { throw new InvalitContextException("implicit operator"); } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/Condition.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.ConverterServices; 2 | using LambdicSql.Specialized.SymbolConverters; 3 | 4 | namespace LambdicSql 5 | { 6 | /// 7 | /// Condition building helper. 8 | /// condition is used if enable is valid. 9 | /// It can only be used within lambda of the LambdicSql. 10 | /// 11 | public class Condition 12 | { 13 | /// 14 | /// Condition building helper. 15 | /// condition is used if enable is valid. 16 | /// 17 | /// Whether condition is valid. 18 | /// Condition expression. 19 | [ConditionConverter] 20 | public Condition(object enable, object condition) { throw new InvalitContextException("new " + nameof(Condition)); } 21 | 22 | /// 23 | /// Implicit conversion to bool type. 24 | /// 25 | /// Condition 26 | public static implicit operator bool(Condition src) { throw new InvalitContextException("implicit operator bool(Condition src)"); } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/CodeParts/BinaryExpressionCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices; 2 | using LambdicSql.BuilderServices.CodeParts; 3 | 4 | namespace LambdicSql.ConverterServices.Inside.CodeParts 5 | { 6 | class BinaryExpressionCode : ICode 7 | { 8 | ICode _core; 9 | 10 | internal BinaryExpressionCode(ICode core) 11 | { 12 | _core = core; 13 | } 14 | 15 | public bool IsEmpty => _core.IsEmpty; 16 | 17 | public bool IsSingleLine(BuildingContext context) => _core.IsSingleLine(context); 18 | 19 | public string ToString(BuildingContext context) => _core.ToString(context); 20 | 21 | public ICode Accept(ICodeCustomizer customizer) 22 | { 23 | var dst = customizer.Visit(this); 24 | if (!ReferenceEquals(this, dst)) return dst; 25 | return new BinaryExpressionCode(_core.Accept(customizer)); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/CodeParts/DbColumnCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices; 2 | using LambdicSql.BuilderServices.Inside; 3 | using LambdicSql.BuilderServices.CodeParts; 4 | 5 | namespace LambdicSql.ConverterServices.Inside.CodeParts 6 | { 7 | class DbColumnCode : ICode 8 | { 9 | ColumnInfo _col; 10 | bool _columnOnly; 11 | 12 | internal DbColumnCode(ColumnInfo col) 13 | { 14 | _col = col; 15 | } 16 | 17 | internal DbColumnCode(ColumnInfo col, bool columnOnly) 18 | { 19 | _col = col; 20 | _columnOnly = columnOnly; 21 | } 22 | 23 | internal ICode ToColumnOnly() => new DbColumnCode(_col, true); 24 | 25 | internal string ColumnName => _columnOnly ? _col.SqlColumnName : _col.SqlFullName; 26 | 27 | public bool IsEmpty => false; 28 | 29 | public bool IsSingleLine(BuildingContext context) => true; 30 | 31 | public string ToString(BuildingContext context) => PartsUtils.GetIndent(context.Indent) + ColumnName; 32 | 33 | public ICode Accept(ICodeCustomizer customizer) => customizer.Visit(this); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/CodeParts/DbSchemaCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices; 2 | using LambdicSql.BuilderServices.Inside; 3 | using LambdicSql.BuilderServices.CodeParts; 4 | 5 | namespace LambdicSql.ConverterServices.Inside.CodeParts 6 | { 7 | class DbSchemaCode : ICode 8 | { 9 | internal string Text { get; } 10 | 11 | internal DbSchemaCode(string schema) 12 | { 13 | Text = schema; 14 | } 15 | 16 | public bool IsEmpty => false; 17 | 18 | public bool IsSingleLine(BuildingContext context) => true; 19 | 20 | public string ToString(BuildingContext context) => PartsUtils.GetIndent(context.Indent) + Text; 21 | 22 | public ICode Accept(ICodeCustomizer customizer) => customizer.Visit(this); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/CodeParts/DbTableCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices; 2 | using LambdicSql.BuilderServices.Inside; 3 | using LambdicSql.BuilderServices.CodeParts; 4 | 5 | namespace LambdicSql.ConverterServices.Inside.CodeParts 6 | { 7 | class DbTableCode : ICode 8 | { 9 | internal DbTableCode(TableInfo info) 10 | { 11 | Info = info; 12 | } 13 | 14 | internal TableInfo Info { get; } 15 | 16 | public bool IsEmpty => false; 17 | 18 | public bool IsSingleLine(BuildingContext context) => true; 19 | 20 | public string ToString(BuildingContext context) => PartsUtils.GetIndent(context.Indent) + Info.SqlFullName; 21 | 22 | public ICode Accept(ICodeCustomizer customizer) => customizer.Visit(this); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/CodeParts/ISqlCode.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.ConverterServices.Inside.CodeParts 2 | { 3 | interface ISqlCode { } 4 | } 5 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/CodeParts/ParameterCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices; 2 | using LambdicSql.BuilderServices.Inside; 3 | using LambdicSql.BuilderServices.CodeParts; 4 | using System; 5 | 6 | namespace LambdicSql.ConverterServices.Inside.CodeParts 7 | { 8 | class ParameterCode : ICode 9 | { 10 | internal string Name { get; private set; } 11 | internal MetaId MetaId { get; private set; } 12 | internal object Value => _param.Value; 13 | internal IDbParam Param => _param; 14 | 15 | IDbParam _param; 16 | bool _displayValue; 17 | 18 | internal ParameterCode(object value) 19 | { 20 | Name = null; 21 | MetaId = null; 22 | _param = new DbParamValueOnly() {Value = value }; 23 | } 24 | 25 | internal ParameterCode(string name, MetaId metaId, IDbParam param) 26 | { 27 | Name = name; 28 | MetaId = metaId; 29 | _param = param; 30 | } 31 | 32 | ParameterCode(string name, MetaId metaId, IDbParam param, bool displayValue) 33 | { 34 | Name = name; 35 | MetaId = metaId; 36 | _param = param; 37 | _displayValue = displayValue; 38 | } 39 | 40 | public bool IsEmpty => false; 41 | 42 | public bool IsSingleLine(BuildingContext context) => true; 43 | 44 | public string ToString(BuildingContext context) => PartsUtils.GetIndent(context.Indent) + GetDisplayText(context); 45 | 46 | public ICode Accept(ICodeCustomizer customizer) => customizer.Visit(this); 47 | 48 | internal ICode ToDisplayValue() => new ParameterCode(Name, MetaId, _param, true); 49 | 50 | string GetDisplayText(BuildingContext context) 51 | { 52 | if (_displayValue) 53 | { 54 | if (Value == null) 55 | { 56 | return "NULL"; 57 | } 58 | 59 | var type = Value.GetType(); 60 | if (type == typeof(string) || 61 | type == typeof(DateTime) || 62 | type == typeof(DateTimeOffset) || 63 | type == typeof(TimeSpan)) 64 | { 65 | return "'" + Value + "'"; 66 | } 67 | if (type == typeof(DateTime?)) 68 | { 69 | return "'" + ((DateTime?)Value).Value + "'"; 70 | } 71 | if (type == typeof(DateTimeOffset?)) 72 | { 73 | return "'" + ((DateTimeOffset?)Value).Value + "'"; 74 | } 75 | if (type == typeof(TimeSpan?)) 76 | { 77 | return "'" + ((TimeSpan?)Value).Value + "'"; 78 | } 79 | return Value.ToString(); 80 | } 81 | return context.ParameterInfo.Push(_param.Value, Name, MetaId, _param); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/CodeParts/QueryCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices; 2 | using LambdicSql.BuilderServices.CodeParts; 3 | 4 | namespace LambdicSql.ConverterServices.Inside.CodeParts 5 | { 6 | internal class QueryCode : ICode 7 | { 8 | ICode _core; 9 | 10 | internal QueryCode(ICode core) 11 | { 12 | _core = core; 13 | } 14 | 15 | public bool IsEmpty => _core.IsEmpty; 16 | 17 | public bool IsSingleLine(BuildingContext context) => _core.IsSingleLine(context); 18 | 19 | public string ToString(BuildingContext context) => _core.ToString(context.ChangeTopLevelQuery(false)); 20 | 21 | public ICode Accept(ICodeCustomizer customizer) 22 | { 23 | var dst = customizer.Visit(this); 24 | if (!ReferenceEquals(this, dst)) return dst; 25 | return new QueryCode(_core.Accept(customizer)); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/CodeParts/SqlCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices; 2 | using LambdicSql.BuilderServices.CodeParts; 3 | 4 | namespace LambdicSql.ConverterServices.Inside.CodeParts 5 | { 6 | class SqlCode : ICode, ISqlCode 7 | { 8 | ICode _core; 9 | 10 | internal SqlCode(ICode core) 11 | { 12 | _core = core; 13 | } 14 | 15 | public bool IsEmpty => _core.IsEmpty; 16 | 17 | public bool IsSingleLine(BuildingContext context) => _core.IsSingleLine(context); 18 | 19 | public string ToString(BuildingContext context) => _core.ToString(context); 20 | 21 | public ICode Accept(ICodeCustomizer customizer) 22 | { 23 | var dst = customizer.Visit(this); 24 | if (!ReferenceEquals(this, dst)) return dst; 25 | return new SqlCode(_core.Accept(customizer)); 26 | } 27 | 28 | internal static ICode Create(ICode core) 29 | { 30 | var topQuery = core as ITopQueryCode; 31 | return topQuery == null ? new SqlCode(core) : (ICode)new TopQuerySqlCode(topQuery); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/CodeParts/StringAddOperatorCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices; 2 | using LambdicSql.BuilderServices.Inside; 3 | using LambdicSql.BuilderServices.CodeParts; 4 | 5 | namespace LambdicSql.ConverterServices.Inside.CodeParts 6 | { 7 | class StringAddOperatorCode : ICode 8 | { 9 | internal StringAddOperatorCode() { } 10 | 11 | public bool IsEmpty => false; 12 | 13 | public bool IsSingleLine(BuildingContext context) => true; 14 | 15 | public string ToString(BuildingContext context) => PartsUtils.GetIndent(context.Indent) + context.DialectOption.StringAddOperator; 16 | 17 | public ICode Accept(ICodeCustomizer customizer) => customizer.Visit(this); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/CodeParts/TopQuerySqlCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices; 2 | using LambdicSql.BuilderServices.CodeParts; 3 | 4 | namespace LambdicSql.ConverterServices.Inside.CodeParts 5 | { 6 | class TopQuerySqlCode : ITopQueryCode, ISqlCode 7 | { 8 | ITopQueryCode _core; 9 | public ICode Core => _core.Core; 10 | 11 | public bool IsEmpty => Core.IsEmpty; 12 | 13 | public bool IsSingleLine(BuildingContext context) => _core.IsSingleLine(context); 14 | 15 | public string ToString(BuildingContext context) => _core.ToString(context); 16 | 17 | internal TopQuerySqlCode(ITopQueryCode core) 18 | { 19 | _core = core; 20 | } 21 | 22 | public ICode Accept(ICodeCustomizer customizer) 23 | { 24 | var dst = customizer.Visit(this); 25 | if (!ReferenceEquals(this, dst)) return dst; 26 | return new TopQuerySqlCode((ITopQueryCode)_core.Accept(customizer)); 27 | } 28 | 29 | public ITopQueryCode Create(ICode core) 30 | => new TopQuerySqlCode(_core.Create(core)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/ColumnInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LambdicSql.ConverterServices.Inside 4 | { 5 | class ColumnInfo 6 | { 7 | internal Type Type { get; } 8 | internal string LambdaFullName { get; } 9 | internal string SqlFullName { get; } 10 | internal string SqlColumnName { get; } 11 | 12 | internal ColumnInfo(Type type, string lambdaFullName, string sqlFullName, string sqlColumnName) 13 | { 14 | Type = type; 15 | LambdaFullName = lambdaFullName; 16 | SqlFullName = sqlFullName; 17 | SqlColumnName = sqlColumnName; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/DBDefineAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using LambdicSql.MultiplatformCompatibe; 6 | 7 | namespace LambdicSql.ConverterServices.Inside 8 | { 9 | static class DBDefineAnalyzer 10 | { 11 | static Dictionary _dbInfos = new Dictionary(); 12 | 13 | internal static DbInfo GetDbInfo() where T : class 14 | { 15 | DbInfo db; 16 | lock (_dbInfos) 17 | { 18 | if (_dbInfos.TryGetValue(typeof(T), out db)) 19 | { 20 | return db.Clone(); 21 | } 22 | } 23 | 24 | var checkRecursive = new List(); 25 | db = new DbInfo(); 26 | foreach (var column in FindColumns(typeof(T), new string[0], new string[0], checkRecursive)) 27 | { 28 | db.Add(column); 29 | } 30 | 31 | lock (_dbInfos) 32 | { 33 | if (!_dbInfos.ContainsKey(typeof(T))) 34 | { 35 | _dbInfos.Add(typeof(T), db); 36 | } 37 | } 38 | return db; 39 | } 40 | 41 | static IEnumerable FindColumns(Type type, IEnumerable lambdicNames, string[] sqlNames, List checkRecursive) where T : class 42 | { 43 | //for entity framework. 44 | if (type.IsGenericTypeEx()) type = type.GetGenericArgumentsEx()[0]; 45 | 46 | var defineCustomizer = Db.DefinitionCustomizer; 47 | 48 | if (SupportedTypeSpec.IsSupported(type)) 49 | { 50 | var lambdicName = string.Join(".", lambdicNames.ToArray()); 51 | var sqlName = string.Join(".", sqlNames.ToArray()); 52 | return new[] { new ColumnInfo(type, lambdicName, sqlName, sqlNames[sqlNames.Length - 1]) }; 53 | } 54 | else if (type.IsClassEx()) 55 | { 56 | //check recursive. 57 | if (checkRecursive.Contains(type)) return new List(); 58 | checkRecursive.Add(type); 59 | 60 | var list = new List(); 61 | foreach (var p in type.GetPropertiesEx()) 62 | { 63 | //for entity framework. 64 | if (p.DeclaringType.FullName == "System.Data.Entity.DbContext") continue; 65 | 66 | list.AddRange(FindColumns(p.PropertyType, 67 | lambdicNames.Concat(new[] { p.Name }).ToArray(), 68 | sqlNames.Concat(new[] { GetSqlName(defineCustomizer, p) }).ToArray(), new List(checkRecursive))); 69 | } 70 | return list; 71 | } 72 | throw new NotSupportedException(type.FullName); 73 | } 74 | 75 | internal static string GetSqlName(DbDefinitionCustomizerDelegate defineCustomizer, PropertyInfo property) 76 | { 77 | if (defineCustomizer != null) 78 | { 79 | var name = defineCustomizer(property); 80 | if (!string.IsNullOrEmpty(name)) return name; 81 | } 82 | return ReflectionAdapter.GetSqlName(property); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/DbInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace LambdicSql.ConverterServices.Inside 6 | { 7 | class DbInfo 8 | { 9 | Dictionary _lambdaNameAndColumn = new Dictionary(); 10 | Dictionary _lambdaNameAndTable = new Dictionary(); 11 | Dictionary _lambdaNameSchema = new Dictionary(); 12 | 13 | internal void Add(ColumnInfo col) 14 | { 15 | _lambdaNameAndColumn.Add(col.LambdaFullName, col); 16 | 17 | var sepLambda = col.LambdaFullName.Split('.'); 18 | var tableLambda = string.Join(".", sepLambda.Take(sepLambda.Length - 1).ToArray()); 19 | if (!_lambdaNameAndTable.ContainsKey(tableLambda)) 20 | { 21 | var sepSql = col.SqlFullName.Split('.'); 22 | var tableSql = string.Join(".", sepSql.Take(sepSql.Length - 1).ToArray()); 23 | _lambdaNameAndTable.Add(tableLambda, new TableInfo(tableLambda, tableSql)); 24 | 25 | //has schema. 26 | if (2 < sepSql.Length && 2 < sepLambda.Length) 27 | { 28 | _lambdaNameSchema[sepLambda[0]] = sepSql[0]; 29 | } 30 | } 31 | } 32 | 33 | internal bool TryGetTable(string name, out TableInfo table) 34 | => _lambdaNameAndTable.TryGetValue(name, out table); 35 | 36 | internal bool TryGetColumn(string name, out ColumnInfo col) 37 | => _lambdaNameAndColumn.TryGetValue(name, out col); 38 | 39 | internal bool TryGetSchema(string name, out string schema) 40 | => _lambdaNameSchema.TryGetValue(name, out schema); 41 | 42 | internal DbInfo Clone() 43 | { 44 | var clone = new DbInfo(); 45 | clone._lambdaNameAndColumn = _lambdaNameAndColumn.ToDictionary(e => e.Key, e => e.Value); 46 | clone._lambdaNameAndTable = _lambdaNameAndTable.ToDictionary(e => e.Key, e => e.Value); 47 | clone._lambdaNameSchema = _lambdaNameSchema.ToDictionary(e => e.Key, e => e.Value); 48 | return clone; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/DbParamValueOnly.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.ConverterServices.Inside 2 | { 3 | class DbParamValueOnly : IDbParam 4 | { 5 | public object Value { get; set; } 6 | 7 | public IDbParam ChangeValue(object value) => new DbParamValueOnly { Value = value }; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/GeneralStyleConverterCore.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.MultiplatformCompatibe; 3 | using LambdicSql.BuilderServices.Inside; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Linq.Expressions; 8 | 9 | namespace LambdicSql.ConverterServices.Inside 10 | { 11 | class GeneralStyleConverterCore 12 | { 13 | bool[] _isParamArray; 14 | int _startIndex = -1; 15 | 16 | internal string Name { get; set; } 17 | internal ICode NameCode { get; set; } 18 | internal bool VanishIfEmptyParams { get; set; } 19 | 20 | internal IEnumerable InitAndConvertArguments(MethodCallExpression expression, ExpressionConverter converter) 21 | { 22 | lock (this) 23 | { 24 | if (string.IsNullOrEmpty(Name)) Name = expression.Method.Name.ToUpper(); 25 | 26 | if (NameCode == null) NameCode = Name.ToCode(); 27 | 28 | if (_startIndex == -1) _startIndex = expression.SkipMethodChain(0); 29 | 30 | if (_isParamArray == null) 31 | { 32 | var paramsInfo = expression.Method.GetParameters(); 33 | _isParamArray = new bool[paramsInfo.Length]; 34 | for (int i = 0; i < paramsInfo.Length; i++) 35 | { 36 | _isParamArray[i] = paramsInfo[i].GetAttribute() != null; 37 | } 38 | } 39 | } 40 | 41 | var args = new List(); 42 | for (int i = _startIndex; i < expression.Arguments.Count; i++) 43 | { 44 | var argExp = expression.Arguments[i]; 45 | if (_isParamArray[i]) 46 | { 47 | var newArrayExp = argExp as NewArrayExpression; 48 | if (newArrayExp != null) 49 | { 50 | bool isEmpty = true; 51 | foreach (var e in newArrayExp.Expressions) 52 | { 53 | var argCode = converter.ConvertToCode(e); 54 | if (isEmpty) isEmpty = argCode.IsEmpty; 55 | args.Add(argCode); 56 | } 57 | if (VanishIfEmptyParams && isEmpty) return null; 58 | } 59 | else 60 | { 61 | var obj = converter.ConvertToObject(argExp); 62 | foreach (var e in (IEnumerable)obj) args.Add(converter.ConvertToCode(e)); 63 | } 64 | } 65 | else 66 | { 67 | args.Add(converter.ConvertToCode(argExp)); 68 | } 69 | } 70 | return args; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/OperatorCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.BuilderServices.Inside; 3 | using LambdicSql.ConverterServices.Inside.CodeParts; 4 | 5 | namespace LambdicSql.ConverterServices.Inside 6 | { 7 | class OperatorCode 8 | { 9 | internal static readonly ICode Equal = " = ".ToCode(); 10 | internal static readonly ICode NotEqual = " <> ".ToCode(); 11 | internal static readonly ICode LessThan = " < ".ToCode(); 12 | internal static readonly ICode LessThanOrEqual = " <= ".ToCode(); 13 | internal static readonly ICode GreaterThan = " > ".ToCode(); 14 | internal static readonly ICode GreaterThanOrEqual = " >= ".ToCode(); 15 | internal static readonly ICode Add = " + ".ToCode(); 16 | internal static readonly ICode AddString = new StringAddOperatorCode(); 17 | internal static readonly ICode Subtract = " - ".ToCode(); 18 | internal static readonly ICode Multiply = " * ".ToCode(); 19 | internal static readonly ICode Divide = " / ".ToCode(); 20 | internal static readonly ICode Modulo = " % ".ToCode(); 21 | internal static readonly ICode And = " AND ".ToCode(); 22 | internal static readonly ICode AndAlso = " AND ".ToCode(); 23 | internal static readonly ICode Or = " OR ".ToCode(); 24 | internal static readonly ICode OrElse = " OR ".ToCode(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/SupportedTypeSpec.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.MultiplatformCompatibe; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace LambdicSql.ConverterServices.Inside 7 | { 8 | static class SupportedTypeSpec 9 | { 10 | static List _supported = new List(); 11 | 12 | static SupportedTypeSpec() 13 | { 14 | //TODO more types. 15 | //for entity framework. 16 | _supported.Add(typeof(ushort)); 17 | _supported.Add(typeof(ushort?)); 18 | _supported.Add(typeof(uint)); 19 | _supported.Add(typeof(uint?)); 20 | _supported.Add(typeof(ulong)); 21 | _supported.Add(typeof(ulong?)); 22 | 23 | _supported.Add(typeof(object)); 24 | _supported.Add(typeof(string)); 25 | _supported.Add(typeof(bool)); 26 | _supported.Add(typeof(bool?)); 27 | _supported.Add(typeof(byte)); 28 | _supported.Add(typeof(byte?)); 29 | _supported.Add(typeof(short)); 30 | _supported.Add(typeof(short?)); 31 | _supported.Add(typeof(int)); 32 | _supported.Add(typeof(int?)); 33 | _supported.Add(typeof(long)); 34 | _supported.Add(typeof(long?)); 35 | _supported.Add(typeof(float)); 36 | _supported.Add(typeof(float?)); 37 | _supported.Add(typeof(double)); 38 | _supported.Add(typeof(double?)); 39 | _supported.Add(typeof(decimal)); 40 | _supported.Add(typeof(decimal?)); 41 | _supported.Add(typeof(DateTime)); 42 | _supported.Add(typeof(DateTime?)); 43 | _supported.Add(typeof(DateTimeOffset)); 44 | _supported.Add(typeof(DateTimeOffset?)); 45 | _supported.Add(typeof(TimeSpan)); 46 | _supported.Add(typeof(TimeSpan?)); 47 | _supported.Add(typeof(byte[])); 48 | _supported.Add(typeof(char[])); 49 | } 50 | 51 | public static bool IsSupported(Type type) 52 | { 53 | lock (_supported) 54 | { 55 | return _supported.Contains(type) || type.IsArray || !ReflectionAdapter.IsClass(type); 56 | } 57 | } 58 | 59 | internal static object ConvertArray(Type arrayType, IEnumerable src) 60 | { 61 | if (arrayType == typeof(byte[])) return src.Cast().ToArray(); 62 | else if (arrayType == typeof(char[])) return src.Cast().ToArray(); 63 | throw new NotSupportedException(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/TableInfo.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.ConverterServices.Inside 2 | { 3 | class TableInfo 4 | { 5 | internal string LambdaFullName { get; } 6 | internal string SqlFullName { get; } 7 | 8 | internal TableInfo(string lambdaFullName, string sqlFullName) 9 | { 10 | LambdaFullName = lambdaFullName; 11 | SqlFullName = sqlFullName; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/Inside/TowWaySqlSpec.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LambdicSql.ConverterServices.Inside 4 | { 5 | static class TowWaySqlSpec 6 | { 7 | internal static string ToStringFormat(string sql) 8 | { 9 | for (int i = 0; true; i++) 10 | { 11 | int changeCount = 0; 12 | while (true) 13 | { 14 | var start = "/*" + i + "*/"; 15 | var startIndex = sql.IndexOf(start); 16 | if (startIndex == -1) 17 | { 18 | break; 19 | } 20 | changeCount++; 21 | var end = "/**/"; 22 | var endIndex = sql.IndexOf(end, startIndex + start.Length); 23 | if (endIndex == -1) 24 | { 25 | throw new NotSupportedException("Invalid 2WaySql format."); 26 | } 27 | 28 | var before = sql.Substring(0, startIndex); 29 | var after = sql.Substring(endIndex + end.Length); 30 | sql = before + "{" + i + "}" + after; 31 | } 32 | if (changeCount == 0) break; 33 | } 34 | return sql; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/InvalitContextException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LambdicSql.ConverterServices 4 | { 5 | /// 6 | /// It is thrown if the method is called with an illegal context. 7 | /// 8 | public class InvalitContextException : Exception 9 | { 10 | /// 11 | /// Constructor. 12 | /// 13 | public InvalitContextException() { } 14 | 15 | /// 16 | /// Constructor. 17 | /// 18 | /// error method name. 19 | public InvalitContextException(string name) : base("[" + name + "] can't be called outside lambda.") { } 20 | 21 | /// 22 | /// Constructor. 23 | /// 24 | /// Message. 25 | /// InnerException. 26 | public InvalitContextException(string message, Exception innerException) : base(message, innerException) { } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/ObjectCreateInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Linq.Expressions; 2 | 3 | namespace LambdicSql.ConverterServices 4 | { 5 | /// 6 | /// Object generation information. 7 | /// 8 | public class ObjectCreateInfo 9 | { 10 | /// 11 | /// Members. 12 | /// 13 | public ObjectCreateMemberInfo[] Members { get; } 14 | 15 | /// 16 | /// Expression became the basis. 17 | /// It is null when made from type information. 18 | /// 19 | public Expression Expression { get; } 20 | 21 | /// 22 | /// Constructor. 23 | /// 24 | /// Members. 25 | /// Expression became the basis.It is null when made from type information. 26 | public ObjectCreateInfo(ObjectCreateMemberInfo[] members, Expression expression) 27 | { 28 | Members = members; 29 | Expression = expression; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/ObjectCreateMemberInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Linq.Expressions; 2 | 3 | namespace LambdicSql.ConverterServices 4 | { 5 | /// 6 | /// Member information of object creation. 7 | /// 8 | public class ObjectCreateMemberInfo 9 | { 10 | /// 11 | /// Member name. 12 | /// 13 | public string Name { get; } 14 | 15 | /// 16 | /// Expression became the basis. 17 | /// It is null when made from type information. 18 | /// 19 | public Expression Expression { get; } 20 | 21 | /// 22 | /// Constructor. 23 | /// 24 | /// Member name. 25 | /// Expression became the basis.It is null when made from type information. 26 | public ObjectCreateMemberInfo(string name, Expression expression) 27 | { 28 | Name = name; 29 | Expression = expression; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/SymbolConverters/ClauseStyleConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using System.Linq.Expressions; 3 | using LambdicSql.ConverterServices.Inside; 4 | using LambdicSql.BuilderServices.Inside; 5 | 6 | namespace LambdicSql.ConverterServices.SymbolConverters 7 | { 8 | /// 9 | /// SQL symbol converter attribute for clause. 10 | /// 11 | public class ClauseStyleConverterAttribute : MethodConverterAttribute 12 | { 13 | GeneralStyleConverterCore _core = new GeneralStyleConverterCore(); 14 | 15 | /// 16 | /// Indent. 17 | /// 18 | public int Indent { get; set; } 19 | 20 | /// 21 | /// Name.If it is empty, use the name of the method. 22 | /// 23 | public string Name { get { return _core.Name; } set { _core.Name = value; } } 24 | 25 | /// 26 | /// Vanish, if empty params. 27 | /// 28 | public bool VanishIfEmptyParams { get { return _core.VanishIfEmptyParams; } set { _core.VanishIfEmptyParams = value; } } 29 | 30 | /// 31 | /// Constructor. 32 | /// 33 | public ClauseStyleConverterAttribute() { } 34 | 35 | /// 36 | /// Constructor. 37 | /// 38 | /// name. 39 | public ClauseStyleConverterAttribute(string name) => Name = name; 40 | 41 | /// 42 | /// Convert expression to code. 43 | /// 44 | /// Expression. 45 | /// Expression converter. 46 | /// Parts. 47 | public override ICode Convert(MethodCallExpression expression, ExpressionConverter converter) 48 | { 49 | var args = _core.InitAndConvertArguments(expression, converter); 50 | if (args == null) return string.Empty.ToCode(); 51 | var hArgs = new HCode(args) { Separator = ", " }; 52 | return new HCode(_core.NameCode, hArgs) { AddIndentNewLine = true, Separator = " ", Indent = Indent }; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/SymbolConverters/EnumToStringConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.BuilderServices.Inside; 3 | using LambdicSql.MultiplatformCompatibe; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace LambdicSql.ConverterServices.SymbolConverters 8 | { 9 | /// 10 | /// SQL symbol converter attribute for keyword. 11 | /// 12 | [AttributeUsage(AttributeTargets.Enum)] 13 | public class EnumToStringConverterAttribute : ObjectConverterAttribute 14 | { 15 | Dictionary _resolver; 16 | 17 | /// 18 | /// Convert object to code. 19 | /// 20 | /// Object. 21 | /// Parts. 22 | public override ICode Convert(object value) 23 | { 24 | lock (this) 25 | { 26 | if (_resolver == null) 27 | { 28 | _resolver = new Dictionary(); 29 | var type = value.GetType(); 30 | foreach (var e in type.GetFieldsEx()) 31 | { 32 | var fieldName = e.GetAttribute(); 33 | var sqlName = fieldName == null ? e.Name.ToUpper() : fieldName.Name; 34 | _resolver.Add(e.Name, sqlName.ToCode()); 35 | } 36 | } 37 | } 38 | return _resolver[value.ToString()]; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/SymbolConverters/FieldSqlNameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LambdicSql.ConverterServices.SymbolConverters 4 | { 5 | /// 6 | /// SQL symbol converter attribute for keyword. 7 | /// 8 | [AttributeUsage(AttributeTargets.Field)] 9 | public class FieldSqlNameAttribute : Attribute 10 | { 11 | internal string Name { get; } 12 | 13 | /// 14 | /// Constructor. 15 | /// 16 | /// Name. 17 | public FieldSqlNameAttribute(string name) 18 | { 19 | Name = name; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/SymbolConverters/FormatDirection.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql.ConverterServices.SymbolConverters 2 | { 3 | /// 4 | /// Direction to arrange. 5 | /// 6 | public enum FormatDirection 7 | { 8 | /// 9 | /// Horizontal. 10 | /// 11 | Horizontal, 12 | 13 | /// 14 | /// Vertical. 15 | /// 16 | Vertical 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/SymbolConverters/FuncStyleConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using System.Linq.Expressions; 3 | using LambdicSql.BuilderServices.Inside; 4 | using LambdicSql.ConverterServices.Inside; 5 | using static LambdicSql.BuilderServices.Inside.PartsUtils; 6 | 7 | namespace LambdicSql.ConverterServices.SymbolConverters 8 | { 9 | /// 10 | /// SQL symbol converter attribute for SQL Function. 11 | /// 12 | public class FuncStyleConverterAttribute : MethodConverterAttribute 13 | { 14 | GeneralStyleConverterCore _core = new GeneralStyleConverterCore(); 15 | 16 | /// 17 | /// Indent. 18 | /// 19 | public int Indent { get; set; } 20 | 21 | /// 22 | /// Name.If it is empty, use the name of the method. 23 | /// 24 | public string Name { get { return _core.Name; } set { _core.Name = value; } } 25 | 26 | /// 27 | /// Vanish, if empty params. 28 | /// 29 | public bool VanishIfEmptyParams { get { return _core.VanishIfEmptyParams; } set { _core.VanishIfEmptyParams = value; } } 30 | 31 | /// 32 | /// Constructor. 33 | /// 34 | public FuncStyleConverterAttribute() { } 35 | 36 | /// 37 | /// Constructor. 38 | /// 39 | /// name. 40 | public FuncStyleConverterAttribute(string name) => Name = name; 41 | 42 | /// 43 | /// Convert expression to code. 44 | /// 45 | /// Expression. 46 | /// Expression converter. 47 | /// Parts. 48 | public override ICode Convert(MethodCallExpression expression, ExpressionConverter converter) 49 | { 50 | var args = _core.InitAndConvertArguments(expression, converter); 51 | if (args == null) return string.Empty.ToCode(); 52 | var hArgs = new AroundCode(new HCode(args) { Separator = ", " }, "", ")"); 53 | return new HCode(Line(_core.NameCode, "(".ToCode()), hArgs) { AddIndentNewLine = true, Indent = Indent }; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/SymbolConverters/MemberConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.BuilderServices.Inside; 3 | using System; 4 | using System.Linq.Expressions; 5 | 6 | namespace LambdicSql.ConverterServices.SymbolConverters 7 | { 8 | /// 9 | /// SQL symbol converter attribute for property or field. 10 | /// 11 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] 12 | public class MemberConverterAttribute : Attribute 13 | { 14 | /// 15 | /// Name.If it is empty, use the name of the member. 16 | /// 17 | public string Name { get; set; } 18 | 19 | /// 20 | /// Constructor. 21 | /// 22 | public MemberConverterAttribute() { } 23 | 24 | /// 25 | /// Constructor. 26 | /// 27 | /// name. 28 | public MemberConverterAttribute(string name) => Name = name; 29 | 30 | /// 31 | /// Convert expression to code. 32 | /// 33 | /// Expression. 34 | /// Expression converter. 35 | /// Parts. 36 | public ICode Convert(MemberExpression expression, ExpressionConverter converter) 37 | { 38 | if (string.IsNullOrEmpty(Name)) Name = expression.Member.Name.ToUpper(); 39 | return Name.ToCode(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/SymbolConverters/MemberTableConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LambdicSql.ConverterServices.SymbolConverters 4 | { 5 | /// 6 | /// SQL symbol converter attribute for member. You can define system tables. 7 | /// 8 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] 9 | public class MemberTableConverterAttribute : Attribute 10 | { 11 | /// 12 | /// Name.If it is empty, use the name of the member. 13 | /// 14 | public string Name { get; set; } 15 | 16 | /// 17 | /// Constructor. 18 | /// 19 | public MemberTableConverterAttribute() { } 20 | 21 | /// 22 | /// Constructor. 23 | /// 24 | /// name. 25 | public MemberTableConverterAttribute(string name) => Name = name; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/SymbolConverters/MethodConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using System; 3 | using System.Linq.Expressions; 4 | 5 | namespace LambdicSql.ConverterServices.SymbolConverters 6 | { 7 | /// 8 | /// SQL symbol converter attribute for method. 9 | /// 10 | [AttributeUsage(AttributeTargets.Method)] 11 | public abstract class MethodConverterAttribute : Attribute 12 | { 13 | /// 14 | /// Convert expression to code. 15 | /// 16 | /// Expression. 17 | /// Expression converter. 18 | /// Parts. 19 | public abstract ICode Convert(MethodCallExpression expression, ExpressionConverter converter); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/SymbolConverters/MethodFormatConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using System.Linq.Expressions; 3 | using LambdicSql.ConverterServices.Inside; 4 | 5 | namespace LambdicSql.ConverterServices.SymbolConverters 6 | { 7 | /// 8 | /// SQL symbol converter attribute for clause. 9 | /// 10 | public class MethodFormatConverterAttribute : MethodConverterAttribute 11 | { 12 | FormatConverterCore _core = new FormatConverterCore(); 13 | 14 | /// 15 | /// Direction to arrange. 16 | /// 17 | public FormatDirection FormatDirection { get { return _core.FormatDirection; } set { _core.FormatDirection = value; } } 18 | 19 | /// 20 | /// Format. 21 | /// for exsample... 22 | /// [MethodFormatConverter(Format = "GROUP BY |[< ,>0] WITH ROLLUP")] 23 | /// | -> | Letters that are more distant are not broken. The character on the right side will be broken as appropriate. 24 | /// [i] -> It is converted to the argument of the specified index. 25 | /// [<>i] -> Indicates that arguments of the specified index will be expanded. It must be an array type. Specify a separator in <>. 26 | /// [$i] -> It means converting an argument to a direct value. 27 | /// [#i] -> It specifies that the argument contains a column and that it is converted to only column names without a table name. 28 | /// [!i] -> Specifies that the argument is a special character and is to be converted with intact characters without ''. 29 | /// [*i] -> It use the variable name. 30 | /// &left; -> ] 31 | /// &right; -> ] 32 | /// 33 | public string Format { get { return _core.Format; } set { _core.Format = value; } } 34 | 35 | /// 36 | /// Vanish, if empty params. 37 | /// 38 | public bool VanishIfEmptyParams { get { return _core.VanishIfEmptyParams; } set { _core.VanishIfEmptyParams = value; } } 39 | 40 | /// 41 | /// Indent. 42 | /// 43 | public int Indent { get { return _core.Indent; } set { _core.Indent = value; } } 44 | 45 | /// 46 | /// Constructor. 47 | /// 48 | public MethodFormatConverterAttribute() { } 49 | 50 | /// 51 | /// Constructor. 52 | /// 53 | /// format. 54 | public MethodFormatConverterAttribute(string format) => Format = format; 55 | 56 | /// 57 | /// Convert expression to code. 58 | /// 59 | /// Expression. 60 | /// Expression converter. 61 | /// Parts. 62 | public override ICode Convert(MethodCallExpression expression, ExpressionConverter converter) 63 | => _core.Convert(expression.Arguments, converter); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/SymbolConverters/NewConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using System; 3 | using System.Linq.Expressions; 4 | 5 | namespace LambdicSql.ConverterServices.SymbolConverters 6 | { 7 | /// 8 | /// SQL symbol converter attribute for constructor. 9 | /// 10 | [AttributeUsage(AttributeTargets.Constructor)] 11 | public abstract class NewConverterAttribute : Attribute 12 | { 13 | /// 14 | /// Convert expression to code. 15 | /// 16 | /// Expression. 17 | /// Expression converter. 18 | /// Parts. 19 | public abstract ICode Convert(NewExpression expression, ExpressionConverter converter); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/SymbolConverters/NewFormatConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.ConverterServices.Inside; 3 | using System.Linq.Expressions; 4 | 5 | namespace LambdicSql.ConverterServices.SymbolConverters 6 | { 7 | /// 8 | /// SQL symbol converter attribute for clause. 9 | /// 10 | public class NewFormatConverterAttribute : NewConverterAttribute 11 | { 12 | FormatConverterCore _core = new FormatConverterCore(); 13 | 14 | /// 15 | /// Format. 16 | /// for exsample... 17 | /// [MethodFormatConverter(Format = "GROUP BY |[< ,>0] WITH ROLLUP")] 18 | /// | -> | Letters that are more distant are not broken. The character on the right side will be broken as appropriate. 19 | /// [i] -> It is converted to the argument of the specified index. 20 | /// [<>i] -> Indicates that arguments of the specified index will be expanded. It must be an array type. Specify a separator in <>. 21 | /// [$i] -> It means converting an argument to a direct value. 22 | /// [#i] -> It specifies that the argument contains a column and that it is converted to only column names without a table name. 23 | /// [!i] -> Specifies that the argument is a special character and is to be converted with intact characters without ''. 24 | /// [*i] -> It use the variable name. 25 | /// &left; -> ] 26 | /// &right; -> ] 27 | /// 28 | public string Format { get { return _core.Format; } set { _core.Format = value; } } 29 | 30 | /// 31 | /// Vanish, if empty params. 32 | /// 33 | public bool VanishIfEmptyParams { get { return _core.VanishIfEmptyParams; } set { _core.VanishIfEmptyParams = value; } } 34 | 35 | /// 36 | /// Constructor. 37 | /// 38 | public NewFormatConverterAttribute() { } 39 | 40 | /// 41 | /// Constructor. 42 | /// 43 | /// format. 44 | public NewFormatConverterAttribute(string format) => Format = format; 45 | 46 | /// 47 | /// Convert expression to code. 48 | /// 49 | /// Expression. 50 | /// Expression converter. 51 | /// Parts. 52 | public override ICode Convert(NewExpression expression, ExpressionConverter converter) 53 | => _core.Convert(expression.Arguments, converter); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/ConverterServices/SymbolConverters/ObjectConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using System; 3 | 4 | namespace LambdicSql.ConverterServices.SymbolConverters 5 | { 6 | /// 7 | /// SQL symbol converter attribute for object. 8 | /// 9 | public abstract class ObjectConverterAttribute : Attribute 10 | { 11 | /// 12 | /// Convert object to code. 13 | /// 14 | /// Object. 15 | /// Parts. 16 | public abstract ICode Convert(object obj); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/Db.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.ConverterServices; 2 | using LambdicSql.ConverterServices.Inside; 3 | using System; 4 | using System.Linq.Expressions; 5 | using LambdicSql.BuilderServices.Inside; 6 | 7 | namespace LambdicSql 8 | { 9 | /// 10 | /// Holds the database type. 11 | /// 12 | /// DB's type. 13 | public partial class Db where T : class 14 | { 15 | /// 16 | /// Create sql. 17 | /// 18 | /// The type represented by expression. 19 | /// Expression expressing Sql by lambda. 20 | /// Sql. 21 | public static Sql Sql(Expression> expression) 22 | { 23 | var db = DBDefineAnalyzer.GetDbInfo(); 24 | return new Sql(ExpressionConverter.CreateCode(db, expression.Body)); 25 | } 26 | 27 | /// 28 | /// Create a sql. 29 | /// 30 | /// It is the type selected in the SELECT clause. 31 | /// Expression expressing Sql by lambda. 32 | /// Sql. 33 | public static Sql Sql(Expression>> expression) 34 | { 35 | var db = DBDefineAnalyzer.GetDbInfo(); 36 | return new Sql(ExpressionConverter.CreateCode(db, expression.Body)); 37 | } 38 | 39 | /// 40 | /// Create a sql. 41 | /// 42 | /// Expression expressing Sql by lambda. 43 | /// Sql. 44 | public static Sql Sql(Expression>> expression) 45 | { 46 | var db = DBDefineAnalyzer.GetDbInfo(); 47 | return new Sql(ExpressionConverter.CreateCode(db, expression.Body)); 48 | } 49 | 50 | /// 51 | /// Create a sql. 52 | /// Add name. 53 | /// 54 | /// It is the type selected in the SELECT clause. 55 | /// Expression expressing Sql by lambda. 56 | /// Sql. 57 | public static Sql Sql(Expression>> expression) 58 | { 59 | var core = expression.Body as MemberExpression; 60 | if (core == null) 61 | { 62 | var db = DBDefineAnalyzer.GetDbInfo(); 63 | return new Sql(ExpressionConverter.CreateCode(db, expression.Body)); 64 | } 65 | return new Sql(core.Member.Name.ToCode()); 66 | } 67 | 68 | /// 69 | /// This is a method to customize the names of DB tables and columns. 70 | /// 71 | public static DbDefinitionCustomizerDelegate DefinitionCustomizer { get; set; } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/DbDefinitionCustomizerDelegate.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace LambdicSql 4 | { 5 | /// 6 | /// This is a method to customize the names of DB tables and columns. The following properties of T will be passed, so change the name appropriately. 7 | /// 8 | /// Property 9 | /// Customized name.If you do not customize, please return null or empty. 10 | public delegate string DbDefinitionCustomizerDelegate(PropertyInfo prop); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/IDbParam.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql 2 | { 3 | /// 4 | /// Represents a parameter information. 5 | /// 6 | public interface IDbParam 7 | { 8 | /// 9 | /// Gets or sets the value of the parameter. 10 | /// 11 | object Value { get; } 12 | 13 | /// 14 | /// Change Value. 15 | /// 16 | /// New Value. 17 | /// IDbParam after change. 18 | IDbParam ChangeValue(object value); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/LambdicSql.Shared.shproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | c69db6f7-9921-4351-a163-047d2550003f 5 | 14.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/Non.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql 2 | { 3 | /// 4 | /// Class not to express anything. 5 | /// 6 | public abstract class Non { } 7 | } 8 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/Specialized/Inside/CodeParts/StringFormatCode.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices; 2 | using LambdicSql.BuilderServices.Inside; 3 | using LambdicSql.BuilderServices.CodeParts; 4 | using System.Linq; 5 | 6 | namespace LambdicSql.Inside.CodeParts 7 | { 8 | class StringFormatCode : ICode 9 | { 10 | string _formatText; 11 | ICode[] _args; 12 | 13 | internal StringFormatCode(string formatText, ICode[] args) 14 | { 15 | _formatText = formatText; 16 | _args = args; 17 | } 18 | 19 | public bool IsSingleLine(BuildingContext context) => true; 20 | 21 | public bool IsEmpty => false; 22 | 23 | public string ToString(BuildingContext context) 24 | { 25 | var next = context.ChangeTopLevelQuery(true).ChangeIndent(0); 26 | return PartsUtils.GetIndent(context.Indent) + 27 | string.Format(_formatText, _args.Select(e => e.ToString(next)).ToArray()); 28 | } 29 | 30 | public ICode Accept(ICodeCustomizer customizer) => customizer.Visit(this); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/Specialized/SymbolConverters/ConditionConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.BuilderServices.Inside; 3 | using LambdicSql.ConverterServices; 4 | using LambdicSql.ConverterServices.SymbolConverters; 5 | using System.Linq.Expressions; 6 | 7 | namespace LambdicSql.Specialized.SymbolConverters 8 | { 9 | /// 10 | /// Attributes for converting the Condition utility. 11 | /// 12 | public class ConditionConverterAttribute : NewConverterAttribute 13 | { 14 | /// 15 | /// Convert expression to code. 16 | /// 17 | /// Expression. 18 | /// Expression converter. 19 | /// Parts. 20 | public override ICode Convert(NewExpression expression, ExpressionConverter converter) 21 | { 22 | var obj = converter.ConvertToObject(expression.Arguments[0]); 23 | return (bool)obj ? (ICode)new AroundCode(converter.ConvertToCode(expression.Arguments[1]), "(", ")") : string.Empty.ToCode(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/Specialized/SymbolConverters/ToSqlConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.ConverterServices; 3 | using LambdicSql.ConverterServices.SymbolConverters; 4 | using LambdicSql.Inside.CodeParts; 5 | using System.Linq; 6 | using System.Linq.Expressions; 7 | 8 | namespace LambdicSql.Specialized.SymbolConverters 9 | { 10 | /// 11 | /// Converter for ToSql conversion. 12 | /// 13 | public class ToSqlConverterAttribute : MethodConverterAttribute 14 | { 15 | /// 16 | /// Convert expression to code. 17 | /// 18 | /// Expression. 19 | /// Expression converter. 20 | /// Parts. 21 | public override ICode Convert(MethodCallExpression expression, ExpressionConverter converter) 22 | { 23 | var text = (string)converter.ConvertToObject(expression.Arguments[0]); 24 | var array = expression.Arguments[1] as NewArrayExpression; 25 | return new StringFormatCode(text, array.Expressions.Select(e => converter.ConvertToCode(e)).ToArray()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/Specialized/SymbolConverters/TwoWaySqlConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.BuilderServices.CodeParts; 2 | using LambdicSql.ConverterServices; 3 | using LambdicSql.ConverterServices.SymbolConverters; 4 | using LambdicSql.ConverterServices.Inside; 5 | using LambdicSql.Inside.CodeParts; 6 | using System.Linq; 7 | using System.Linq.Expressions; 8 | 9 | namespace LambdicSql.Specialized.SymbolConverters 10 | { 11 | /// 12 | /// Converter for TwoWaySql conversion. 13 | /// 14 | public class TwoWaySqlConverterAttribute : MethodConverterAttribute 15 | { 16 | /// 17 | /// Convert expression to code. 18 | /// 19 | /// Expression. 20 | /// Expression converter. 21 | /// Parts. 22 | public override ICode Convert(MethodCallExpression expression, ExpressionConverter converter) 23 | { 24 | var obj = converter.ConvertToObject(expression.Arguments[0]); 25 | var text = TowWaySqlSpec.ToStringFormat((string)obj); 26 | var array = expression.Arguments[1] as NewArrayExpression; 27 | return new StringFormatCode(text, array.Expressions.Select(e => converter.ConvertToCode(e)).ToArray()); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/SqlExpression.cs: -------------------------------------------------------------------------------- 1 | namespace LambdicSql 2 | { 3 | /// 4 | /// Express sql or part thereof. 5 | /// 6 | public abstract class SqlExpression { } 7 | } 8 | -------------------------------------------------------------------------------- /Project/LambdicSql.Shared/feat/NotInitializedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LambdicSql.feat 4 | { 5 | /// 6 | /// An exception if the required that is not initialized. 7 | /// 8 | public class NotInitializedException : Exception 9 | { 10 | /// 11 | /// Constructor. 12 | /// 13 | public NotInitializedException() { } 14 | 15 | /// 16 | /// Constructor. 17 | /// 18 | /// Message. 19 | public NotInitializedException(string message) : base(message) { } 20 | 21 | /// 22 | /// Constructor. 23 | /// 24 | /// Message. 25 | /// InnerException. 26 | public NotInitializedException(string message, Exception innerException) : base(message, innerException) { } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Project/LambdicSql.System.Data.Shared/DbParam.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.ConverterServices; 2 | using System.Data; 3 | 4 | namespace LambdicSql 5 | { 6 | /// 7 | /// Represents a parameter information. 8 | /// 9 | public class DbParam : IDbParam 10 | { 11 | /// 12 | /// Gets or sets the value of the parameter. 13 | /// 14 | public object Value { get; set; } 15 | 16 | /// 17 | /// Gets or sets the DbType of the parameter. 18 | /// 19 | public DbType? DbType { get; set; } 20 | 21 | /// 22 | /// Gets or sets a value indicating whether the parameter is input-only, output-only, bidirectional, or a stored procedure return value parameter. 23 | /// 24 | public ParameterDirection? Direction { get; set; } 25 | 26 | /// 27 | /// Gets or sets the name of the source column that is mapped to the DataSet and used for loading or returning the Value. 28 | /// 29 | public string SourceColumn { get; set; } 30 | 31 | /// 32 | /// Gets or sets the DataRowVersion to use when loading Value. 33 | /// 34 | public DataRowVersion? SourceVersion { get; set; } 35 | 36 | /// 37 | /// Indicates the precision of numeric parameters. 38 | /// 39 | public byte? Precision { get; set; } 40 | 41 | /// 42 | /// Indicates the scale of numeric parameters. 43 | /// 44 | public byte? Scale { get; set; } 45 | 46 | /// 47 | /// The size of the parameter. 48 | /// 49 | public int? Size { get; set; } 50 | 51 | /// 52 | /// Change Value. 53 | /// 54 | /// New Value. 55 | /// IDbParam after change. 56 | public virtual IDbParam ChangeValue(object value) 57 | { 58 | var clone = (DbParam)MemberwiseClone(); 59 | clone.Value = value; 60 | return clone; 61 | } 62 | } 63 | 64 | /// 65 | /// Represents a parameter information. 66 | /// 67 | /// The type that the parameter represents 68 | public class DbParam : DbParam 69 | { 70 | /// 71 | /// Converter for converting to T 72 | /// 73 | /// Source. 74 | public static implicit operator T(DbParam src) { throw new InvalitContextException("new DbParameter"); } 75 | 76 | /// 77 | /// Change Value. 78 | /// 79 | /// New Value. 80 | /// IDbParam after change. 81 | public override IDbParam ChangeValue(object value) 82 | { 83 | var clone = (DbParam)MemberwiseClone(); 84 | clone.Value = value; 85 | return clone; 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Project/LambdicSql.System.Data.Shared/LambdicSql.System.Data.Shared.projitems: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | 3a55b636-45b4-475d-9f5d-d91f8a188bb8 7 | 8 | 9 | LambdicSql.System.Data.Shared 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Project/LambdicSql.System.Data.Shared/LambdicSql.System.Data.Shared.shproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 3a55b636-45b4-475d-9f5d-d91f8a188bb8 5 | 14.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Project/LambdicSql.System.Data.Shared/MultiplatformCompatibe/BuildedSqlExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LambdicSql 4 | { 5 | /// 6 | /// Extensions for BuildedSql. 7 | /// 8 | public static class BuildedSqlExtensions 9 | { 10 | /// 11 | /// Get parameters. 12 | /// 13 | /// BuildedSql. 14 | /// Parameters. 15 | public static Dictionary GetParams(this BuildedSql sql) 16 | { 17 | return sql.GetParams(e => 18 | { 19 | var dbParam = e as DbParam; 20 | return dbParam ?? new DbParam { Value = e.Value }; 21 | }); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Project/Performance/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Project/Performance/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 6 | // アセンブリに関連付けられている情報を変更するには、 7 | // これらの属性値を変更してください。 8 | [assembly: AssemblyTitle("Performance")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Performance")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから 18 | // 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、 19 | // その型の ComVisible 属性を true に設定してください。 20 | [assembly: ComVisible(false)] 21 | 22 | // このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります 23 | [assembly: Guid("78a98bde-6d67-40ef-bd40-705ea697ed2e")] 24 | 25 | // アセンブリのバージョン情報は次の 4 つの値で構成されています: 26 | // 27 | // メジャー バージョン 28 | // マイナー バージョン 29 | // ビルド番号 30 | // Revision 31 | // 32 | // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を 33 | // 既定値にすることができます: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Project/Performance/binsample3.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Codeer-Software/LambdicSql/99e964011f5848e448127fbc28af2c4bd892e66b/Project/Performance/binsample3.db -------------------------------------------------------------------------------- /Project/Performance/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Project/Test.NET35/Helper/AssertHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Microsoft.VisualStudio.TestTools.UnitTesting 4 | { 5 | class Assert 6 | { 7 | internal static void AreEqual(object lhs, object rhs) 8 | { 9 | if (lhs == null && rhs == null) return; 10 | if (lhs == null || rhs == null) throw new InvalidProgramException(); 11 | if (!lhs.Equals(rhs)) throw new InvalidProgramException(); 12 | } 13 | 14 | internal static void AreNotEqual(object lhs, object rhs) 15 | { 16 | if (lhs == null && rhs == null) throw new InvalidProgramException(); 17 | if (lhs == null || rhs == null) return; 18 | if (lhs.Equals(rhs)) throw new InvalidProgramException(); 19 | } 20 | 21 | internal static void IsTrue(bool condition) 22 | { 23 | if (!condition) throw new InvalidProgramException(); 24 | } 25 | 26 | internal static void IsFalse(bool condition) 27 | { 28 | if (condition) throw new InvalidProgramException(); 29 | } 30 | } 31 | 32 | public enum DataAccessMethod 33 | { 34 | Sequential 35 | } 36 | public class TestContext { } 37 | public class TestClassAttribute : Attribute { } 38 | public class TestInitializeAttribute : Attribute { } 39 | public class TestCleanupAttribute : Attribute { } 40 | public class TestMethodAttribute : Attribute { } 41 | public class IgnoreAttribute : Attribute { } 42 | public class DataSourceAttribute : Attribute 43 | { 44 | internal DataSourceAttribute(string providerInvariantName, string connectionString, string tableName, DataAccessMethod dataAccessMethod) { } 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Project/Test.NET35/Helper/DBProviderInfo.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Test.Helper 8 | { 9 | public static class DBProviderInfo 10 | { 11 | public const string Operation = ""; 12 | public const string Connection = ""; 13 | public const string Sheet = ""; 14 | public const DataAccessMethod Method = DataAccessMethod.Sequential; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Project/Test.NET35/Helper/DataType.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql.ConverterServices; 2 | using LambdicSql.ConverterServices.SymbolConverters; 3 | 4 | namespace LambdicSql 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /Project/Test.NET35/Helper/ReflectionAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Test 4 | { 5 | static class ReflectionAdapter 6 | { 7 | internal static bool IsAssignableFromEx(this Type type, Type target) => type.IsAssignableFrom(target); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Project/Test.NET35/Helper/Symbol.Clauses.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Codeer-Software/LambdicSql/99e964011f5848e448127fbc28af2c4bd892e66b/Project/Test.NET35/Helper/Symbol.Clauses.cs -------------------------------------------------------------------------------- /Project/Test.NET35/Helper/Symbol.Etc.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql; 2 | using LambdicSql.ConverterServices; 3 | using LambdicSql.ConverterServices.SymbolConverters; 4 | 5 | namespace Test 6 | { 7 | /// 8 | /// SQL Symbols. 9 | /// It can only be used within methods of the LambdicSql.Db class. 10 | /// Use[using static LambdicSql.Keywords;], you can use to write natural SQL. 11 | /// 12 | public static partial class Symbol 13 | { 14 | /// 15 | /// It's *. 16 | /// 17 | /// Type of selected. 18 | /// The type you want to obtain with the SELECT clause. Usually you specify a table element. 19 | /// * 20 | [ClauseStyleConverter(Name = "*")] 21 | public static AsteriskElement Asterisk(TSelected selected) { throw new InvalitContextException(nameof(Asterisk)); } 22 | 23 | /// 24 | /// It's *. 25 | /// 26 | /// Type of selected. 27 | /// * 28 | [ClauseStyleConverter(Name = "*")] 29 | public static AsteriskElement Asterisk() { throw new InvalitContextException(nameof(Asterisk)); } 30 | 31 | /// 32 | /// It's *. 33 | /// 34 | /// * 35 | [ClauseStyleConverter(Name = "*")] 36 | public static AsteriskElement Asterisk() { throw new InvalitContextException(nameof(Asterisk)); } 37 | 38 | /// 39 | /// ASC Keyword. 40 | /// 41 | /// target column. 42 | /// ASC. 43 | [MethodFormatConverter(Format = "[0] ASC")] 44 | public static OrderByElement Asc(object target) { throw new InvalitContextException(nameof(Asc)); } 45 | 46 | /// 47 | /// DESC Keyword. 48 | /// 49 | /// target column. 50 | /// DESC. 51 | [MethodFormatConverter(Format = "[0] DESC")] 52 | public static OrderByElement Desc(object target) { throw new InvalitContextException(nameof(Desc)); } 53 | 54 | /// 55 | /// TOP Keyword. 56 | /// 57 | /// Count. 58 | /// TOP. 59 | [MethodFormatConverter(Format = "TOP [$0]")] 60 | public static TopElement Top(long count) { throw new InvalitContextException(nameof(Top)); } 61 | 62 | /// 63 | /// ALL Keyword 64 | /// 65 | /// ALL. 66 | [ClauseStyleConverter] 67 | public static AggregatePredicateAllElement All() { throw new InvalitContextException(nameof(All)); } 68 | 69 | /// 70 | /// DISTINCT Keyword. 71 | /// 72 | /// DISTINCT. 73 | [ClauseStyleConverter] 74 | public static AggregatePredicateElement Distinct() { throw new InvalitContextException(nameof(All)); } 75 | 76 | [MethodFormatConverter(Format = "INSERTED")] 77 | public static T Inserted() => throw new InvalitContextException(nameof(Inserted)); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Project/Test.NET35/Helper/Symbol.Funcs.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql; 2 | using LambdicSql.ConverterServices; 3 | using LambdicSql.ConverterServices.SymbolConverters; 4 | using System; 5 | 6 | namespace Test 7 | { 8 | /// 9 | /// SQL Symbols. 10 | /// It can only be used within methods of the LambdicSql.Db class. 11 | /// Use[using static LambdicSql.Keywords;], you can use to write natural SQL. 12 | /// 13 | public static partial class Symbol 14 | { 15 | /// 16 | /// SUM function. 17 | /// 18 | /// Type represented by expression. 19 | /// The column or expression that is function target. 20 | /// Total. 21 | [FuncStyleConverter] 22 | public static T Sum(T column) { throw new InvalitContextException(nameof(Sum)); } 23 | 24 | /// 25 | /// SUM function. 26 | /// 27 | /// Type represented by expression. 28 | /// Specify All or Distinct. 29 | /// The column or expression that is function target. 30 | /// Total. 31 | [MethodFormatConverter(Format = "SUM(|[0] [1])")] 32 | public static T Sum(AggregatePredicateElement aggregatePredicate, T column) { throw new InvalitContextException(nameof(Sum)); } 33 | 34 | /// 35 | /// Constructor. 36 | /// 37 | /// Preceding row count. 38 | [MethodFormatConverter(Format = "ROWS [$0] PRECEDING")] 39 | public static OverElement Rows(long preceding) { throw new InvalitContextException(nameof(Rows)); } 40 | 41 | /// 42 | /// Constructor. 43 | /// 44 | /// Preceding row count. 45 | /// Following row count. 46 | [MethodFormatConverter(Format = "ROWS BETWEEN [$0] PRECEDING AND [$1] FOLLOWING")] 47 | public static OverElement Rows(long preceding, long following) { throw new InvalitContextException(nameof(Rows)); } 48 | 49 | /// 50 | /// Constructor. 51 | /// 52 | /// Specify column or expression. 53 | [MethodFormatConverter(Format = "PARTITION BY|[<,>0]", FormatDirection = FormatDirection.Vertical)] 54 | public static OverElement PartitionBy(params object[] columns) { throw new InvalitContextException(nameof(PartitionBy)); } 55 | 56 | /// 57 | /// 58 | /// 59 | /// 60 | /// 61 | /// 62 | /// 63 | [MethodFormatConverter(Format = "OVER(|[< >1])", FormatDirection = FormatDirection.Vertical)] 64 | public static T Over(this T before, params OverElement[] args) { throw new InvalitContextException(nameof(Over)); } 65 | 66 | /// 67 | /// 68 | /// 69 | /// 70 | /// 71 | [MethodFormatConverter(Format = "OVER(|[< >0])", FormatDirection = FormatDirection.Vertical)] 72 | public static OverReturnValue Over(params OverElement[] args) { throw new InvalitContextException(nameof(Over)); } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Project/Test.NET35/Helper/TestEnvironment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using System.Data; 5 | using System.Data.SqlClient; 6 | 7 | namespace Test.Helper 8 | { 9 | static class TestEnvironment 10 | { 11 | internal static string ConnectionString => File.ReadAllText(FindNearFile("db.txt")).Trim(); 12 | 13 | static string FindNearFile(string fileName) 14 | { 15 | var path = typeof(TestEnvironment).Assembly.Location; 16 | while (true) 17 | { 18 | var filePath = Path.Combine(path, fileName); 19 | if (File.Exists(filePath)) 20 | { 21 | return filePath; 22 | } 23 | path = Path.GetDirectoryName(path); 24 | } 25 | throw new NotSupportedException(); 26 | } 27 | 28 | internal static IDbConnection CreateConnection(TestContext context) 29 | => new SqlConnection(ConnectionString); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Project/Test.NET35/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 6 | // アセンブリに関連付けられている情報を変更するには、 7 | // これらの属性値を変更してください。 8 | [assembly: AssemblyTitle("Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Test")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから 18 | // 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、 19 | // その型の ComVisible 属性を true に設定してください。 20 | [assembly: ComVisible(false)] 21 | 22 | // このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります 23 | [assembly: Guid("71a68d09-e2e8-44c8-99e9-e890e19db10b")] 24 | 25 | // アセンブリのバージョン情報は次の 4 つの値で構成されています: 26 | // 27 | // メジャー バージョン 28 | // マイナー バージョン 29 | // ビルド番号 30 | // Revision 31 | // 32 | // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を 33 | // 既定値にすることができます: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Project/Test.NET35/TestDbDefine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Linq; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using LambdicSql; 6 | using LambdicSql.feat.Dapper; 7 | using static Test.Symbol; 8 | using static Test.Helper.DBProviderInfo; 9 | using Test.Helper; 10 | 11 | namespace Test 12 | { 13 | [TestClass] 14 | public class TestDbDefine 15 | { 16 | public TestContext TestContext { get; set; } 17 | public IDbConnection _connection; 18 | 19 | [TestInitialize] 20 | public void TestInitialize() 21 | { 22 | _connection = TestEnvironment.CreateConnection(TestContext); 23 | _connection.Open(); 24 | } 25 | 26 | [TestCleanup] 27 | public void TestCleanup() => _connection.Dispose(); 28 | 29 | public class SelecteData 30 | { 31 | public string name { get; set; } 32 | public DateTime payment_date { get; set; } 33 | public decimal money { get; set; } 34 | } 35 | 36 | [TestMethod, DataSource(Operation, Connection, Sheet, Method)] 37 | public void Test_Normal() 38 | { 39 | var sql = Db.Sql(db => 40 | Select(new SelecteData 41 | { 42 | name = db.tbl_staff.name, 43 | payment_date = db.tbl_remuneration.payment_date, 44 | money = db.tbl_remuneration.money 45 | }). 46 | From(db.tbl_remuneration). 47 | Join(db.tbl_staff, db.tbl_staff.id == db.tbl_remuneration.staff_id)); 48 | 49 | var datas = _connection.Query(sql).ToList(); 50 | Assert.IsTrue(0 < datas.Count); 51 | AssertEx.AreEqual(sql, _connection, 52 | @"SELECT 53 | tbl_staff.name AS name, 54 | tbl_remuneration.payment_date AS payment_date, 55 | tbl_remuneration.money AS money 56 | FROM tbl_remuneration 57 | JOIN tbl_staff ON tbl_staff.id = tbl_remuneration.staff_id"); 58 | } 59 | 60 | [TestMethod, DataSource(Operation, Connection, Sheet, Method)] 61 | public void Test_Schema() 62 | { 63 | if (!_connection.IsTarget(TargetDB.SqlServer)) return; 64 | 65 | var sql = Db.Sql(db => 66 | Select(new SelecteData 67 | { 68 | name = db.dbo.tbl_staff.name, 69 | payment_date = db.dbo.tbl_remuneration.payment_date, 70 | money = db.dbo.tbl_remuneration.money 71 | }). 72 | From(db.dbo.tbl_remuneration). 73 | Join(db.dbo.tbl_staff, db.dbo.tbl_staff.id == db.dbo.tbl_remuneration.staff_id)); 74 | 75 | var datas = _connection.Query(sql).ToList(); 76 | Assert.IsTrue(0 < datas.Count); 77 | AssertEx.AreEqual(sql, _connection, 78 | @"SELECT 79 | dbo.tbl_staff.name AS name, 80 | dbo.tbl_remuneration.payment_date AS payment_date, 81 | dbo.tbl_remuneration.money AS money 82 | FROM dbo.tbl_remuneration 83 | JOIN dbo.tbl_staff ON dbo.tbl_staff.id = dbo.tbl_remuneration.staff_id"); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Project/Test.NET35/TestMethodFormatConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Linq; 4 | using System.Collections.Generic; 5 | using System.Data.SqlClient; 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | using LambdicSql; 8 | using LambdicSql.feat.Dapper; 9 | using static Test.Symbol; 10 | using static Test.Helper.DBProviderInfo; 11 | using Test.Helper; 12 | using LambdicSql.ConverterServices.SymbolConverters; 13 | 14 | namespace Test 15 | { 16 | 17 | [TestClass] 18 | public class TestMethodFormatConverter 19 | { 20 | [TestMethod] 21 | public void TestEscape() 22 | { 23 | var sql = Db.Sql(db => Escape(1)); 24 | Assert.AreEqual(sql.Build(typeof(SqlConnection)).Text, "ESCAPE[@p_0]"); 25 | } 26 | 27 | class A { } 28 | 29 | [TestMethod] 30 | public void TestVariableName() 31 | { 32 | Staff starff = null; 33 | var sql = Db.Sql(db => Variable(starff)); 34 | Assert.AreEqual(sql.Build(typeof(SqlConnection)).Text, "starff"); 35 | } 36 | 37 | [MethodFormatConverter(Format = "ESCAPE&left;[0]&right;")] 38 | static int Escape(int val) => 0; 39 | 40 | [MethodFormatConverter(Format = "[*0]")] 41 | static int Variable(object variable) => 0; 42 | 43 | [MethodFormatConverter(Format = "[0],[0]")] 44 | static int SameParameter(object variable) => 0; 45 | 46 | [TestMethod] 47 | public void TestSameParameter() 48 | { 49 | var sql = Db.Sql(db => SameParameter(db.tbl_staff)); 50 | Assert.AreEqual(sql.Build(typeof(SqlConnection)).Text, "tbl_staff,tbl_staff"); 51 | } 52 | 53 | // [TestMethod] 54 | public void XXX() 55 | { 56 | var id = 1; 57 | var ID = 1; 58 | Db.Sql(db => Where(id == 1 || ID == 2)); // exception 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Project/Test.NET35/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Project/Test.NET35/db.txt: -------------------------------------------------------------------------------- 1 | Data Source=DESKTOP-IBN02LQ;Initial Catalog=LambdicSqlTest;User ID=sa;Password=codeer; -------------------------------------------------------------------------------- /Project/Test.NET35/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Project/Test.NetCore/BaseClassTest.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql; 2 | using LambdicSql.BuilderServices; 3 | using LambdicSql.ConverterServices; 4 | using LambdicSql.ConverterServices.SymbolConverters; 5 | using Xunit; 6 | 7 | namespace Test.NetCore 8 | { 9 | public class BaseClassTest 10 | { 11 | class A 12 | { 13 | public int Id { get; set; } 14 | } 15 | 16 | class B : A 17 | { 18 | public string Text { get; set; } 19 | } 20 | 21 | class DB 22 | { 23 | public B B{ get; set; } 24 | } 25 | 26 | [ClauseStyleConverter] 27 | public static DataTypeElement NText() { throw new InvalitContextException(nameof(NText)); } 28 | 29 | [ClauseStyleConverter] 30 | public static DataTypeElement Int() { throw new InvalitContextException(nameof(Int)); } 31 | 32 | [MethodFormatConverter(Format = "CREATE TABLE [0](|[#$<,>1])", FormatDirection = FormatDirection.Vertical)] 33 | public static Clause CreateTable(object table, params TableDefinitionElement[] designer) { throw new InvalitContextException(nameof(CreateTable)); } 34 | 35 | [Fact] 36 | public void Test() 37 | { 38 | var text = Db.Sql(db => CreateTable(db.B, 39 | new Column(db.B.Id, Int()), 40 | new Column(db.B.Text, NText()))).Build(new DialectOption()).Text; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Project/Test.NetCore/ReflectionAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace Test 5 | { 6 | static class ReflectionAdapter 7 | { 8 | internal static bool IsAssignableFromEx(this Type type, Type target) 9 | => type.GetTypeInfo().IsAssignableFrom(target.GetTypeInfo()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Project/Test.NetCore/Test.NetCore.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | all 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Project/Test.NetCore/TestDbDefineCustomizer.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql; 2 | using LambdicSql.BuilderServices; 3 | using System; 4 | using System.Text.RegularExpressions; 5 | using Xunit; 6 | using static Test.Symbol; 7 | 8 | namespace Test 9 | { 10 | public class TestDbDefineCustomizer 11 | { 12 | public class Staff 13 | { 14 | public int Id { get; set; } 15 | public string Name { get; set; } 16 | } 17 | 18 | public class Remuneration 19 | { 20 | public int id { get; set; } 21 | public int staff_id { get; set; } 22 | public DateTime payment_date { get; set; } 23 | public decimal money { get; set; } 24 | } 25 | 26 | public class DB1 27 | { 28 | public Staff TblStaff { get; set; } 29 | public Remuneration tbl_remuneration { get; set; } 30 | } 31 | public class DB2 32 | { 33 | public Staff TblStaff { get; set; } 34 | } 35 | 36 | [Fact] 37 | public void Test1() 38 | { 39 | Db.DefinitionCustomizer = p => null; 40 | 41 | var sql = Db.Sql(db => 42 | Select(new 43 | { 44 | name = db.TblStaff.Name, 45 | }). 46 | From(db.TblStaff)); 47 | 48 | var txt = sql.Build(new DialectOption()).Text; 49 | var expected = @"SELECT 50 | TblStaff.Name AS name 51 | FROM TblStaff"; 52 | Assert.Equal(expected, txt); 53 | } 54 | 55 | [Fact] 56 | public void Test2() 57 | { 58 | Db.DefinitionCustomizer = p => 59 | { 60 | var input = p.Name; 61 | if (string.IsNullOrEmpty(input)) { return input; } 62 | var startUnderscores = Regex.Match(input, @"^_+"); 63 | return startUnderscores + Regex.Replace(input, @"([a-z0-9])([A-Z])", "$1_$2").ToLower(); 64 | }; 65 | 66 | var sql = Db.Sql(db => 67 | Select(new 68 | { 69 | name = db.TblStaff.Name, 70 | }). 71 | From(db.TblStaff)); 72 | 73 | var txt = sql.Build(new DialectOption()).Text; 74 | var expected = @"SELECT 75 | tbl_staff.name AS name 76 | FROM tbl_staff"; 77 | Assert.Equal(expected, txt); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Project/Test.PCL/Helper/DB.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Test.PCL 4 | { 5 | public class Staff 6 | { 7 | public int id { get; set; } 8 | public string name { get; set; } 9 | } 10 | 11 | public class Remuneration 12 | { 13 | public int id { get; set; } 14 | public int staff_id { get; set; } 15 | public DateTime payment_date { get; set; } 16 | public decimal money { get; set; } 17 | } 18 | 19 | public class Data 20 | { 21 | public int id { get; set; } 22 | public int val1 { get; set; } 23 | public string val2 { get; set; } 24 | } 25 | 26 | public class DB 27 | { 28 | public Staff tbl_staff { get; set; } 29 | public Remuneration tbl_remuneration { get; set; } 30 | public Data tbl_data { get; set; } 31 | } 32 | 33 | public class DBEX 34 | { 35 | public DB dbo { get; set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Project/Test.PCL/Helper/TestEnvironment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using SQLite; 5 | 6 | namespace Test.PCL 7 | { 8 | static class TestEnvironment 9 | { 10 | internal static string SQLiteTest1Path => Path.GetFullPath("../../../SQLiteTest1.db"); 11 | 12 | internal static SQLiteConnection CreateConnection(TestContext context) 13 | => new SQLiteConnection(SQLiteTest1Path); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Project/Test.PCL/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 6 | // アセンブリに関連付けられている情報を変更するには、 7 | // これらの属性値を変更してください。 8 | [assembly: AssemblyTitle("TestPlc")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TestPlc")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから 18 | // 参照できなくなります。このアセンブリ内で COM から型にアクセスする必要がある場合は、 19 | // その型の ComVisible 属性を true に設定してください。 20 | [assembly: ComVisible(false)] 21 | 22 | // このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります 23 | [assembly: Guid("b49d78f2-618c-475c-9537-14748d94b3aa")] 24 | 25 | // アセンブリのバージョン情報は次の 4 つの値で構成されています: 26 | // 27 | // メジャー バージョン 28 | // マイナー バージョン 29 | // ビルド番号 30 | // Revision 31 | // 32 | // すべての値を指定するか、以下のように '*' を使用してビルド番号とリビジョン番号を 33 | // 既定値にすることができます: 34 | //[アセンブリ: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Project/Test.PCL/Test.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql; 2 | using static LambdicSql.Symbol; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using System.Diagnostics; 5 | using LambdicSql.feat.SQLiteNetPcl; 6 | 7 | namespace Test.PCL 8 | { 9 | [TestClass] 10 | public class Test 11 | { 12 | public TestContext TestContext { get; set; } 13 | 14 | [TestMethod] 15 | public void TestSelect() 16 | { 17 | int id = 2; 18 | var sql = Db.Sql(db => 19 | Select(Asterisk(db.tbl_staff)). 20 | From(db.tbl_staff). 21 | Where(db.tbl_staff.id == id || db.tbl_staff.id == 4 || db.tbl_staff.id < id) 22 | ); 23 | 24 | using (var con = TestEnvironment.CreateConnection(TestContext)) 25 | { 26 | SQLiteNetPclAdapter.Log = e => Debug.Print(e); 27 | var list = con.Query(sql); 28 | } 29 | } 30 | 31 | [TestMethod] 32 | public void Test_Delete_All() 33 | { 34 | var deleteAll = Db.Sql(db => 35 | Delete(). 36 | From(db.tbl_data)); 37 | 38 | var insert = Db.Sql(db => 39 | InsertInto(db.tbl_data, db.tbl_data.id, db.tbl_data.val2).Values(1, "val2")); 40 | 41 | using (var con = TestEnvironment.CreateConnection(TestContext)) 42 | { 43 | SQLiteNetPclAdapter.Log = e => Debug.Print(e); 44 | var countDel = con.Execute(deleteAll); 45 | var countInsert = con.Execute(insert); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Project/Test.PCL/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Project/Test/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Project/Test/Helper/CodeGenerate.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | 5 | namespace Test.Helper 6 | { 7 | // [TestClass] 8 | public class CodeGenerate 9 | { 10 | [TestMethod] 11 | public void CreateGetter() 12 | { 13 | string template = @" 14 | class GetterCore<[Ts]> : IGetter 15 | { 16 | public delegate object Func([DefArgs]); 17 | Func _func; 18 | public void Init(Expression exp, ParameterExpression[] param) => _func = Expression.Lambda(exp, param).Compile(); 19 | public object GetMemberObject(object[] arguments) => _func([Args]); 20 | }"; 21 | 22 | for (int i = 1; i < 31; i++) 23 | { 24 | var ts = string.Join(",", Enumerable.Range(0, i).Select(e => "T" + e)); 25 | var defArgs = string.Join(",", Enumerable.Range(0, i).Select(e => "T" + e + " t" + e)); 26 | var args = string.Join(",", Enumerable.Range(0, i).Select(e => "(T" + e + ")arguments[" + e + "]")); 27 | Debug.Print(template.Replace("[Ts]", ts).Replace("[Args]", args).Replace("[DefArgs]", defArgs)); 28 | } 29 | } 30 | 31 | [TestMethod] 32 | public void CreateSwitch() 33 | { 34 | string template = @"case [Len]: return Activator.CreateInstance(typeof(GetterCore<[Count]>).MakeGenericType(args), true) as IGetter;"; 35 | for (int i = 1; i < 30; i++) 36 | { 37 | var count = string.Empty; 38 | Enumerable.Range(0, i - 1).ToList().ForEach(e => count += ","); 39 | Debug.Print(template.Replace("[Len]", i.ToString()).Replace("[Count]", count)); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Project/Test/Helper/DBProviderInfo.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | 3 | namespace Test.Helper 4 | { 5 | public static class DBProviderInfo 6 | { 7 | public const string Operation = "System.Data.OleDB"; 8 | public const string Connection = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=Params.xlsx; Extended Properties='Excel 12.0;HDR=yes';"; 9 | public const string Sheet = "DB$"; 10 | public const DataAccessMethod Method = DataAccessMethod.Sequential; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Project/Test/Helper/ReflectionAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Test 4 | { 5 | static class ReflectionAdapter 6 | { 7 | internal static bool IsAssignableFromEx(this Type type, Type target) => type.IsAssignableFrom(target); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Project/Test/Model/ModelLambdicSqlTestDB.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Model 2 | { 3 | using System; 4 | using System.Data.Entity; 5 | using System.ComponentModel.DataAnnotations.Schema; 6 | using System.Linq; 7 | using Test.Helper; 8 | 9 | public partial class ModelLambdicSqlTestDB : DbContext 10 | { 11 | public ModelLambdicSqlTestDB() 12 | : base(TestEnvironment.EFConnectionString) 13 | { 14 | } 15 | 16 | public virtual DbSet tbl_data { get; set; } 17 | public virtual DbSet tbl_remuneration { get; set; } 18 | public virtual DbSet tbl_staff { get; set; } 19 | 20 | protected override void OnModelCreating(DbModelBuilder modelBuilder) 21 | { 22 | modelBuilder.Entity() 23 | .Property(e => e.id) 24 | .IsFixedLength(); 25 | 26 | modelBuilder.Entity() 27 | .Property(e => e.val2) 28 | .IsFixedLength(); 29 | 30 | modelBuilder.Entity() 31 | .Property(e => e.payment_date) 32 | .IsFixedLength(); 33 | 34 | modelBuilder.Entity() 35 | .Property(e => e.money) 36 | .HasPrecision(19, 4); 37 | 38 | modelBuilder.Entity() 39 | .Property(e => e.name) 40 | .IsUnicode(false); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Project/Test/Model/tbl_data.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Model 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.ComponentModel.DataAnnotations.Schema; 7 | using System.Data.Entity.Spatial; 8 | 9 | public partial class tbl_data 10 | { 11 | [StringLength(10)] 12 | public string id { get; set; } 13 | 14 | public int? val1 { get; set; } 15 | 16 | [StringLength(10)] 17 | public string val2 { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Project/Test/Model/tbl_remuneration.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Model 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.ComponentModel.DataAnnotations.Schema; 7 | using System.Data.Entity.Spatial; 8 | 9 | public partial class tbl_remuneration 10 | { 11 | public int? staff_id { get; set; } 12 | 13 | [StringLength(10)] 14 | public string payment_date { get; set; } 15 | 16 | [DatabaseGenerated(DatabaseGeneratedOption.None)] 17 | public int id { get; set; } 18 | 19 | [Column(TypeName = "money")] 20 | public decimal? money { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Project/Test/Model/tbl_staff.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Model 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.ComponentModel.DataAnnotations.Schema; 7 | using System.Data.Entity.Spatial; 8 | 9 | public partial class tbl_staff 10 | { 11 | [DatabaseGenerated(DatabaseGeneratedOption.None)] 12 | public int id { get; set; } 13 | 14 | [StringLength(50)] 15 | public string name { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Project/Test/Params.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Codeer-Software/LambdicSql/99e964011f5848e448127fbc28af2c4bd892e66b/Project/Test/Params.xlsx -------------------------------------------------------------------------------- /Project/Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 6 | // アセンブリに関連付けられている情報を変更するには、 7 | // これらの属性値を変更してください。 8 | [assembly: AssemblyTitle("Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Test")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから 18 | // 参照できなくなります。このアセンブリ内で COM から型にアクセスする必要がある場合は、 19 | // その型の ComVisible 属性を true に設定してください。 20 | [assembly: ComVisible(false)] 21 | 22 | // このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります 23 | [assembly: Guid("9f085001-f527-4cd1-bbbc-46eca30e1207")] 24 | 25 | // アセンブリのバージョン情報は次の 4 つの値で構成されています: 26 | // 27 | // メジャー バージョン 28 | // マイナー バージョン 29 | // ビルド番号 30 | // Revision 31 | // 32 | // すべての値を指定するか、以下のように '*' を使用してビルド番号とリビジョン番号を 33 | // 既定値にすることができます: 34 | //[アセンブリ: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Project/Test/Resources/CreateTableDataChange.txt: -------------------------------------------------------------------------------- 1 | CREATE TABLE tbl_data ( 2 | id INTEGER NOT NULL, 3 | val1 INTEGER, 4 | val2 VARCHAR(50), 5 | PRIMARY KEY (id) 6 | ) 7 | -------------------------------------------------------------------------------- /Project/Test/Resources/CreateTableRemuneration.txt: -------------------------------------------------------------------------------- 1 | CREATE TABLE tbl_remuneration ( 2 | id INTEGER NOT NULL, 3 | staff_id INTEGER, 4 | payment_date VARCHAR(50), 5 | money DECIMAL, 6 | PRIMARY KEY (id) 7 | ) 8 | -------------------------------------------------------------------------------- /Project/Test/Resources/CreateTableStaff.txt: -------------------------------------------------------------------------------- 1 | CREATE TABLE tbl_staff ( 2 | id INTEGER NOT NULL, 3 | name VARCHAR(50), 4 | PRIMARY KEY (id) 5 | ) 6 | -------------------------------------------------------------------------------- /Project/Test/Resources/InsertTableRemuneration.txt: -------------------------------------------------------------------------------- 1 | INSERT INTO tbl_remuneration (id, staff_id, payment_date, money) VALUES({0}, {1}, {2}, {3}) -------------------------------------------------------------------------------- /Project/Test/Resources/InsertTableStaff.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO tbl_staff (id, name) VALUES({0}, {1}) -------------------------------------------------------------------------------- /Project/Test/Test.csproj.qsx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | public Oracle.ManagedDataAccess.Client.OracleConnection Con => 5 | new Oracle.ManagedDataAccess.Client.OracleConnection("User Id=system; Password=orcl; Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA =(SERVICE_NAME = orcl)))"); 6 | -------------------------------------------------------------------------------- /Project/Test/TestCondition.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql; 2 | using LambdicSql.BuilderServices; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | namespace Test 6 | { 7 | [TestClass] 8 | public class TestCondition 9 | { 10 | class A 11 | { 12 | public int Id { get; set; } 13 | } 14 | 15 | class DB 16 | { 17 | public A A { get; set; } 18 | } 19 | 20 | [TestMethod] 21 | public void Test1() 22 | { 23 | var condition = new Sql(); 24 | 25 | foreach (var e in new[] { 1, 2, 3 }) 26 | { 27 | condition = Db.Sql(db => condition && db.A.Id == e); 28 | } 29 | var text = condition.Build(new DialectOption()).Text; 30 | var expected = @"((A.Id = @e) AND A.Id = @e_) AND A.Id = @e__"; 31 | Assert.AreEqual(expected, text); 32 | } 33 | 34 | [TestMethod] 35 | public void Test2() 36 | { 37 | var condition = new Sql(); 38 | 39 | foreach (var e in new[] { 1, 2, 3 }) 40 | { 41 | var value = e; 42 | condition = Db.Sql(db => condition && db.A.Id == value.NoName()); 43 | } 44 | var text = condition.Build(new DialectOption()).Text; 45 | var expected = @"((A.Id = @p_0) AND A.Id = @p_1) AND A.Id = @p_2"; 46 | Assert.AreEqual(expected, text); 47 | } 48 | } 49 | 50 | internal static class XX 51 | { 52 | internal static T NoName(this T value) => value; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Project/Test/TestDbDefineCustomizer.cs: -------------------------------------------------------------------------------- 1 | using LambdicSql; 2 | using LambdicSql.ConverterServices.SymbolConverters; 3 | using LambdicSql.feat.Dapper; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using Npgsql; 6 | using System; 7 | using System.ComponentModel.DataAnnotations.Schema; 8 | using System.Data; 9 | using System.Linq; 10 | using System.Text.RegularExpressions; 11 | using Test.Helper; 12 | using static Test.Helper.DBProviderInfo; 13 | using static Test.Symbol; 14 | 15 | namespace Test 16 | { 17 | [TestClass] 18 | public class TestDbDefineCustomizer 19 | { 20 | public class Staff 21 | { 22 | public int Id { get; set; } 23 | public string Name { get; set; } 24 | } 25 | 26 | public class DB1 27 | { 28 | public Staff TblStaff { get; set; } 29 | } 30 | public class DB2 31 | { 32 | public Staff TblStaff { get; set; } 33 | } 34 | 35 | [TestMethod] 36 | public void Test1() 37 | { 38 | Db.DefinitionCustomizer = p => null; 39 | 40 | var sql = Db.Sql(db => 41 | Select(new 42 | { 43 | name = db.TblStaff.Name, 44 | }). 45 | From(db.TblStaff)); 46 | 47 | var txt = sql.Build(typeof(NpgsqlConnection)).Text; 48 | var expected = @"SELECT 49 | TblStaff.Name AS name 50 | FROM TblStaff"; 51 | Assert.AreEqual(expected, txt); 52 | } 53 | 54 | [TestMethod] 55 | public void Test2() 56 | { 57 | Db.DefinitionCustomizer = p => 58 | { 59 | var input = p.Name; 60 | if (string.IsNullOrEmpty(input)) { return input; } 61 | var startUnderscores = Regex.Match(input, @"^_+"); 62 | return startUnderscores + Regex.Replace(input, @"([a-z0-9])([A-Z])", "$1_$2").ToLower(); 63 | }; 64 | 65 | var sql = Db.Sql(db => 66 | Select(new 67 | { 68 | name = db.TblStaff.Name, 69 | }). 70 | From(db.TblStaff)); 71 | 72 | var txt = sql.Build(typeof(NpgsqlConnection)).Text; 73 | var expected = @"SELECT 74 | tbl_staff.name AS name 75 | FROM tbl_staff"; 76 | Assert.AreEqual(expected, txt); 77 | } 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Project/Test/TestEF.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | using System.Linq; 3 | using Test.Helper; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using static Test.Helper.DBProviderInfo; 6 | using LambdicSql; 7 | using LambdicSql.feat.EntityFramework; 8 | using static Test.Symbol; 9 | using Test.Model; 10 | using System.Diagnostics; 11 | 12 | namespace Test 13 | { 14 | [TestClass] 15 | public class TestEF 16 | { 17 | public TestContext TestContext { get; set; } 18 | public IDbConnection _connection; 19 | 20 | [TestInitialize] 21 | public void TestInitialize() 22 | { 23 | _connection = TestEnvironment.CreateConnection(TestContext); 24 | _connection.Open(); 25 | } 26 | 27 | [TestCleanup] 28 | public void TestCleanup() => _connection.Dispose(); 29 | 30 | public class SelectData 31 | { 32 | public string name { get; set; } 33 | public string payment_date { get; set; } 34 | public decimal? money { get; set; } 35 | } 36 | 37 | [TestMethod, DataSource(Operation, Connection, Sheet, Method)] 38 | public void TestQuery() 39 | { 40 | if (!_connection.IsTarget(TargetDB.SqlServer)) return; 41 | 42 | var sql = Db.Sql(db => 43 | Select(new SelectData 44 | { 45 | name = db.tbl_staff.T().name, 46 | payment_date = db.tbl_remuneration.T().payment_date, 47 | money = db.tbl_remuneration.T().money 48 | }). 49 | From(db.tbl_remuneration). 50 | Join(db.tbl_staff, db.tbl_staff.T().id == db.tbl_remuneration.T().staff_id)); 51 | 52 | EFAdapter.Log = e => Debug.Print(e); 53 | 54 | var datas = new ModelLambdicSqlTestDB().Query(sql).ToList(); 55 | Assert.IsTrue(0 < datas.Count); 56 | AssertEx.AreEqual(sql, _connection, 57 | @"SELECT 58 | tbl_staff.name AS name, 59 | tbl_remuneration.payment_date AS payment_date, 60 | tbl_remuneration.money AS money 61 | FROM tbl_remuneration 62 | JOIN tbl_staff ON tbl_staff.id = tbl_remuneration.staff_id"); 63 | } 64 | 65 | [TestMethod, DataSource(Operation, Connection, Sheet, Method)] 66 | public void TestExecute() 67 | { 68 | if (!_connection.IsTarget(TargetDB.SqlServer)) return; 69 | 70 | var sql = Db.Sql(db => 71 | Delete(). 72 | From(db.tbl_data) 73 | ); 74 | 75 | new ModelLambdicSqlTestDB().Execute(sql); 76 | 77 | AssertEx.AreEqual(sql, _connection, 78 | @"DELETE 79 | FROM tbl_data"); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Project/Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /SummaryCode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Codeer-Software/LambdicSql/99e964011f5848e448127fbc28af2c4bd892e66b/SummaryCode.png -------------------------------------------------------------------------------- /lambdicSqlImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Codeer-Software/LambdicSql/99e964011f5848e448127fbc28af2c4bd892e66b/lambdicSqlImage.png --------------------------------------------------------------------------------