|
3 | 3 | // URL: https://github.com/kubo/rust-oracle
|
4 | 4 | //
|
5 | 5 | //-----------------------------------------------------------------------------
|
6 |
| -// Copyright (c) 2017-2021 Kubo Takehiro <[email protected]>. All rights reserved. |
| 6 | +// Copyright (c) 2017-2024 Kubo Takehiro <[email protected]>. All rights reserved. |
7 | 7 | // This program is free software: you can modify it and/or redistribute it
|
8 | 8 | // under the terms of:
|
9 | 9 | //
|
|
17 | 17 | //!
|
18 | 18 | //! Some types at the top-level module will move here in future.
|
19 | 19 | use crate::binding::*;
|
| 20 | +use crate::to_rust_str; |
20 | 21 | #[cfg(doc)]
|
21 | 22 | use crate::Connection;
|
| 23 | +use crate::Error; |
| 24 | +use crate::Result; |
22 | 25 |
|
23 | 26 | /// The mode to use when closing connections to the database
|
24 | 27 | ///
|
@@ -55,3 +58,90 @@ impl Purity {
|
55 | 58 | }
|
56 | 59 | }
|
57 | 60 | }
|
| 61 | + |
| 62 | +/// The type of server process associated with a connection |
| 63 | +/// |
| 64 | +/// It is only available with Oracle Client libraries 23.4 or higher. |
| 65 | +#[derive(Debug, Copy, Clone, PartialEq, Eq)] |
| 66 | +pub enum ServerType { |
| 67 | + /// A dedicated server process is being used with the connection. |
| 68 | + Dedicated, |
| 69 | + /// A pooled server process (DRCP) is being used with the connection. |
| 70 | + Pooled, |
| 71 | + /// A shared server process is being used with the connection. |
| 72 | + Shared, |
| 73 | + /// The type of server process is unknown. |
| 74 | + Unknown, |
| 75 | +} |
| 76 | + |
| 77 | +impl ServerType { |
| 78 | + pub(crate) fn from_dpi(server_type: u8) -> Result<ServerType> { |
| 79 | + match server_type as u32 { |
| 80 | + DPI_SERVER_TYPE_DEDICATED => Ok(ServerType::Dedicated), |
| 81 | + DPI_SERVER_TYPE_POOLED => Ok(ServerType::Pooled), |
| 82 | + DPI_SERVER_TYPE_SHARED => Ok(ServerType::Shared), |
| 83 | + DPI_SERVER_TYPE_UNKNOWN => Ok(ServerType::Unknown), |
| 84 | + _ => Err(Error::internal_error(format!( |
| 85 | + "Unknown dpiServerType {}", |
| 86 | + server_type |
| 87 | + ))), |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +/// Information about a connection |
| 93 | +/// |
| 94 | +/// This is a return value of [`Connection::info()`]. |
| 95 | +#[non_exhaustive] |
| 96 | +#[derive(Debug, Clone, PartialEq)] |
| 97 | +pub struct Info { |
| 98 | + /// The name of the Oracle Database Domain name associated with the connection |
| 99 | + /// |
| 100 | + /// This is the same value returned by the SQL expression |
| 101 | + /// `SELECT VALUE FROM V$PARAMETER WHERE NAME = 'db_domain'`. |
| 102 | + pub db_domain: String, |
| 103 | + |
| 104 | + /// The Oracle Database name associated with the connection |
| 105 | + pub db_name: String, |
| 106 | + |
| 107 | + /// The Oracle Database instance name associated with the connection |
| 108 | + pub instance_name: String, |
| 109 | + |
| 110 | + /// The Oracle Database service name associated with the connection |
| 111 | + /// |
| 112 | + /// This is the same value returned by the SQL expression |
| 113 | + /// `SELECT SYS_CONTEXT('USERENV', 'SERVICE_NAME') FROM DUAL`. |
| 114 | + pub service_name: String, |
| 115 | + |
| 116 | + /// The maximum length of identifiers (in bytes) supported by the |
| 117 | + /// database to which the connection has been established |
| 118 | + /// |
| 119 | + /// See [Database Object Naming Rules](https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-75337742-67FD-4EC0-985F-741C93D918DA). |
| 120 | + pub max_identifier_length: u32, |
| 121 | + |
| 122 | + /// The maximum number of cursors that can be opened |
| 123 | + /// |
| 124 | + /// This is the same value returned by the SQL expression |
| 125 | + /// `SELECT VALUE FROM V$PARAMETER WHERE NAME = 'open_cursors'`. |
| 126 | + pub max_open_cursors: u32, |
| 127 | + |
| 128 | + /// The type of server process used by the connection |
| 129 | + /// |
| 130 | + /// This is only available with Oracle Client libraries 23.4 or higher. |
| 131 | + /// Otherwise, it is always `ServerType::Unknown`. |
| 132 | + pub server_type: ServerType, |
| 133 | +} |
| 134 | + |
| 135 | +impl Info { |
| 136 | + pub(crate) fn from_dpi(info: &dpiConnInfo) -> Result<Info> { |
| 137 | + Ok(Info { |
| 138 | + db_domain: to_rust_str(info.dbDomain, info.dbDomainLength), |
| 139 | + db_name: to_rust_str(info.dbName, info.dbNameLength), |
| 140 | + instance_name: to_rust_str(info.instanceName, info.instanceNameLength), |
| 141 | + service_name: to_rust_str(info.serviceName, info.serviceNameLength), |
| 142 | + max_identifier_length: info.maxIdentifierLength, |
| 143 | + max_open_cursors: info.maxOpenCursors, |
| 144 | + server_type: ServerType::from_dpi(info.serverType)?, |
| 145 | + }) |
| 146 | + } |
| 147 | +} |
0 commit comments