protected void Application_BeginRequest(object sender, EventArgs e) { if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS") { Response.Flush(); Response.End(); } else { string sessionId = Request.Headers.Get("sessionId"); if (!string.IsNullOrEmpty(sessionId)) { if (!HttpContext.Current.Application.AllKeys.Contains(sessionId)) { MsSqlUtility msSqlUtility = new MsSqlUtility(); HttpContext.Current.Application.Add(sessionId, msSqlUtility); } } else { //TODO: Create new session Id instead of throwing error. throw new Exception("Invalid Session Id"); } } }
public object GetTables() { MsSqlUtility msSqlUtility = (MsSqlUtility)HttpContext.Current.Application[HttpContext.Current.Request.Headers["sessionId"]]; LoadTestData(msSqlUtility); return(msSqlUtility.GetAllTableSchema()); }
public void InterpretSqlExceptionUserMessage() { var msSqlUtility = new MsSqlUtility(); var interpretedException = msSqlUtility.InterpretSqlException( NewSqlException("test message", 50000, 16, 101)); // State 101 is Rhetos convention for user error message. Assert.AreEqual("UserException: test message", interpretedException.GetType().Name + ": " + interpretedException.Message); }
private void SetContextInfo(DbCommand sqlCommand) { if (_userInfo.IsUserRecognized) { sqlCommand.CommandText = MsSqlUtility.SetUserContextInfoQuery(_userInfo); sqlCommand.ExecuteNonQuery(); } }
private void SetContextInfo(DbConnection connection, DbTransaction transaction) { if (_userInfo.IsUserRecognized) { var sqlCommand = MsSqlUtility.SetUserContextInfoQuery(_userInfo); sqlCommand.Connection = connection; sqlCommand.Transaction = transaction; sqlCommand.ExecuteNonQuery(); } }
private byte[] GetOrmHash() { var hashes = new[] { _cache.LoadHash(Paths.GetDomAssemblyFile(DomAssemblies.Model)), _cache.LoadHash(Paths.GetDomAssemblyFile(DomAssemblies.Orm)), // TODO: Add DatabaseGenerator hash for new created ConceptApplications. _cache.GetHash(MsSqlUtility.GetProviderManifestToken()) }; return(_cache.JoinHashes(hashes)); }
private void TestInterpretedException(ListOfTuples <Exception, string> tests) { var msSqlUtility = new MsSqlUtility(); foreach (var test in tests) { string reportInput = "Input: " + (test.Item1 != null ? test.Item1.ToString() : "null"); Console.WriteLine(reportInput); var interpretedException = msSqlUtility.InterpretSqlException(test.Item1); Console.WriteLine("Output: " + (interpretedException != null ? interpretedException.ToString() : "null")); Assert.AreEqual(test.Item2, Report(interpretedException), reportInput); } }
public void MsSqlUtilityUnitTest_SelectFromSingleTable() { using (MsSqlUtility utility = new MsSqlUtility()) { try { utility.AddTableSchema(@"..\..\Data\DimProduct.xml"); utility.GenerateQuery("{\"QueryType\":\"Select\",\"QueryName\":\"SimpleSelectQueryWithSingleTable\",\"QueryData\":[{\"TableName\":\"DimProduct\",\"ColumnList\":[{\"ColumnName\":\"ProductKey\",\"Alias\":\"Product Key\"},{\"ColumnName\":\"ProductAlternateKey\",\"Alias\":\"Product Alternate Key\"},{\"ColumnName\":\"SafetyStockLevel\"},{\"ColumnName\":\"EnglishProductName\",\"Alias\":\"Product Name\"}],\"TableClause\":[]}],\"QueryClause\":[]}"); } catch (Exception) { throw; } } }
public void MsSqlUtilityUnitTest_SelectFromMultiTable() { using (MsSqlUtility utility = new MsSqlUtility()) { try { utility.AddTableSchema(@"..\..\Data\DimProduct.xml"); utility.AddTableSchema(@"..\..\Data\DimProductSubcategory.xml"); utility.GenerateQuery("{\"QueryType\":\"Select\",\"QueryName\":\"SimpleSelectQueryWithSingleTable\",\"QueryData\":[{\"TableName\":\"DimProduct\",\"ColumnList\":[{\"ColumnName\":\"ProductKey\",\"Alias\":\"Product Key\",\"BelongsToTable\":\"DimProduct\"},{\"ColumnName\":\"EnglishProductName\",\"Alias\":\"Product Name\",\"BelongsToTable\":\"DimProduct\"},{\"ColumnName\":\"EnglishProductSubcategoryName\",\"Alias\":\"Product Subcategory Name\",\"BelongsToTable\":\"DimProductSubcategory\"}],\"TableClause\":[{\"ClauseType\":\"JOIN\",\"ClauseValue\":\"DimProduct.ProductSubcategoryKey = DimProductSubcategory.ProductSubcategoryKey\",\"JoinType\":\"Inner\",\"JoinTableName\":\"DimProductSubcategory\"}]}],\"QueryClause\":[]}"); } catch (Exception) { throw; } } }
/// <param name="saveException">SqlException, or an exception that has SqlException as an inner exception (directly or indirectly).</param> public static void ThrowInterpretedException(bool checkUserPermissions, Exception saveException, RhetosException interpretedException, ISqlUtility sqlUtility, string tableName) { if (checkUserPermissions) { MsSqlUtility.ThrowIfPrimaryKeyErrorOnInsert(interpretedException, tableName); } if (interpretedException != null) { ExceptionsUtility.Rethrow(interpretedException); } var sqlException = sqlUtility.ExtractSqlException(saveException); if (sqlException != null) { ExceptionsUtility.Rethrow(sqlException); } ExceptionsUtility.Rethrow(saveException); }
public void GetDatabaseTimeTest() { // More detailed tests are implemented in the DatabaseTimeCacheTest class. // This is only a smoke test for SqlUtility. var sqlExecuter = new MockSqlExecuter(); Enumerable.Range(0, 4).Select(x => SqlUtility.GetDatabaseTime(sqlExecuter)); // Caching initialization. var notCachedDatabaseTime = MsSqlUtility.GetDatabaseTime(sqlExecuter); var cachedTime = SqlUtility.GetDatabaseTime(sqlExecuter); Console.WriteLine(notCachedDatabaseTime.ToString("o")); Console.WriteLine(cachedTime.ToString("o")); Assert.IsTrue(notCachedDatabaseTime - cachedTime <= TimeSpan.FromSeconds(0.01)); Assert.IsTrue(cachedTime - notCachedDatabaseTime <= TimeSpan.FromSeconds(0.01)); }
public void MsSqlGetSchemaName() { Assert.AreEqual("someschema", MsSqlUtility.GetSchemaName("someschema.someview")); Assert.AreEqual("dbo", MsSqlUtility.GetSchemaName("someview")); }
public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { codeBuilder.InsertCode( $@"<Schema Namespace=""{EntityFrameworkMapping.ConceptualModelNamespace}"" Alias=""Self"" annotation:UseStrongSpatialTypes=""false"" xmlns:annotation=""http://schemas.microsoft.com/ado/2009/02/edm/annotation"" xmlns:customannotation=""http://schemas.microsoft.com/ado/2013/11/edm/customannotation"" xmlns=""http://schemas.microsoft.com/ado/2009/11/edm""> {EntityFrameworkMapping.ConceptualModelTag} <EntityContainer Name=""EntityFrameworkContext"" customannotation:UseClrTypes=""true""> {EntityFrameworkMapping.ConceptualModelEntityContainerTag} </EntityContainer> </Schema> {_segmentSplitter} <Mapping Space=""C-S"" xmlns=""http://schemas.microsoft.com/ado/2009/11/mapping/cs""> {EntityFrameworkMapping.MappingTag} <EntityContainerMapping StorageEntityContainer=""CodeFirstDatabase"" CdmEntityContainer=""EntityFrameworkContext""> {EntityFrameworkMapping.MappingEntityContainerTag} </EntityContainerMapping> </Mapping> {_segmentSplitter} <Schema Namespace=""{EntityFrameworkMapping.StorageModelNamespace}"" Provider=""System.Data.SqlClient"" ProviderManifestToken=""{MsSqlUtility.GetProviderManifestToken()}"" Alias=""Self"" xmlns:customannotation=""http://schemas.microsoft.com/ado/2013/11/edm/customannotation"" xmlns=""http://schemas.microsoft.com/ado/2009/11/edm/ssdl""> {EntityFrameworkMapping.StorageModelTag} <EntityContainer Name=""CodeFirstDatabase""> {EntityFrameworkMapping.StorageModelEntityContainerTag} </EntityContainer> </Schema>"); }
private void LoadTestData(MsSqlUtility msSqlUtility) { msSqlUtility.RemoveAllTableSchema(); msSqlUtility.AddTableSchema("<xsd:schema xmlns:schema=\"urn: schemas - microsoft - com:sql: SqlRowSet4\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:sqltypes=\"http://schemas.microsoft.com/sqlserver/2004/sqltypes\" targetNamespace=\"urn:schemas-microsoft-com:sql:SqlRowSet4\" elementFormDefault=\"qualified\"><xsd:import namespace=\"http://schemas.microsoft.com/sqlserver/2004/sqltypes\" schemaLocation=\"http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd\" /><xsd:element name=\"AdventureWorksDW2012.dbo.DimProduct\"><xsd:complexType><xsd:attribute name=\"ProductKey\" type=\"sqltypes:int\" use=\"required\" /><xsd:attribute name=\"ProductAlternateKey\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"25\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"ProductSubcategoryKey\" type=\"sqltypes:int\" /><xsd:attribute name=\"WeightUnitMeasureCode\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"3\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"SizeUnitMeasureCode\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"3\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"EnglishProductName\" use=\"required\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"50\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"SpanishProductName\" use=\"required\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"50\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"FrenchProductName\" use=\"required\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"50\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"StandardCost\" type=\"sqltypes:money\" /><xsd:attribute name=\"FinishedGoodsFlag\" type=\"sqltypes:bit\" use=\"required\" /><xsd:attribute name=\"Color\" use=\"required\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"15\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"SafetyStockLevel\" type=\"sqltypes:smallint\" /><xsd:attribute name=\"ReorderPoint\" type=\"sqltypes:smallint\" /><xsd:attribute name=\"ListPrice\" type=\"sqltypes:money\" /><xsd:attribute name=\"Size\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"50\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"SizeRange\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"50\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"Weight\" type=\"sqltypes:float\" /><xsd:attribute name=\"DaysToManufacture\" type=\"sqltypes:int\" /><xsd:attribute name=\"ProductLine\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"2\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"DealerPrice\" type=\"sqltypes:money\" /><xsd:attribute name=\"Class\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"2\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"Style\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"2\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"ModelName\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"50\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"LargePhoto\" type=\"sqltypes:dbobject\" /><xsd:attribute name=\"EnglishDescription\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"400\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"FrenchDescription\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1036\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\"><xsd:maxLength value=\"400\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"ChineseDescription\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"2052\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreNonSpace IgnoreKanaType IgnoreWidth\"><xsd:maxLength value=\"400\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"ArabicDescription\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1025\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\"><xsd:maxLength value=\"400\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"HebrewDescription\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1037\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\"><xsd:maxLength value=\"400\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"ThaiDescription\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1054\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\"><xsd:maxLength value=\"400\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"GermanDescription\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlCollationVersion=\"2\"><xsd:maxLength value=\"400\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"JapaneseDescription\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1041\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\"><xsd:maxLength value=\"400\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"TurkishDescription\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1055\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\"><xsd:maxLength value=\"400\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"StartDate\" type=\"sqltypes:datetime\" /><xsd:attribute name=\"EndDate\" type=\"sqltypes:datetime\" /><xsd:attribute name=\"Status\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"7\" /></xsd:restriction></xsd:simpleType></xsd:attribute></xsd:complexType></xsd:element></xsd:schema>"); msSqlUtility.AddTableSchema("<xsd:schema xmlns:schema=\"urn:schemas-microsoft-com:sql:SqlRowSet5\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:sqltypes=\"http://schemas.microsoft.com/sqlserver/2004/sqltypes\" targetNamespace=\"urn:schemas-microsoft-com:sql:SqlRowSet5\" elementFormDefault=\"qualified\"><xsd:import namespace=\"http://schemas.microsoft.com/sqlserver/2004/sqltypes\" schemaLocation=\"http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd\" /><xsd:element name=\"AdventureWorksDW2012.dbo.DimProductCategory\"><xsd:complexType><xsd:attribute name=\"ProductCategoryKey\" type=\"sqltypes:int\" use=\"required\" /><xsd:attribute name=\"ProductCategoryAlternateKey\" type=\"sqltypes:int\" /><xsd:attribute name=\"EnglishProductCategoryName\" use=\"required\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"50\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"SpanishProductCategoryName\" use=\"required\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"50\" /></xsd:restriction></xsd:simpleType></xsd:attribute><xsd:attribute name=\"FrenchProductCategoryName\" use=\"required\"><xsd:simpleType><xsd:restriction base=\"sqltypes:nvarchar\" sqltypes:localeId=\"1033\" sqltypes:sqlCompareOptions=\"IgnoreCase IgnoreKanaType IgnoreWidth\" sqltypes:sqlSortId=\"52\"><xsd:maxLength value=\"50\" /></xsd:restriction></xsd:simpleType></xsd:attribute></xsd:complexType></xsd:element></xsd:schema>"); }