PageRenderTime 75ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/ruby/gems/1.8/gems/pg-0.8.0/doc/postgres.html

https://github.com/tjgillies/gems
HTML | 278 lines | 263 code | 1 blank | 14 comment | 0 complexity | 6a9db83268d013ea5b69274c0379019c MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <meta http-equiv="Content-Style-Type" content="text/css">
  7. <meta name="Keywords" lang="en" content="Ruby PostgreSQL">
  8. <link rev="made" href="mailto:noborus@netlab.jp">
  9. <style type="text/css">
  10. <!--
  11. body {
  12. background-color: white;
  13. color: black;
  14. }
  15. address { text-align: right }
  16. div.lastmodifed { text-align: right }
  17. div.language { text-align: right }
  18. pre {
  19. white-space: pre;
  20. background-color: antiquewhite;
  21. border: inset thin;
  22. }
  23. -->
  24. </style>
  25. <title>Postgres reference</title>
  26. </head>
  27. <body>
  28. <div class = "language">
  29. [English | <a href="postgres.jp.html">Japanese</a>]
  30. </div>
  31. <h1><a name="reference">Postgres reference</a></h1>
  32. <div class = "lastmodifed">
  33. Last update: Sun, 4 Mar 2001 15:40:08 +0000
  34. </div>
  35. <hr>
  36. <div>
  37. <h2><a name="PGconn">PGconn</a></h2>
  38. <p>
  39. The class to access PostgreSQL database. All other functionality of libpq
  40. save the large object to a file.
  41. </p>
  42. <p>
  43. For example, to send query to the database on the localhost.
  44. </p>
  45. <pre>
  46. require &quot;postgres&quot;
  47. conn = PGconn.connect("localhost", 5432, &quot;&quot;, &quot;&quot;, &quot;test1&quot;)
  48. # or: conn = PGconn.open('dbname=test1')
  49. res = conn.exec(&quot;select * from a;&quot;)
  50. </pre>
  51. <h3>super class:</h3>
  52. <code>Object</code>
  53. <h3>class methods:</h3>
  54. <p>
  55. <a name="PGconn.connect"><code>connect(<var>pghost</var>,
  56. <var>pgport</var>, <var>pgoptions</var>,
  57. <var>pgtty</var>, <var>dbname</var>, <var>login</var>,
  58. <var>passwd</var>)</code></a>
  59. <a name="PGconn.new"><code>new(<var>pghost</var>,
  60. <var>pgport</var>, <var>pgoptions</var>,
  61. <var>pgtty</var>, <var>dbname</var>, <var>login</var>,
  62. <var>passwd</var>)</code></a>
  63. <a name="PGconn.open"><code>open(<var>string</var>)</code></a>
  64. </p>
  65. <dl>
  66. <dt>Connect to the PostgreSQL server. Options are:</dt>
  67. <dd><var>pghost</var> : Server hostname(string)
  68. <dd><var>pgport</var> : Server port number(integer)
  69. <dd><var>pgoptions</var> : backend options(string)
  70. <dd><var>pgtty</var> : tty to print backend debug message(string)
  71. <dd><var>dbname</var> : connecting database name(string)
  72. <dd><var>login</var> : login user name(string)
  73. <dd><var>passwd</var> : login password(string)
  74. <dt>Options in string format (separated by whitespace) are:</dt>
  75. <dd><var>host=name</var> : Server hostname(string) (defaults to localhost)
  76. <dd><var>hostaddr=addr</var> : Server host IP address(string)
  77. <dd><var>port=number</var> : Server port number(integer) (default: 5432)
  78. <dd><var>options=string</var> : backend options(string) (sent to server, not well explained)
  79. <dd><var>tty=anything</var> : ignored, used to be debug TTY(string)
  80. <dd><var>dbname=name</var> : connecting database name(string) (default: your username)
  81. <dd><var>user=username</var> : login user name(string) (default: your username)
  82. <dd><var>password=censored</var> : login password(string)
  83. <dd><var>sslmode=mode</var> : how to treat SSL(string) (one of disable, allow, prefer, require)
  84. <dd><var>service=name</var> : service name in pg_service.conf(string)
  85. <dd><var>connect_timeout=seconds</var> : how long to wait for a connection(integer) (0 means forever)
  86. </dl>
  87. <p>On failure, it raises <code>PGError</code> exception.</p>
  88. <h3>methods:</h3>
  89. <dl>
  90. <dt><a name="db"><code>db</code></a>
  91. <dd>Returns the connected database name.
  92. <dt><a name="host"><code>host</code></a>
  93. <dd>Returns the connected server name.
  94. <dt><a name="user"><code>user</code></a>
  95. <dd>Returns the authenticated user name.
  96. <dt><a name="options"><code>options</code></a>
  97. <dd>Returns backend option string.
  98. <dt><a name="port"><code>port</code></a>
  99. <dd>Returns the connected server port number.
  100. <dt><a name="tty"><code>tty</code></a>
  101. <dd>Returns the connected pgtty.
  102. <dt><a name="error"><code>error</code></a>
  103. <dd>Returns the error message about connection.
  104. <dt> <a name="finish"><code>finish</code></a>
  105. <dt> <a name="close"><code>close</code></a>
  106. <dd>Closes the backend connection.
  107. <dt><a name="reset"><code>reset</code></a>
  108. <dd>Resets the backend connection. This method closes the backend
  109. connection and tries to re-connect.
  110. <dt><a name="trace"><code>trace(<var>port</var>)</code></a>
  111. <dd>Enables tracing message passing between backend. The trace
  112. message will be written to the port object, which is the
  113. instance of the class File.
  114. <dt><a name="untrace"><code>untrace</code></a>
  115. <dd>Disables the message tracing.
  116. <dt><a name="exec"><code>exec(<var>sql</var>)</code></a>
  117. <dd>Sends SQL query request specified by <var>sql</var> to the
  118. PostgreSQL. Returns the <a href="#PGresult">PGresult</a>
  119. instance on success. On failure, it raises <code>PGError</code>
  120. exception.
  121. <dt><a name="query"><code>query(<var>sql</var>)</code></a>
  122. <dd>Sends SQL query request specified by <var>sql</var> to the
  123. PostgreSQL.Returns an Array as the resulting tuple on success.
  124. On failure, it returns nil, and error detail can be obtained
  125. by error.
  126. <dt><a name="async_exec"><code>async_exec(<var>sql</var>)</code></a>
  127. <dd>Sends SQL asynchronous query request specified by <var>sql</var>
  128. to the PostgreSQL. Returns the <a href="#PGresult">PGresult</a>
  129. instance on success. On failure, it raises <code>PGError</code>
  130. exception.
  131. <dt><a name="async_query"><code>async_query(<var>sql</var>)</code></a>
  132. <dd>Sends SQL asynchronous query request specified by <var>sql</var>
  133. to the PostgreSQL.Returns an Array as the resulting tuple on
  134. success. On failure, it returns nil, and error detail can be
  135. obtained by error.
  136. <dt><a name="get_notify"><code>get_notify</code></a>
  137. <dd>Returns the array of the unprocessed notifiers.
  138. If there is no unprocessed notifier, it returns nil.
  139. <dt><a name="insert_table"><code>insert_table(<var>table</var>,
  140. <var>array</var>)</code></a>
  141. <dd>Inserts contents of the <var>array</var> into the
  142. <var>table</var>.
  143. <dt><a name="getline"><code>getline</code></a>
  144. <dd>Reads a line from the backend server into internal buffer.
  145. Returns nil for EOF, 0 for success, 1 for buffer overflowed.
  146. You need to ensure single &quot;.&quot; from backend to confirm
  147. transmission completion. The sample program <a href="../sample/psql.rb">psql.rb</a>
  148. treats this copy protocol right.
  149. <dt><a name="putline"><code>putline(<var>string</var>)</code></a>
  150. <dd>Sends the <var>string</var> to the backend server.
  151. Users must send a single &quot;.&quot; to denote the end of data transmission.
  152. <dt><a name="endcopy"><code>endcopy</code></a>
  153. <dd>Waits until the backend completes the copying. You should call
  154. this method after putline, or getline.Returns nil on success,
  155. raises an exception otherwise.
  156. <dt><a name="set_client_encoding"><code>set_client_encoding</code></a>
  157. <dd>Set client encoding(String).
  158. <dt><a name="client_encoding"><code>client_encoding</code></a>
  159. <dd>Returns client encoding(String).
  160. <dt><a name="set_notice_processor"><code>set_notice_processor(proc)</code></a>
  161. <dd>Control reporting of notice and warning messages generated by the
  162. backend server (with Proc or anything else responding to :call).
  163. Pass nil to disable processing of the messages.
  164. <dt><a name="lo_import"><code>lo_import(<var>file</var>)</code></a>
  165. <dd>Import a <var>file</var> to a large object. Return the <a href="#PGlarge">PGlarge</a> instance on success. On failure, it raises <code>PGError</code> exception.
  166. <dt><a name="lo_export"><code>lo_export(<var>oid</var>, <var>file</var>)</code></a>
  167. <dd>Save a large object of oid to a <var>file</var>.
  168. <dt><a name="lo_create"><code>lo_create([<var>mode</var>])</code></a>
  169. <dd>Return the <a href="#PGlarge">PGlarge</a> instance on success. On failure, it raises <code>PGError</code> exception.
  170. <dt><a name="lo_open"><code>lo_open(<var>oid</var>, [<var>mode</var>])</code></a>
  171. <dd>Open a large object of oid. Return the <a href="#PGlarge">PGlarge</a> instance on success. The mode argument specifies the mode for the opened large object, which is either <var>&quot;INV_READ&quot;</var>, or <var>&quot;INV_WRITE&quot;</var>. If mode On failure, it raises <code>PGError</code> exception. If mode omitted, the default is <var>&quot;INV_READ&quot;</var>
  172. <dt><a name="lo_unlink"><code>lo_unlink(<var>oid</var>)</code></a>
  173. <dd>Unlink (deletes) the postgres large object of oid.
  174. </dl>
  175. </div>
  176. <hr>
  177. <div>
  178. <h2><a name="PGresult">PGresult</a></h2>
  179. <P>
  180. The class to represent the query result tuples. The object of this
  181. class is created as the result of every query. You may need to invoke
  182. clear method for the finished object for better memory performance.
  183. </P>
  184. <h3>super class:</h3>
  185. <p>
  186. <code>Object</code>
  187. </p>
  188. <h2>methods:</h2>
  189. <dl>
  190. <dt><a name="status"><code>status</code></a>
  191. <dd><dl>
  192. <dt>Returns the status of the query. The status value is
  193. either:
  194. <dd>EMPTY_QUERY
  195. <dd>COMMAND_OK
  196. <dd>TUPLES_OK
  197. <dd>COPY_OUT
  198. <dd>COPY_IN
  199. </dl>
  200. <dt><a name="result"><code>result</code></a>
  201. <dd>Returns the query result tuple in the array.
  202. <dt><a name="fields"><code>fields</code></a>
  203. <dd>Returns the array of the fields of the query result.
  204. <dt><a name="num_tuples"><code>num_tuples</code></a>
  205. <dd>Returns the number of tuples of the query result.
  206. <dt><a name="num_fields"><code>num_fields</code></a>
  207. <dd>Returns the number of fields of the query result.
  208. <dt><a name="fieldname"><code>fieldname(<var>index</var>)</code></a>
  209. <dd>Returns the field name corresponding field index.
  210. <dt><a name="fieldnum"><code>fieldnum(<var>name</var>)</code></a>
  211. <dd>Returns the index of the <var>name</var>ed field.
  212. <dt><a name="type"><code>type(<var>index</var>)</code></a>
  213. <dd>Returns the integer corresponding the type of the field.
  214. The field indicator starts from zero.
  215. <dt><a name="size"><code>size(<var>index</var>)</code></a>
  216. <dd>Returns the size of the field in bytes.
  217. Returns <code>-1</code> if the field is variable sized.
  218. <dt><a name="getvalue"><code>getvalue(<var>tup_num, field_num</var>)
  219. </code></a>
  220. <dd>Returns the field value.
  221. <dt><a name="getlength"><code>getlength(<var>tup_num, field_num</var>)
  222. </code></a>
  223. <dd>Returns the length of the field in bytes.
  224. <dt><a name="cmdstatus"><code>cmdtuples</code></a>
  225. <dd>the number of tuples (rows) affected by the SQL command.
  226. <dt><a name="cmdstatus"><code>cmdstatus</code></a>
  227. <dd>Returns the status string of the last query command.
  228. <dt><a name="oid"><code>oid</code></a>
  229. <dd>Returns the oid of the inserted row, or <code>nil</code> if
  230. the last statement was not an <code>INSERT</code>
  231. <dt><a name="clear"><code>clear</code></a>
  232. <dd>Clears the <a href="#PGresult">PGresult</a> object as the result
  233. of the query.
  234. </dl>
  235. </div>
  236. <hr>
  237. <div>
  238. <h2><a name="PGlarge">PGlarge</a></h2>
  239. <P>
  240. The class to access large objects. The object of this class is created as the
  241. result of <a href="#lo_import">lo_import</a>, <a href="#lo_create">lo_create</a>, and <a href="#lo_open">lo_open</a>.
  242. </P>
  243. <h3>super class:</h3>
  244. <p>
  245. <code>Object</code>
  246. </p>
  247. <h2>methods:</h2>
  248. <dl>
  249. <dt><a name="open"><code>open([<var>mode</var>])</code></a>
  250. <dd>Open a large object. The mode argument specifies the mode for the opened large object, which is either <var>&quot;INV_READ&quot;</var>,<var>&quot;INV_READ&quot;</var>.
  251. <dt><a name="close"><code>close</code></a>
  252. <dd>Close a large object. Closed when they are garbage-collected.
  253. <dt><a name="read"><code>read([<var>length</var>])</code></a>
  254. <dd>Attempts to read <var>length</var> bytes from large object. If no <var>length</var> given, reads all data.
  255. <dt><a name="write"><code>write(<var>str</var>)</code></a>
  256. <dd>Write the string to the large object. Return the number of bytes written.
  257. <dt><a name="seek"><code>seek(<var>offset</var>, <var>whence</var>)</code></a>
  258. <dd>Move the large object pointer to the <var>offset</var>. The value for <var>whence</var> are SEEK_SET, SEEK_CUR, and SEEK_END.Or it is 0,1,2.
  259. <dt><a name="tell"><code>tell</code></a>
  260. <dd>Return the current position of the large object pointer.
  261. <dt><a name="unlink"><code>unlink</code></a>
  262. <dd>Delete large object.
  263. <dt><a name="oid"><code>oid</code></a>
  264. <dd>Return the large object oid.
  265. <dt><a name="size"><code>size</code></a>
  266. <dd>Return the size of large object.
  267. <dt><a name="export"><code>export(<var>file</var>)</code></a>
  268. <dd>Save a large object of oid to a <var>file</var>.
  269. </dl>
  270. </div>
  271. <hr>
  272. <address>
  273. mailto:
  274. <a href="mailto:noborus@netlab.jp">Noboru Saitou</a>
  275. </address>
  276. </body>
  277. </html>