Struct libpq::connection::Connection
source · pub struct Connection { /* private fields */ }
Implementations§
§impl Connection
impl Connection
pub fn send_query(&self, command: &str) -> Result
pub fn send_query(&self, command: &str) -> Result
Submits a command to the server without waiting for the result(s).
See PQsendQuery.
pub fn send_query_params(
&self,
command: &str,
param_types: &[Oid],
param_values: &[Option<Vec<u8>>],
param_formats: &[Format],
result_format: Format
) -> Result
pub fn send_query_params( &self, command: &str, param_types: &[Oid], param_values: &[Option<Vec<u8>>], param_formats: &[Format], result_format: Format ) -> Result
Submits a command and separate parameters to the server without waiting for the result(s).
See PQsendQueryParams.
pub fn send_prepare(
&self,
name: Option<&str>,
query: &str,
param_types: &[Oid]
) -> Result
pub fn send_prepare( &self, name: Option<&str>, query: &str, param_types: &[Oid] ) -> Result
Sends a request to create a prepared statement with the given parameters, without waiting for completion.
See PQsendPrepare.
pub fn send_query_prepared(
&self,
name: Option<&str>,
param_values: &[Option<Vec<u8>>],
param_formats: &[Format],
result_format: Format
) -> Result
pub fn send_query_prepared( &self, name: Option<&str>, param_values: &[Option<Vec<u8>>], param_formats: &[Format], result_format: Format ) -> Result
Sends a request to execute a prepared statement with given parameters, without waiting for the result(s).
See PQsendQueryPrepared.
pub fn send_describe_prepared(&self, name: Option<&str>) -> Result
pub fn send_describe_prepared(&self, name: Option<&str>) -> Result
Submits a request to obtain information about the specified prepared statement, without waiting for completion.
See PQsendDescribePortal.
pub fn send_describe_portal(&self, name: Option<&str>) -> Result
pub fn send_describe_portal(&self, name: Option<&str>) -> Result
Submits a request to obtain information about the specified portal, without waiting for completion.
See PQsendDescribePortal.
pub fn result(&self) -> Option<Result>
pub fn result(&self) -> Option<Result>
Waits for the next result a prior send_*
call, and returns it.
See PQgetResult.
pub fn consume_input(&self) -> Result
pub fn consume_input(&self) -> Result
If input is available from the server, consume it.
See PQconsumeInput.
pub fn is_busy(&self) -> bool
pub fn is_busy(&self) -> bool
Returns true
if a command is busy, that is, Result
would block waiting for input.
See PQisBusy.
pub fn set_non_blocking(&self, non_blocking: bool) -> Result
pub fn set_non_blocking(&self, non_blocking: bool) -> Result
Sets the nonblocking status of the connection.
See PQsetnonblocking.
pub fn is_non_blocking(&self) -> bool
pub fn is_non_blocking(&self) -> bool
Returns the blocking status of the database connection.
See PQisnonblocking.
§impl Connection
impl Connection
pub fn cancel(&self) -> Cancel
pub fn cancel(&self) -> Cancel
Creates a data structure containing the information needed to cancel a command issued through a particular database connection.
See PQgetCancel.
§impl Connection
impl Connection
pub fn new(dsn: &str) -> Result<Self>
pub fn new(dsn: &str) -> Result<Self>
Makes a new connection to the database server.
See PQconnectdb.
pub fn with_params(
params: &HashMap<&str, &str>,
expand_dbname: bool
) -> Result<Self>
pub fn with_params( params: &HashMap<&str, &str>, expand_dbname: bool ) -> Result<Self>
Makes a new connection to the database server.
See PQconnectdbParams.
pub fn start(conninfo: &str) -> Result<Self>
pub fn start(conninfo: &str) -> Result<Self>
Make a connection to the database server in a nonblocking manner.
See PQconnectStart.
pub fn start_params(
params: &HashMap<String, String>,
expand_dbname: bool
) -> Result<Self>
pub fn start_params( params: &HashMap<String, String>, expand_dbname: bool ) -> Result<Self>
Make a connection to the database server in a nonblocking manner.
See PQconnectStartParams.
pub fn set_db(
host: Option<&str>,
port: Option<&str>,
options: Option<&str>,
tty: Option<&str>,
db_name: Option<&str>
) -> Result<Self>
pub fn set_db( host: Option<&str>, port: Option<&str>, options: Option<&str>, tty: Option<&str>, db_name: Option<&str> ) -> Result<Self>
Makes a new connection to the database server.
See PQsetdb.
pub fn login(
host: Option<&str>,
port: Option<&str>,
options: Option<&str>,
tty: Option<&str>,
db_name: Option<&str>,
login: Option<&str>,
pwd: Option<&str>
) -> Result<Self>
pub fn login( host: Option<&str>, port: Option<&str>, options: Option<&str>, tty: Option<&str>, db_name: Option<&str>, login: Option<&str>, pwd: Option<&str> ) -> Result<Self>
Makes a new connection to the database server.
See PQsetdbLogin.
pub fn poll(&self) -> Status
pub fn poll(&self) -> Status
See PQconnectPoll.
pub fn reset_start(&self)
pub fn reset_start(&self)
Reset the communication channel to the server, in a nonblocking manner.
See PQresetStart.
pub fn reset_poll(&self) -> Status
pub fn reset_poll(&self) -> Status
See PQresetPoll.
pub fn ping_params(
params: &HashMap<String, String>,
expand_dbname: bool
) -> Status
pub fn ping_params( params: &HashMap<String, String>, expand_dbname: bool ) -> Status
Reports the status of the server.
It accepts connection parameters identical to those of libpq::Connection::with_params
. It
is not necessary to supply correct user name, password, or database name values to obtain
the server status; however, if incorrect values are provided, the server will log a failed
connection attempt.
See PQpingParams.
pub fn ping(dsn: &str) -> Status
pub fn ping(dsn: &str) -> Status
Reports the status of the server.
It accepts connection parameters identical to those of libpq::Connection::new
. It is not
necessary to supply correct user name, password, or database name values to obtain the
server status; however, if incorrect values are provided, the server will log a failed
connection attempt.
See PQping.
§impl Connection
impl Connection
pub fn client_encoding(&self) -> Encoding
pub fn client_encoding(&self) -> Encoding
Returns the client encoding.
See PQclientEncoding.
pub fn set_client_encoding(&self, encoding: Encoding)
pub fn set_client_encoding(&self, encoding: Encoding)
Sets the client encoding.
See PQsetClientEncoding.
pub fn set_error_verbosity(&self, verbosity: Verbosity) -> Verbosity
pub fn set_error_verbosity(&self, verbosity: Verbosity) -> Verbosity
Determines the verbosity of messages returned by libpq::Connection::error_message
and
libpq::Result::error_message
.
See PQsetErrorVerbosity.
§impl Connection
impl Connection
pub fn put_copy_data(&self, buffer: &[u8]) -> Result
pub fn put_copy_data(&self, buffer: &[u8]) -> Result
Sends data to the server during libpq::Status::CopyIn
state.
See PQputCopyData.
pub fn put_copy_end(&self, errormsg: Option<&str>) -> Result
pub fn put_copy_end(&self, errormsg: Option<&str>) -> Result
Sends end-of-data indication to the server during libpq::Status::CopyIn
state.
See PQputCopyEnd.
§impl Connection
impl Connection
pub fn exec(&self, query: &str) -> Result
pub fn exec(&self, query: &str) -> Result
Submits a command to the server and waits for the result.
See PQexec.
pub fn exec_params(
&self,
command: &str,
param_types: &[Oid],
param_values: &[Option<Vec<u8>>],
param_formats: &[Format],
result_format: Format
) -> Result
pub fn exec_params( &self, command: &str, param_types: &[Oid], param_values: &[Option<Vec<u8>>], param_formats: &[Format], result_format: Format ) -> Result
Submits a command to the server and waits for the result, with the ability to pass parameters separately from the SQL command text.
See PQexecParams.
pub fn prepare(
&self,
name: Option<&str>,
query: &str,
param_types: &[Oid]
) -> Result
pub fn prepare( &self, name: Option<&str>, query: &str, param_types: &[Oid] ) -> Result
Submits a request to create a prepared statement with the given parameters, and waits for completion.
See PQprepare.
pub fn exec_prepared(
&self,
name: Option<&str>,
param_values: &[Option<Vec<u8>>],
param_formats: &[Format],
result_format: Format
) -> Result
pub fn exec_prepared( &self, name: Option<&str>, param_values: &[Option<Vec<u8>>], param_formats: &[Format], result_format: Format ) -> Result
Sends a request to execute a prepared statement with given parameters, and waits for the result.
See PQexecPrepared.
pub fn describe_prepared(&self, name: Option<&str>) -> Result
pub fn describe_prepared(&self, name: Option<&str>) -> Result
Submits a request to obtain information about the specified prepared statement, and waits for completion.
See PQdescribePrepared.
pub fn describe_portal(&self, name: Option<&str>) -> Result
pub fn describe_portal(&self, name: Option<&str>) -> Result
Submits a request to obtain information about the specified portal, and waits for completion.
See PQdescribePortal.
pub fn escape_literal(&self, str: &str) -> Result<PqString>
pub fn escape_literal(&self, str: &str) -> Result<PqString>
Escape a string for use within an SQL command.
On success, this method returns PqString
.
See
PQescapeLiteral.
pub fn escape_identifier(&self, str: &str) -> Result<PqString>
pub fn escape_identifier(&self, str: &str) -> Result<PqString>
Escapes a string for use as an SQL identifier, such as a table, column, or function name.
On success, this method returns PqString
.
See PQescapeIdentifier.
pub fn escape_string(&self, from: &str) -> Result<String>
pub fn escape_string(&self, from: &str) -> Result<String>
Escape string literals, much like libpq::Connection::literal
.
On success, this method returns String
.
See PQescapeStringConn.
pub fn escape_bytea(&self, from: &[u8]) -> Result<PqBytes>
pub fn escape_bytea(&self, from: &[u8]) -> Result<PqBytes>
Escapes binary data for use within an SQL command with the type bytea.
On success, this method returns PqBytes
.
See PQescapeByteaConn.
§impl Connection
impl Connection
pub unsafe fn set_notice_processor(
&self,
proc: NoticeProcessor,
arg: *mut c_void
) -> NoticeProcessor
pub unsafe fn set_notice_processor( &self, proc: NoticeProcessor, arg: *mut c_void ) -> NoticeProcessor
Safety
This function takes a void*
pointer as argument.
pub unsafe fn set_notice_receiver(
&self,
proc: NoticeReceiver,
arg: *mut c_void
) -> NoticeReceiver
pub unsafe fn set_notice_receiver( &self, proc: NoticeReceiver, arg: *mut c_void ) -> NoticeReceiver
Safety
This function takes a void*
pointer as argument.
§impl Connection
impl Connection
§impl Connection
impl Connection
pub fn set_single_row_mode(&self) -> Result
pub fn set_single_row_mode(&self) -> Result
Select single-row mode for the currently-executing query.
See PQsetSingleRowMode.
§impl Connection
impl Connection
pub fn init_openssl(do_ssl: bool, do_crypto: bool)
pub fn init_openssl(do_ssl: bool, do_crypto: bool)
Allows applications to select which security libraries to initialize.
See PQinitOpenSSL.
§impl Connection
impl Connection
pub fn host(&self) -> Result<String>
pub fn host(&self) -> Result<String>
Returns the server host name of the active connection.
This can be a host name, an IP address, or a directory path if the connection is via Unix socket. (The path case can be distinguished because it will always be an absolute path, beginning with /.)
See PQhost.
pub fn tty(&self) -> Result<Option<String>>
👎Deprecated: the server no longer pays attention to the TTY setting, but the function remains for backward compatibility.
pub fn tty(&self) -> Result<Option<String>>
Returns the debug TTY of the connection.
See PQtty.
pub fn options(&self) -> Result<Option<String>>
pub fn options(&self) -> Result<Option<String>>
Returns the command-line options passed in the connection request.
See PQoptions.
pub fn transaction_status(&self) -> Status
pub fn transaction_status(&self) -> Status
Returns the current in-transaction status of the server.
See PQtransactionStatus.
pub fn parameter_status(&self, param: &str) -> Result<String>
pub fn parameter_status(&self, param: &str) -> Result<String>
Looks up a current parameter setting of the server.
See PQparameterStatus.
pub fn protocol_version(&self) -> i32
pub fn protocol_version(&self) -> i32
Interrogates the frontend/backend protocol being used.
See PQprotocolVersion.
pub fn server_version(&self) -> i32
pub fn server_version(&self) -> i32
Returns an integer representing the server version.
See PQserverVersion.
pub fn error_message(&self) -> Option<&str>
pub fn error_message(&self) -> Option<&str>
Returns the error message most recently generated by an operation on the connection.
See PQerrorMessage.
Implemenatation Notes:
PQerrorMessage returns a localizable string, which depends on the locale settings and is it not guaranteed to be UTF-8 encoded.
Since rust strings are UTF-8 encoded, if the error message cannot be converted to UTF-8, the returned string will not be the actual error message but “PQerrorMessage internal error: the error message is not UTF-8”. You can get the actual error message, by changing your locale settings an UTF-8 compatible one.
pub fn socket(&self) -> Result<i32>
pub fn socket(&self) -> Result<i32>
Obtains the file descriptor number of the connection socket to the server.
See PQsocket.
pub fn backend_pid(&self) -> u32
pub fn backend_pid(&self) -> u32
Returns the process ID (PID) of the backend process handling this connection.
See PQbackendPID.
pub fn needs_password(&self) -> bool
pub fn needs_password(&self) -> bool
Returns true
if the connection authentication method required a password, but none was
available. Returns false
if not.
pub fn used_password(&self) -> bool
pub fn used_password(&self) -> bool
Returns true
if the connection authentication method used a password. Returns false
if
not.
pub fn ssl_in_use(&self) -> bool
pub fn ssl_in_use(&self) -> bool
Returns true
if the connection uses SSL, false
if not.
See PQsslInUse.
pub fn ssl_attribute(&self, attribute: Attribute) -> Result<Option<String>>
pub fn ssl_attribute(&self, attribute: Attribute) -> Result<Option<String>>
Returns SSL-related information about the connection.
See PQsslAttribute.
pub fn ssl_attribute_names(&self) -> Result<Vec<Attribute>>
pub fn ssl_attribute_names(&self) -> Result<Vec<Attribute>>
Return an array of SSL attribute names available.
See PQsslAttributeNames.
pub unsafe fn ssl_struct(&self, struct_name: &str) -> *const c_void
pub unsafe fn ssl_struct(&self, struct_name: &str) -> *const c_void
Return a pointer to an SSL-implementation-specific object describing the connection.
See PQsslStruct.
Safety
This function returns a void*
pointer.
§impl Connection
impl Connection
pub fn is_thread_safe() -> bool
pub fn is_thread_safe() -> bool
Returns the thread safety status of the libpq library.
See PQisthreadsafe.
§impl Connection
impl Connection
Trait Implementations§
source§impl Clone for Connection
impl Clone for Connection
source§fn clone(&self) -> Connection
fn clone(&self) -> Connection
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more