├── .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