/// <summary> /// This method writes a set of bytes to the stream. It also enables logging of them. /// </summary> public static Stream WriteBytesNullTerminated(this Stream stream, byte[] the_bytes) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteBytes"); NpgsqlEventLog.LogMsg(resman, "Log_BytesWritten", LogLevel.Debug, the_bytes); stream.Write(the_bytes, 0, the_bytes.Length); stream.WriteByte(0); return(stream); }
/// <summary> /// Internal constructor to handle parameter creation from CommandBuilder passing a NpgsqlNativeTypeInfo directly. /// </summary> internal NpgsqlParameter(String parameterName, NpgsqlNativeTypeInfo type_info) { resman = new System.Resources.ResourceManager(this.GetType()); NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME, parameterName, value, type_info); this.ParameterName = parameterName; this.value = DBNull.Value; this.type_info = (type_info == null) ? NpgsqlTypesHelper.GetNativeTypeInfo(typeof(String)) : type_info; }
private static NpgsqlConnectionStringBuilder GetBuilder(String connectionString) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME, "NpgsqlConnection()"); NpgsqlConnectionStringBuilder builder = cache[connectionString]; return(builder == null ? new NpgsqlConnectionStringBuilder(connectionString) : builder.Clone()); }
/// <summary> /// Return the data type OID of the column at index <param name="Index"></param>. /// </summary> /// FIXME: Why this method returns String? public String GetDataTypeOID(Int32 Index) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetDataTypeName"); CheckHaveResultSet(); NpgsqlBackendTypeInfo TI = GetTypeInfo(Index); return(_currentResultset.RowDescription[Index].type_oid.ToString()); }
/// <summary> /// Adds a <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> to the <see cref="Npgsql.NpgsqlParameterCollection">NpgsqlParameterCollection</see> given the specified parameter name and value. /// </summary> /// <param name="parameterName">The name of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see>.</param> /// <param name="value">The Value of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> to add to the collection.</param> /// <param name="parameterType">One of the NpgsqlDbType values.</param> /// <param name="size">The length of the column.</param> /// <param name="sourceColumn">The name of the source column.</param> /// <returns>The paramater that was added.</returns> public NpgsqlParameter AddWithValue(string parameterName, NpgsqlDbType parameterType, int size, string sourceColumn, object value) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "AddWithValue", parameterName, parameterType, size, sourceColumn, value); NpgsqlParameter param = new NpgsqlParameter(parameterName, parameterType, size, sourceColumn); param.Value = value; return(this.Add(param)); }
protected override RowUpdatingEventArgs CreateRowUpdatingEvent( DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping ) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "CreateRowUpdatingEvent"); return(new NpgsqlRowUpdatingEventArgs(dataRow, command, statementType, tableMapping)); }
protected override void OnRowUpdating( RowUpdatingEventArgs value ) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "OnRowUpdating"); if ((RowUpdating != null) && (value is NpgsqlRowUpdatingEventArgs)) { RowUpdating(this, (NpgsqlRowUpdatingEventArgs)value); } }
public void PrepareTransaction() { if (!_prepared) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "PrepareTransaction"); NpgsqlConnection connection = GetConnection(); NpgsqlCommand.ExecuteBlind(connection.Connector, string.Format("PREPARE TRANSACTION '{0}'", _txName)); _prepared = true; } }
///<summary> /// This method writes a C NULL terminated string to the network stream. /// It appends a NULL terminator to the end of the String. /// </summary> ///<summary> /// This method writes a C NULL terminated string to the network stream. /// It appends a NULL terminator to the end of the String. /// </summary> public static void WriteString(String the_string, Stream network_stream) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteString"); NpgsqlEventLog.LogMsg(resman, "Log_StringWritten", LogLevel.Debug, the_string); byte[] bytes = ENCODING_UTF8.GetBytes(the_string + NULL_TERMINATOR_STRING); network_stream.Write(bytes, 0, bytes.Length); }
/// <summary> /// Opens a database connection with the property settings specified by the /// <see cref="Npgsql.NpgsqlConnection.ConnectionString">ConnectionString</see>. /// </summary> public override void Open() { // If we're postponing a close (see doc on this variable), the connection is already // open and can be silently reused if (_postponingClose) { return; } CheckConnectionClosed(); NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Open"); // Check if there is any missing argument. if (!settings.ContainsKey(Keywords.Host)) { throw new ArgumentException(resman.GetString("Exception_MissingConnStrArg"), NpgsqlConnectionStringBuilder.GetKeyName(Keywords.Host)); } if (!settings.ContainsKey(Keywords.UserName) && !settings.ContainsKey(Keywords.IntegratedSecurity)) { throw new ArgumentException(resman.GetString("Exception_MissingConnStrArg"), NpgsqlConnectionStringBuilder.GetKeyName(Keywords.UserName)); } // Get a Connector, either from the pool or creating one ourselves. if (Pooling) { connector = NpgsqlConnectorPool.ConnectorPoolMgr.RequestConnector(this); } else { connector = new NpgsqlConnector(this); connector.ProvideClientCertificatesCallback += ProvideClientCertificatesCallbackDelegate; connector.CertificateSelectionCallback += CertificateSelectionCallbackDelegate; connector.CertificateValidationCallback += CertificateValidationCallbackDelegate; connector.PrivateKeySelectionCallback += PrivateKeySelectionCallbackDelegate; connector.Open(); } connector.Notice += NoticeDelegate; connector.Notification += NotificationDelegate; if (SyncNotification) { connector.AddNotificationThread(); } if (Enlist) { Promotable.Enlist(Transaction.Current); } }
public override IEnumerable <IServerResponseObject> ExecuteEnum(NpgsqlConnector context, NpgsqlExecute execute) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Execute"); NpgsqlDescribe describe = new NpgsqlDescribe('P', execute.PortalName); Stream stream = context.Stream; describe.WriteToStream(stream); execute.WriteToStream(stream); //stream.Flush(); return(SyncEnum(context)); }
/// <summary> /// Creates a prepared version of the command on a PostgreSQL server. /// </summary> public override void Prepare() { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Prepare"); // Check the connection state. CheckConnectionState(); UnPrepare(); PrepareInternal(); }
/// <summary> /// Removes all items from the collection. /// </summary> public override void Clear() { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Clear"); foreach (NpgsqlParameter toRemove in this.InternalList) { // clean up the parameter so it can be added to another command if required. toRemove.Collection = null; } this.InternalList.Clear(); this.InvalidateHashLookups(); }
/// <summary> /// Returns a System.Data.DataTable that describes the column metadata of the DataReader. /// </summary> public DataTable GetSchemaTable() { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetSchemaTable"); if (_currentResultsetSchema == null) { _currentResultsetSchema = GetResultsetSchema(); } return(_currentResultsetSchema); }
/// <summary> /// Initializes a new instance of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> /// </summary> /// <param m_Name="parameterName">The m_Name of the parameter to map.</param> /// <param m_Name="parameterType">One of the <see cref="NpgsqlTypes.NpgsqlDbType">NpgsqlDbType</see> values.</param> /// <param m_Name="size">The length of the parameter.</param> /// <param m_Name="sourceColumn">The m_Name of the source column.</param> public NpgsqlParameter(String parameterName, NpgsqlDbType parameterType, Int32 size, String sourceColumn) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME, parameterName, parameterType, size, source_column); this.ParameterName = parameterName; NpgsqlDbType = parameterType; //Allow the setter to catch any exceptions. this.size = size; source_column = sourceColumn; }
public override void Execute(NpgsqlConnector context, NpgsqlExecute execute) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Execute"); NpgsqlDescribe describe = new NpgsqlDescribe('P', execute.PortalName); Stream stream = context.Stream; describe.WriteToStream(stream); execute.WriteToStream(stream); //stream.Flush(); Sync(context); }
/// <summary> /// Removes the specified <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> from the collection using the parameter name. /// </summary> /// <param name="parameterName">The name of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> object to retrieve.</param> public override void RemoveAt(string parameterName) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "RemoveAt", parameterName); int index = IndexOf(parameterName); NpgsqlParameter existing = InternalList[index]; this.InternalList.RemoveAt(index); existing.Collection = null; this.InvalidateHashLookups(); }
/// <summary> /// Removes the specified <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> from the collection. /// </summary> /// <param name="parameterName">The name of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> to remove from the collection.</param> public void Remove(string parameterName) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Remove", parameterName); int index = IndexOf(parameterName); if (index < 0) { throw new InvalidOperationException("No parameter with the specified name exists in the collection"); } RemoveAt(index); }
/// <summary> /// This method substitutes the <see cref="Npgsql.NpgsqlCommand.Parameters">Parameters</see>, if exist, in the command /// to their actual values. /// The parameter name format is <b>:ParameterName</b>. /// </summary> /// <returns>A version of <see cref="Npgsql.NpgsqlCommand.CommandText">CommandText</see> with the <see cref="Npgsql.NpgsqlCommand.Parameters">Parameters</see> inserted.</returns> internal byte[] GetCommandText() { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetCommandText"); byte[] ret = string.IsNullOrEmpty(planName) ? GetCommandText(false, false) : GetExecuteCommandText(); // In constructing the command text, we potentially called internal // queries. Reset command timeout and SQL sent. m_Connector.Mediator.ResetResponses(); m_Connector.Mediator.CommandTimeout = CommandTimeout; return ret; }
///<summary> /// This method writes a string to the network stream. /// </summary> public static Stream WriteString(this Stream stream, String theString) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteString"); NpgsqlEventLog.LogMsg(resman, "Log_StringWritten", LogLevel.Debug, theString); byte[] bytes = BackendEncoding.UTF8Encoding.GetBytes(theString); stream.Write(bytes, 0, bytes.Length); return(stream); }
///<summary> /// This method writes a C NULL terminated string limited in length to the /// backend server. /// It pads the string with null bytes to the size specified. /// </summary> public static void WriteLimString(String the_string, Int32 n, Stream network_stream, Encoding encoding) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteLimString"); // [FIXME] Parameters should be validated. And what about strings // larger than or equal to n? // Pad the string to the specified value. String string_padded = the_string.PadRight(n, '\x00'); network_stream.Write(encoding.GetBytes(string_padded), 0, n); }
/// <summary> /// When a connection is closed within an enclosing TransactionScope and the transaction /// hasn't been promoted, we defer the actual closing until the scope ends. /// </summary> internal void PromotableLocalTransactionEnded() { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "PromotableLocalTransactionEnded"); if (_postponingDispose) { Dispose(true); } else if (_postponingClose) { ReallyClose(); } }
/// <summary> /// Removes the specified <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> from the collection using a specific index. /// </summary> /// <param name="index">The zero-based index of the parameter.</param> public override void RemoveAt(int index) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "RemoveAt", index); if (InternalList.Count - 1 < index) { throw new IndexOutOfRangeException(); } InternalList[index].Collection = null; InternalList.RemoveAt(index); InvalidateHashLookups(); }
/// <summary> /// Begins a database transaction with the specified isolation level. /// </summary> /// <param name="level">The <see cref="System.Data.IsolationLevel">isolation level</see> under which the transaction should run.</param> /// <returns>A <see cref="Npgsql.NpgsqlTransaction">NpgsqlTransaction</see> /// object representing the new transaction.</returns> /// <remarks> /// Currently the IsolationLevel ReadCommitted and Serializable are supported by the PostgreSQL backend. /// There's no support for nested transactions. /// </remarks> public new NpgsqlTransaction BeginTransaction(IsolationLevel level) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "BeginTransaction", level); CheckConnectionOpen(); if (connector.Transaction != null) { throw new InvalidOperationException(resman.GetString("Exception_NoNestedTransactions")); } return(new NpgsqlTransaction(this, level)); }
/// <summary> /// Return the value of the column at index <param name="Index"></param>. /// </summary> public Object GetValue(Int32 Index) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetValue"); if (Index < 0 || Index >= _currentResultset.RowDescription.NumFields) { throw new IndexOutOfRangeException("Column index out of range"); } CheckHaveRow(); return(((NpgsqlAsciiRow)_currentResultset[_rowIndex])[Index]); }
public void RollbackTransaction() { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "RollbackTransaction"); NpgsqlConnection connection = GetConnection(); if (_prepared) { NpgsqlCommand.ExecuteBlind(connection.Connector, string.Format("ROLLBACK PREPARED '{0}'", _txName)); } else { NpgsqlCommand.ExecuteBlind(connection.Connector, "ROLLBACK"); } }
public void CommitTransaction() { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "CommitTransaction"); NpgsqlConnection connection = GetConnection(); if (_prepared) { NpgsqlCommand.ExecuteBlind(connection.Connector, string.Format("COMMIT PREPARED '{0}'", _txName)); } else { NpgsqlCommand.ExecuteBlind(connection.Connector, NpgsqlQuery.CommitTransaction); } }
/// <summary> /// Opens a database connection with the property settings specified by the /// <see cref="Npgsql.NpgsqlConnection.ConnectionString">ConnectionString</see>. /// </summary> public override void Open() { CheckConnectionClosed(); NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Open"); // Check if there is any missing argument. if (!settings.ContainsKey(Keywords.Host)) { throw new ArgumentException(resman.GetString("Exception_MissingConnStrArg"), NpgsqlConnectionStringBuilder.GetKeyName(Keywords.Host)); } if (!settings.ContainsKey(Keywords.UserName) && !settings.ContainsKey(Keywords.IntegratedSecurity)) { throw new ArgumentException(resman.GetString("Exception_MissingConnStrArg"), NpgsqlConnectionStringBuilder.GetKeyName(Keywords.UserName)); } // Get a Connector, either from the pool or creating one ourselves. if (Pooling) { connector = NpgsqlConnectorPool.ConnectorPoolMgr.RequestConnector(this); } else { connector = new NpgsqlConnector(this); connector.ProvideClientCertificatesCallback += ProvideClientCertificatesCallbackDelegate; connector.CertificateSelectionCallback += CertificateSelectionCallbackDelegate; connector.CertificateValidationCallback += CertificateValidationCallbackDelegate; connector.PrivateKeySelectionCallback += PrivateKeySelectionCallbackDelegate; connector.Open(); } connector.Notice += NoticeDelegate; connector.Notification += NotificationDelegate; connector.StateChanged += connector_StateChanged; if (SyncNotification) { connector.AddNotificationThread(); } if (Enlist) { Promotable.Enlist(Transaction.Current); } this.OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open)); }
public override void WriteToStream(Stream output_stream) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "WriteToStream"); // Packet length = 296 output_stream .WriteInt32(296) .WriteInt32(PGUtil.ConvertProtocolVersion(this.protocol_version)) .WriteLimBytes(database_name, 64) .WriteLimBytes(user_name, 32) .WriteLimBytes(arguments, 64) .WriteLimBytes(unused, 64) .WriteLimBytes(optional_tty, 64); }
/// <summary> /// Initializes a new instance of the /// <see cref="Npgsql.NpgsqlConnection">NpgsqlConnection</see> class /// and sets the <see cref="Npgsql.NpgsqlConnection.ConnectionString">ConnectionString</see>. /// </summary> /// <param name="ConnectionString">The connection used to open the PostgreSQL database.</param> public NpgsqlConnection(String ConnectionString) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME, "NpgsqlConnection()"); connection_string = NpgsqlConnectionString.ParseConnectionString(ConnectionString); LogConnectionString(); NoticeDelegate = new NoticeEventHandler(OnNotice); NotificationDelegate = new NotificationEventHandler(OnNotification); CertificateValidationCallbackDelegate = new CertificateValidationCallback(DefaultCertificateValidationCallback); CertificateSelectionCallbackDelegate = new CertificateSelectionCallback(DefaultCertificateSelectionCallback); PrivateKeySelectionCallbackDelegate = new PrivateKeySelectionCallback(DefaultPrivateKeySelectionCallback); }