using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Reflection.Emit;
using ICOMARCHeShop.Helpers;
internal sealed class NpgsqlConnection : DbConnection
protected override DbTransaction BeginDbTransaction(System.Data.IsolationLevel isolationLevel)
return BeginTransaction(isolationLevel);
public new NpgsqlTransaction BeginTransaction(IsolationLevel level)
return new NpgsqlTransaction();
public override void ChangeDatabase(string databaseName)
throw new NotImplementedException();
public override void Close()
throw new NotImplementedException();
public override string ConnectionString
throw new NotImplementedException();
throw new NotImplementedException();
protected override DbCommand CreateDbCommand()
throw new NotImplementedException();
public override string DataSource
get { throw new NotImplementedException(); }
public override string Database
get { throw new NotImplementedException(); }
public override void Open()
throw new NotImplementedException();
public override string ServerVersion
get { throw new NotImplementedException(); }
public override System.Data.ConnectionState State
get { throw new NotImplementedException(); }
internal sealed class NpgsqlCommand : DbCommand
public override void Cancel()
throw new NotImplementedException();
public override string CommandText
throw new NotImplementedException();
throw new NotImplementedException();
public override int CommandTimeout
throw new NotImplementedException();
throw new NotImplementedException();
public override CommandType CommandType
throw new NotImplementedException();
throw new NotImplementedException();
protected override DbParameter CreateDbParameter()
throw new NotImplementedException();
protected override DbConnection DbConnection
throw new NotImplementedException();
throw new NotImplementedException();
protected override DbParameterCollection DbParameterCollection
get { throw new NotImplementedException(); }
protected override DbTransaction DbTransaction
throw new NotImplementedException();
throw new NotImplementedException();
public override bool DesignTimeVisible
throw new NotImplementedException();
throw new NotImplementedException();
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
return this.ExecuteReader(behavior);
public new NpgsqlDataReader ExecuteReader(CommandBehavior cb)
return new NpgsqlDataReader();
public override int ExecuteNonQuery()
throw new NotImplementedException();
public override object ExecuteScalar()
throw new NotImplementedException();
public override void Prepare()
throw new NotImplementedException();
public override UpdateRowSource UpdatedRowSource
throw new NotImplementedException();
throw new NotImplementedException();
internal sealed class NpgsqlParameter : DbParameter
public override DbType DbType
throw new NotImplementedException();
throw new NotImplementedException();
public override ParameterDirection Direction
throw new NotImplementedException();
throw new NotImplementedException();
public override bool IsNullable
throw new NotImplementedException();
throw new NotImplementedException();
public override string ParameterName
throw new NotImplementedException();
throw new NotImplementedException();
public override void ResetDbType()
throw new NotImplementedException();
throw new NotImplementedException();
throw new NotImplementedException();
public override string SourceColumn
throw new NotImplementedException();
throw new NotImplementedException();
public override bool SourceColumnNullMapping
throw new NotImplementedException();
throw new NotImplementedException();
public override DataRowVersion SourceVersion
throw new NotImplementedException();
throw new NotImplementedException();
public override object Value
throw new NotImplementedException();
throw new NotImplementedException();
internal sealed class NpgsqlDataReader : DbDataReader
public override void Close()
throw new NotImplementedException();
public override int Depth
get { throw new NotImplementedException(); }
public override int FieldCount
get { throw new NotImplementedException(); }
public override bool GetBoolean(int ordinal)
throw new NotImplementedException();
public override byte GetByte(int ordinal)
throw new NotImplementedException();
public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length)
throw new NotImplementedException();
public override char GetChar(int ordinal)
throw new NotImplementedException();
public override long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length)
throw new NotImplementedException();
public override string GetDataTypeName(int ordinal)
throw new NotImplementedException();
public override DateTime GetDateTime(int ordinal)
throw new NotImplementedException();
public override decimal GetDecimal(int ordinal)
throw new NotImplementedException();
public override double GetDouble(int ordinal)
throw new NotImplementedException();
public override System.Collections.IEnumerator GetEnumerator()
throw new NotImplementedException();
public override Type GetFieldType(int ordinal)
throw new NotImplementedException();
public override float GetFloat(int ordinal)
throw new NotImplementedException();
public override Guid GetGuid(int ordinal)
throw new NotImplementedException();
public override short GetInt16(int ordinal)
throw new NotImplementedException();
public override int GetInt32(int ordinal)
throw new NotImplementedException();
public override long GetInt64(int ordinal)
throw new NotImplementedException();
public override string GetName(int ordinal)
throw new NotImplementedException();
public override int GetOrdinal(string name)
throw new NotImplementedException();
public override DataTable GetSchemaTable()
throw new NotImplementedException();
public override string GetString(int ordinal)
throw new NotImplementedException();
public override object GetValue(int ordinal)
throw new NotImplementedException();
public override int GetValues(object[] values)
throw new NotImplementedException();
public override bool HasRows
get { throw new NotImplementedException(); }
public override bool IsClosed
get { throw new NotImplementedException(); }
public override bool IsDBNull(int ordinal)
throw new NotImplementedException();
public override bool NextResult()
throw new NotImplementedException();
public override bool Read()
throw new NotImplementedException();
public override int RecordsAffected
get { throw new NotImplementedException(); }
public override object this[string name]
get { throw new NotImplementedException(); }
public override object this[int ordinal]
get { throw new NotImplementedException(); }
internal sealed class NpgsqlTransaction : DbTransaction
public override void Commit()
throw new NotImplementedException();
protected override DbConnection DbConnection
get { throw new NotImplementedException(); }
public override IsolationLevel IsolationLevel
get { throw new NotImplementedException(); }
public override void Rollback()
throw new NotImplementedException();
internal abstract class DbConnectionW : IDisposable
internal static int FailuresCount = 0;
public abstract void Dispose();
internal abstract class DbConnectionW<CONN, COMM> : DbConnectionW
where CONN : DbConnection
protected readonly CONN _conn;
internal DbConnectionW(string cs2)
_conn = CreateConnection(cs2);
var skipTypes = new[] { typeof(Nebula.Search.Crawl), typeof(Nebula.PriceComparison.XmlHandler) };
if (System.Linq.Enumerable.All(new System.Diagnostics.StackTrace().GetFrames(), z => !System.Linq.Enumerable.Contains(skipTypes, z.GetMethod().DeclaringType)))
var t = System.Runtime.Remoting.Messaging.CallContext.LogicalGetData(_conn.ConnectionString);
if (t.ToString() == _conn.ConnectionString)
throw new InvalidOperationException("DbConnectionW nested");
System.Runtime.Remoting.Messaging.CallContext.LogicalSetData(_conn.ConnectionString, _conn.ConnectionString);
private void OpenConnectionPv()
Interlocked.Increment(ref FailuresCount);
protected abstract CONN CreateConnection(string cs);
protected abstract void OpenConnection();
internal abstract COMM CreateCommand();
public sealed override void Dispose()
System.Runtime.Remoting.Messaging.CallContext.LogicalSetData(_conn.ConnectionString, null);
internal sealed class MsSqlConnection : DbConnectionW<SqlConnection, SqlCommand>
private static readonly Action<SqlConnection> __DisableReset;
private static readonly Func<SqlConnection, bool> __GetInnerPV;
var tSqlConn = typeof(SqlConnection);
var inner = tSqlConn.GetField("_innerConnection", BindingFlags.Instance | BindingFlags.NonPublic);
var innerFieldReset = Assembly.GetAssembly(tSqlConn).GetType("System.Data.SqlClient.SqlInternalConnectionTds").GetField("_fResetConnection", BindingFlags.Instance | BindingFlags.NonPublic);
var dynM = new DynamicMethod(string.Empty, typeof(void), new Type[] { typeof(SqlConnection) }, typeof(SqlConnection).Module, true);
var ilGen = dynM.GetILGenerator();
ilGen.Emit(OpCodes.Ldarg_0);
ilGen.Emit(OpCodes.Ldfld, inner);
ilGen.Emit(OpCodes.Ldc_I4_0);
ilGen.Emit(OpCodes.Stfld, innerFieldReset);
__DisableReset = (Action<SqlConnection>)dynM.CreateDelegate(typeof(Action<SqlConnection>));
var dm = new DynamicMethod(string.Empty, typeof(bool), new Type[] { typeof(SqlConnection) }, typeof(SqlConnection).Module, true);
var il = dm.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, inner);
il.Emit(OpCodes.Ldfld, innerFieldReset);
__GetInnerPV = (Func<SqlConnection, bool>)dm.CreateDelegate(typeof(Func<SqlConnection, bool>));
internal MsSqlConnection(string cs)
protected sealed override SqlConnection CreateConnection(string cs)
return new SqlConnection(cs);
protected override void OpenConnection()
using (var comm = _conn.CreateCommand())
comm.CommandText = "SET ARITHABORT ON;";
var iar = comm.BeginExecuteNonQuery();
comm.EndExecuteNonQuery(iar);
Interlocked.Increment(ref FailuresCount);
internal override SqlCommand CreateCommand()
throw new NotImplementedException();
internal SqlCommand CreateCommand(string commandText, params SqlParameter[] parameters)
var command = _conn.CreateCommand();
command.CommandTimeout = 600;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = commandText;
command.Parameters.AddRange(parameters);
internal sealed class PgSqlConnection : DbConnectionW<NpgsqlConnection, NpgsqlCommand>
internal PgSqlConnection(string cs)
protected override NpgsqlConnection CreateConnection(string cs)
return new NpgsqlConnection();
protected override void OpenConnection()
internal NpgsqlTransaction BeginTransaction()
return _conn.BeginTransaction(IsolationLevel.Snapshot);
internal override NpgsqlCommand CreateCommand()
throw new NotImplementedException();
internal abstract class DbWrapper<CONNW, CONN, COMM, PARAM, RDR>
where CONNW : DbConnectionW<CONN, COMM>
where CONN : DbConnection
where PARAM : DbParameter
protected readonly string _cs;
internal DbWrapper(string cs)
public void ExecuteNonQuery()
using (var sqlConn = CreateConnection())
using (var comm = sqlConn.CreateCommand())
public object ExecuteScalar()
}, CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow);
public void ExecuteReader(Action<RDR> a, CommandBehavior cb)
using (var sqlConn = CreateConnection())
using (var comm = sqlConn.CreateCommand())
ExecuteReaderPt(comm, cb, a);
public virtual void ExecuteReader_refcursor(Action<RDR> a, CommandBehavior cb)
protected abstract CONNW CreateConnection();
protected abstract void ExecuteReaderPt(COMM comm, CommandBehavior cb, Action<RDR> a);
protected abstract void ExecuteNonQueryPt(COMM comm);
internal sealed class MsSqlDbWrapper : DbWrapper<MsSqlConnection, SqlConnection, SqlCommand, SqlParameter, SqlDataReader>
internal MsSqlDbWrapper(string cs)
protected sealed override MsSqlConnection CreateConnection()
return new MsSqlConnection(_cs);
protected override void ExecuteNonQueryPt(SqlCommand comm)
var iar = comm.BeginExecuteNonQuery();
comm.EndExecuteNonQuery(iar);
protected override void ExecuteReaderPt(SqlCommand comm, CommandBehavior cb, Action<SqlDataReader> a)
var iar = comm.BeginExecuteReader(cb);
using (var r = comm.EndExecuteReader(iar))
internal sealed class PgSqlDbWrapper : DbWrapper<PgSqlConnection, NpgsqlConnection, NpgsqlCommand, NpgsqlParameter, NpgsqlDataReader>
internal PgSqlDbWrapper(string cs)
protected sealed override PgSqlConnection CreateConnection()
return new PgSqlConnection(_cs);
protected sealed override void ExecuteNonQueryPt(NpgsqlCommand comm)
protected override void ExecuteReaderPt(NpgsqlCommand comm, CommandBehavior cb, Action<NpgsqlDataReader> a)
using (var r = comm.ExecuteReader(cb))
public override void ExecuteReader_refcursor(Action<NpgsqlDataReader> a, CommandBehavior cb)
using (var sqlConn = CreateConnection())
using (var comm = sqlConn.CreateCommand())
using (var t = sqlConn.BeginTransaction())
var portals = new FastForwardList<string>();
using (var r = comm.ExecuteReader(CommandBehavior.SequentialAccess))
for (int i = 0; i != r.FieldCount; i++)
portals.Add(r[i].ToString());
} while (r.NextResult());
foreach (var portal in portals)
using (var commInn = sqlConn.CreateCommand())
commInn.CommandText = "FETCH ALL IN \"" + portal + "\";";
using (var rInn = commInn.ExecuteReader(CommandBehavior.SingleResult | cb))
internal enum AbstractCommandResultType
internal enum AbstractCommandType