gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

462 行
27KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>33.2. Connection Status Functions</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="libpq-connect.html" title="33.1. Database Connection Control Functions" /><link rel="next" href="libpq-exec.html" title="33.3. Command Execution Functions" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">33.2. Connection Status Functions</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="libpq-connect.html" title="33.1. Database Connection Control Functions">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="libpq.html" title="Chapter 33. libpq - C Library">Up</a></td><th width="60%" align="center">Chapter 33. <span xmlns="http://www.w3.org/1999/xhtml" class="application">libpq</span> - C Library</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="libpq-exec.html" title="33.3. Command Execution Functions">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="LIBPQ-STATUS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">33.2. Connection Status Functions</h2></div></div></div><p>
  3. These functions can be used to interrogate the status
  4. of an existing database connection object.
  5. </p><div class="tip"><h3 class="title">Tip</h3><p>
  6. <a id="id-1.7.3.9.3.1.1" class="indexterm"></a>
  7. <a id="id-1.7.3.9.3.1.2" class="indexterm"></a>
  8. <span class="application">libpq</span> application programmers should be careful to
  9. maintain the <code class="structname">PGconn</code> abstraction. Use the accessor
  10. functions described below to get at the contents of <code class="structname">PGconn</code>.
  11. Reference to internal <code class="structname">PGconn</code> fields using
  12. <code class="filename">libpq-int.h</code> is not recommended because they are subject to change
  13. in the future.
  14. </p></div><p>
  15. The following functions return parameter values established at connection.
  16. These values are fixed for the life of the connection. If a multi-host
  17. connection string is used, the values of <code class="function">PQhost</code>,
  18. <code class="function">PQport</code>, and <code class="function">PQpass</code> can change if a new connection
  19. is established using the same <code class="structname">PGconn</code> object. Other values
  20. are fixed for the lifetime of the <code class="structname">PGconn</code> object.
  21. </p><div class="variablelist"><dl class="variablelist"><dt id="LIBPQ-PQDB"><span class="term">
  22. <code class="function">PQdb</code>
  23. <a id="id-1.7.3.9.4.6.1.1.2" class="indexterm"></a>
  24. </span></dt><dd><p>
  25. Returns the database name of the connection.
  26. </p><pre class="synopsis">
  27. char *PQdb(const PGconn *conn);
  28. </pre><p>
  29. </p></dd><dt id="LIBPQ-PQUSER"><span class="term">
  30. <code class="function">PQuser</code>
  31. <a id="id-1.7.3.9.4.6.2.1.2" class="indexterm"></a>
  32. </span></dt><dd><p>
  33. Returns the user name of the connection.
  34. </p><pre class="synopsis">
  35. char *PQuser(const PGconn *conn);
  36. </pre><p>
  37. </p></dd><dt id="LIBPQ-PQPASS"><span class="term">
  38. <code class="function">PQpass</code>
  39. <a id="id-1.7.3.9.4.6.3.1.2" class="indexterm"></a>
  40. </span></dt><dd><p>
  41. Returns the password of the connection.
  42. </p><pre class="synopsis">
  43. char *PQpass(const PGconn *conn);
  44. </pre><p>
  45. </p><p>
  46. <code class="function">PQpass</code> will return either the password specified
  47. in the connection parameters, or if there was none and the password
  48. was obtained from the <a class="link" href="libpq-pgpass.html" title="33.15. The Password File">password
  49. file</a>, it will return that. In the latter case,
  50. if multiple hosts were specified in the connection parameters, it is
  51. not possible to rely on the result of <code class="function">PQpass</code> until
  52. the connection is established. The status of the connection can be
  53. checked using the function <code class="function">PQstatus</code>.
  54. </p></dd><dt id="LIBPQ-PQHOST"><span class="term">
  55. <code class="function">PQhost</code>
  56. <a id="id-1.7.3.9.4.6.4.1.2" class="indexterm"></a>
  57. </span></dt><dd><p>
  58. Returns the server host name of the active connection.
  59. This can be a host name, an IP address, or a directory path if the
  60. connection is via Unix socket. (The path case can be distinguished
  61. because it will always be an absolute path, beginning
  62. with <code class="literal">/</code>.)
  63. </p><pre class="synopsis">
  64. char *PQhost(const PGconn *conn);
  65. </pre><p>
  66. </p><p>
  67. If the connection parameters specified both <code class="literal">host</code> and
  68. <code class="literal">hostaddr</code>, then <code class="function">PQhost</code> will
  69. return the <code class="literal">host</code> information. If only
  70. <code class="literal">hostaddr</code> was specified, then that is returned.
  71. If multiple hosts were specified in the connection parameters,
  72. <code class="function">PQhost</code> returns the host actually connected to.
  73. </p><p>
  74. <code class="function">PQhost</code> returns <code class="symbol">NULL</code> if the
  75. <em class="parameter"><code>conn</code></em> argument is <code class="symbol">NULL</code>.
  76. Otherwise, if there is an error producing the host information (perhaps
  77. if the connection has not been fully established or there was an
  78. error), it returns an empty string.
  79. </p><p>
  80. If multiple hosts were specified in the connection parameters, it is
  81. not possible to rely on the result of <code class="function">PQhost</code> until
  82. the connection is established. The status of the connection can be
  83. checked using the function <code class="function">PQstatus</code>.
  84. </p></dd><dt id="LIBPQ-PQHOSTADDR"><span class="term">
  85. <code class="function">PQhostaddr</code>
  86. <a id="id-1.7.3.9.4.6.5.1.2" class="indexterm"></a>
  87. </span></dt><dd><p>
  88. Returns the server IP address of the active connection.
  89. This can be the address that a host name resolved to,
  90. or an IP address provided through the <code class="literal">hostaddr</code>
  91. parameter.
  92. </p><pre class="synopsis">
  93. char *PQhostaddr(const PGconn *conn);
  94. </pre><p>
  95. </p><p>
  96. <code class="function">PQhostaddr</code> returns <code class="symbol">NULL</code> if the
  97. <em class="parameter"><code>conn</code></em> argument is <code class="symbol">NULL</code>.
  98. Otherwise, if there is an error producing the host information
  99. (perhaps if the connection has not been fully established or
  100. there was an error), it returns an empty string.
  101. </p></dd><dt id="LIBPQ-PQPORT"><span class="term">
  102. <code class="function">PQport</code>
  103. <a id="id-1.7.3.9.4.6.6.1.2" class="indexterm"></a>
  104. </span></dt><dd><p>
  105. Returns the port of the active connection.
  106. </p><pre class="synopsis">
  107. char *PQport(const PGconn *conn);
  108. </pre><p>
  109. </p><p>
  110. If multiple ports were specified in the connection parameters,
  111. <code class="function">PQport</code> returns the port actually connected to.
  112. </p><p>
  113. <code class="function">PQport</code> returns <code class="symbol">NULL</code> if the
  114. <em class="parameter"><code>conn</code></em> argument is <code class="symbol">NULL</code>.
  115. Otherwise, if there is an error producing the port information (perhaps
  116. if the connection has not been fully established or there was an
  117. error), it returns an empty string.
  118. </p><p>
  119. If multiple ports were specified in the connection parameters, it is
  120. not possible to rely on the result of <code class="function">PQport</code> until
  121. the connection is established. The status of the connection can be
  122. checked using the function <code class="function">PQstatus</code>.
  123. </p></dd><dt id="LIBPQ-PQTTY"><span class="term">
  124. <code class="function">PQtty</code>
  125. <a id="id-1.7.3.9.4.6.7.1.2" class="indexterm"></a>
  126. </span></dt><dd><p>
  127. Returns the debug <acronym class="acronym">TTY</acronym> of the connection.
  128. (This is obsolete, since the server no longer pays attention
  129. to the <acronym class="acronym">TTY</acronym> setting, but the function remains
  130. for backward compatibility.)
  131. </p><pre class="synopsis">
  132. char *PQtty(const PGconn *conn);
  133. </pre><p>
  134. </p></dd><dt id="LIBPQ-PQOPTIONS"><span class="term">
  135. <code class="function">PQoptions</code>
  136. <a id="id-1.7.3.9.4.6.8.1.2" class="indexterm"></a>
  137. </span></dt><dd><p>
  138. Returns the command-line options passed in the connection request.
  139. </p><pre class="synopsis">
  140. char *PQoptions(const PGconn *conn);
  141. </pre><p>
  142. </p></dd></dl></div><p>
  143. </p><p>
  144. The following functions return status data that can change as operations
  145. are executed on the <code class="structname">PGconn</code> object.
  146. </p><div class="variablelist"><dl class="variablelist"><dt id="LIBPQ-PQSTATUS"><span class="term">
  147. <code class="function">PQstatus</code>
  148. <a id="id-1.7.3.9.5.2.1.1.2" class="indexterm"></a>
  149. </span></dt><dd><p>
  150. Returns the status of the connection.
  151. </p><pre class="synopsis">
  152. ConnStatusType PQstatus(const PGconn *conn);
  153. </pre><p>
  154. </p><p>
  155. The status can be one of a number of values. However, only two of
  156. these are seen outside of an asynchronous connection procedure:
  157. <code class="literal">CONNECTION_OK</code> and
  158. <code class="literal">CONNECTION_BAD</code>. A good connection to the database
  159. has the status <code class="literal">CONNECTION_OK</code>. A failed
  160. connection attempt is signaled by status
  161. <code class="literal">CONNECTION_BAD</code>. Ordinarily, an OK status will
  162. remain so until <code class="function">PQfinish</code>, but a communications
  163. failure might result in the status changing to
  164. <code class="literal">CONNECTION_BAD</code> prematurely. In that case the
  165. application could try to recover by calling
  166. <code class="function">PQreset</code>.
  167. </p><p>
  168. See the entry for <code class="function">PQconnectStartParams</code>, <code class="function">PQconnectStart</code>
  169. and <code class="function">PQconnectPoll</code> with regards to other status codes that
  170. might be returned.
  171. </p></dd><dt id="LIBPQ-PQTRANSACTIONSTATUS"><span class="term">
  172. <code class="function">PQtransactionStatus</code>
  173. <a id="id-1.7.3.9.5.2.2.1.2" class="indexterm"></a>
  174. </span></dt><dd><p>
  175. Returns the current in-transaction status of the server.
  176. </p><pre class="synopsis">
  177. PGTransactionStatusType PQtransactionStatus(const PGconn *conn);
  178. </pre><p>
  179. The status can be <code class="literal">PQTRANS_IDLE</code> (currently idle),
  180. <code class="literal">PQTRANS_ACTIVE</code> (a command is in progress),
  181. <code class="literal">PQTRANS_INTRANS</code> (idle, in a valid transaction block),
  182. or <code class="literal">PQTRANS_INERROR</code> (idle, in a failed transaction block).
  183. <code class="literal">PQTRANS_UNKNOWN</code> is reported if the connection is bad.
  184. <code class="literal">PQTRANS_ACTIVE</code> is reported only when a query
  185. has been sent to the server and not yet completed.
  186. </p></dd><dt id="LIBPQ-PQPARAMETERSTATUS"><span class="term">
  187. <code class="function">PQparameterStatus</code>
  188. <a id="id-1.7.3.9.5.2.3.1.2" class="indexterm"></a>
  189. </span></dt><dd><p>
  190. Looks up a current parameter setting of the server.
  191. </p><pre class="synopsis">
  192. const char *PQparameterStatus(const PGconn *conn, const char *paramName);
  193. </pre><p>
  194. Certain parameter values are reported by the server automatically at
  195. connection startup or whenever their values change.
  196. <code class="function">PQparameterStatus</code> can be used to interrogate these settings.
  197. It returns the current value of a parameter if known, or <code class="symbol">NULL</code>
  198. if the parameter is not known.
  199. </p><p>
  200. Parameters reported as of the current release include
  201. <code class="varname">server_version</code>,
  202. <code class="varname">server_encoding</code>,
  203. <code class="varname">client_encoding</code>,
  204. <code class="varname">application_name</code>,
  205. <code class="varname">is_superuser</code>,
  206. <code class="varname">session_authorization</code>,
  207. <code class="varname">DateStyle</code>,
  208. <code class="varname">IntervalStyle</code>,
  209. <code class="varname">TimeZone</code>,
  210. <code class="varname">integer_datetimes</code>, and
  211. <code class="varname">standard_conforming_strings</code>.
  212. (<code class="varname">server_encoding</code>, <code class="varname">TimeZone</code>, and
  213. <code class="varname">integer_datetimes</code> were not reported by releases before 8.0;
  214. <code class="varname">standard_conforming_strings</code> was not reported by releases
  215. before 8.1;
  216. <code class="varname">IntervalStyle</code> was not reported by releases before 8.4;
  217. <code class="varname">application_name</code> was not reported by releases before 9.0.)
  218. Note that
  219. <code class="varname">server_version</code>,
  220. <code class="varname">server_encoding</code> and
  221. <code class="varname">integer_datetimes</code>
  222. cannot change after startup.
  223. </p><p>
  224. Pre-3.0-protocol servers do not report parameter settings, but
  225. <span class="application">libpq</span> includes logic to obtain values for
  226. <code class="varname">server_version</code> and <code class="varname">client_encoding</code> anyway.
  227. Applications are encouraged to use <code class="function">PQparameterStatus</code>
  228. rather than <span class="foreignphrase"><em class="foreignphrase">ad hoc</em></span> code to determine these values.
  229. (Beware however that on a pre-3.0 connection, changing
  230. <code class="varname">client_encoding</code> via <code class="command">SET</code> after connection
  231. startup will not be reflected by <code class="function">PQparameterStatus</code>.)
  232. For <code class="varname">server_version</code>, see also
  233. <code class="function">PQserverVersion</code>, which returns the information in a
  234. numeric form that is much easier to compare against.
  235. </p><p>
  236. If no value for <code class="varname">standard_conforming_strings</code> is reported,
  237. applications can assume it is <code class="literal">off</code>, that is, backslashes
  238. are treated as escapes in string literals. Also, the presence of
  239. this parameter can be taken as an indication that the escape string
  240. syntax (<code class="literal">E'...'</code>) is accepted.
  241. </p><p>
  242. Although the returned pointer is declared <code class="literal">const</code>, it in fact
  243. points to mutable storage associated with the <code class="literal">PGconn</code> structure.
  244. It is unwise to assume the pointer will remain valid across queries.
  245. </p></dd><dt id="LIBPQ-PQPROTOCOLVERSION"><span class="term">
  246. <code class="function">PQprotocolVersion</code>
  247. <a id="id-1.7.3.9.5.2.4.1.2" class="indexterm"></a>
  248. </span></dt><dd><p>
  249. Interrogates the frontend/backend protocol being used.
  250. </p><pre class="synopsis">
  251. int PQprotocolVersion(const PGconn *conn);
  252. </pre><p>
  253. Applications might wish to use this function to determine whether certain
  254. features are supported. Currently, the possible values are 2 (2.0
  255. protocol), 3 (3.0 protocol), or zero (connection bad). The
  256. protocol version will
  257. not change after connection startup is complete, but it could
  258. theoretically change during a connection reset. The 3.0 protocol
  259. will normally be used when communicating with
  260. <span class="productname">PostgreSQL</span> 7.4 or later servers; pre-7.4 servers
  261. support only protocol 2.0. (Protocol 1.0 is obsolete and not
  262. supported by <span class="application">libpq</span>.)
  263. </p></dd><dt id="LIBPQ-PQSERVERVERSION"><span class="term">
  264. <code class="function">PQserverVersion</code>
  265. <a id="id-1.7.3.9.5.2.5.1.2" class="indexterm"></a>
  266. </span></dt><dd><p>
  267. Returns an integer representing the server version.
  268. </p><pre class="synopsis">
  269. int PQserverVersion(const PGconn *conn);
  270. </pre><p>
  271. </p><p>
  272. Applications might use this function to determine the version of the
  273. database server they are connected to. The result is formed by
  274. multiplying the server's major version number by 10000 and adding
  275. the minor version number. For example, version 10.1 will be
  276. returned as 100001, and version 11.0 will be returned as 110000.
  277. Zero is returned if the connection is bad.
  278. </p><p>
  279. Prior to major version 10, <span class="productname">PostgreSQL</span> used
  280. three-part version numbers in which the first two parts together
  281. represented the major version. For those
  282. versions, <code class="function">PQserverVersion</code> uses two digits for each
  283. part; for example version 9.1.5 will be returned as 90105, and
  284. version 9.2.0 will be returned as 90200.
  285. </p><p>
  286. Therefore, for purposes of determining feature compatibility,
  287. applications should divide the result of <code class="function">PQserverVersion</code>
  288. by 100 not 10000 to determine a logical major version number.
  289. In all release series, only the last two digits differ between
  290. minor releases (bug-fix releases).
  291. </p></dd><dt id="LIBPQ-PQERRORMESSAGE"><span class="term">
  292. <code class="function">PQerrorMessage</code>
  293. <a id="id-1.7.3.9.5.2.6.1.2" class="indexterm"></a>
  294. </span></dt><dd><p>
  295. <a id="id-1.7.3.9.5.2.6.2.1.1" class="indexterm"></a> Returns the error message
  296. most recently generated by an operation on the connection.
  297. </p><pre class="synopsis">
  298. char *PQerrorMessage(const PGconn *conn);
  299. </pre><p>
  300. </p><p>
  301. Nearly all <span class="application">libpq</span> functions will set a message for
  302. <code class="function">PQerrorMessage</code> if they fail. Note that by
  303. <span class="application">libpq</span> convention, a nonempty
  304. <code class="function">PQerrorMessage</code> result can consist of multiple lines,
  305. and will include a trailing newline. The caller should not free
  306. the result directly. It will be freed when the associated
  307. <code class="structname">PGconn</code> handle is passed to
  308. <code class="function">PQfinish</code>. The result string should not be
  309. expected to remain the same across operations on the
  310. <code class="literal">PGconn</code> structure.
  311. </p></dd><dt id="LIBPQ-PQSOCKET"><span class="term"><code class="function">PQsocket</code><a id="id-1.7.3.9.5.2.7.1.2" class="indexterm"></a></span></dt><dd><p>
  312. Obtains the file descriptor number of the connection socket to
  313. the server. A valid descriptor will be greater than or equal
  314. to 0; a result of -1 indicates that no server connection is
  315. currently open. (This will not change during normal operation,
  316. but could change during connection setup or reset.)
  317. </p><pre class="synopsis">
  318. int PQsocket(const PGconn *conn);
  319. </pre><p>
  320. </p></dd><dt id="LIBPQ-PQBACKENDPID"><span class="term"><code class="function">PQbackendPID</code><a id="id-1.7.3.9.5.2.8.1.2" class="indexterm"></a></span></dt><dd><p>
  321. Returns the process <acronym class="acronym">ID</acronym> (PID)<a id="id-1.7.3.9.5.2.8.2.1.2" class="indexterm"></a>
  322. of the backend process handling this connection.
  323. </p><pre class="synopsis">
  324. int PQbackendPID(const PGconn *conn);
  325. </pre><p>
  326. </p><p>
  327. The backend <acronym class="acronym">PID</acronym> is useful for debugging
  328. purposes and for comparison to <code class="command">NOTIFY</code>
  329. messages (which include the <acronym class="acronym">PID</acronym> of the
  330. notifying backend process). Note that the
  331. <acronym class="acronym">PID</acronym> belongs to a process executing on the
  332. database server host, not the local host!
  333. </p></dd><dt id="LIBPQ-PQCONNECTIONNEEDSPASSWORD"><span class="term"><code class="function">PQconnectionNeedsPassword</code><a id="id-1.7.3.9.5.2.9.1.2" class="indexterm"></a></span></dt><dd><p>
  334. Returns true (1) if the connection authentication method
  335. required a password, but none was available.
  336. Returns false (0) if not.
  337. </p><pre class="synopsis">
  338. int PQconnectionNeedsPassword(const PGconn *conn);
  339. </pre><p>
  340. </p><p>
  341. This function can be applied after a failed connection attempt
  342. to decide whether to prompt the user for a password.
  343. </p></dd><dt id="LIBPQ-PQCONNECTIONUSEDPASSWORD"><span class="term"><code class="function">PQconnectionUsedPassword</code><a id="id-1.7.3.9.5.2.10.1.2" class="indexterm"></a></span></dt><dd><p>
  344. Returns true (1) if the connection authentication method
  345. used a password. Returns false (0) if not.
  346. </p><pre class="synopsis">
  347. int PQconnectionUsedPassword(const PGconn *conn);
  348. </pre><p>
  349. </p><p>
  350. This function can be applied after either a failed or successful
  351. connection attempt to detect whether the server demanded a password.
  352. </p></dd></dl></div><p>
  353. </p><p>
  354. The following functions return information related to SSL. This information
  355. usually doesn't change after a connection is established.
  356. </p><div class="variablelist"><dl class="variablelist"><dt id="LIBPQ-PQSSLINUSE"><span class="term"><code class="function">PQsslInUse</code><a id="id-1.7.3.9.6.1.1.1.2" class="indexterm"></a></span></dt><dd><p>
  357. Returns true (1) if the connection uses SSL, false (0) if not.
  358. </p><pre class="synopsis">
  359. int PQsslInUse(const PGconn *conn);
  360. </pre><p>
  361. </p></dd><dt id="LIBPQ-PQSSLATTRIBUTE"><span class="term"><code class="function">PQsslAttribute</code><a id="id-1.7.3.9.6.1.2.1.2" class="indexterm"></a></span></dt><dd><p>
  362. Returns SSL-related information about the connection.
  363. </p><pre class="synopsis">
  364. const char *PQsslAttribute(const PGconn *conn, const char *attribute_name);
  365. </pre><p>
  366. </p><p>
  367. The list of available attributes varies depending on the SSL library
  368. being used, and the type of connection. If an attribute is not
  369. available, returns NULL.
  370. </p><p>
  371. The following attributes are commonly available:
  372. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">library</code></span></dt><dd><p>
  373. Name of the SSL implementation in use. (Currently, only
  374. <code class="literal">"OpenSSL"</code> is implemented)
  375. </p></dd><dt><span class="term"><code class="literal">protocol</code></span></dt><dd><p>
  376. SSL/TLS version in use. Common values
  377. are <code class="literal">"TLSv1"</code>, <code class="literal">"TLSv1.1"</code>
  378. and <code class="literal">"TLSv1.2"</code>, but an implementation may
  379. return other strings if some other protocol is used.
  380. </p></dd><dt><span class="term"><code class="literal">key_bits</code></span></dt><dd><p>
  381. Number of key bits used by the encryption algorithm.
  382. </p></dd><dt><span class="term"><code class="literal">cipher</code></span></dt><dd><p>
  383. A short name of the ciphersuite used, e.g.
  384. <code class="literal">"DHE-RSA-DES-CBC3-SHA"</code>. The names are specific
  385. to each SSL implementation.
  386. </p></dd><dt><span class="term"><code class="literal">compression</code></span></dt><dd><p>
  387. If SSL compression is in use, returns the name of the compression
  388. algorithm, or "on" if compression is used but the algorithm is
  389. not known. If compression is not in use, returns "off".
  390. </p></dd></dl></div><p>
  391. </p></dd><dt id="LIBPQ-PQSSLATTRIBUTENAMES"><span class="term"><code class="function">PQsslAttributeNames</code><a id="id-1.7.3.9.6.1.3.1.2" class="indexterm"></a></span></dt><dd><p>
  392. Return an array of SSL attribute names available. The array is terminated by a NULL pointer.
  393. </p><pre class="synopsis">
  394. const char * const * PQsslAttributeNames(const PGconn *conn);
  395. </pre><p>
  396. </p></dd><dt id="LIBPQ-PQSSLSTRUCT"><span class="term"><code class="function">PQsslStruct</code><a id="id-1.7.3.9.6.1.4.1.2" class="indexterm"></a></span></dt><dd><p>
  397. Return a pointer to an SSL-implementation-specific object describing
  398. the connection.
  399. </p><pre class="synopsis">
  400. void *PQsslStruct(const PGconn *conn, const char *struct_name);
  401. </pre><p>
  402. </p><p>
  403. The struct(s) available depend on the SSL implementation in use.
  404. For OpenSSL, there is one struct, available under the name "OpenSSL",
  405. and it returns a pointer to the OpenSSL <code class="literal">SSL</code> struct.
  406. To use this function, code along the following lines could be used:
  407. </p><pre class="programlisting">
  408. #include &lt;libpq-fe.h&gt;
  409. #include &lt;openssl/ssl.h&gt;
  410. ...
  411. SSL *ssl;
  412. dbconn = PQconnectdb(...);
  413. ...
  414. ssl = PQsslStruct(dbconn, "OpenSSL");
  415. if (ssl)
  416. {
  417. /* use OpenSSL functions to access ssl */
  418. }
  419. </pre><p>
  420. </p><p>
  421. This structure can be used to verify encryption levels, check server
  422. certificates, and more. Refer to the <span class="productname">OpenSSL</span>
  423. documentation for information about this structure.
  424. </p></dd><dt id="LIBPQ-PQGETSSL"><span class="term"><code class="function">PQgetssl</code><a id="id-1.7.3.9.6.1.5.1.2" class="indexterm"></a></span></dt><dd><p>
  425. <a id="id-1.7.3.9.6.1.5.2.1.1" class="indexterm"></a>
  426. Returns the SSL structure used in the connection, or null
  427. if SSL is not in use.
  428. </p><pre class="synopsis">
  429. void *PQgetssl(const PGconn *conn);
  430. </pre><p>
  431. </p><p>
  432. This function is equivalent to <code class="literal">PQsslStruct(conn, "OpenSSL")</code>. It should
  433. not be used in new applications, because the returned struct is
  434. specific to OpenSSL and will not be available if another SSL
  435. implementation is used. To check if a connection uses SSL, call
  436. <code class="function">PQsslInUse</code> instead, and for more details about the
  437. connection, use <code class="function">PQsslAttribute</code>.
  438. </p></dd></dl></div><p>
  439. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="libpq-connect.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="libpq.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="libpq-exec.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">33.1. Database Connection Control Functions </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 33.3. Command Execution Functions</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1