static SqlServerTestSuite() { SqlDatabase.CacheQueries = false; ResetDapperTypes(); try { using (var connection = new SqlConnection(ConnectionString)) { connection.Open(); // For paginated queries prior to 2012 sql server uses row_number over var sqlVersion = connection.ServerVersion; if (!string.IsNullOrEmpty(sqlVersion) && sqlVersion.Length > 2) { var mv = int.Parse(sqlVersion.Substring(0, 2)); if (mv < 11) { SqlMapperExtensions.AddSqlAdapter <SqlConnection>(new SqlServerPre2012Adapter()); } } var awfile = File.ReadAllText(".\\Scripts\\sqlserverawlite.sql"); connection.Execute(awfile); connection.Execute("delete from [Person]"); } } catch (SqlException e) { if (e.Message.Contains("The server was not found ") || e.Message.Contains("Cannot open database")) { _skip = true; } else { throw; } } }
static OracleTestSuite() { SqlDatabase.CacheQueries = false; ResetDapperTypes(); SqlMapper.AddTypeHandler <Guid>(new GuidTypeHandler()); try { using (var connection = new OracleConnection(ConnectionString)) { connection.Open(); if (connection.ServerVersion != null && connection.ServerVersion.StartsWith("11.", StringComparison.OrdinalIgnoreCase)) { // We have to override the Oracle adapter with the 11g adapter because: // - The managed Oracle drivers (which are 12.1 and later) have some bugs when run against 11.2, which the 11g adapter works around // - Oracle's "free" edition (XE) never had a 12.x release (latest is still 11.2) SqlMapperExtensions.AddSqlAdapter <OracleConnection>(new Oracle11gAdapter()); } var awfile = File.ReadAllText(".\\Scripts\\oracleawlite.sql"); // Because the Oracle driver does not support multiple statements in a single IDbCommand, we have to manually split the file. // The file is marked with lines with just forward slashes ("/"), which is the way SQL*Plus and other tools recognize the end of a command in such situations, so just use that. // (It also helps the ability to debug the script in SQL*Plus or another tool.) foreach (var command in CommandSeparator.Split(awfile)) { // don't execute blank commands (e.g. last line) if (string.IsNullOrWhiteSpace(command)) { continue; } // don't execute anything starting with a comment indicating use of SQL*Plus if (command.StartsWith("/*SQLPLUS*/", StringComparison.OrdinalIgnoreCase)) { continue; } try { connection.Execute(command); } catch (OracleException e) { var sb = new StringBuilder(); sb.AppendLine(e.Message); sb.AppendLine("For command:"); sb.Append(command); // can't throw new OracleException or DbException... throw new InvalidOperationException(sb.ToString(), e); } } connection.Execute("delete from Person"); } } catch (OracleException e) { // All ORA- errors (12500-12599) are TNS errors indicating connectivity. _skip = e.Message.StartsWith("ORA-125", StringComparison.OrdinalIgnoreCase) || e.Message.Contains("No connection could be made because the target machine actively refused it") || e.Message.Contains("Unable to resolve connect hostname") || e.Message.Contains("Connection request timed out"); } catch (SocketException e) when(e.Message.Contains("No connection could be made because the target machine actively refused it")) { _skip = true; } }