Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ Desktop.ini
docs/Gemfile.lock
docs/.sass-cache/
docs/_site/
_site/
_site/
appsettings.local.json
109 changes: 109 additions & 0 deletions DBScripts/Oracle.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
declare
name_exists_exception exception;
index_exists_exception exception;
column_exists_exception exception;
column_not_exists_exception exception;
pragma exception_init( name_exists_exception, -955 );
pragma exception_init( index_exists_exception, -1408 );
pragma exception_init( column_exists_exception, -1430 );
pragma exception_init( column_not_exists_exception, -904 );
begin
begin
execute immediate 'CREATE TABLE Exceptions(
Id number generated always as Identity(start with 1 increment by 1),
GUID varchar2(36) NOT NULL,
ApplicationName varchar2(50) NOT NULL,
MachineName varchar2(50) NOT NULL,
CreationDate timestamp NOT NULL,
"TYPE" varchar2(100) NOT NULL,
IsProtected number(1) default 0 NOT NULL,
Host varchar2(100) NULL,
Url varchar2(500) NULL,
HTTPMethod varchar2(10) NULL,
IPAddress varchar2(40) NULL,
"SOURCE" varchar2(100) NULL,
Message varchar2(1000) NULL,
Detail Nclob NULL,
StatusCode number NULL,
DeletionDate timestamp NULL,
FullJson Nclob NULL,
ErrorHash number NULL,
DuplicateCount number default 1 NOT NULL,
LastLogDate timestamp NULL,
Category varchar2(100) NULL
)';
exception
when name_exists_exception then
null;
end;

begin
execute immediate('CREATE INDEX IX_Exceptions_One ON Exceptions(GUID, ApplicationName, DeletionDate, CreationDate DESC)');
exception
when index_exists_exception then
null;
when name_exists_exception then
null;
end;

begin
execute immediate('CREATE INDEX IX_Exceptions_Two ON Exceptions(ErrorHash, ApplicationName, CreationDate DESC, DeletionDate)');
exception
when index_exists_exception then
null;
when name_exists_exception then
null;
end;

--Begin V2 Schema changes

begin
execute immediate('ALTER TABLE Exceptions ADD LastLogDate timestamp NULL');
exception
when column_exists_exception then
null;
end;

begin
execute immediate('ALTER TABLE Exceptions ADD Category varchar2(100) NULL');
exception
when column_exists_exception then
null;
end;

begin
execute immediate('ALTER TABLE Exceptions DROP COLUMN SQL');
exception
when column_not_exists_exception then
null;
end;
end;
/

create or replace
function ExceptionsLogUpdate(p_DuplicateCount in number,
p_CreationDate in timestamp,
p_ErrorHash in number,
p_ApplicationName in varchar2,
p_MinDate in timestamp)
return varchar2 is
pragma autonomous_transaction;
begin
declare
v_guid varchar2(36);
begin

update Exceptions
set DuplicateCount = DuplicateCount + p_DuplicateCount,
LastLogDate = (Case When LastLogDate Is Null Or p_CreationDate > LastLogDate Then p_CreationDate Else LastLogDate End)
where ErrorHash = p_ErrorHash
and ApplicationName = p_ApplicationName
and DeletionDate Is Null
and CreationDate >= p_MinDate
and rownum = 1
returning GUID into v_guid;
commit;

return v_guid;
end;
end;
10 changes: 9 additions & 1 deletion StackExchange.Exceptional.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DBScripts", "DBScripts", "{7669A017-BBDA-45B0-89B1-A9E0F2FD0BF8}"
ProjectSection(SolutionItems) = preProject
DBScripts\MySQL.sql = DBScripts\MySQL.sql
DBScripts\Oracle.sql = DBScripts\Oracle.sql
DBScripts\PostgreSql.sql = DBScripts\PostgreSql.sql
DBScripts\SqlServer.sql = DBScripts\SqlServer.sql
EndProjectSection
Expand All @@ -56,7 +57,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackExchange.Exceptional.P
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackExchange.Exceptional.MongoDB", "src\StackExchange.Exceptional.MongoDB\StackExchange.Exceptional.MongoDB.csproj", "{8CFA59A5-5180-4466-A32E-507F3D541163}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.ConsoleNetCore", "samples\Samples.ConsoleNetCore\Samples.ConsoleNetCore.csproj", "{6CE269E1-6DC9-43A4-B6B8-683CE8A19E6A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.ConsoleNetCore", "samples\Samples.ConsoleNetCore\Samples.ConsoleNetCore.csproj", "{6CE269E1-6DC9-43A4-B6B8-683CE8A19E6A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackExchange.Exceptional.Oracle", "src\StackExchange.Exceptional.Oracle\StackExchange.Exceptional.Oracle.csproj", "{A51A932D-67DB-4A1C-89D2-886DE2258E58}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -112,6 +115,10 @@ Global
{6CE269E1-6DC9-43A4-B6B8-683CE8A19E6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CE269E1-6DC9-43A4-B6B8-683CE8A19E6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CE269E1-6DC9-43A4-B6B8-683CE8A19E6A}.Release|Any CPU.Build.0 = Release|Any CPU
{A51A932D-67DB-4A1C-89D2-886DE2258E58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A51A932D-67DB-4A1C-89D2-886DE2258E58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A51A932D-67DB-4A1C-89D2-886DE2258E58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A51A932D-67DB-4A1C-89D2-886DE2258E58}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -129,6 +136,7 @@ Global
{0A412433-C2CE-4EBE-BB5A-C3E48983E941} = {8B91532F-A112-4F73-80BD-A95B7359BBC3}
{8CFA59A5-5180-4466-A32E-507F3D541163} = {8B91532F-A112-4F73-80BD-A95B7359BBC3}
{6CE269E1-6DC9-43A4-B6B8-683CE8A19E6A} = {001E5AA4-42C8-4AC3-B14A-AF1DFA02E9FB}
{A51A932D-67DB-4A1C-89D2-886DE2258E58} = {8B91532F-A112-4F73-80BD-A95B7359BBC3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7F066A86-14D8-4A2C-848A-D4371BB704FA}
Expand Down
62 changes: 62 additions & 0 deletions src/StackExchange.Exceptional.Oracle/OracleClobParameter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;

namespace StackExchange.Exceptional.Stores
{
/// <summary>
/// Needed because long strings can not be passed.
/// </summary>
/// <remarks>
/// https://github.com/StackExchange/Dapper/issues/142
/// </remarks>
internal class OracleClobParameter : SqlMapper.ICustomQueryParameter
{
private readonly string value;

public OracleClobParameter(string value)
{
this.value = value;
}

public void AddParameter(IDbCommand command, string name)
{
// accesing the connection in open state.
var connection = command.Connection as OracleConnection;

connection.StateChange += (object sender, StateChangeEventArgs e) =>
{
if (e.CurrentState != ConnectionState.Open)
return;

var clob = new OracleClob(connection);

// It should be Unicode oracle throws an exception when
// the length is not even.
var bytes = System.Text.Encoding.Unicode.GetBytes(value);
var length = System.Text.Encoding.Unicode.GetByteCount(value);

int pos = 0;
int chunkSize = 1024; // Oracle does not allow large chunks.

while (pos < length)
{
chunkSize = chunkSize > (length - pos) ? chunkSize = length - pos : chunkSize;
clob.Write(bytes, pos, chunkSize);
pos += chunkSize;
}

var param = new OracleParameter(name, OracleDbType.Clob);
param.Value = clob;

command.Parameters.Add(param);
};
}
}
}
Loading