├── .gitignore ├── BuildProcessTemplates ├── DefaultTemplate.11.1.xaml ├── DefaultTemplate.xaml ├── LabDefaultTemplate.11.xaml └── UpgradeTemplate.xaml ├── LICENSE ├── README └── src ├── External Libraries ├── Log4Net 1.2 │ ├── log4net.dll │ └── log4net.xml └── Log4netCF │ ├── log4net.dll │ └── log4net.xml ├── ExternalFunction ├── AssemblyInfo.cs ├── ExternalFunction.csproj ├── ExternalFunction.csproj.vspscc └── Simple.cs ├── Providertest ├── App.ico ├── AssemblyInfo.cs ├── Class1.cs ├── Providertest.csproj └── Providertest.csproj.vspscc ├── SharpHSQL.sln ├── SharpHSQL.vssscc ├── SharpHSQL ├── Access.cs ├── AssemblyInfo.cs ├── ByteArray.cs ├── Cache.cs ├── CacheFree.cs ├── Channel.cs ├── Column.cs ├── Constraint.cs ├── Database.cs ├── DatabaseController.cs ├── DatabaseInformation.cs ├── Declare.cs ├── Enum.cs ├── Expression.cs ├── ExpressionType.cs ├── Function.cs ├── Index.cs ├── Library.cs ├── Like.cs ├── Logging │ ├── EventLogHelper.cs │ ├── Log.cs │ ├── LogHelper.cs │ └── TracingHelper.cs ├── Node.cs ├── Parsing │ ├── Parser.cs │ └── Tokenizer.cs ├── PocketSharpHSQL.csproj ├── PocketSharpHsql.csproj.vspscc ├── Provider_AdoNet │ ├── CommandBuilder.cs │ ├── CommandBuilderBehavior.cs │ ├── SharpHsqlCommand.cs │ ├── SharpHsqlCommandBuilder.cs │ ├── SharpHsqlConnection.cs │ ├── SharpHsqlConnectionString.cs │ ├── SharpHsqlConnectionStringBuilder.cs │ ├── SharpHsqlDataAdapter.cs │ ├── SharpHsqlDbProviderFactory.cs │ ├── SharpHsqlError.cs │ ├── SharpHsqlErrorCollection.cs │ ├── SharpHsqlEvents.cs │ ├── SharpHsqlException.cs │ ├── SharpHsqlParameter.cs │ ├── SharpHsqlParameterCollection.cs │ ├── SharpHsqlReader.cs │ └── SharpHsqlTransaction.cs ├── Record.cs ├── ReflexHelper.cs ├── Result.cs ├── Row.cs ├── Select.cs ├── SharpHsql.csproj ├── SharpHsql.csproj.vspscc ├── StringConverter.cs ├── Table.cs ├── TableFilter.cs ├── Transaction.cs ├── Types │ ├── AccessType.cs │ ├── ColumnType.cs │ ├── ConstraintType.cs │ ├── ResultType.cs │ ├── SelectType.cs │ └── TokenType.cs ├── User.cs └── doc │ └── SharpHsql.xml ├── SharpHsql.Linq ├── App.config ├── DmlSqlGenerator.cs ├── ISharpHsqlSchemaExtensions.cs ├── MetadataHelpers.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Resources │ ├── SQLiteProviderServices.StoreSchemaDefinition.ssdl │ ├── SQLiteProviderServices.StoreSchemaMapping.msl │ └── SharpHsqlProviderServices.ProviderManifest.xml ├── SQL_Generation │ ├── ISqlFragment.cs │ ├── InternalBase.cs │ ├── JoinSymbol.cs │ ├── KeyToListMap.cs │ ├── SkipClause.cs │ ├── SqlBuilder.cs │ ├── SqlGenerator.cs │ ├── SqlSelectStatement.cs │ ├── SqlWriter.cs │ ├── StringUtil.cs │ ├── Symbol.cs │ ├── SymbolPair.cs │ ├── SymbolTable.cs │ └── TopClause.cs ├── SharpHsql.Linq.csproj ├── SharpHsqlConvert.cs ├── SharpHsqlDateFormats.cs ├── SharpHsqlProviderManifest.cs ├── SharpHsqlProviderServices.cs └── packages.config ├── hsqltest ├── App.ico ├── AssemblyInfo.cs ├── Class1.cs ├── hsqltest.csproj └── hsqltest.csproj.vspscc └── pocketSample ├── AssemblyInfo.cs ├── Form1.resx ├── form1.cs ├── pocketSample.csproj └── pocketSample.csproj.vspscc /.gitignore: -------------------------------------------------------------------------------- 1 | **/bin/ 2 | **/obj/ 3 | *.userprefs 4 | -------------------------------------------------------------------------------- /BuildProcessTemplates/UpgradeTemplate.xaml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | [New Microsoft.TeamFoundation.Build.Workflow.Activities.AgentSettings() With {.MaxWaitTime = New System.TimeSpan(4, 0, 0), .MaxExecutionTime = New System.TimeSpan(0, 0, 0), .TagComparison = Microsoft.TeamFoundation.Build.Workflow.Activities.TagComparison.MatchExactly }] 21 | 22 | 23 | 24 | [Microsoft.TeamFoundation.Build.Workflow.Activities.ToolPlatform.Auto] 25 | [False] 26 | [False] 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | [Microsoft.TeamFoundation.VersionControl.Client.RecursionType.OneLevel] 37 | [Microsoft.TeamFoundation.Build.Workflow.BuildVerbosity.Normal] 38 | 39 | 40 | 41 | All 42 | Assembly references and imported namespaces serialized as XML namespaces 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Small & embebdded database engine witten in C#. 2 | It is a port of the Hypersonic SQL v1.4 (HSQL) Java project 3 | and a continuation of the initial work done by Mark Tutt 4 | (http://www.codeproject.com/KB/database/sharphsql.aspx) 5 | -------------------------------------------------------------------------------- /src/External Libraries/Log4Net 1.2/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/External Libraries/Log4Net 1.2/log4net.dll -------------------------------------------------------------------------------- /src/External Libraries/Log4netCF/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/External Libraries/Log4netCF/log4net.dll -------------------------------------------------------------------------------- /src/ExternalFunction/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | // 9 | [assembly: AssemblyTitle("")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("")] 14 | [assembly: AssemblyCopyright("")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Revision and Build Numbers 27 | // by using the '*' as shown below: 28 | 29 | [assembly: AssemblyVersion("1.0.*")] 30 | 31 | // 32 | // In order to sign your assembly you must specify a key to use. Refer to the 33 | // Microsoft .NET Framework documentation for more information on assembly signing. 34 | // 35 | // Use the attributes below to control which key is used for signing. 36 | // 37 | // Notes: 38 | // (*) If no key is specified, the assembly is not signed. 39 | // (*) KeyName refers to a key that has been installed in the Crypto Service 40 | // Provider (CSP) on your machine. KeyFile refers to a file which contains 41 | // a key. 42 | // (*) If the KeyFile and the KeyName values are both specified, the 43 | // following processing occurs: 44 | // (1) If the KeyName can be found in the CSP, that key is used. 45 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 46 | // in the KeyFile is installed into the CSP and used. 47 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. 48 | // When specifying the KeyFile, the location of the KeyFile should be 49 | // relative to the project output directory which is 50 | // %Project Directory%\obj\. For example, if your KeyFile is 51 | // located in the project directory, you would specify the AssemblyKeyFile 52 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] 53 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 54 | // documentation for more information on this. 55 | // 56 | [assembly: AssemblyDelaySign(false)] 57 | [assembly: AssemblyKeyFile("")] 58 | [assembly: AssemblyKeyName("")] 59 | -------------------------------------------------------------------------------- /src/ExternalFunction/ExternalFunction.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Local 5 | {7E430EE6-B587-428A-9FB9-C1269A3FE4FD} 6 | Debug 7 | AnyCPU 8 | 9 | 10 | ExternalFunction 11 | JScript 12 | Grid 13 | IE50 14 | false 15 | Library 16 | ExternalFunction 17 | OnBuildSuccess 18 | 19 | 20 | 0.0 21 | 22 | 23 | SAK 24 | SAK 25 | SAK 26 | SAK 27 | http://localhost/ExternalFunction/ 28 | true 29 | Web 30 | true 31 | Foreground 32 | 7 33 | Days 34 | false 35 | false 36 | true 37 | 0 38 | 1.0.0.%2a 39 | true 40 | false 41 | true 42 | v4.5 43 | 44 | 45 | bin\Debug\ 46 | 285212672 47 | 48 | 49 | DEBUG;TRACE 50 | true 51 | 4096 52 | false 53 | false 54 | false 55 | 4 56 | full 57 | prompt 58 | 59 | 60 | bin\Release\ 61 | 285212672 62 | 63 | 64 | TRACE 65 | 4096 66 | true 67 | false 68 | false 69 | 4 70 | none 71 | prompt 72 | 73 | 74 | 75 | System 76 | 77 | 78 | System.Data 79 | 80 | 81 | 82 | 83 | 84 | Code 85 | 86 | 87 | Code 88 | 89 | 90 | 91 | 92 | False 93 | .NET Framework 2.0 %28x86%29 94 | true 95 | 96 | 97 | False 98 | .NET Framework 3.0 %28x86%29 99 | false 100 | 101 | 102 | False 103 | .NET Framework 3.5 104 | false 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /src/ExternalFunction/ExternalFunction.csproj.vspscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" 10 | } 11 | -------------------------------------------------------------------------------- /src/ExternalFunction/Simple.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ExternalFunction 4 | { 5 | /// 6 | /// Summary description for Simple. 7 | /// 8 | public class Simple 9 | { 10 | public Simple() 11 | { 12 | } 13 | 14 | public decimal calcrate( decimal amount, decimal percent ) 15 | { 16 | return amount + ( amount * percent / 100 ); 17 | } 18 | 19 | public static double tan( double value ) 20 | { 21 | return Math.Tan( value ); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Providertest/App.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/Providertest/App.ico -------------------------------------------------------------------------------- /src/Providertest/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | // 9 | [assembly: AssemblyTitle("")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("")] 14 | [assembly: AssemblyCopyright("")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Revision and Build Numbers 27 | // by using the '*' as shown below: 28 | 29 | [assembly: AssemblyVersion("1.0.*")] 30 | 31 | // 32 | // In order to sign your assembly you must specify a key to use. Refer to the 33 | // Microsoft .NET Framework documentation for more information on assembly signing. 34 | // 35 | // Use the attributes below to control which key is used for signing. 36 | // 37 | // Notes: 38 | // (*) If no key is specified, the assembly is not signed. 39 | // (*) KeyName refers to a key that has been installed in the Crypto Service 40 | // Provider (CSP) on your machine. KeyFile refers to a file which contains 41 | // a key. 42 | // (*) If the KeyFile and the KeyName values are both specified, the 43 | // following processing occurs: 44 | // (1) If the KeyName can be found in the CSP, that key is used. 45 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 46 | // in the KeyFile is installed into the CSP and used. 47 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. 48 | // When specifying the KeyFile, the location of the KeyFile should be 49 | // relative to the project output directory which is 50 | // %Project Directory%\obj\. For example, if your KeyFile is 51 | // located in the project directory, you would specify the AssemblyKeyFile 52 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] 53 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 54 | // documentation for more information on this. 55 | // 56 | [assembly: AssemblyDelaySign(false)] 57 | [assembly: AssemblyKeyFile("")] 58 | [assembly: AssemblyKeyName("")] 59 | -------------------------------------------------------------------------------- /src/Providertest/Class1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/Providertest/Class1.cs -------------------------------------------------------------------------------- /src/Providertest/Providertest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Local 5 | {8388AFBC-8E76-45B2-AA2D-F49A360747AE} 6 | Debug 7 | AnyCPU 8 | App.ico 9 | 10 | 11 | Providertest 12 | JScript 13 | Grid 14 | IE50 15 | false 16 | Exe 17 | Providertest 18 | OnBuildSuccess 19 | 20 | 21 | 0.0 22 | 23 | 24 | SAK 25 | SAK 26 | SAK 27 | SAK 28 | http://localhost/Providertest/ 29 | true 30 | Web 31 | true 32 | Foreground 33 | 7 34 | Days 35 | false 36 | false 37 | true 38 | 0 39 | 1.0.0.%2a 40 | true 41 | false 42 | true 43 | v4.5 44 | 45 | 46 | bin\Debug\ 47 | 285212672 48 | 49 | 50 | DEBUG;TRACE 51 | true 52 | 4096 53 | false 54 | false 55 | false 56 | 4 57 | full 58 | prompt 59 | true 60 | 61 | 62 | bin\Release\ 63 | 285212672 64 | 65 | 66 | TRACE 67 | 4096 68 | true 69 | false 70 | false 71 | 4 72 | none 73 | prompt 74 | 75 | 76 | 77 | System 78 | 79 | 80 | System.Data 81 | 82 | 83 | System.XML 84 | 85 | 86 | ExternalFunction 87 | {7E430EE6-B587-428A-9FB9-C1269A3FE4FD} 88 | 89 | 90 | SharpHsql 91 | {B98F7374-FF00-4BB7-93EC-39763A76BFFF} 92 | 93 | 94 | 95 | 96 | 97 | Code 98 | 99 | 100 | Code 101 | 102 | 103 | 104 | 105 | False 106 | .NET Framework 2.0 %28x86%29 107 | true 108 | 109 | 110 | False 111 | .NET Framework 3.0 %28x86%29 112 | false 113 | 114 | 115 | False 116 | .NET Framework 3.5 117 | false 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /src/Providertest/Providertest.csproj.vspscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" 10 | } 11 | -------------------------------------------------------------------------------- /src/SharpHSQL.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpHsql", "SharpHSQL\SharpHsql.csproj", "{B98F7374-FF00-4BB7-93EC-39763A76BFFF}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hsqltest", "hsqltest\hsqltest.csproj", "{264A06D6-76FB-4652-8619-9B651DF182D5}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Providertest", "Providertest\Providertest.csproj", "{8388AFBC-8E76-45B2-AA2D-F49A360747AE}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExternalFunction", "ExternalFunction\ExternalFunction.csproj", "{7E430EE6-B587-428A-9FB9-C1269A3FE4FD}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpHsql.Linq", "SharpHsql.Linq\SharpHsql.Linq.csproj", "{DEAFCB16-9BC4-4D3A-A850-C3B9423026C5}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {264A06D6-76FB-4652-8619-9B651DF182D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {264A06D6-76FB-4652-8619-9B651DF182D5}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {264A06D6-76FB-4652-8619-9B651DF182D5}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {264A06D6-76FB-4652-8619-9B651DF182D5}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {7E430EE6-B587-428A-9FB9-C1269A3FE4FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {7E430EE6-B587-428A-9FB9-C1269A3FE4FD}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {7E430EE6-B587-428A-9FB9-C1269A3FE4FD}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {7E430EE6-B587-428A-9FB9-C1269A3FE4FD}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {8388AFBC-8E76-45B2-AA2D-F49A360747AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {8388AFBC-8E76-45B2-AA2D-F49A360747AE}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {8388AFBC-8E76-45B2-AA2D-F49A360747AE}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {8388AFBC-8E76-45B2-AA2D-F49A360747AE}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {B98F7374-FF00-4BB7-93EC-39763A76BFFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {B98F7374-FF00-4BB7-93EC-39763A76BFFF}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {B98F7374-FF00-4BB7-93EC-39763A76BFFF}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {B98F7374-FF00-4BB7-93EC-39763A76BFFF}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {DEAFCB16-9BC4-4D3A-A850-C3B9423026C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {DEAFCB16-9BC4-4D3A-A850-C3B9423026C5}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {DEAFCB16-9BC4-4D3A-A850-C3B9423026C5}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {DEAFCB16-9BC4-4D3A-A850-C3B9423026C5}.Release|Any CPU.Build.0 = Release|Any CPU 40 | EndGlobalSection 41 | GlobalSection(MonoDevelopProperties) = preSolution 42 | Policies = $0 43 | $0.TextStylePolicy = $1 44 | $1.inheritsSet = null 45 | $1.scope = text/x-csharp 46 | $0.CSharpFormattingPolicy = $2 47 | $2.AfterDelegateDeclarationParameterComma = True 48 | $2.inheritsSet = Mono 49 | $2.inheritsScope = text/x-csharp 50 | $2.scope = text/x-csharp 51 | $0.TextStylePolicy = $3 52 | $3.FileWidth = 120 53 | $3.TabsToSpaces = False 54 | $3.RemoveTrailingWhitespace = False 55 | $3.EolMarker = Windows 56 | $3.inheritsSet = VisualStudio 57 | $3.inheritsScope = text/plain 58 | $3.scope = text/plain 59 | $0.TextStylePolicy = $4 60 | $4.inheritsSet = null 61 | $4.scope = application/config+xml 62 | $0.XmlFormattingPolicy = $5 63 | $5.inheritsSet = null 64 | $5.scope = application/config+xml 65 | $0.TextStylePolicy = $6 66 | $6.inheritsSet = null 67 | $6.scope = application/xml 68 | $0.XmlFormattingPolicy = $7 69 | $7.inheritsSet = Mono 70 | $7.inheritsScope = application/xml 71 | $7.scope = application/xml 72 | $0.TextStylePolicy = $8 73 | $8.inheritsSet = null 74 | $8.scope = text/microsoft-resx 75 | $0.XmlFormattingPolicy = $9 76 | $9.inheritsSet = null 77 | $9.scope = text/microsoft-resx 78 | $0.StandardHeader = $10 79 | $10.Text = 80 | $10.IncludeInNewFiles = True 81 | EndGlobalSection 82 | GlobalSection(TeamFoundationVersionControl) = preSolution 83 | SccNumberOfProjects = 7 84 | SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} 85 | SccTeamFoundationServer = https://tfs07.codeplex.com/ 86 | SccLocalPath0 = . 87 | SccProjectUniqueName1 = ExternalFunction\\ExternalFunction.csproj 88 | SccProjectName1 = ExternalFunction 89 | SccLocalPath1 = ExternalFunction 90 | SccProjectUniqueName2 = hsqltest\\hsqltest.csproj 91 | SccProjectName2 = hsqltest 92 | SccLocalPath2 = hsqltest 93 | SccProjectUniqueName3 = pocketSample\\pocketSample.csproj 94 | SccProjectName3 = pocketSample 95 | SccLocalPath3 = pocketSample 96 | SccProjectUniqueName4 = Providertest\\Providertest.csproj 97 | SccProjectName4 = Providertest 98 | SccLocalPath4 = Providertest 99 | SccProjectUniqueName5 = SharpHSQL\\PocketSharpHsql.csproj 100 | SccProjectName5 = SharpHSQL 101 | SccLocalPath5 = SharpHSQL 102 | SccProjectUniqueName6 = SharpHSQL\\SharpHsql.csproj 103 | SccProjectName6 = SharpHSQL 104 | SccLocalPath6 = SharpHSQL 105 | EndGlobalSection 106 | GlobalSection(SolutionProperties) = preSolution 107 | HideSolutionNode = FALSE 108 | EndGlobalSection 109 | GlobalSection(DPCodeReviewSolutionGUID) = preSolution 110 | DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} 111 | EndGlobalSection 112 | EndGlobal 113 | -------------------------------------------------------------------------------- /src/SharpHSQL.vssscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" 10 | } 11 | -------------------------------------------------------------------------------- /src/SharpHSQL/Access.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Access.cs -------------------------------------------------------------------------------- /src/SharpHSQL/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Runtime.InteropServices; 4 | using System.Runtime.CompilerServices; 5 | 6 | // 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | // 11 | [assembly: AssemblyTitle("SharpHSQL")] 12 | [assembly: AssemblyDescription("C# port of Java HSQLDB")] 13 | #if DEBUG 14 | [assembly: AssemblyConfiguration("DEBUG")] 15 | #else 16 | [assembly: AssemblyConfiguration("RELEASE")] 17 | #endif 18 | [assembly: AssemblyCompany("")] 19 | [assembly: AssemblyProduct("SharpHSQL")] 20 | [assembly: AssemblyCopyright("Mark Tutt")] 21 | [assembly: AssemblyTrademark("")] 22 | [assembly: AssemblyCulture("")] 23 | 24 | // 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Revision 30 | // Build Number 31 | // 32 | // You can specify all the value or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | 35 | [assembly: AssemblyVersion("4.0.1.0")] 36 | #if !POCKETPC 37 | [assembly: AssemblyFileVersion("4.0.1.0")] 38 | #endif 39 | // 40 | // In order to sign your assembly you must specify a key to use. Refer to the 41 | // Microsoft .NET Framework documentation for more information on assembly signing. 42 | // 43 | // Use the attributes below to control which key is used for signing. 44 | // 45 | // Notes: 46 | // (*) If no key is specified - the assembly cannot be signed. 47 | // (*) KeyName refers to a key that has been installed in the Crypto Service 48 | // Provider (CSP) on your machine. 49 | // (*) If the key file and a key name attributes are both specified, the 50 | // following processing occurs: 51 | // (1) If the KeyName can be found in the CSP - that key is used. 52 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 53 | // in the file is installed into the CSP and used. 54 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 55 | // documentation for more information on this. 56 | // 57 | [assembly: ComVisible(false)] 58 | [assembly: CLSCompliant(true)] 59 | 60 | -------------------------------------------------------------------------------- /src/SharpHSQL/ByteArray.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/ByteArray.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Cache.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Cache.cs -------------------------------------------------------------------------------- /src/SharpHSQL/CacheFree.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/CacheFree.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Channel.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Channel.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Column.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Column.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Constraint.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Constraint.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Database.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Database.cs -------------------------------------------------------------------------------- /src/SharpHSQL/DatabaseController.cs: -------------------------------------------------------------------------------- 1 | #region Usings 2 | using System; 3 | using System.Collections; 4 | using System.Reflection; 5 | using System.Threading; 6 | #endregion 7 | 8 | namespace SharpHsql 9 | { 10 | /// 11 | /// Controller class for single point database access. 12 | /// 13 | public sealed class DatabaseController 14 | { 15 | private static object SyncRoot = new object(); 16 | private static Hashtable _dbs = Hashtable.Synchronized( new Hashtable() ); 17 | private static Timer _checkPoint; 18 | 19 | private DatabaseController(){} 20 | 21 | static DatabaseController() 22 | { 23 | try 24 | { 25 | // try to shutdown gracefully when process exits 26 | #if !POCKETPC 27 | AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); 28 | #endif 29 | 30 | // do a checkpoint every minute 31 | _checkPoint = new Timer( new TimerCallback(DoCheckPoint), null, 60000, 60000); 32 | } 33 | catch( Exception ex ) 34 | { 35 | LogHelper.Publish( "Unexpected exception on [DatabaseController] constructor.", ex ); 36 | } 37 | } 38 | 39 | /// 40 | /// Gets a instance by name. 41 | /// 42 | /// 43 | /// This class mantains a cache of already created database 44 | /// objects to prevent opening the same database more than once, 45 | /// because database files are open exclusively. 46 | /// 47 | /// Database full path. 48 | /// A reference of a new or existing database object. 49 | public static Database GetDatabase(string name) 50 | { 51 | lock( SyncRoot ) 52 | { 53 | try 54 | { 55 | Database db = null; 56 | if( _dbs.ContainsKey( name ) ) 57 | { 58 | db = (Database)_dbs[name]; 59 | } 60 | else 61 | { 62 | db = new Database(name); 63 | _dbs.Add(name, db); 64 | } 65 | return db; 66 | } 67 | catch( Exception ex ) 68 | { 69 | LogHelper.Publish( String.Format("Unexpected exception on [GetDatabase] method for database {0}.", name ), ex ); 70 | 71 | throw; 72 | } 73 | } 74 | } 75 | 76 | /// 77 | /// Shutdown an already open database. 78 | /// 79 | /// The name of the database. 80 | public static void Shutdown( string name ) 81 | { 82 | lock( SyncRoot ) 83 | { 84 | try 85 | { 86 | Database db = _dbs[name] as Database; 87 | if( db != null ) 88 | { 89 | lock( db ) 90 | { 91 | db.Execute("SHUTDOWN", db.SysChannel ); 92 | } 93 | _dbs.Remove( name ); 94 | } 95 | } 96 | catch( Exception ex ) 97 | { 98 | LogHelper.Publish( String.Format("Unexpected exception on [Shutdown] method for database {0}.", name ), ex ); 99 | 100 | throw; 101 | } 102 | } 103 | } 104 | 105 | /// 106 | /// Shut down all active database instances. 107 | /// 108 | public static void ShutdownAll() 109 | { 110 | lock( SyncRoot ) 111 | { 112 | try 113 | { 114 | object[] keys = new object[_dbs.Keys.Count]; 115 | _dbs.Keys.CopyTo( keys, 0 ); 116 | foreach( string name in keys ) 117 | { 118 | Database db = _dbs[name] as Database; 119 | if( db != null ) 120 | { 121 | lock( db ) 122 | { 123 | db.Execute("SHUTDOWN", db.SysChannel); 124 | } 125 | _dbs.Remove( name ); 126 | } 127 | } 128 | } 129 | catch( Exception ex ) 130 | { 131 | LogHelper.Publish( "Unexpected exception on [ShutdownAll] method.", ex ); 132 | 133 | throw; 134 | } 135 | } 136 | } 137 | 138 | private static void CurrentDomain_ProcessExit(object sender, EventArgs e) 139 | { 140 | try 141 | { 142 | // disable timer 143 | _checkPoint.Change(-1, -1); 144 | _checkPoint.Dispose(); 145 | _checkPoint = null; 146 | 147 | ShutdownAll(); 148 | } 149 | catch{} 150 | } 151 | 152 | private static void DoCheckPoint( object state ) 153 | { 154 | lock( SyncRoot ) 155 | { 156 | try 157 | { 158 | // disable timer 159 | _checkPoint.Change(-1, -1); 160 | 161 | // do a checkpoint an all open databases 162 | object[] keys = new object[_dbs.Keys.Count]; 163 | _dbs.Keys.CopyTo( keys, 0 ); 164 | foreach( string name in keys ) 165 | { 166 | Database db = _dbs[name] as Database; 167 | if( db != null ) 168 | { 169 | try 170 | { 171 | lock( db ) 172 | { 173 | db.Execute("CHECKPOINT", db.SysChannel); 174 | } 175 | } 176 | catch( Exception e ) 177 | { 178 | LogHelper.Publish( String.Format("Unexpected exception executing CHECKPOINT statement on database {0}.", db.Name ), e ); 179 | 180 | db.Log.Write( db.SysChannel, "Error on CHECKPOINT: " + e.Message ); 181 | } 182 | } 183 | } 184 | } 185 | catch( Exception ex ) 186 | { 187 | LogHelper.Publish( "Unexpected exception on [DoCheckPoint] method.", ex ); 188 | } 189 | finally 190 | { 191 | // re-enable checkpoint 192 | if( _checkPoint != null ) 193 | _checkPoint.Change( 60000, 60000 ); 194 | } 195 | } 196 | } 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /src/SharpHSQL/DatabaseInformation.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/DatabaseInformation.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Declare.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Declare.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Expression.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Expression.cs -------------------------------------------------------------------------------- /src/SharpHSQL/ExpressionType.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/ExpressionType.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Function.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Function.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Index.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Index.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Library.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Library.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Like.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Like.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Logging/EventLogHelper.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Logging/EventLogHelper.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Logging/Log.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Logging/Log.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Logging/LogHelper.cs: -------------------------------------------------------------------------------- 1 | #region using 2 | using System; 3 | using System.Text; 4 | using System.Collections; 5 | using System.Collections.Specialized; 6 | using System.Diagnostics; 7 | using System.Reflection; 8 | using System.Security; 9 | using System.Security.Permissions; 10 | using System.IO; 11 | #endregion 12 | 13 | namespace SharpHsql 14 | { 15 | /// 16 | /// Specifies the event type of an log entry. 17 | /// 18 | /// 19 | /// The type of an log entry is used to indicate the severity of a log entry. 20 | /// Each log must be of a single type, which the application indicates when it reports the log. 21 | /// 22 | public enum LogEntryType 23 | { 24 | /// 25 | /// An audit log. This indicates a successful audit. 26 | /// 27 | Audit, 28 | /// 29 | /// A debug log. This is for testing and debugging operations. 30 | /// 31 | Debug, 32 | /// 33 | /// An information log. This indicates a significant, successful operation. 34 | /// 35 | Information, 36 | /// 37 | /// A warning log. 38 | /// This indicates a problem that is not immediately significant, 39 | /// but that may signify conditions that could cause future problems. 40 | /// 41 | Warning, 42 | /// 43 | /// An error log. 44 | /// This indicates a significant problem the user should know about; 45 | /// usually a loss of functionality or data. 46 | /// 47 | Error, 48 | /// 49 | /// An fatal log. 50 | /// This indicates a fatal problem the user should know about; 51 | /// allways a loss of functionality or data. 52 | /// 53 | Fatal 54 | } 55 | 56 | class LogHelperBase 57 | { 58 | protected static void PublishInternal(string message, Exception exception, LogEntryType exceptionTpe) 59 | { 60 | Trace.WriteLine (message); 61 | } 62 | } 63 | 64 | internal class LogHelper : LogHelperBase 65 | { 66 | #region Publish 67 | /// 68 | /// Write Exception Info to the ILog interface. 69 | /// 70 | /// 71 | /// For Debugging or Information uses, its faster to use ILog 72 | /// interface directly, instead of this method. 73 | /// 74 | /// Additional exception info. 75 | public static void Publish(string message) 76 | { 77 | PublishInternal(message, null, LogEntryType.Information); 78 | } 79 | 80 | /// 81 | /// Write Exception Info to the ILog interface. 82 | /// 83 | /// Exception object. 84 | public static void Publish(Exception exception) 85 | { 86 | PublishInternal(null, exception, LogEntryType.Error); 87 | } 88 | 89 | /// 90 | /// Write Exception Info to the ILog interface. 91 | /// 92 | /// Exception object. 93 | /// See . 94 | public static void Publish(Exception exception, LogEntryType exceptionTpe) 95 | { 96 | PublishInternal(null, exception, exceptionTpe); 97 | } 98 | 99 | /// 100 | /// Write Exception Info to the ILog interface. 101 | /// 102 | /// 103 | /// For Debugging or Information uses, its faster to use ILog 104 | /// interface directly, instead of this method. 105 | /// 106 | /// Additional exception info. 107 | /// See . 108 | public static void Publish(string message, LogEntryType exceptionTpe) 109 | { 110 | PublishInternal(message, null, exceptionTpe); 111 | } 112 | 113 | /// 114 | /// Write Exception Info to the ILog interface. 115 | /// 116 | /// Additional exception info. 117 | /// Exception object. 118 | public static void Publish(string message, Exception exception) 119 | { 120 | PublishInternal(message, exception, LogEntryType.Error); 121 | } 122 | 123 | /// 124 | /// Write Exception Info to the ILog interface. 125 | /// 126 | /// Additional exception info. 127 | /// Exception object. 128 | /// See . 129 | public static void Publish(string message, Exception exception, LogEntryType exceptionTpe) 130 | { 131 | PublishInternal(message, exception, exceptionTpe); 132 | } 133 | 134 | #endregion 135 | } 136 | } -------------------------------------------------------------------------------- /src/SharpHSQL/Logging/TracingHelper.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Logging/TracingHelper.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Node.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Node.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Parsing/Parser.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Parsing/Parser.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Parsing/Tokenizer.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Parsing/Tokenizer.cs -------------------------------------------------------------------------------- /src/SharpHSQL/PocketSharpHSQL.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Local 5 | {B1247008-F987-4C90-9EA1-A8FA1EDA3799} 6 | Debug 7 | AnyCPU 8 | {4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 9 | 10 | 11 | 12 | 13 | PocketSharpHsql 14 | KeyPair.snk 15 | true 16 | Library 17 | \Program Files\PocketSharpHSQL 18 | SharpHsql 19 | 20 | 21 | 22 | 23 | 4.20 24 | 0.0 25 | Pocket PC 2003 26 | 27 | 28 | 29 | 30 | true 31 | SAK 32 | SAK 33 | SAK 34 | SAK 35 | 36 | 37 | 3C41C503-53EF-4c2a-8DD4-A8217CAD115E 38 | PocketPC 39 | $(AssemblyName) 40 | v2.0 41 | 42 | 43 | bincf\Debug\ 44 | true 45 | 0 46 | false 47 | 48 | 49 | DEBUG;TRACE;POCKETPC; 50 | PocketSharpSQL.xml 51 | true 52 | 4096 53 | false 54 | false 55 | false 56 | false 57 | 4 58 | full 59 | true 60 | true 61 | off 62 | 63 | 64 | bincf\Release\ 65 | true 66 | 0 67 | false 68 | 69 | 70 | POCKETPC; 71 | PocketSharpSQL.xml 72 | 4096 73 | true 74 | false 75 | false 76 | false 77 | 4 78 | none 79 | true 80 | true 81 | off 82 | 83 | 84 | 85 | MSCorLib 86 | False 87 | 88 | 89 | System 90 | False 91 | 92 | 93 | 94 | System.XML 95 | False 96 | 97 | 98 | 99 | 100 | Code 101 | 102 | 103 | Code 104 | 105 | 106 | Code 107 | 108 | 109 | Code 110 | 111 | 112 | Code 113 | 114 | 115 | Code 116 | 117 | 118 | Code 119 | 120 | 121 | Code 122 | 123 | 124 | Code 125 | 126 | 127 | Code 128 | 129 | 130 | Code 131 | 132 | 133 | Code 134 | 135 | 136 | Code 137 | 138 | 139 | Code 140 | 141 | 142 | Code 143 | 144 | 145 | Code 146 | 147 | 148 | Code 149 | 150 | 151 | Code 152 | 153 | 154 | Code 155 | 156 | 157 | Code 158 | 159 | 160 | Code 161 | 162 | 163 | Code 164 | 165 | 166 | Code 167 | 168 | 169 | Code 170 | 171 | 172 | Code 173 | 174 | 175 | Code 176 | 177 | 178 | Code 179 | 180 | 181 | Code 182 | 183 | 184 | Code 185 | 186 | 187 | Code 188 | 189 | 190 | Code 191 | 192 | 193 | Code 194 | 195 | 196 | Code 197 | 198 | 199 | Code 200 | 201 | 202 | Code 203 | 204 | 205 | Code 206 | 207 | 208 | Code 209 | 210 | 211 | Code 212 | 213 | 214 | Code 215 | 216 | 217 | Code 218 | 219 | 220 | Code 221 | 222 | 223 | Code 224 | 225 | 226 | Code 227 | 228 | 229 | Code 230 | 231 | 232 | Component 233 | 234 | 235 | Component 236 | 237 | 238 | Component 239 | 240 | 241 | Code 242 | 243 | 244 | Component 245 | 246 | 247 | Code 248 | 249 | 250 | Code 251 | 252 | 253 | Code 254 | 255 | 256 | Code 257 | 258 | 259 | Code 260 | 261 | 262 | Code 263 | 264 | 265 | Code 266 | 267 | 268 | Code 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | -------------------------------------------------------------------------------- /src/SharpHSQL/PocketSharpHsql.csproj.vspscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" 10 | } 11 | -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/CommandBuilder.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/CommandBuilder.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/CommandBuilderBehavior.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/CommandBuilderBehavior.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlCommand.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlCommand.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlCommandBuilder.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlCommandBuilder.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlConnection.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlConnection.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlConnectionString.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlConnectionString.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlConnectionStringBuilder.cs: -------------------------------------------------------------------------------- 1 | #region Usings 2 | using System; 3 | using System.Data; 4 | using System.Data.Common; 5 | using System.Collections; 6 | using System.Collections.Specialized; 7 | using System.Globalization; 8 | #endregion 9 | 10 | #region License 11 | /* 12 | * SharpHsqlConnectionString.cs 13 | * 14 | * Copyright (c) 2004, Andres G Vettori 15 | * All rights reserved. 16 | * 17 | * Redistribution and use in source and binary forms, with or without 18 | * modification, are permitted provided that the following conditions are met: 19 | * 20 | * Redistributions of source code must retain the above copyright notice, this 21 | * list of conditions and the following disclaimer. 22 | * 23 | * Redistributions in binary form must reproduce the above copyright notice, 24 | * this list of conditions and the following disclaimer in the documentation 25 | * and/or other materials provided with the distribution. 26 | * 27 | * Neither the name of the HSQL Development Group nor the names of its 28 | * contributors may be used to endorse or promote products derived from this 29 | * software without specific prior written permission. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 32 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR 35 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 36 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 38 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 40 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 | * 42 | * This package is based on HypersonicSQL, originally developed by Thomas Mueller. 43 | * 44 | * C# SharpHsql ADO.NET Provider by Andrés G Vettori. 45 | * http://workspaces.gotdotnet.com/sharphsql 46 | */ 47 | #endregion 48 | 49 | namespace System.Data.Hsql 50 | { 51 | /// 52 | /// Helper static class for building SharpHsql connection strings. 53 | /// 54 | internal sealed class SharpHsqlConnectionStringBuilder : DbConnectionStringBuilder 55 | { 56 | #region Constructors 57 | 58 | /// 59 | /// Static constructor. 60 | /// 61 | static SharpHsqlConnectionStringBuilder() 62 | { 63 | invariantComparer = CultureInfo.InvariantCulture.CompareInfo; 64 | } 65 | 66 | /// 67 | /// Creates a new object 68 | /// using a connection string. 69 | /// 70 | /// 71 | internal SharpHsqlConnectionStringBuilder( string connstring ) 72 | { 73 | if( connstring == null || connstring.Length == 0 || connstring.Trim().Length == 0 ) 74 | throw new ArgumentNullException("connstring"); 75 | 76 | string[] pairs = connstring.Split(';'); 77 | 78 | if( pairs.Length < 3 ) 79 | throw new ArgumentException("The connection string is invalid.", "connstring"); 80 | 81 | for( int i=0;i 125 | /// Returns the connection string built. 126 | /// 127 | /// 128 | public override string ToString() 129 | { 130 | return _connstring; 131 | } 132 | 133 | #endregion 134 | 135 | #region Public Fields 136 | 137 | /// 138 | /// Database name. 139 | /// 140 | public string Database = String.Empty; 141 | /// 142 | /// User name. 143 | /// 144 | public string UserName = String.Empty; 145 | /// 146 | /// User password. 147 | /// 148 | public string UserPassword = String.Empty; 149 | 150 | #endregion 151 | 152 | #region Internal Vars 153 | 154 | /// 155 | /// Class used internally for comparisons. 156 | /// 157 | internal static CompareInfo invariantComparer; 158 | 159 | #endregion 160 | 161 | #region Internal String Constants 162 | 163 | internal const string Initial_Catalog = "initial catalog"; 164 | internal const string DB = "database"; 165 | internal const string User_ID = "user id"; 166 | internal const string UID = "uid"; 167 | internal const string Pwd = "pwd"; 168 | internal const string Password = "password"; 169 | 170 | #endregion 171 | 172 | #region Private Vars 173 | 174 | private string _connstring = String.Empty; 175 | 176 | #endregion 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlDataAdapter.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlDataAdapter.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlDbProviderFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace System.Data.Hsql 4 | { 5 | using System.Data.Common; 6 | 7 | /// 8 | /// Sharp hsql db provider factory. 9 | /// 10 | public class SharpHsqlDbProviderFactory : DbProviderFactory 11 | { 12 | /// 13 | /// Static instance member which returns an instanced SharpHsqlFactory class. 14 | /// 15 | public static readonly SharpHsqlDbProviderFactory Instance = new SharpHsqlDbProviderFactory(); 16 | 17 | public SharpHsqlDbProviderFactory() 18 | { 19 | Trace.WriteLine ("SharpHsqlDbProviderFactory.ctor()"); 20 | } 21 | /// 22 | /// Returns a new SharpHsqlCommand object. 23 | /// 24 | /// A SharpHsqlCommand object. 25 | public override DbCommand CreateCommand() 26 | { 27 | return new SharpHsqlCommand(); 28 | } 29 | /// 30 | /// Returns a new SharpHsqlCommandBuilder object. 31 | /// 32 | /// A SharpHsqlCommandBuilder object. 33 | public override DbCommandBuilder CreateCommandBuilder() 34 | { 35 | return new SharpHsqlCommandBuilder(); 36 | } 37 | /// 38 | /// Creates a new SharpHsqlConnection. 39 | /// 40 | /// A SharpHsqlConnection object. 41 | public override DbConnection CreateConnection() 42 | { 43 | return new SharpHsqlConnection(); 44 | } 45 | 46 | /// 47 | /// Creates a new SharpHsqlConnectionStringBuilder. 48 | /// 49 | /// A SharpHsqlConnectionStringBuilder object. 50 | public override DbConnectionStringBuilder CreateConnectionStringBuilder() 51 | { 52 | return new SharpHsqlConnectionStringBuilder(String.Empty); 53 | } 54 | 55 | /// 56 | /// Creates a new SharpHsqlDataAdapter. 57 | /// 58 | /// A SharpHsqlDataAdapter object. 59 | public override DbDataAdapter CreateDataAdapter() 60 | { 61 | return new SharpHsqlDataAdapter(); 62 | } 63 | 64 | /// 65 | /// Creates a new SharpHsqlParameter. 66 | /// 67 | /// A SharpHsqlParameter object. 68 | public override DbParameter CreateParameter() 69 | { 70 | return new SharpHsqlParameter(); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlError.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlError.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlErrorCollection.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlErrorCollection.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlEvents.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlEvents.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlException.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlException.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlParameter.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlParameter.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlParameterCollection.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlParameterCollection.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlReader.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlReader.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Provider_AdoNet/SharpHsqlTransaction.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Provider_AdoNet/SharpHsqlTransaction.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Record.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Record.cs -------------------------------------------------------------------------------- /src/SharpHSQL/ReflexHelper.cs: -------------------------------------------------------------------------------- 1 | //=============================================================================== 2 | // SharpHsql 3 | // 4 | // ReflexHelper.cs 5 | // 6 | // This file contains the implementations of reflection utility methods. 7 | // 8 | //=============================================================================== 9 | 10 | using System; 11 | using System.Collections; 12 | using System.Diagnostics; 13 | using System.IO; 14 | using System.Reflection; 15 | using System.Security.Permissions; 16 | using System.Threading; 17 | using System.Globalization; 18 | 19 | namespace SharpHsql 20 | { 21 | /// 22 | /// Provides utility methods for reflection-related operations. 23 | /// 24 | sealed class ReflexHelper 25 | { 26 | #if !POCKETPC 27 | /// 28 | /// Gets the Assembly Configuration Attribute. 29 | /// 30 | /// Assembly to get configuration. 31 | /// 32 | public static string GetAssemblyConfiguration(Assembly assembly) 33 | { 34 | object [] att = assembly.GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false); 35 | return ((att.Length > 0) ? ((AssemblyConfigurationAttribute) att [0]).Configuration : String.Empty); 36 | } 37 | #endif 38 | 39 | #if !POCKETPC 40 | /// 41 | /// Gets an assembly full path and file name. 42 | /// 43 | /// Assembly to get path. 44 | /// 45 | public static string GetAssemblyPath(Assembly assembly) 46 | { 47 | Uri uri = new Uri(assembly.CodeBase); 48 | return uri.LocalPath; 49 | } 50 | #endif 51 | 52 | #if !POCKETPC 53 | /// 54 | /// Gets the Assembly Title. 55 | /// 56 | /// Assembly to get title. 57 | /// 58 | public static string GetAssemblyTitle(Assembly assembly) 59 | { 60 | object [] att = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false); 61 | return ((att.Length > 0) ? ((AssemblyTitleAttribute) att [0]).Title : String.Empty); 62 | } 63 | #endif 64 | 65 | #if !POCKETPC 66 | /// 67 | /// Instructs a compiler to use a specific version number for the Win32 file version resource. 68 | /// The Win32 file version is not required to be the same as the assembly's version number. 69 | /// 70 | /// Assembly to get version. 71 | /// 72 | public static string GetAssemblyFileVersion(Assembly assembly) 73 | { 74 | object [] att = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false); 75 | return ((att.Length > 0) ? ((AssemblyFileVersionAttribute) att [0]).Version : String.Empty); 76 | } 77 | #endif 78 | 79 | #if !POCKETPC 80 | /// 81 | /// Gets the Assembly Product. 82 | /// 83 | /// Assembly to get product. 84 | /// 85 | public static string GetAssemblyProduct(Assembly assembly) 86 | { 87 | object [] att = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false); 88 | return ((att.Length > 0) ? ((AssemblyProductAttribute) att [0]).Product : String.Empty); 89 | } 90 | #endif 91 | } 92 | } -------------------------------------------------------------------------------- /src/SharpHSQL/Result.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Result.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Row.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Row.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Select.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Select.cs -------------------------------------------------------------------------------- /src/SharpHSQL/SharpHsql.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Local 5 | {B98F7374-FF00-4BB7-93EC-39763A76BFFF} 6 | Debug 7 | AnyCPU 8 | 9 | 10 | SharpHsql 11 | KeyPair.snk 12 | JScript 13 | Flow 14 | IE32Nav30 15 | false 16 | Library 17 | SharpHsql 18 | OnBuildSuccess 19 | 20 | 21 | 0.0 22 | 23 | 24 | http://localhost/SharpHsql/ 25 | true 26 | Web 27 | true 28 | Foreground 29 | 7 30 | Days 31 | false 32 | false 33 | true 34 | 0 35 | 1.0.0.%2a 36 | true 37 | false 38 | true 39 | false 40 | SAK 41 | SAK 42 | SAK 43 | SAK 44 | v4.5 45 | 46 | 47 | bin\Debug\ 48 | true 49 | 0 50 | 51 | 52 | DEBUG;TRACE 53 | doc\SharpHsql.xml 54 | true 55 | 4096 56 | false 57 | false 58 | false 59 | 4 60 | full 61 | prompt 62 | 63 | 64 | bin\Release\ 65 | true 66 | 0 67 | 68 | 69 | doc\SharpHsql.xml 70 | 4096 71 | true 72 | false 73 | false 74 | 4 75 | none 76 | prompt 77 | 78 | 79 | 80 | mscorlib 81 | 82 | 83 | System 84 | 85 | 86 | System.Data 87 | 88 | 89 | System.XML 90 | 91 | 92 | 93 | 94 | 95 | 96 | Code 97 | 98 | 99 | Code 100 | 101 | 102 | Code 103 | 104 | 105 | Code 106 | 107 | 108 | Code 109 | 110 | 111 | Code 112 | 113 | 114 | Code 115 | 116 | 117 | Code 118 | 119 | 120 | Code 121 | 122 | 123 | Code 124 | 125 | 126 | Code 127 | 128 | 129 | Code 130 | 131 | 132 | Code 133 | 134 | 135 | Code 136 | 137 | 138 | Code 139 | 140 | 141 | Code 142 | 143 | 144 | Code 145 | 146 | 147 | Code 148 | 149 | 150 | Code 151 | 152 | 153 | Code 154 | 155 | 156 | Code 157 | 158 | 159 | Code 160 | 161 | 162 | Code 163 | 164 | 165 | Code 166 | 167 | 168 | Code 169 | 170 | 171 | Code 172 | 173 | 174 | Code 175 | 176 | 177 | Code 178 | 179 | 180 | Code 181 | 182 | 183 | Code 184 | 185 | 186 | Code 187 | 188 | 189 | Code 190 | 191 | 192 | Code 193 | 194 | 195 | Code 196 | 197 | 198 | Code 199 | 200 | 201 | Code 202 | 203 | 204 | Code 205 | 206 | 207 | Code 208 | 209 | 210 | Code 211 | 212 | 213 | Code 214 | 215 | 216 | Code 217 | 218 | 219 | Code 220 | 221 | 222 | Component 223 | 224 | 225 | Component 226 | 227 | 228 | Component 229 | 230 | 231 | Component 232 | 233 | 234 | Code 235 | 236 | 237 | Code 238 | 239 | 240 | Code 241 | 242 | 243 | Code 244 | 245 | 246 | Code 247 | 248 | 249 | Code 250 | 251 | 252 | Code 253 | 254 | 255 | Code 256 | 257 | 258 | Code 259 | 260 | 261 | 262 | Code 263 | 264 | 265 | 266 | 267 | 268 | False 269 | .NET Framework 2.0 %28x86%29 270 | true 271 | 272 | 273 | False 274 | .NET Framework 3.0 %28x86%29 275 | false 276 | 277 | 278 | False 279 | .NET Framework 3.5 280 | false 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | -------------------------------------------------------------------------------- /src/SharpHSQL/SharpHsql.csproj.vspscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" 10 | } 11 | -------------------------------------------------------------------------------- /src/SharpHSQL/StringConverter.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/StringConverter.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Table.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Table.cs -------------------------------------------------------------------------------- /src/SharpHSQL/TableFilter.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/TableFilter.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Transaction.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Transaction.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Types/AccessType.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Types/AccessType.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Types/ColumnType.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Types/ColumnType.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Types/ConstraintType.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Types/ConstraintType.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Types/ResultType.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Types/ResultType.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Types/SelectType.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Types/SelectType.cs -------------------------------------------------------------------------------- /src/SharpHSQL/Types/TokenType.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/Types/TokenType.cs -------------------------------------------------------------------------------- /src/SharpHSQL/User.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/SharpHSQL/User.cs -------------------------------------------------------------------------------- /src/SharpHsql.Linq/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/ISharpHsqlSchemaExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace System.Data.Hsql.Linq 4 | { 5 | internal interface ISharpHsqlSchemaExtensions 6 | { 7 | void BuildTempSchema(SharpHsqlConnection cnn); 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/MetadataHelpers.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System; 4 | using System.Data; 5 | using System.Collections.Generic; 6 | using System.Data.Entity.Core.Metadata.Edm; 7 | using System.Diagnostics; 8 | 9 | /// 10 | /// A set of static helpers for type metadata 11 | /// 12 | static class MetadataHelpers 13 | { 14 | #region Type Helpers 15 | 16 | /// 17 | /// Cast the EdmType of the given type usage to the given TEdmType 18 | /// 19 | /// 20 | /// 21 | /// 22 | internal static TEdmType GetEdmType(TypeUsage typeUsage) 23 | where TEdmType : EdmType 24 | { 25 | return (TEdmType)typeUsage.EdmType; 26 | } 27 | 28 | /// 29 | /// Gets the TypeUsage of the elment if the given type is a collection type 30 | /// 31 | /// 32 | /// 33 | internal static TypeUsage GetElementTypeUsage(TypeUsage type) 34 | { 35 | if (MetadataHelpers.IsCollectionType(type)) 36 | { 37 | return ((CollectionType)type.EdmType).TypeUsage; 38 | } 39 | return null; 40 | } 41 | 42 | /// 43 | /// Retrieves the properties of in the EdmType underlying the input type usage, 44 | /// if that EdmType is a structured type (EntityType, RowType). 45 | /// 46 | /// 47 | /// 48 | internal static IList GetProperties(TypeUsage typeUsage) 49 | { 50 | return MetadataHelpers.GetProperties(typeUsage.EdmType); 51 | } 52 | 53 | /// 54 | /// Retrieves the properties of the given EdmType, if it is 55 | /// a structured type (EntityType, RowType). 56 | /// 57 | /// 58 | /// 59 | internal static IList GetProperties(EdmType edmType) 60 | { 61 | switch (edmType.BuiltInTypeKind) 62 | { 63 | case BuiltInTypeKind.ComplexType: 64 | return ((ComplexType)edmType).Properties; 65 | case BuiltInTypeKind.EntityType: 66 | return ((EntityType)edmType).Properties; 67 | case BuiltInTypeKind.RowType: 68 | return ((RowType)edmType).Properties; 69 | default: 70 | return new List(); 71 | } 72 | } 73 | 74 | /// 75 | /// Is the given type usage over a collection type 76 | /// 77 | /// 78 | /// 79 | internal static bool IsCollectionType(TypeUsage typeUsage) 80 | { 81 | return MetadataHelpers.IsCollectionType(typeUsage.EdmType); 82 | } 83 | 84 | /// 85 | /// Is the given type a collection type 86 | /// 87 | /// 88 | /// 89 | internal static bool IsCollectionType(EdmType type) 90 | { 91 | return (BuiltInTypeKind.CollectionType == type.BuiltInTypeKind); 92 | } 93 | 94 | /// 95 | /// Is the given type usage over a primitive type 96 | /// 97 | /// 98 | /// 99 | internal static bool IsPrimitiveType(TypeUsage type) 100 | { 101 | return MetadataHelpers.IsPrimitiveType(type.EdmType); 102 | } 103 | 104 | /// 105 | /// Is the given type a primitive type 106 | /// 107 | /// 108 | /// 109 | internal static bool IsPrimitiveType(EdmType type) 110 | { 111 | return (BuiltInTypeKind.PrimitiveType == type.BuiltInTypeKind); 112 | } 113 | 114 | /// 115 | /// Is the given type usage over a row type 116 | /// 117 | /// 118 | /// 119 | internal static bool IsRowType(TypeUsage type) 120 | { 121 | return MetadataHelpers.IsRowType(type.EdmType); 122 | } 123 | 124 | /// 125 | /// Is the given type a row type 126 | /// 127 | /// 128 | /// 129 | internal static bool IsRowType(EdmType type) 130 | { 131 | return (BuiltInTypeKind.RowType == type.BuiltInTypeKind); 132 | } 133 | 134 | /// 135 | /// Gets the type of the given type usage if it is a primitive type 136 | /// 137 | /// 138 | /// 139 | /// 140 | internal static bool TryGetPrimitiveTypeKind(TypeUsage type, out PrimitiveTypeKind typeKind) 141 | { 142 | if (type != null && type.EdmType != null && type.EdmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType) 143 | { 144 | typeKind = ((PrimitiveType)type.EdmType).PrimitiveTypeKind; 145 | return true; 146 | } 147 | 148 | typeKind = default(PrimitiveTypeKind); 149 | return false; 150 | } 151 | 152 | internal static PrimitiveTypeKind GetPrimitiveTypeKind(TypeUsage type) 153 | { 154 | PrimitiveTypeKind returnValue; 155 | if (!MetadataHelpers.TryGetPrimitiveTypeKind(type, out returnValue)) 156 | { 157 | Debug.Assert(false, "Cannot create parameter of non-primitive type"); 158 | throw new NotSupportedException("Cannot create parameter of non-primitive type"); 159 | } 160 | return returnValue; 161 | } 162 | 163 | /// 164 | /// Gets the value for the metadata property with the given name 165 | /// 166 | /// 167 | /// 168 | /// 169 | /// 170 | internal static T TryGetValueForMetadataProperty(MetadataItem item, string propertyName) 171 | { 172 | MetadataProperty property; 173 | if (!item.MetadataProperties.TryGetValue(propertyName, true, out property)) 174 | { 175 | return default(T); 176 | } 177 | 178 | return (T)property.Value; 179 | } 180 | 181 | internal static bool IsPrimitiveType(TypeUsage type, PrimitiveTypeKind primitiveType) 182 | { 183 | PrimitiveTypeKind typeKind; 184 | if (TryGetPrimitiveTypeKind(type, out typeKind)) 185 | { 186 | return (typeKind == primitiveType); 187 | } 188 | return false; 189 | } 190 | 191 | internal static DbType GetDbType(PrimitiveTypeKind primitiveType) 192 | { 193 | switch (primitiveType) 194 | { 195 | case PrimitiveTypeKind.Binary: return DbType.Binary; 196 | case PrimitiveTypeKind.Boolean: return DbType.Boolean; 197 | case PrimitiveTypeKind.Byte: return DbType.Byte; 198 | case PrimitiveTypeKind.DateTime: return DbType.DateTime; 199 | case PrimitiveTypeKind.Decimal: return DbType.Decimal; 200 | case PrimitiveTypeKind.Double: return DbType.Double; 201 | case PrimitiveTypeKind.Single: return DbType.Single; 202 | case PrimitiveTypeKind.Guid: return DbType.Guid; 203 | case PrimitiveTypeKind.Int16: return DbType.Int16; 204 | case PrimitiveTypeKind.Int32: return DbType.Int32; 205 | case PrimitiveTypeKind.Int64: return DbType.Int64; 206 | //case PrimitiveTypeKind.Money: return DbType.Decimal; 207 | case PrimitiveTypeKind.SByte: return DbType.SByte; 208 | case PrimitiveTypeKind.String: return DbType.String; 209 | //case PrimitiveTypeKind.UInt16: return DbType.UInt16; 210 | //case PrimitiveTypeKind.UInt32: return DbType.UInt32; 211 | //case PrimitiveTypeKind.UInt64: return DbType.UInt64; 212 | //case PrimitiveTypeKind.Xml: return DbType.Xml; 213 | default: 214 | Debug.Fail("unknown PrimitiveTypeKind" + primitiveType.ToString()); 215 | throw new InvalidOperationException(string.Format("Unknown PrimitiveTypeKind {0}", primitiveType)); 216 | } 217 | } 218 | 219 | #endregion 220 | 221 | #region Facet Support 222 | internal static readonly int UnicodeStringMaxMaxLength = Int32.MaxValue; 223 | internal static readonly int AsciiStringMaxMaxLength = Int32.MaxValue; 224 | internal static readonly int BinaryMaxMaxLength = Int32.MaxValue; 225 | 226 | #region Facet Names 227 | /// 228 | /// Name of the MaxLength Facet 229 | /// 230 | public static readonly string MaxLengthFacetName = "MaxLength"; 231 | 232 | /// 233 | /// Name of the Unicode Facet 234 | /// 235 | public static readonly string UnicodeFacetName = "Unicode"; 236 | 237 | /// 238 | /// Name of the FixedLength Facet 239 | /// 240 | public static readonly string FixedLengthFacetName = "FixedLength"; 241 | 242 | /// 243 | /// Name of the PreserveSeconds Facet 244 | /// 245 | public static readonly string PreserveSecondsFacetName = "PreserveSeconds"; 246 | 247 | /// 248 | /// Name of the Precision Facet 249 | /// 250 | public static readonly string PrecisionFacetName = "Precision"; 251 | 252 | /// 253 | /// Name of the Scale Facet 254 | /// 255 | public static readonly string ScaleFacetName = "Scale"; 256 | 257 | /// 258 | /// Name of the DefaultValue Facet 259 | /// 260 | public static readonly string DefaultValueFacetName = "DefaultValue"; 261 | 262 | /// 263 | /// Name of the Nullable Facet 264 | /// 265 | internal const string NullableFacetName = "Nullable"; 266 | #endregion 267 | 268 | #region Facet Retreival Helpers 269 | 270 | /// 271 | /// Get the value specified on the given type usage for the given facet name. 272 | /// If the faces does not have a value specifid or that value is null returns 273 | /// the default value for that facet. 274 | /// 275 | /// 276 | /// 277 | /// 278 | /// 279 | /// 280 | internal static T GetFacetValueOrDefault(TypeUsage type, string facetName, T defaultValue) 281 | { 282 | //Get the value for the facet, if any 283 | Facet facet; 284 | if (type.Facets.TryGetValue(facetName, false, out facet) && facet.Value != null && !facet.IsUnbounded) 285 | { 286 | return (T)facet.Value; 287 | } 288 | else 289 | { 290 | return defaultValue; 291 | } 292 | } 293 | 294 | internal static bool IsFacetValueConstant(TypeUsage type, string facetName) 295 | { 296 | return MetadataHelpers.GetFacet(((PrimitiveType)type.EdmType).FacetDescriptions, facetName).IsConstant; 297 | } 298 | 299 | private static FacetDescription GetFacet(IEnumerable facetCollection, string facetName) 300 | { 301 | foreach (FacetDescription facetDescription in facetCollection) 302 | { 303 | if (facetDescription.FacetName == facetName) 304 | { 305 | return facetDescription; 306 | } 307 | } 308 | 309 | return null; 310 | } 311 | 312 | /// 313 | /// Given a facet name and an EdmType, tries to get that facet's description. 314 | /// 315 | /// 316 | /// 317 | /// 318 | /// 319 | internal static bool TryGetTypeFacetDescriptionByName(EdmType edmType, string facetName, out FacetDescription facetDescription) 320 | { 321 | facetDescription = null; 322 | if (MetadataHelpers.IsPrimitiveType(edmType)) 323 | { 324 | PrimitiveType primitiveType = (PrimitiveType)edmType; 325 | foreach (FacetDescription fd in primitiveType.FacetDescriptions) 326 | { 327 | if (facetName.Equals(fd.FacetName, StringComparison.OrdinalIgnoreCase)) 328 | { 329 | facetDescription = fd; 330 | return true; 331 | } 332 | } 333 | } 334 | return false; 335 | } 336 | 337 | internal static bool IsNullable(TypeUsage type) 338 | { 339 | Facet nullableFacet; 340 | if (type.Facets.TryGetValue(NullableFacetName, false, out nullableFacet)) 341 | { 342 | return (bool)nullableFacet.Value; 343 | } 344 | return false; 345 | } 346 | 347 | internal static bool TryGetMaxLength(TypeUsage type, out int maxLength) 348 | { 349 | if (!IsPrimitiveType(type, PrimitiveTypeKind.String) && 350 | !IsPrimitiveType(type, PrimitiveTypeKind.Binary)) 351 | { 352 | maxLength = 0; 353 | return false; 354 | } 355 | 356 | // Binary and String FixedLength facets share the same name 357 | return TryGetIntFacetValue(type, MaxLengthFacetName, out maxLength); 358 | } 359 | 360 | internal static bool TryGetIntFacetValue(TypeUsage type, string facetName, out int intValue) 361 | { 362 | intValue = 0; 363 | Facet intFacet; 364 | 365 | if (type.Facets.TryGetValue(facetName, false, out intFacet) && intFacet.Value != null && !intFacet.IsUnbounded) 366 | { 367 | intValue = (int)intFacet.Value; 368 | return true; 369 | } 370 | 371 | return false; 372 | } 373 | 374 | internal static bool TryGetIsFixedLength(TypeUsage type, out bool isFixedLength) 375 | { 376 | if (!IsPrimitiveType(type, PrimitiveTypeKind.String) && 377 | !IsPrimitiveType(type, PrimitiveTypeKind.Binary)) 378 | { 379 | isFixedLength = false; 380 | return false; 381 | } 382 | 383 | // Binary and String MaxLength facets share the same name 384 | return TryGetBooleanFacetValue(type, FixedLengthFacetName, out isFixedLength); 385 | } 386 | 387 | internal static bool TryGetBooleanFacetValue(TypeUsage type, string facetName, out bool boolValue) 388 | { 389 | boolValue = false; 390 | Facet boolFacet; 391 | if (type.Facets.TryGetValue(facetName, false, out boolFacet) && boolFacet.Value != null) 392 | { 393 | boolValue = (bool)boolFacet.Value; 394 | return true; 395 | } 396 | 397 | return false; 398 | } 399 | 400 | internal static bool TryGetIsUnicode(TypeUsage type, out bool isUnicode) 401 | { 402 | if (!IsPrimitiveType(type, PrimitiveTypeKind.String)) 403 | { 404 | isUnicode = false; 405 | return false; 406 | } 407 | 408 | return TryGetBooleanFacetValue(type, UnicodeFacetName, out isUnicode); 409 | } 410 | 411 | #endregion 412 | 413 | #endregion 414 | 415 | internal static bool IsCanonicalFunction(EdmFunction function) 416 | { 417 | return (function.NamespaceName == "Edm"); 418 | } 419 | 420 | internal static bool IsStoreFunction(EdmFunction function) 421 | { 422 | return !IsCanonicalFunction(function); 423 | } 424 | 425 | // Returns ParameterDirection corresponding to given ParameterMode 426 | internal static ParameterDirection ParameterModeToParameterDirection(ParameterMode mode) 427 | { 428 | switch (mode) 429 | { 430 | case ParameterMode.In: 431 | return ParameterDirection.Input; 432 | 433 | case ParameterMode.InOut: 434 | return ParameterDirection.InputOutput; 435 | 436 | case ParameterMode.Out: 437 | return ParameterDirection.Output; 438 | 439 | case ParameterMode.ReturnValue: 440 | return ParameterDirection.ReturnValue; 441 | 442 | default: 443 | Debug.Fail("unrecognized mode " + mode.ToString()); 444 | return default(ParameterDirection); 445 | } 446 | } 447 | } 448 | } 449 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle ("SharpHsql.Linq")] 8 | [assembly: AssemblyDescription ("")] 9 | [assembly: AssemblyConfiguration ("")] 10 | [assembly: AssemblyCompany ("")] 11 | [assembly: AssemblyProduct ("")] 12 | [assembly: AssemblyCopyright ("user")] 13 | [assembly: AssemblyTrademark ("")] 14 | [assembly: AssemblyCulture ("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion ("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | 28 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Mono Runtime Version: 4.0.30319.17020 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | // ------------------------------------------------------------------------------ 10 | 11 | namespace Properties { 12 | using System; 13 | 14 | 15 | [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 16 | [System.Diagnostics.DebuggerNonUserCodeAttribute()] 17 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 18 | public class Resources { 19 | 20 | private static System.Resources.ResourceManager resourceMan; 21 | 22 | private static System.Globalization.CultureInfo resourceCulture; 23 | 24 | [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 25 | internal Resources() { 26 | } 27 | 28 | [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 29 | public static System.Resources.ResourceManager ResourceManager { 30 | get { 31 | if (object.Equals(null, resourceMan)) { 32 | System.Resources.ResourceManager temp = new System.Resources.ResourceManager("System.Data.Hsql.Linq.Resources", typeof(Resources).Assembly); 33 | resourceMan = temp; 34 | } 35 | return resourceMan; 36 | } 37 | } 38 | 39 | [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 40 | public static System.Globalization.CultureInfo Culture { 41 | get { 42 | return resourceCulture; 43 | } 44 | set { 45 | resourceCulture = value; 46 | } 47 | } 48 | 49 | public static string SQL_CONSTRAINTCOLUMNS { 50 | get { 51 | return ResourceManager.GetString("SQL_CONSTRAINTCOLUMNS", resourceCulture); 52 | } 53 | } 54 | 55 | public static string SQL_CONSTRAINTS { 56 | get { 57 | return ResourceManager.GetString("SQL_CONSTRAINTS", resourceCulture); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | CREATE TEMP VIEW SCHEMACONSTRAINTCOLUMNS AS 123 | SELECT CONSTRAINT_CATALOG, 124 | NULL AS CONSTRAINT_SCHEMA, 125 | CONSTRAINT_NAME, 126 | TABLE_CATALOG, 127 | NULL AS TABLE_SCHEMA, 128 | TABLE_NAME, 129 | COLUMN_NAME 130 | FROM TEMP.SCHEMAINDEXCOLUMNS 131 | UNION 132 | SELECT CONSTRAINT_CATALOG, 133 | NULL, 134 | CONSTRAINT_NAME, 135 | TABLE_CATALOG, 136 | NULL, 137 | TABLE_NAME, 138 | FKEY_FROM_COLUMN 139 | FROM TEMP.SCHEMAFOREIGNKEYS; 140 | 141 | 142 | 143 | 144 | CREATE TEMP VIEW SCHEMACONSTRAINTS AS 145 | SELECT INDEX_CATALOG AS CONSTRAINT_CATALOG, 146 | NULL AS CONSTRAINT_SCHEMA, 147 | INDEX_NAME AS CONSTRAINT_NAME, 148 | TABLE_CATALOG, 149 | NULL AS TABLE_SCHEMA, 150 | TABLE_NAME, 151 | 'PRIMARY KEY' AS CONSTRAINT_TYPE, 152 | 0 AS IS_DEFERRABLE, 153 | 0 AS INITIALLY_DEFERRED, 154 | NULL AS CHECK_CLAUSE 155 | FROM TEMP.SCHEMAINDEXES 156 | WHERE PRIMARY_KEY = 1 157 | UNION 158 | SELECT INDEX_CATALOG, 159 | NULL, 160 | INDEX_NAME, 161 | TABLE_CATALOG, 162 | NULL, 163 | TABLE_NAME, 164 | 'UNIQUE', 165 | 0, 166 | 0, 167 | NULL 168 | FROM TEMP.SCHEMAINDEXES 169 | WHERE PRIMARY_KEY = 0 AND [UNIQUE] = 1 170 | UNION 171 | SELECT CONSTRAINT_CATALOG, 172 | NULL, 173 | CONSTRAINT_NAME, 174 | TABLE_CATALOG, 175 | NULL, 176 | TABLE_NAME, 177 | CONSTRAINT_TYPE, 178 | IS_DEFERRABLE, 179 | INITIALLY_DEFERRED, 180 | NULL 181 | FROM TEMP.SCHEMAFOREIGNKEYS; 182 | 183 | 184 | 185 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/ISqlFragment.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System.Data.Entity.Core.Common.CommandTrees; 4 | 5 | /// 6 | /// Represents the sql fragment for any node in the query tree. 7 | /// 8 | /// 9 | /// The nodes in a query tree produce various kinds of sql 10 | /// 11 | /// A select statement. 12 | /// A reference to an extent. (symbol) 13 | /// A raw string. 14 | /// 15 | /// We have this interface to allow for a common return type for the methods 16 | /// in the expression visitor 17 | /// 18 | /// At the end of translation, the sql fragments are converted into real strings. 19 | /// 20 | internal interface ISqlFragment 21 | { 22 | /// 23 | /// Write the string represented by this fragment into the stream. 24 | /// 25 | /// The stream that collects the strings. 26 | /// Context information used for renaming. 27 | /// The global lists are used to generated new names without collisions. 28 | void WriteSql(SqlWriter writer, SqlGenerator sqlGenerator); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/InternalBase.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System.Text; 4 | #if NET_40 || NET_45 5 | using System.Runtime; 6 | #endif 7 | 8 | internal abstract class InternalBase 9 | { 10 | // Methods 11 | #if NET_40 || NET_45 12 | [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] 13 | #endif 14 | protected InternalBase() 15 | { 16 | } 17 | 18 | internal abstract void ToCompactString(StringBuilder builder); 19 | internal virtual string ToFullString() 20 | { 21 | StringBuilder builder = new StringBuilder(); 22 | this.ToFullString(builder); 23 | return builder.ToString(); 24 | } 25 | 26 | #if NET_40 || NET_45 27 | [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] 28 | #endif 29 | internal virtual void ToFullString(StringBuilder builder) 30 | { 31 | this.ToCompactString(builder); 32 | } 33 | 34 | public override string ToString() 35 | { 36 | StringBuilder builder = new StringBuilder(); 37 | this.ToCompactString(builder); 38 | return builder.ToString(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/JoinSymbol.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Data.Entity.Core.Metadata.Edm; 6 | using System.Data.Entity.Core.Common.CommandTrees; 7 | 8 | /// 9 | /// A Join symbol is a special kind of Symbol. 10 | /// It has to carry additional information 11 | /// 12 | /// ColumnList for the list of columns in the select clause if this 13 | /// symbol represents a sql select statement. This is set by . 14 | /// ExtentList is the list of extents in the select clause. 15 | /// FlattenedExtentList - if the Join has multiple extents flattened at the 16 | /// top level, we need this information to ensure that extent aliases are renamed 17 | /// correctly in 18 | /// NameToExtent has all the extents in ExtentList as a dictionary. 19 | /// This is used by to flatten 20 | /// record accesses. 21 | /// IsNestedJoin - is used to determine whether a JoinSymbol is an 22 | /// ordinary join symbol, or one that has a corresponding SqlSelectStatement. 23 | /// 24 | /// 25 | /// All the lists are set exactly once, and then used for lookups/enumerated. 26 | /// 27 | internal sealed class JoinSymbol : Symbol 28 | { 29 | private List columnList; 30 | internal List ColumnList 31 | { 32 | get 33 | { 34 | if (null == columnList) 35 | { 36 | columnList = new List(); 37 | } 38 | return columnList; 39 | } 40 | set { columnList = value; } 41 | } 42 | 43 | private List extentList; 44 | internal List ExtentList 45 | { 46 | get { return extentList; } 47 | } 48 | 49 | private List flattenedExtentList; 50 | internal List FlattenedExtentList 51 | { 52 | get 53 | { 54 | if (null == flattenedExtentList) 55 | { 56 | flattenedExtentList = new List(); 57 | } 58 | return flattenedExtentList; 59 | } 60 | set { flattenedExtentList = value; } 61 | } 62 | 63 | private Dictionary nameToExtent; 64 | internal Dictionary NameToExtent 65 | { 66 | get { return nameToExtent; } 67 | } 68 | 69 | private bool isNestedJoin; 70 | internal bool IsNestedJoin 71 | { 72 | get { return isNestedJoin; } 73 | set { isNestedJoin = value; } 74 | } 75 | 76 | public JoinSymbol(string name, TypeUsage type, List extents) 77 | : base(name, type) 78 | { 79 | extentList = new List(extents.Count); 80 | nameToExtent = new Dictionary(extents.Count, StringComparer.OrdinalIgnoreCase); 81 | foreach (Symbol symbol in extents) 82 | { 83 | this.nameToExtent[symbol.Name] = symbol; 84 | this.ExtentList.Add(symbol); 85 | } 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/KeyToListMap.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Collections.ObjectModel; 6 | using System.Collections; 7 | 8 | #if NET_40 || NET_45 9 | using System.Runtime; 10 | #endif 11 | 12 | internal sealed class KeyToListMap : InternalBase 13 | { 14 | // Fields 15 | private Dictionary> m_map; 16 | 17 | // Methods 18 | internal KeyToListMap(IEqualityComparer comparer) 19 | { 20 | this.m_map = new Dictionary>(comparer); 21 | } 22 | 23 | internal void Add(TKey key, TValue value) 24 | { 25 | List list; 26 | if (!this.m_map.TryGetValue(key, out list)) 27 | { 28 | list = new List(); 29 | this.m_map[key] = list; 30 | } 31 | list.Add(value); 32 | } 33 | 34 | internal void AddRange(TKey key, IEnumerable values) 35 | { 36 | foreach (TValue local in values) 37 | { 38 | this.Add(key, local); 39 | } 40 | } 41 | 42 | internal bool ContainsKey(TKey key) 43 | { 44 | return this.m_map.ContainsKey(key); 45 | } 46 | 47 | internal IEnumerable EnumerateValues(TKey key) 48 | { 49 | List values; 50 | if (m_map.TryGetValue(key, out values)) 51 | { 52 | foreach (TValue value in values) { yield return value; } 53 | } 54 | } 55 | 56 | internal ReadOnlyCollection ListForKey(TKey key) 57 | { 58 | return new ReadOnlyCollection(this.m_map[key]); 59 | } 60 | 61 | internal bool RemoveKey(TKey key) 62 | { 63 | return this.m_map.Remove(key); 64 | } 65 | 66 | internal override void ToCompactString(StringBuilder builder) 67 | { 68 | foreach (TKey local in this.Keys) 69 | { 70 | StringUtil.FormatStringBuilder(builder, "{0}", new object[] { local }); 71 | builder.Append(": "); 72 | IEnumerable list = this.ListForKey(local); 73 | StringUtil.ToSeparatedString(builder, list, ",", "null"); 74 | builder.Append("; "); 75 | } 76 | } 77 | 78 | internal bool TryGetListForKey(TKey key, out ReadOnlyCollection valueCollection) 79 | { 80 | List list; 81 | valueCollection = null; 82 | if (this.m_map.TryGetValue(key, out list)) 83 | { 84 | valueCollection = new ReadOnlyCollection(list); 85 | return true; 86 | } 87 | return false; 88 | } 89 | 90 | // Properties 91 | internal IEnumerable AllValues 92 | { 93 | get 94 | { 95 | foreach (TKey key in Keys) 96 | { 97 | foreach (TValue value in ListForKey(key)) 98 | { 99 | yield return value; 100 | } 101 | } 102 | } 103 | } 104 | 105 | internal IEnumerable Keys 106 | { 107 | get 108 | { 109 | return this.m_map.Keys; 110 | } 111 | } 112 | 113 | internal IEnumerable>> KeyValuePairs 114 | { 115 | #if NET_40 || NET_45 116 | [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] 117 | #endif 118 | get 119 | { 120 | return this.m_map; 121 | } 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/SkipClause.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System.Globalization; 4 | 5 | /// 6 | /// SkipClause represents the a SKIP expression in a SqlSelectStatement. 7 | /// It has a count property, which indicates how many rows should be skipped. 8 | /// 9 | class SkipClause : ISqlFragment 10 | { 11 | ISqlFragment skipCount; 12 | 13 | /// 14 | /// How many rows should be skipped. 15 | /// 16 | internal ISqlFragment SkipCount 17 | { 18 | get { return skipCount; } 19 | } 20 | 21 | /// 22 | /// Creates a SkipClause with the given skipCount. 23 | /// 24 | /// 25 | internal SkipClause(ISqlFragment skipCount) 26 | { 27 | this.skipCount = skipCount; 28 | } 29 | 30 | /// 31 | /// Creates a SkipClause with the given skipCount. 32 | /// 33 | /// 34 | internal SkipClause(int skipCount) 35 | { 36 | SqlBuilder sqlBuilder = new SqlBuilder(); 37 | sqlBuilder.Append(skipCount.ToString(CultureInfo.InvariantCulture)); 38 | this.skipCount = sqlBuilder; 39 | } 40 | 41 | #region ISqlFragment Members 42 | /// 43 | /// Write out the SKIP part of sql select statement 44 | /// It basically writes OFFSET (X). 45 | /// 46 | /// 47 | /// 48 | public void WriteSql(SqlWriter writer, SqlGenerator sqlGenerator) 49 | { 50 | writer.Write(" OFFSET "); 51 | this.SkipCount.WriteSql(writer, sqlGenerator); 52 | } 53 | #endregion 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/SqlBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Diagnostics; 6 | using System.Data.Entity.Core.Common.CommandTrees; 7 | 8 | /// 9 | /// This class is like StringBuilder. While traversing the tree for the first time, 10 | /// we do not know all the strings that need to be appended e.g. things that need to be 11 | /// renamed, nested select statements etc. So, we use a builder that can collect 12 | /// all kinds of sql fragments. 13 | /// 14 | internal sealed class SqlBuilder : ISqlFragment 15 | { 16 | private List _sqlFragments; 17 | private List sqlFragments 18 | { 19 | get 20 | { 21 | if (null == _sqlFragments) 22 | { 23 | _sqlFragments = new List(); 24 | } 25 | return _sqlFragments; 26 | } 27 | } 28 | 29 | 30 | /// 31 | /// Add an object to the list - we do not verify that it is a proper sql fragment 32 | /// since this is an internal method. 33 | /// 34 | /// 35 | public void Append(object s) 36 | { 37 | Debug.Assert(s != null); 38 | sqlFragments.Add(s); 39 | } 40 | 41 | /// 42 | /// This is to pretty print the SQL. The writer 43 | /// needs to know about new lines so that it can add the right amount of 44 | /// indentation at the beginning of lines. 45 | /// 46 | public void AppendLine() 47 | { 48 | sqlFragments.Add("\r\n"); 49 | } 50 | 51 | /// 52 | /// Whether the builder is empty. This is used by the 53 | /// to determine whether a sql statement can be reused. 54 | /// 55 | public bool IsEmpty 56 | { 57 | get { return ((null == _sqlFragments) || (0 == _sqlFragments.Count)); } 58 | } 59 | 60 | #region ISqlFragment Members 61 | 62 | /// 63 | /// We delegate the writing of the fragment to the appropriate type. 64 | /// 65 | /// 66 | /// 67 | public void WriteSql(SqlWriter writer, SqlGenerator sqlGenerator) 68 | { 69 | if (null != _sqlFragments) 70 | { 71 | foreach (object o in _sqlFragments) 72 | { 73 | string str = (o as String); 74 | if (null != str) 75 | { 76 | writer.Write(str); 77 | } 78 | else 79 | { 80 | ISqlFragment sqlFragment = (o as ISqlFragment); 81 | if (null != sqlFragment) 82 | { 83 | sqlFragment.WriteSql(writer, sqlGenerator); 84 | } 85 | else 86 | { 87 | throw new InvalidOperationException(); 88 | } 89 | } 90 | } 91 | } 92 | } 93 | 94 | #endregion 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/SqlSelectStatement.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Data.Entity.Core.Common.CommandTrees; 6 | 7 | /// 8 | /// A SqlSelectStatement represents a canonical SQL SELECT statement. 9 | /// It has fields for the 5 main clauses 10 | /// 11 | /// SELECT 12 | /// FROM 13 | /// WHERE 14 | /// GROUP BY 15 | /// ORDER BY 16 | /// 17 | /// We do not have HAVING, since it does not correspond to anything in the DbCommandTree. 18 | /// Each of the fields is a SqlBuilder, so we can keep appending SQL strings 19 | /// or other fragments to build up the clause. 20 | /// 21 | /// We have a IsDistinct property to indicate that we want distict columns. 22 | /// This is given out of band, since the input expression to the select clause 23 | /// may already have some columns projected out, and we use append-only SqlBuilders. 24 | /// The DISTINCT is inserted when we finally write the object into a string. 25 | /// 26 | /// Also, we have a Top property, which is non-null if the number of results should 27 | /// be limited to certain number. It is given out of band for the same reasons as DISTINCT. 28 | /// 29 | /// The FromExtents contains the list of inputs in use for the select statement. 30 | /// There is usually just one element in this - Select statements for joins may 31 | /// temporarily have more than one. 32 | /// 33 | /// If the select statement is created by a Join node, we maintain a list of 34 | /// all the extents that have been flattened in the join in AllJoinExtents 35 | /// 36 | /// in J(j1= J(a,b), c) 37 | /// FromExtents has 2 nodes JoinSymbol(name=j1, ...) and Symbol(name=c) 38 | /// AllJoinExtents has 3 nodes Symbol(name=a), Symbol(name=b), Symbol(name=c) 39 | /// 40 | /// 41 | /// If any expression in the non-FROM clause refers to an extent in a higher scope, 42 | /// we add that extent to the OuterExtents list. This list denotes the list 43 | /// of extent aliases that may collide with the aliases used in this select statement. 44 | /// It is set by . 45 | /// An extent is an outer extent if it is not one of the FromExtents. 46 | /// 47 | /// 48 | /// 49 | internal sealed class SqlSelectStatement : ISqlFragment 50 | { 51 | private bool isDistinct; 52 | 53 | /// 54 | /// Do we need to add a DISTINCT at the beginning of the SELECT 55 | /// 56 | internal bool IsDistinct 57 | { 58 | get { return isDistinct; } 59 | set { isDistinct = value; } 60 | } 61 | 62 | private List allJoinExtents; 63 | internal List AllJoinExtents 64 | { 65 | get { return allJoinExtents; } 66 | // We have a setter as well, even though this is a list, 67 | // since we use this field only in special cases. 68 | set { allJoinExtents = value; } 69 | } 70 | 71 | private List fromExtents; 72 | internal List FromExtents 73 | { 74 | get 75 | { 76 | if (null == fromExtents) 77 | { 78 | fromExtents = new List(); 79 | } 80 | return fromExtents; 81 | } 82 | } 83 | 84 | private Dictionary outerExtents; 85 | internal Dictionary OuterExtents 86 | { 87 | get 88 | { 89 | if (null == outerExtents) 90 | { 91 | outerExtents = new Dictionary(); 92 | } 93 | return outerExtents; 94 | } 95 | } 96 | 97 | private TopClause top; 98 | internal TopClause Top 99 | { 100 | get { return top; } 101 | set 102 | { 103 | Debug.Assert(top == null, "SqlSelectStatement.Top has already been set"); 104 | top = value; 105 | } 106 | } 107 | 108 | private SkipClause skip; 109 | internal SkipClause Skip 110 | { 111 | get { return skip; } 112 | set 113 | { 114 | Debug.Assert(skip == null, "SqlSelectStatement.Skip has already been set"); 115 | skip = value; 116 | } 117 | } 118 | 119 | private SqlBuilder select = new SqlBuilder(); 120 | internal SqlBuilder Select 121 | { 122 | get { return select; } 123 | } 124 | 125 | private SqlBuilder from = new SqlBuilder(); 126 | internal SqlBuilder From 127 | { 128 | get { return from; } 129 | } 130 | 131 | 132 | private SqlBuilder where; 133 | internal SqlBuilder Where 134 | { 135 | get 136 | { 137 | if (null == where) 138 | { 139 | where = new SqlBuilder(); 140 | } 141 | return where; 142 | } 143 | } 144 | 145 | private SqlBuilder groupBy; 146 | internal SqlBuilder GroupBy 147 | { 148 | get 149 | { 150 | if (null == groupBy) 151 | { 152 | groupBy = new SqlBuilder(); 153 | } 154 | return groupBy; 155 | } 156 | } 157 | 158 | private SqlBuilder orderBy; 159 | public SqlBuilder OrderBy 160 | { 161 | get 162 | { 163 | if (null == orderBy) 164 | { 165 | orderBy = new SqlBuilder(); 166 | } 167 | return orderBy; 168 | } 169 | } 170 | 171 | //indicates whether it is the top most select statement, 172 | // if not Order By should be omitted unless there is a corresponding TOP 173 | private bool isTopMost; 174 | internal bool IsTopMost 175 | { 176 | get { return this.isTopMost; } 177 | set { this.isTopMost = value; } 178 | } 179 | 180 | #region ISqlFragment Members 181 | 182 | /// 183 | /// Write out a SQL select statement as a string. 184 | /// We have to 185 | /// 186 | /// Check whether the aliases extents we use in this statement have 187 | /// to be renamed. 188 | /// We first create a list of all the aliases used by the outer extents. 189 | /// For each of the FromExtents( or AllJoinExtents if it is non-null), 190 | /// rename it if it collides with the previous list. 191 | /// 192 | /// Write each of the clauses (if it exists) as a string 193 | /// 194 | /// 195 | /// 196 | /// 197 | public void WriteSql(SqlWriter writer, SqlGenerator sqlGenerator) 198 | { 199 | #region Check if FROM aliases need to be renamed 200 | 201 | // Create a list of the aliases used by the outer extents 202 | // JoinSymbols have to be treated specially. 203 | List outerExtentAliases = null; 204 | if ((null != outerExtents) && (0 < outerExtents.Count)) 205 | { 206 | foreach (Symbol outerExtent in outerExtents.Keys) 207 | { 208 | JoinSymbol joinSymbol = outerExtent as JoinSymbol; 209 | if (joinSymbol != null) 210 | { 211 | foreach (Symbol symbol in joinSymbol.FlattenedExtentList) 212 | { 213 | if (null == outerExtentAliases) { outerExtentAliases = new List(); } 214 | outerExtentAliases.Add(symbol.NewName); 215 | } 216 | } 217 | else 218 | { 219 | if (null == outerExtentAliases) { outerExtentAliases = new List(); } 220 | outerExtentAliases.Add(outerExtent.NewName); 221 | } 222 | } 223 | } 224 | 225 | // An then rename each of the FromExtents we have 226 | // If AllJoinExtents is non-null - it has precedence. 227 | // The new name is derived from the old name - we append an increasing int. 228 | List extentList = this.AllJoinExtents ?? this.fromExtents; 229 | if (null != extentList) 230 | { 231 | foreach (Symbol fromAlias in extentList) 232 | { 233 | if ((null != outerExtentAliases) && outerExtentAliases.Contains(fromAlias.Name)) 234 | { 235 | int i = sqlGenerator.AllExtentNames[fromAlias.Name]; 236 | string newName; 237 | do 238 | { 239 | ++i; 240 | newName = fromAlias.Name + i.ToString(System.Globalization.CultureInfo.InvariantCulture); 241 | } 242 | while (sqlGenerator.AllExtentNames.ContainsKey(newName)); 243 | sqlGenerator.AllExtentNames[fromAlias.Name] = i; 244 | fromAlias.NewName = newName; 245 | 246 | // Add extent to list of known names (although i is always incrementing, "prefix11" can 247 | // eventually collide with "prefix1" when it is extended) 248 | sqlGenerator.AllExtentNames[newName] = 0; 249 | } 250 | 251 | // Add the current alias to the list, so that the extents 252 | // that follow do not collide with me. 253 | if (null == outerExtentAliases) { outerExtentAliases = new List(); } 254 | outerExtentAliases.Add(fromAlias.NewName); 255 | } 256 | } 257 | #endregion 258 | 259 | // Increase the indent, so that the Sql statement is nested by one tab. 260 | writer.Indent += 1; // ++ can be confusing in this context 261 | 262 | writer.Write("SELECT "); 263 | if (IsDistinct) 264 | { 265 | writer.Write("DISTINCT "); 266 | } 267 | 268 | if ((null == this.select) || this.Select.IsEmpty) 269 | { 270 | Debug.Assert(false); // we have removed all possibilities of SELECT *. 271 | writer.Write("*"); 272 | } 273 | else 274 | { 275 | this.Select.WriteSql(writer, sqlGenerator); 276 | } 277 | 278 | writer.WriteLine(); 279 | writer.Write("FROM "); 280 | this.From.WriteSql(writer, sqlGenerator); 281 | 282 | if ((null != this.where) && !this.Where.IsEmpty) 283 | { 284 | writer.WriteLine(); 285 | writer.Write("WHERE "); 286 | this.Where.WriteSql(writer, sqlGenerator); 287 | } 288 | 289 | if ((null != this.groupBy) && !this.GroupBy.IsEmpty) 290 | { 291 | writer.WriteLine(); 292 | writer.Write("GROUP BY "); 293 | this.GroupBy.WriteSql(writer, sqlGenerator); 294 | } 295 | 296 | if ((null != this.orderBy) && !this.OrderBy.IsEmpty && (this.IsTopMost || this.Top != null)) 297 | { 298 | writer.WriteLine(); 299 | writer.Write("ORDER BY "); 300 | this.OrderBy.WriteSql(writer, sqlGenerator); 301 | } 302 | 303 | if (this.Top != null) 304 | { 305 | this.Top.WriteSql(writer, sqlGenerator); 306 | } 307 | 308 | if (this.skip != null) 309 | { 310 | this.Skip.WriteSql(writer, sqlGenerator); 311 | } 312 | 313 | --writer.Indent; 314 | } 315 | 316 | #endregion 317 | } 318 | } 319 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/SqlWriter.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System.IO; 4 | using System.Text; 5 | 6 | /// 7 | /// This extends StringWriter primarily to add the ability to add an indent 8 | /// to each line that is written out. 9 | /// 10 | class SqlWriter : StringWriter 11 | { 12 | // We start at -1, since the first select statement will increment it to 0. 13 | int indent = -1; 14 | /// 15 | /// The number of tabs to be added at the beginning of each new line. 16 | /// 17 | internal int Indent 18 | { 19 | get { return indent; } 20 | set { indent = value; } 21 | } 22 | 23 | bool atBeginningOfLine = true; 24 | 25 | /// 26 | /// 27 | /// 28 | /// 29 | public SqlWriter(StringBuilder b) 30 | : base(b, System.Globalization.CultureInfo.InvariantCulture) 31 | { 32 | } 33 | 34 | /// 35 | /// Reset atBeginningofLine if we detect the newline string. 36 | /// 37 | /// Add as many tabs as the value of indent if we are at the 38 | /// beginning of a line. 39 | /// 40 | /// 41 | public override void Write(string value) 42 | { 43 | if (value == "\r\n") 44 | { 45 | base.WriteLine(); 46 | atBeginningOfLine = true; 47 | } 48 | else 49 | { 50 | if (atBeginningOfLine) 51 | { 52 | if (indent > 0) 53 | { 54 | base.Write(new string('\t', indent)); 55 | } 56 | atBeginningOfLine = false; 57 | } 58 | base.Write(value); 59 | } 60 | } 61 | 62 | /// 63 | /// 64 | /// 65 | public override void WriteLine() 66 | { 67 | base.WriteLine(); 68 | atBeginningOfLine = true; 69 | } 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/StringUtil.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Globalization; 6 | using System.Collections; 7 | 8 | #if NET_40 || NET_45 9 | using System.Runtime; 10 | #endif 11 | 12 | internal static class StringUtil 13 | { 14 | // Fields 15 | private const string s_defaultDelimiter = ", "; 16 | 17 | // Methods 18 | internal static string BuildDelimitedList(IEnumerable values, ToStringConverter converter, string delimiter) 19 | { 20 | if (values == null) 21 | { 22 | return string.Empty; 23 | } 24 | if (converter == null) 25 | { 26 | converter = new ToStringConverter(StringUtil.InvariantConvertToString); 27 | } 28 | if (delimiter == null) 29 | { 30 | delimiter = ", "; 31 | } 32 | StringBuilder builder = new StringBuilder(); 33 | bool flag = true; 34 | foreach (T local in values) 35 | { 36 | if (flag) 37 | { 38 | flag = false; 39 | } 40 | else 41 | { 42 | builder.Append(delimiter); 43 | } 44 | builder.Append(converter(local)); 45 | } 46 | return builder.ToString(); 47 | } 48 | 49 | internal static string FormatIndex(string arrayVarName, int index) 50 | { 51 | StringBuilder builder = new StringBuilder((arrayVarName.Length + 10) + 2); 52 | return builder.Append(arrayVarName).Append('[').Append(index).Append(']').ToString(); 53 | } 54 | 55 | internal static string FormatInvariant(string format, params object[] args) 56 | { 57 | return string.Format(CultureInfo.InvariantCulture, format, args); 58 | } 59 | 60 | internal static StringBuilder FormatStringBuilder(StringBuilder builder, string format, params object[] args) 61 | { 62 | builder.AppendFormat(CultureInfo.InvariantCulture, format, args); 63 | return builder; 64 | } 65 | 66 | internal static StringBuilder IndentNewLine(StringBuilder builder, int indent) 67 | { 68 | builder.AppendLine(); 69 | for (int i = 0; i < indent; i++) 70 | { 71 | builder.Append(" "); 72 | } 73 | return builder; 74 | } 75 | 76 | private static string InvariantConvertToString(T value) 77 | { 78 | return string.Format(CultureInfo.InvariantCulture, "{0}", new object[] { value }); 79 | } 80 | 81 | #if NET_40 || NET_45 82 | [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] 83 | #endif 84 | internal static bool IsNullOrEmptyOrWhiteSpace(string value) 85 | { 86 | return IsNullOrEmptyOrWhiteSpace(value, 0); 87 | } 88 | 89 | internal static bool IsNullOrEmptyOrWhiteSpace(string value, int offset) 90 | { 91 | if (value != null) 92 | { 93 | for (int i = offset; i < value.Length; i++) 94 | { 95 | if (!char.IsWhiteSpace(value[i])) 96 | { 97 | return false; 98 | } 99 | } 100 | } 101 | return true; 102 | } 103 | 104 | internal static bool IsNullOrEmptyOrWhiteSpace(string value, int offset, int length) 105 | { 106 | if (value != null) 107 | { 108 | length = Math.Min(value.Length, length); 109 | for (int i = offset; i < length; i++) 110 | { 111 | if (!char.IsWhiteSpace(value[i])) 112 | { 113 | return false; 114 | } 115 | } 116 | } 117 | return true; 118 | } 119 | 120 | internal static string MembersToCommaSeparatedString(IEnumerable members) 121 | { 122 | StringBuilder builder = new StringBuilder(); 123 | builder.Append("{"); 124 | ToCommaSeparatedString(builder, members); 125 | builder.Append("}"); 126 | return builder.ToString(); 127 | } 128 | 129 | internal static string ToCommaSeparatedString(IEnumerable list) 130 | { 131 | return ToSeparatedString(list, ", ", string.Empty); 132 | } 133 | 134 | internal static void ToCommaSeparatedString(StringBuilder builder, IEnumerable list) 135 | { 136 | ToSeparatedStringPrivate(builder, list, ", ", string.Empty, false); 137 | } 138 | 139 | internal static string ToCommaSeparatedStringSorted(IEnumerable list) 140 | { 141 | return ToSeparatedStringSorted(list, ", ", string.Empty); 142 | } 143 | 144 | internal static void ToCommaSeparatedStringSorted(StringBuilder builder, IEnumerable list) 145 | { 146 | ToSeparatedStringPrivate(builder, list, ", ", string.Empty, true); 147 | } 148 | 149 | internal static string ToSeparatedString(IEnumerable list, string separator, string nullValue) 150 | { 151 | StringBuilder stringBuilder = new StringBuilder(); 152 | ToSeparatedString(stringBuilder, list, separator, nullValue); 153 | return stringBuilder.ToString(); 154 | } 155 | 156 | internal static void ToSeparatedString(StringBuilder builder, IEnumerable list, string separator) 157 | { 158 | ToSeparatedStringPrivate(builder, list, separator, string.Empty, false); 159 | } 160 | 161 | #if NET_40 || NET_45 162 | [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] 163 | #endif 164 | internal static void ToSeparatedString(StringBuilder stringBuilder, IEnumerable list, string separator, string nullValue) 165 | { 166 | ToSeparatedStringPrivate(stringBuilder, list, separator, nullValue, false); 167 | } 168 | 169 | private static void ToSeparatedStringPrivate(StringBuilder stringBuilder, IEnumerable list, string separator, string nullValue, bool toSort) 170 | { 171 | if (list != null) 172 | { 173 | bool flag = true; 174 | List list2 = new List(); 175 | foreach (object obj2 in list) 176 | { 177 | string str; 178 | if (obj2 == null) 179 | { 180 | str = nullValue; 181 | } 182 | else 183 | { 184 | str = FormatInvariant("{0}", new object[] { obj2 }); 185 | } 186 | list2.Add(str); 187 | } 188 | if (toSort) 189 | { 190 | list2.Sort(StringComparer.Ordinal); 191 | } 192 | foreach (string str2 in list2) 193 | { 194 | if (!flag) 195 | { 196 | stringBuilder.Append(separator); 197 | } 198 | stringBuilder.Append(str2); 199 | flag = false; 200 | } 201 | } 202 | } 203 | 204 | internal static string ToSeparatedStringSorted(IEnumerable list, string separator, string nullValue) 205 | { 206 | StringBuilder stringBuilder = new StringBuilder(); 207 | ToSeparatedStringPrivate(stringBuilder, list, separator, nullValue, true); 208 | return stringBuilder.ToString(); 209 | } 210 | 211 | internal static void ToSeparatedStringSorted(StringBuilder builder, IEnumerable list, string separator) 212 | { 213 | ToSeparatedStringPrivate(builder, list, separator, string.Empty, true); 214 | } 215 | 216 | // Nested Types 217 | internal delegate string ToStringConverter(T value); 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/Symbol.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Data.Entity.Core.Metadata.Edm; 6 | 7 | /// 8 | /// 9 | /// This class represents an extent/nested select statement, 10 | /// or a column. 11 | /// 12 | /// The important fields are Name, Type and NewName. 13 | /// NewName starts off the same as Name, and is then modified as necessary. 14 | /// 15 | /// 16 | /// The rest are used by special symbols. 17 | /// e.g. NeedsRenaming is used by columns to indicate that a new name must 18 | /// be picked for the column in the second phase of translation. 19 | /// 20 | /// IsUnnest is used by symbols for a collection expression used as a from clause. 21 | /// This allows to add the column list 22 | /// after the alias. 23 | /// 24 | /// 25 | class Symbol : ISqlFragment 26 | { 27 | private Dictionary columns = new Dictionary(StringComparer.CurrentCultureIgnoreCase); 28 | internal Dictionary Columns 29 | { 30 | get { return columns; } 31 | } 32 | 33 | private bool needsRenaming = false; 34 | internal bool NeedsRenaming 35 | { 36 | get { return needsRenaming; } 37 | set { needsRenaming = value; } 38 | } 39 | 40 | bool isUnnest = false; 41 | internal bool IsUnnest 42 | { 43 | get { return isUnnest; } 44 | set { isUnnest = value; } 45 | } 46 | 47 | string name; 48 | public string Name 49 | { 50 | get { return name; } 51 | } 52 | 53 | string newName; 54 | public string NewName 55 | { 56 | get { return newName; } 57 | set { newName = value; } 58 | } 59 | 60 | private TypeUsage type; 61 | internal TypeUsage Type 62 | { 63 | get { return type; } 64 | set { type = value; } 65 | } 66 | 67 | public Symbol(string name, TypeUsage type) 68 | { 69 | this.name = name; 70 | this.newName = name; 71 | this.Type = type; 72 | } 73 | 74 | #region ISqlFragment Members 75 | 76 | /// 77 | /// Write this symbol out as a string for sql. This is just 78 | /// the new name of the symbol (which could be the same as the old name). 79 | /// 80 | /// We rename columns here if necessary. 81 | /// 82 | /// 83 | /// 84 | public void WriteSql(SqlWriter writer, SqlGenerator sqlGenerator) 85 | { 86 | if (this.NeedsRenaming) 87 | { 88 | string newName; 89 | int i = sqlGenerator.AllColumnNames[this.NewName]; 90 | do 91 | { 92 | ++i; 93 | newName = this.Name + i.ToString(System.Globalization.CultureInfo.InvariantCulture); 94 | } while (sqlGenerator.AllColumnNames.ContainsKey(newName)); 95 | sqlGenerator.AllColumnNames[this.NewName] = i; 96 | 97 | // Prevent it from being renamed repeatedly. 98 | this.NeedsRenaming = false; 99 | this.NewName = newName; 100 | 101 | // Add this column name to list of known names so that there are no subsequent 102 | // collisions 103 | sqlGenerator.AllColumnNames[newName] = 0; 104 | } 105 | writer.Write(SqlGenerator.QuoteIdentifier(this.NewName)); 106 | } 107 | 108 | #endregion 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/SymbolPair.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System.Diagnostics; 4 | using System.Data.Entity.Core.Common.CommandTrees; 5 | 6 | /// 7 | /// The SymbolPair exists to solve the record flattening problem. 8 | /// 9 | /// Consider a property expression D(v, "j3.j2.j1.a.x") 10 | /// where v is a VarRef, j1, j2, j3 are joins, a is an extent and x is a columns. 11 | /// This has to be translated eventually into {j'}.{x'} 12 | /// 13 | /// The source field represents the outermost SqlStatement representing a join 14 | /// expression (say j2) - this is always a Join symbol. 15 | /// 16 | /// The column field keeps moving from one join symbol to the next, until it 17 | /// stops at a non-join symbol. 18 | /// 19 | /// This is returned by , 20 | /// but never makes it into a SqlBuilder. 21 | /// 22 | class SymbolPair : ISqlFragment 23 | { 24 | public Symbol Source; 25 | public Symbol Column; 26 | 27 | public SymbolPair(Symbol source, Symbol column) 28 | { 29 | this.Source = source; 30 | this.Column = column; 31 | } 32 | 33 | #region ISqlFragment Members 34 | 35 | public void WriteSql(SqlWriter writer, SqlGenerator sqlGenerator) 36 | { 37 | // Symbol pair should never be part of a SqlBuilder. 38 | Debug.Assert(false); 39 | } 40 | 41 | #endregion 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/SymbolTable.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Data.Entity.Core.Common.CommandTrees; 6 | 7 | /// 8 | /// The symbol table is quite primitive - it is a stack with a new entry for 9 | /// each scope. Lookups search from the top of the stack to the bottom, until 10 | /// an entry is found. 11 | /// 12 | /// The symbols are of the following kinds 13 | /// 14 | /// represents tables (extents/nested selects/unnests) 15 | /// represents Join nodes 16 | /// columns. 17 | /// 18 | /// 19 | /// Symbols represent names to be resolved, 20 | /// or things to be renamed. 21 | /// 22 | internal sealed class SymbolTable 23 | { 24 | private List> symbols = new List>(); 25 | 26 | internal void EnterScope() 27 | { 28 | symbols.Add(new Dictionary(StringComparer.OrdinalIgnoreCase)); 29 | } 30 | 31 | internal void ExitScope() 32 | { 33 | symbols.RemoveAt(symbols.Count - 1); 34 | } 35 | 36 | internal void Add(string name, Symbol value) 37 | { 38 | symbols[symbols.Count - 1][name] = value; 39 | } 40 | 41 | internal Symbol Lookup(string name) 42 | { 43 | for (int i = symbols.Count - 1; i >= 0; --i) 44 | { 45 | if (symbols[i].ContainsKey(name)) 46 | { 47 | return symbols[i][name]; 48 | } 49 | } 50 | 51 | return null; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SQL_Generation/TopClause.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | using System; 4 | using System.Globalization; 5 | 6 | /// 7 | /// TopClause represents the a TOP expression in a SqlSelectStatement. 8 | /// It has a count property, which indicates how many TOP rows should be selected and a 9 | /// boolen WithTies property. 10 | /// 11 | class TopClause : ISqlFragment 12 | { 13 | ISqlFragment topCount; 14 | bool withTies; 15 | 16 | /// 17 | /// Do we need to add a WITH_TIES to the top statement 18 | /// 19 | internal bool WithTies 20 | { 21 | get { return withTies; } 22 | } 23 | 24 | /// 25 | /// How many top rows should be selected. 26 | /// 27 | internal ISqlFragment TopCount 28 | { 29 | get { return topCount; } 30 | } 31 | 32 | /// 33 | /// Creates a TopClause with the given topCount and withTies. 34 | /// 35 | /// 36 | /// 37 | internal TopClause(ISqlFragment topCount, bool withTies) 38 | { 39 | this.topCount = topCount; 40 | this.withTies = withTies; 41 | } 42 | 43 | /// 44 | /// Creates a TopClause with the given topCount and withTies. 45 | /// 46 | /// 47 | /// 48 | internal TopClause(int topCount, bool withTies) 49 | { 50 | SqlBuilder sqlBuilder = new SqlBuilder(); 51 | sqlBuilder.Append(topCount.ToString(CultureInfo.InvariantCulture)); 52 | this.topCount = sqlBuilder; 53 | this.withTies = withTies; 54 | } 55 | 56 | #region ISqlFragment Members 57 | 58 | /// 59 | /// Write out the TOP part of sql select statement 60 | /// It basically writes LIMIT (X). 61 | /// 62 | /// 63 | /// 64 | public void WriteSql(SqlWriter writer, SqlGenerator sqlGenerator) 65 | { 66 | writer.Write(" LIMIT "); 67 | this.TopCount.WriteSql(writer, sqlGenerator); 68 | 69 | if (this.WithTies) 70 | throw new NotSupportedException("WITH TIES"); 71 | 72 | //writer.Write(" "); 73 | 74 | //if (this.WithTies) 75 | //{ 76 | // writer.Write("WITH TIES "); 77 | //} 78 | } 79 | 80 | #endregion 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SharpHsql.Linq.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {DEAFCB16-9BC4-4D3A-A850-C3B9423026C5} 7 | Library 8 | System.Data.Hsql.Linq 9 | SharpHsql.Linq 10 | v4.5 11 | 12 | 13 | true 14 | full 15 | false 16 | bin\Debug 17 | DEBUG; TRACE 18 | prompt 19 | 4 20 | false 21 | 22 | 23 | full 24 | true 25 | bin\Release 26 | prompt 27 | 4 28 | false 29 | 30 | 31 | 32 | 33 | 34 | ..\..\..\ConnectionTest-EF.git\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll 35 | 36 | 37 | ..\..\..\ConnectionTest-EF.git\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll 38 | 39 | 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 | Resources.resx 66 | 67 | 68 | 69 | 70 | 71 | 72 | {B98F7374-FF00-4BB7-93EC-39763A76BFFF} 73 | SharpHsql 74 | 75 | 76 | 77 | 78 | 79 | 80 | Properties 81 | Resources.Designer.cs 82 | PublicResXFileCodeGenerator 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SharpHsqlDateFormats.cs: -------------------------------------------------------------------------------- 1 | namespace System.Data.Hsql.Linq 2 | { 3 | public enum SharpHsqlDateFormats 4 | { 5 | Ticks = 0, 6 | Default = 1, 7 | ISO8601 = 1, 8 | JulianDay = 2, 9 | UnixEpoch = 3, 10 | InvariantCulture = 4, 11 | CurrentCulture = 5, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/SharpHsql.Linq/SharpHsqlProviderManifest.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace System.Data.Hsql.Linq 4 | { 5 | using System; 6 | using System.Data.Entity.Core; 7 | using System.Reflection; 8 | using System.IO; 9 | using System.Xml; 10 | using System.Data.Entity.Core.Common; 11 | using System.Data.Entity.Core.Metadata.Edm; 12 | 13 | /// 14 | /// The Provider Manifest for SQL Server 15 | /// 16 | internal class SharpHsqlProviderManifest : DbXmlEnabledProviderManifest 17 | { 18 | internal SharpHsqlDateFormats _dateFormat; 19 | 20 | /// 21 | /// Constructs the provider manifest. 22 | /// 23 | /// 24 | /// We pass the token as a DateTimeFormat enum text, because all the datetime functions 25 | /// are vastly different depending on how the user is opening the connection 26 | /// 27 | /// A token used to infer the capabilities of the store 28 | public SharpHsqlProviderManifest(string manifestToken) 29 | : base(SharpHsqlProviderManifest.GetProviderManifest()) 30 | { 31 | _dateFormat = (SharpHsqlDateFormats)Enum.Parse(typeof(SharpHsqlDateFormats), manifestToken, true); 32 | } 33 | 34 | internal static XmlReader GetProviderManifest() 35 | { 36 | return GetXmlResource("System.Data.Hsql.Linq.Resources.SharpHsqlProviderServices.ProviderManifest.xml"); 37 | } 38 | 39 | private XmlReader GetStoreSchemaMapping() 40 | { 41 | return GetXmlResource("System.Data.Hsql.Linq.Resources.SharpHsqlProviderServices.StoreSchemaMapping.msl"); 42 | } 43 | 44 | private XmlReader GetStoreSchemaDescription() 45 | { 46 | return GetXmlResource("System.Data.Hsql.Linq.Resources.SharpHsqlProviderServices.StoreSchemaDefinition.ssdl"); 47 | } 48 | 49 | internal static XmlReader GetXmlResource(string resourceName) 50 | { 51 | var assembly = Assembly.GetExecutingAssembly(); 52 | Stream stream = assembly.GetManifestResourceStream(resourceName); 53 | #if DEBUG 54 | if (stream == null) { 55 | // http://stackoverflow.com/questions/3068736/cant-load-a-manifest-resource-with-getmanifestresourcestream 56 | string[] names = assembly.GetManifestResourceNames (); 57 | foreach (var n in names) { 58 | Trace.WriteLine (n); 59 | } 60 | } 61 | #endif 62 | return XmlReader.Create(stream); 63 | } 64 | 65 | /// 66 | /// Returns manifest information for the provider 67 | /// 68 | /// The name of the information to be retrieved. 69 | /// An XmlReader at the begining of the information requested. 70 | protected override XmlReader GetDbInformation(string informationType) 71 | { 72 | if (informationType == DbProviderManifest.StoreSchemaDefinition) 73 | return GetStoreSchemaDescription(); 74 | else if (informationType == DbProviderManifest.StoreSchemaMapping) 75 | return GetStoreSchemaMapping(); 76 | else if (informationType == DbProviderManifest.ConceptualSchemaDefinition) 77 | return null; 78 | 79 | throw new ProviderIncompatibleException(String.Format("SharpHsql does not support this information type '{0}'.", informationType)); 80 | } 81 | 82 | /// 83 | /// This method takes a type and a set of facets and returns the best mapped equivalent type 84 | /// in EDM. 85 | /// 86 | /// A TypeUsage encapsulating a store type and a set of facets 87 | /// A TypeUsage encapsulating an EDM type and a set of facets 88 | public override TypeUsage GetEdmType(TypeUsage storeType) 89 | { 90 | if (storeType == null) 91 | { 92 | throw new ArgumentNullException("storeType"); 93 | } 94 | 95 | string storeTypeName = storeType.EdmType.Name.ToLowerInvariant(); 96 | //if (!base.StoreTypeNameToEdmPrimitiveType.ContainsKey(storeTypeName)) 97 | //{ 98 | // switch (storeTypeName) 99 | // { 100 | // case "integer": 101 | // return TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int64)); 102 | // default: 103 | // throw new ArgumentException(String.Format("SharpHsql does not support the type '{0}'.", storeTypeName)); 104 | // } 105 | //} 106 | 107 | PrimitiveType edmPrimitiveType; 108 | 109 | if (base.StoreTypeNameToEdmPrimitiveType.TryGetValue(storeTypeName, out edmPrimitiveType) == false) 110 | throw new ArgumentException(String.Format("SharpHsql does not support the type '{0}'.", storeTypeName)); 111 | 112 | int maxLength = 0; 113 | bool isUnicode = true; 114 | bool isFixedLen = false; 115 | bool isUnbounded = true; 116 | 117 | PrimitiveTypeKind newPrimitiveTypeKind; 118 | 119 | switch (storeTypeName) 120 | { 121 | case "tinyint": 122 | case "smallint": 123 | case "integer": 124 | case "bit": 125 | case "uniqueidentifier": 126 | case "int": 127 | case "float": 128 | case "real": 129 | return TypeUsage.CreateDefaultTypeUsage(edmPrimitiveType); 130 | 131 | case "varchar": 132 | newPrimitiveTypeKind = PrimitiveTypeKind.String; 133 | isUnbounded = !TypeHelpers.TryGetMaxLength(storeType, out maxLength); 134 | isUnicode = false; 135 | isFixedLen = false; 136 | break; 137 | case "char": 138 | newPrimitiveTypeKind = PrimitiveTypeKind.String; 139 | isUnbounded = !TypeHelpers.TryGetMaxLength(storeType, out maxLength); 140 | isUnicode = false; 141 | isFixedLen = true; 142 | break; 143 | case "nvarchar": 144 | newPrimitiveTypeKind = PrimitiveTypeKind.String; 145 | isUnbounded = !TypeHelpers.TryGetMaxLength(storeType, out maxLength); 146 | isUnicode = true; 147 | isFixedLen = false; 148 | break; 149 | case "nchar": 150 | newPrimitiveTypeKind = PrimitiveTypeKind.String; 151 | isUnbounded = !TypeHelpers.TryGetMaxLength(storeType, out maxLength); 152 | isUnicode = true; 153 | isFixedLen = true; 154 | break; 155 | case "blob": 156 | newPrimitiveTypeKind = PrimitiveTypeKind.Binary; 157 | isUnbounded = !TypeHelpers.TryGetMaxLength(storeType, out maxLength); 158 | isFixedLen = false; 159 | break; 160 | case "decimal": 161 | { 162 | byte precision; 163 | byte scale; 164 | if (TypeHelpers.TryGetPrecision(storeType, out precision) && TypeHelpers.TryGetScale(storeType, out scale)) 165 | { 166 | return TypeUsage.CreateDecimalTypeUsage(edmPrimitiveType, precision, scale); 167 | } 168 | else 169 | { 170 | return TypeUsage.CreateDecimalTypeUsage(edmPrimitiveType); 171 | } 172 | } 173 | case "datetime": 174 | return TypeUsage.CreateDateTimeTypeUsage(edmPrimitiveType, null); 175 | default: 176 | throw new NotSupportedException(String.Format("SharpHsql does not support the type '{0}'.", storeTypeName)); 177 | } 178 | 179 | switch (newPrimitiveTypeKind) 180 | { 181 | case PrimitiveTypeKind.String: 182 | if (!isUnbounded) 183 | { 184 | return TypeUsage.CreateStringTypeUsage(edmPrimitiveType, isUnicode, isFixedLen, maxLength); 185 | } 186 | else 187 | { 188 | return TypeUsage.CreateStringTypeUsage(edmPrimitiveType, isUnicode, isFixedLen); 189 | } 190 | case PrimitiveTypeKind.Binary: 191 | if (!isUnbounded) 192 | { 193 | return TypeUsage.CreateBinaryTypeUsage(edmPrimitiveType, isFixedLen, maxLength); 194 | } 195 | else 196 | { 197 | return TypeUsage.CreateBinaryTypeUsage(edmPrimitiveType, isFixedLen); 198 | } 199 | default: 200 | throw new NotSupportedException(String.Format("SharpHsql does not support the type '{0}'.", storeTypeName)); 201 | } 202 | } 203 | 204 | /// 205 | /// This method takes a type and a set of facets and returns the best mapped equivalent type 206 | /// 207 | /// A TypeUsage encapsulating an EDM type and a set of facets 208 | /// A TypeUsage encapsulating a store type and a set of facets 209 | public override TypeUsage GetStoreType(TypeUsage edmType) 210 | { 211 | if (edmType == null) 212 | throw new ArgumentNullException("edmType"); 213 | 214 | PrimitiveType primitiveType = edmType.EdmType as PrimitiveType; 215 | if (primitiveType == null) 216 | throw new ArgumentException(String.Format("SharpHsql does not support the type '{0}'.", edmType)); 217 | 218 | ReadOnlyMetadataCollection facets = edmType.Facets; 219 | 220 | switch (primitiveType.PrimitiveTypeKind) 221 | { 222 | case PrimitiveTypeKind.Boolean: 223 | return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["bit"]); 224 | case PrimitiveTypeKind.Byte: 225 | return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["tinyint"]); 226 | case PrimitiveTypeKind.Int16: 227 | return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["smallint"]); 228 | case PrimitiveTypeKind.Int32: 229 | return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["int"]); 230 | case PrimitiveTypeKind.Int64: 231 | return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["integer"]); 232 | case PrimitiveTypeKind.Guid: 233 | return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["uniqueidentifier"]); 234 | case PrimitiveTypeKind.Double: 235 | return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["float"]); 236 | case PrimitiveTypeKind.Single: 237 | return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["real"]); 238 | case PrimitiveTypeKind.Decimal: // decimal, numeric, smallmoney, money 239 | { 240 | byte precision; 241 | if (!TypeHelpers.TryGetPrecision(edmType, out precision)) 242 | { 243 | precision = 18; 244 | } 245 | 246 | byte scale; 247 | if (!TypeHelpers.TryGetScale(edmType, out scale)) 248 | { 249 | scale = 0; 250 | } 251 | 252 | return TypeUsage.CreateDecimalTypeUsage(StoreTypeNameToStorePrimitiveType["decimal"], precision, scale); 253 | } 254 | case PrimitiveTypeKind.Binary: // binary, varbinary, varbinary(max), image, timestamp, rowversion 255 | { 256 | bool isFixedLength = null != facets["FixedLength"].Value && (bool)facets["FixedLength"].Value; 257 | Facet f = facets["MaxLength"]; 258 | 259 | bool isMaxLength = f.IsUnbounded || null == f.Value || (int)f.Value > Int32.MaxValue; 260 | int maxLength = !isMaxLength ? (int)f.Value : Int32.MinValue; 261 | 262 | TypeUsage tu; 263 | if (isFixedLength) 264 | tu = TypeUsage.CreateBinaryTypeUsage(StoreTypeNameToStorePrimitiveType["blob"], true, maxLength); 265 | else 266 | { 267 | if (isMaxLength) 268 | tu = TypeUsage.CreateBinaryTypeUsage(StoreTypeNameToStorePrimitiveType["blob"], false); 269 | else 270 | tu = TypeUsage.CreateBinaryTypeUsage(StoreTypeNameToStorePrimitiveType["blob"], false, maxLength); 271 | } 272 | return tu; 273 | } 274 | case PrimitiveTypeKind.String: // char, nchar, varchar, nvarchar, varchar(max), nvarchar(max), ntext, text 275 | { 276 | bool isUnicode = null == facets["Unicode"].Value || (bool)facets["Unicode"].Value; 277 | bool isFixedLength = null != facets["FixedLength"].Value && (bool)facets["FixedLength"].Value; 278 | Facet f = facets["MaxLength"]; 279 | // maxlen is true if facet value is unbounded, the value is bigger than the limited string sizes *or* the facet 280 | // value is null. this is needed since functions still have maxlength facet value as null 281 | bool isMaxLength = f.IsUnbounded || null == f.Value || (int)f.Value > (isUnicode ? Int32.MaxValue : Int32.MaxValue); 282 | int maxLength = !isMaxLength ? (int)f.Value : Int32.MinValue; 283 | 284 | TypeUsage tu; 285 | 286 | if (isUnicode) 287 | { 288 | if (isFixedLength) 289 | tu = TypeUsage.CreateStringTypeUsage(StoreTypeNameToStorePrimitiveType["nchar"], true, true, maxLength); 290 | else 291 | { 292 | if (isMaxLength) 293 | tu = TypeUsage.CreateStringTypeUsage(StoreTypeNameToStorePrimitiveType["nvarchar"], true, false); 294 | else 295 | tu = TypeUsage.CreateStringTypeUsage(StoreTypeNameToStorePrimitiveType["nvarchar"], true, false, maxLength); 296 | } 297 | } 298 | else 299 | { 300 | if (isFixedLength) 301 | tu = TypeUsage.CreateStringTypeUsage(StoreTypeNameToStorePrimitiveType["char"], false, true, maxLength); 302 | else 303 | { 304 | if (isMaxLength) 305 | tu = TypeUsage.CreateStringTypeUsage(StoreTypeNameToStorePrimitiveType["varchar"], false, false); 306 | else 307 | tu = TypeUsage.CreateStringTypeUsage(StoreTypeNameToStorePrimitiveType["varchar"], false, false, maxLength); 308 | } 309 | } 310 | return tu; 311 | } 312 | case PrimitiveTypeKind.DateTime: // datetime, smalldatetime 313 | return TypeUsage.CreateDefaultTypeUsage(StoreTypeNameToStorePrimitiveType["datetime"]); 314 | default: 315 | throw new NotSupportedException(String.Format("There is no store type corresponding to the EDM type '{0}' of primitive type '{1}'.", edmType, primitiveType.PrimitiveTypeKind)); 316 | } 317 | } 318 | 319 | private static class TypeHelpers 320 | { 321 | public static bool TryGetPrecision(TypeUsage tu, out byte precision) 322 | { 323 | Facet f; 324 | 325 | precision = 0; 326 | if (tu.Facets.TryGetValue("Precision", false, out f)) 327 | { 328 | if (!f.IsUnbounded && f.Value != null) 329 | { 330 | precision = (byte)f.Value; 331 | return true; 332 | } 333 | } 334 | return false; 335 | } 336 | 337 | public static bool TryGetMaxLength(TypeUsage tu, out int maxLength) 338 | { 339 | Facet f; 340 | 341 | maxLength = 0; 342 | if (tu.Facets.TryGetValue("MaxLength", false, out f)) 343 | { 344 | if (!f.IsUnbounded && f.Value != null) 345 | { 346 | maxLength = (int)f.Value; 347 | return true; 348 | } 349 | } 350 | return false; 351 | } 352 | 353 | public static bool TryGetScale(TypeUsage tu, out byte scale) 354 | { 355 | Facet f; 356 | 357 | scale = 0; 358 | if (tu.Facets.TryGetValue("Scale", false, out f)) 359 | { 360 | if (!f.IsUnbounded && f.Value != null) 361 | { 362 | scale = (byte)f.Value; 363 | return true; 364 | } 365 | } 366 | return false; 367 | } 368 | } 369 | } 370 | } -------------------------------------------------------------------------------- /src/SharpHsql.Linq/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/hsqltest/App.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArsenShnurkov/SharpHSQL/a3340b985ced363e01855106517422345cacfa36/src/hsqltest/App.ico -------------------------------------------------------------------------------- /src/hsqltest/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | // 9 | [assembly: AssemblyTitle("")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("")] 14 | [assembly: AssemblyCopyright("")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Revision and Build Numbers 27 | // by using the '*' as shown below: 28 | 29 | [assembly: AssemblyVersion("1.0.*")] 30 | 31 | // 32 | // In order to sign your assembly you must specify a key to use. Refer to the 33 | // Microsoft .NET Framework documentation for more information on assembly signing. 34 | // 35 | // Use the attributes below to control which key is used for signing. 36 | // 37 | // Notes: 38 | // (*) If no key is specified, the assembly is not signed. 39 | // (*) KeyName refers to a key that has been installed in the Crypto Service 40 | // Provider (CSP) on your machine. KeyFile refers to a file which contains 41 | // a key. 42 | // (*) If the KeyFile and the KeyName values are both specified, the 43 | // following processing occurs: 44 | // (1) If the KeyName can be found in the CSP, that key is used. 45 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 46 | // in the KeyFile is installed into the CSP and used. 47 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. 48 | // When specifying the KeyFile, the location of the KeyFile should be 49 | // relative to the project output directory which is 50 | // %Project Directory%\obj\. For example, if your KeyFile is 51 | // located in the project directory, you would specify the AssemblyKeyFile 52 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] 53 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 54 | // documentation for more information on this. 55 | // 56 | [assembly: AssemblyDelaySign(false)] 57 | [assembly: AssemblyKeyFile("")] 58 | [assembly: AssemblyKeyName("")] 59 | -------------------------------------------------------------------------------- /src/hsqltest/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using SharpHsql; 3 | 4 | namespace Sample 5 | { 6 | /// 7 | /// Summary description for Class1. 8 | /// 9 | class Class1 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main(string[] args) 16 | { 17 | // Create an in memory database by creating with the name "." 18 | // This has no logging or other disk access 19 | //Database db = new Database("."); 20 | Database db = new Database("mydb"); 21 | // The "sa" user is created by default with no password, so we can connect 22 | // using this user 23 | Channel myChannel = db.Connect("sa",""); 24 | //All queries return a Result object 25 | Result rs; 26 | // We need a string to enter our queries 27 | string query = ""; 28 | 29 | // While the query is not the quit command 30 | while (!query.ToLower().Equals("quit")) 31 | { 32 | // Write a little prompt out to the console 33 | Console.Write("SQL> "); 34 | // Read a line of text 35 | query = Console.ReadLine(); 36 | // Is it our quit command? 37 | if (!query.ToLower().Equals("quit")) 38 | { 39 | // No, execute it using our Channel object 40 | rs = db.Execute(query,myChannel); 41 | // If there was an error 42 | if (rs.Error != null) 43 | { 44 | // Print the error message out to the console 45 | Console.WriteLine(rs.Error); 46 | } 47 | else 48 | { 49 | // Write out some statistics 50 | Console.Write(rs.Size + " rows returned, " + rs.UpdateCount + " rows affected.\n\n"); 51 | // If we had records returned 52 | if (rs.Root != null) 53 | { 54 | // Get the first one 55 | Record r = rs.Root; 56 | // Get the column count from the Result Object 57 | int column_count = rs.ColumnCount; 58 | for (int x = 0; x < column_count;x++) 59 | { 60 | // Print out the column names 61 | Console.Write(rs.Label[x]); 62 | Console.Write("\t"); 63 | } 64 | Console.Write("\n"); 65 | while (r != null) 66 | { 67 | for (int x = 0; x < column_count;x++) 68 | { 69 | // Write out the data values 70 | Console.Write(r.Data[x]); 71 | Console.Write("\t"); 72 | } 73 | Console.Write("\n"); 74 | // Get the next Record object 75 | r = r.Next; 76 | } 77 | Console.Write("\n"); 78 | } 79 | } 80 | } 81 | /*else 82 | { 83 | //System.Diagnostics.Debugger.Launch(); 84 | rs = db.execute("shutdown",myChannel); 85 | // If there was an error 86 | if (rs.Error != null) 87 | { 88 | // Print the error message out to the console 89 | Console.WriteLine(rs.Error); 90 | Console.WriteLine("Press [ENTER] to exit."); 91 | Console.ReadLine(); 92 | } 93 | 94 | }*/ 95 | } 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/hsqltest/hsqltest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Local 5 | {264A06D6-76FB-4652-8619-9B651DF182D5} 6 | Debug 7 | AnyCPU 8 | App.ico 9 | 10 | 11 | Sample 12 | JScript 13 | Grid 14 | IE50 15 | false 16 | Exe 17 | Sample 18 | OnBuildSuccess 19 | 20 | 21 | 0.0 22 | 23 | 24 | SAK 25 | SAK 26 | SAK 27 | SAK 28 | http://localhost/Sample/ 29 | true 30 | Web 31 | true 32 | Foreground 33 | 7 34 | Days 35 | false 36 | false 37 | true 38 | 0 39 | 1.0.0.%2a 40 | true 41 | false 42 | true 43 | v4.5 44 | 45 | 46 | bin\Debug\ 47 | 285212672 48 | 49 | 50 | DEBUG;TRACE 51 | true 52 | 4096 53 | false 54 | false 55 | false 56 | 4 57 | full 58 | prompt 59 | 60 | 61 | bin\Release\ 62 | 285212672 63 | 64 | 65 | TRACE 66 | 4096 67 | true 68 | false 69 | false 70 | 4 71 | none 72 | prompt 73 | 74 | 75 | 76 | System 77 | 78 | 79 | System.Data 80 | 81 | 82 | System.XML 83 | 84 | 85 | SharpHsql 86 | {B98F7374-FF00-4BB7-93EC-39763A76BFFF} 87 | 88 | 89 | 90 | 91 | 92 | Code 93 | 94 | 95 | Code 96 | 97 | 98 | 99 | 100 | False 101 | .NET Framework 2.0 %28x86%29 102 | true 103 | 104 | 105 | False 106 | .NET Framework 3.0 %28x86%29 107 | false 108 | 109 | 110 | False 111 | .NET Framework 3.5 112 | false 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /src/hsqltest/hsqltest.csproj.vspscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" 10 | } 11 | -------------------------------------------------------------------------------- /src/pocketSample/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | // 9 | [assembly: AssemblyTitle("")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("")] 14 | [assembly: AssemblyCopyright("")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Revision and Build Numbers 27 | // by using the '*' as shown below: 28 | 29 | [assembly: AssemblyVersion("1.0.*")] 30 | 31 | // 32 | // In order to sign your assembly you must specify a key to use. Refer to the 33 | // Microsoft .NET Framework documentation for more information on assembly signing. 34 | // 35 | // Use the attributes below to control which key is used for signing. 36 | // 37 | // Notes: 38 | // (*) If no key is specified - the assembly cannot be signed. 39 | // (*) KeyName refers to a key that has been installed in the Crypto Service 40 | // Provider (CSP) on your machine. 41 | // (*) If the key file and a key name attributes are both specified, the 42 | // following processing occurs: 43 | // (1) If the KeyName can be found in the CSP - that key is used. 44 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 45 | // in the file is installed into the CSP and used. 46 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 47 | // documentation for more information on this. 48 | // 49 | [assembly: AssemblyDelaySign(false)] 50 | [assembly: AssemblyKeyFile("")] 51 | [assembly: AssemblyKeyName("")] 52 | -------------------------------------------------------------------------------- /src/pocketSample/Form1.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 17, 17 90 | 91 | 92 | False 93 | 94 | 95 | False 96 | 97 | 98 | (Default) 99 | 100 | 101 | False 102 | 103 | 104 | False 105 | 106 | 107 | Form1 108 | 109 | 110 | 8, 8 111 | 112 | 113 | True 114 | 115 | 116 | 80 117 | 118 | 119 | True 120 | 121 | text/microsoft-resx2.0System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 122 | -------------------------------------------------------------------------------- /src/pocketSample/form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Collections; 4 | using System.Windows.Forms; 5 | using System.Data; 6 | using System.Data.Hsql; 7 | 8 | namespace pocketSample 9 | { 10 | /// 11 | /// Summary description for Form1. 12 | /// 13 | public class Form1 : System.Windows.Forms.Form 14 | { 15 | private System.Windows.Forms.TextBox txtResult; 16 | private System.Windows.Forms.MenuItem menuItem1; 17 | private System.Windows.Forms.MenuItem menuItem2; 18 | private System.Windows.Forms.MenuItem menuItem3; 19 | private System.Windows.Forms.MainMenu mainMenu1; 20 | 21 | public Form1() 22 | { 23 | // 24 | // Required for Windows Form Designer support 25 | // 26 | InitializeComponent(); 27 | 28 | // 29 | // TODO: Add any constructor code after InitializeComponent call 30 | // 31 | } 32 | /// 33 | /// Clean up any resources being used. 34 | /// 35 | protected override void Dispose( bool disposing ) 36 | { 37 | base.Dispose( disposing ); 38 | } 39 | #region Windows Form Designer generated code 40 | /// 41 | /// Required method for Designer support - do not modify 42 | /// the contents of this method with the code editor. 43 | /// 44 | private void InitializeComponent() 45 | { 46 | this.mainMenu1 = new System.Windows.Forms.MainMenu(); 47 | this.menuItem1 = new System.Windows.Forms.MenuItem(); 48 | this.txtResult = new System.Windows.Forms.TextBox(); 49 | this.menuItem2 = new System.Windows.Forms.MenuItem(); 50 | this.menuItem3 = new System.Windows.Forms.MenuItem(); 51 | // 52 | // mainMenu1 53 | // 54 | this.mainMenu1.MenuItems.Add(this.menuItem1); 55 | // 56 | // menuItem1 57 | // 58 | this.menuItem1.MenuItems.Add(this.menuItem2); 59 | this.menuItem1.MenuItems.Add(this.menuItem3); 60 | this.menuItem1.Text = "Test"; 61 | // 62 | // txtResult 63 | // 64 | this.txtResult.Multiline = true; 65 | this.txtResult.ReadOnly = true; 66 | this.txtResult.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; 67 | this.txtResult.Size = new System.Drawing.Size(240, 272); 68 | this.txtResult.Text = ""; 69 | this.txtResult.WordWrap = false; 70 | // 71 | // menuItem2 72 | // 73 | this.menuItem2.Text = "Start"; 74 | this.menuItem2.Click += new System.EventHandler(this.menuItemStart_Click); 75 | // 76 | // menuItem3 77 | // 78 | this.menuItem3.Text = "Exit"; 79 | this.menuItem3.Click += new System.EventHandler(this.menuItemExit_Click); 80 | // 81 | // Form1 82 | // 83 | this.Controls.Add(this.txtResult); 84 | this.Menu = this.mainMenu1; 85 | this.Text = "PocketSharpHSQL"; 86 | 87 | } 88 | #endregion 89 | 90 | /// 91 | /// The main entry point for the application. 92 | /// 93 | 94 | static void Main() 95 | { 96 | Application.Run(new Form1()); 97 | } 98 | 99 | private void DoTest() 100 | { 101 | try 102 | { 103 | txtResult.Text = "Test started..."; 104 | 105 | //System.Diagnostics.Debugger.Launch(); 106 | 107 | SharpHsqlConnection conn = new SharpHsqlConnection("Initial Catalog=\\program files\\pocketSample\\mytest;User Id=sa;Pwd=;"); 108 | conn.Open(); 109 | 110 | SharpHsqlTransaction tran = conn.BeginTransaction(); 111 | 112 | SharpHsqlCommand cmd = new SharpHsqlCommand("", conn); 113 | 114 | int res; 115 | 116 | if( MessageBox.Show( "Drop & create 'clients' table?", "Drop Table", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2 ) == DialogResult.Yes ) 117 | { 118 | 119 | txtResult.Text += "\r\nDropping clients table..."; 120 | 121 | cmd.CommandText = "DROP TABLE IF EXIST \"clients\";CREATE CACHED TABLE \"clients\" (\"id\" int NOT NULL IDENTITY PRIMARY KEY, \"DoubleValue\" double, \"nombre\" char);"; 122 | res = cmd.ExecuteNonQuery(); 123 | 124 | for(int i=0;i<10;i++) 125 | { 126 | cmd.CommandText = "INSERT INTO \"clients\" (\"DoubleValue\", \"nombre\") VALUES (1.1, 'NOMBRE" + i.ToString() + "');"; 127 | res = cmd.ExecuteNonQuery(); 128 | cmd.CommandText = "CALL IDENTITY();"; 129 | int id = (int)cmd.ExecuteScalar(); 130 | txtResult.Text += String.Format("\r\nInserted id={0}", id ); 131 | } 132 | } 133 | 134 | if( MessageBox.Show( "Bulk INSERT 'clients' table?", "Insert Table", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2 ) == DialogResult.Yes ) 135 | { 136 | 137 | txtResult.Text += "\r\nBulk Insert clients table..."; 138 | 139 | for(int i=0;i<1000;i++) 140 | { 141 | cmd.CommandText = "INSERT INTO \"clients\" (\"DoubleValue\", \"nombre\") VALUES (1.1, 'NOMBRE" + i.ToString() + "');"; 142 | res = cmd.ExecuteNonQuery(); 143 | } 144 | 145 | txtResult.Text += "\r\nInserted 1000 rows."; 146 | } 147 | 148 | txtResult.Text += "\r\nSelecting rows..."; 149 | 150 | cmd.CommandText = "SELECT \"clients\".\"id\", \"clients\".\"DoubleValue\", \"clients\".\"nombre\" FROM \"clients\""; 151 | IDataReader reader = cmd.ExecuteReader(); 152 | 153 | string row = ""; 154 | int count = 0; 155 | 156 | while( reader.Read() ) 157 | { 158 | count++; 159 | row = String.Format("id={0}, doubleValue={1}, nombre={2}", reader.GetInt32(0), reader.GetDouble(1), reader.GetString(2) ); 160 | } 161 | 162 | txtResult.Text += String.Format("\r\nSelected {0} rows.", count); 163 | txtResult.Text += String.Format("\r\nLast row: \r\n{0}", row); 164 | 165 | reader.Close(); 166 | 167 | tran.Commit(); 168 | //tran.Rollback(); 169 | 170 | cmd.CommandText = "DELETE FROM \"clients\" WHERE \"clients\".\"id\" = 5;"; 171 | res = cmd.ExecuteNonQuery(); 172 | 173 | cmd.CommandText = "SELECT MAX(\"clients\".\"id\") FROM \"clients\";"; 174 | res = (int)cmd.ExecuteScalar(); 175 | txtResult.Text += "\r\nMAX=" + res; 176 | 177 | cmd.CommandText = "SELECT SUM(\"clients\".\"id\") FROM \"clients\";"; 178 | res = (int)cmd.ExecuteScalar(); 179 | txtResult.Text += "\r\nSUM=" + res; 180 | 181 | cmd.CommandText = "SELECT COUNT(\"clients\".\"id\") FROM \"clients\";"; 182 | res = (int)cmd.ExecuteScalar(); 183 | txtResult.Text += "\r\nCOUNT=" + res; 184 | 185 | cmd.CommandText = "SELECT AVG(\"clients\".\"id\") FROM \"clients\";"; 186 | res = (int)cmd.ExecuteScalar(); 187 | txtResult.Text += "\r\nAVG=" + res; 188 | 189 | cmd.CommandText = "CALL ABS(-33.5632);"; 190 | Double abs = (Double)cmd.ExecuteScalar(); 191 | txtResult.Text += "\r\nABS=" + abs; 192 | 193 | cmd.CommandText = "CREATE ALIAS CALCRATE FOR \"ExternalFunction,ExternalFunction.Simple.calcrate\";"; 194 | res = cmd.ExecuteNonQuery(); 195 | 196 | cmd.CommandText = "CREATE ALIAS EXTTAN FOR \"ExternalFunction,ExternalFunction.Simple.tan\";"; 197 | res = cmd.ExecuteNonQuery(); 198 | 199 | cmd.CommandText = "CALL CALCRATE(100, 21);"; 200 | Decimal rate = (Decimal)cmd.ExecuteScalar(); 201 | txtResult.Text += "\r\nCALCRATE=" + rate; 202 | 203 | cmd.CommandText = "CALL EXTTAN(23.456);"; 204 | Double tan = (Double)cmd.ExecuteScalar(); 205 | txtResult.Text += "\r\nEXTTAN=" + tan; 206 | 207 | cmd.CommandText = "CALL SQRT(3);"; 208 | Double sqrt = (Double)cmd.ExecuteScalar(); 209 | txtResult.Text += "\r\nSQRT=" + sqrt; 210 | 211 | cmd.CommandText = "CALL SUBSTRING('0123456', 3, 2);"; 212 | string subs = (String)cmd.ExecuteScalar(); 213 | txtResult.Text += "\r\nSUBSTRING=" + subs; 214 | 215 | cmd.CommandText = "CALL ASCII('A');"; 216 | int ascii = (int)cmd.ExecuteScalar(); 217 | txtResult.Text += "\r\nASCII=" + ascii; 218 | 219 | cmd.CommandText = "CALL USER();"; 220 | string user = (string)cmd.ExecuteScalar(); 221 | txtResult.Text += "\r\nUSER=" + user; 222 | 223 | cmd.CommandText = "SELECT \"clients\".\"id\", \"clients\".\"DoubleValue\", \"clients\".\"nombre\" FROM \"clients\" WHERE \"clients\".\"id\" = 5;"; 224 | 225 | SharpHsqlDataAdapter adapter = new SharpHsqlDataAdapter(cmd); 226 | DataSet ds = new DataSet(); 227 | res = adapter.Fill( ds ); 228 | adapter = null; 229 | 230 | txtResult.Text += "\r\nDataSet.Fill: " + ds.Tables[0].Rows.Count; 231 | 232 | conn.Close(); 233 | conn = null; 234 | } 235 | catch( SharpHsqlException ex ) 236 | { 237 | txtResult.Text += "\r\nERROR: " + ex.Message; 238 | } 239 | catch( Exception ex ) 240 | { 241 | txtResult.Text += "\r\nERROR: " + ex.Message; 242 | } 243 | } 244 | 245 | private void menuItemStart_Click(object sender, System.EventArgs e) 246 | { 247 | DoTest(); 248 | } 249 | 250 | private void menuItemExit_Click(object sender, System.EventArgs e) 251 | { 252 | this.Close(); 253 | } 254 | } 255 | } 256 | -------------------------------------------------------------------------------- /src/pocketSample/pocketSample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Local 5 | {4B25AF47-5ADA-43C8-A96B-5F5F7A8410C4} 6 | Debug 7 | AnyCPU 8 | {4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 9 | 10 | 11 | 12 | 13 | pocketSample 14 | 15 | 16 | false 17 | WinExe 18 | \Program Files\pocketSample 19 | pocketSample 20 | 21 | 22 | 23 | 24 | 4.20 25 | 0.0 26 | Pocket PC 2003 27 | 28 | 29 | 30 | 31 | SAK 32 | SAK 33 | SAK 34 | SAK 35 | 36 | 37 | 3C41C503-53EF-4c2a-8DD4-A8217CAD115E 38 | PocketPC 39 | $(AssemblyName) 40 | v2.0 41 | 42 | 43 | bin\Debug\ 44 | false 45 | 0 46 | false 47 | 48 | 49 | DEBUG;TRACE 50 | 51 | 52 | true 53 | 4096 54 | false 55 | false 56 | false 57 | false 58 | 4 59 | full 60 | true 61 | true 62 | off 63 | 64 | 65 | bin\Release\ 66 | false 67 | 0 68 | false 69 | 70 | 71 | TRACE 72 | 73 | 74 | 4096 75 | true 76 | false 77 | false 78 | false 79 | 4 80 | none 81 | true 82 | true 83 | off 84 | 85 | 86 | 87 | MSCorLib 88 | False 89 | 90 | 91 | System 92 | False 93 | 94 | 95 | System.Data 96 | False 97 | 98 | 99 | System.Data.Common 100 | 101 | 102 | System.Drawing 103 | False 104 | 105 | 106 | System.Windows.Forms 107 | False 108 | 109 | 110 | System.XML 111 | False 112 | 113 | 114 | ExternalFunction 115 | {7E430EE6-B587-428A-9FB9-C1269A3FE4FD} 116 | {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 117 | 118 | 119 | PocketSharpHsql 120 | {B1247008-F987-4C90-9EA1-A8FA1EDA3799} 121 | {20D4826A-C6FA-45DB-90F4-C717570B9F32} 122 | 123 | 124 | 125 | 126 | Code 127 | 128 | 129 | form1.cs 130 | 131 | 132 | Form 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /src/pocketSample/pocketSample.csproj.vspscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" 10 | } 11 | --------------------------------------------------------------------------------