home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / oraperl2.zip / oraperl.doc < prev    next >
Text File  |  1993-07-01  |  9KB  |  311 lines

  1.  
  2. .ce 2
  3. \fBO R A P E R L\fP
  4. _____________
  5.  
  6.  
  7. This document describes the implementation of \fBOraperl\fP,
  8. an extension of the \fIPerl\fP language
  9. capable of accessing \fIOracle\fP databases.
  10.  
  11. \fIPerl\fP provides a facility known as \fIusersubs\fP,
  12. which allows user\-specified subroutines
  13. to be linked into a \fIPerl\fP interpreter.
  14. \fIOracle\fP provides \fIOCI\fP, the \fIOracle Call Interface\fP,
  15. which is a library of subroutines which may be called from C programs.
  16. \fBOraperl\fP is a combination of these two features.
  17.  
  18.  
  19. .ce 2
  20. \fBInterface\fP
  21. _________
  22.  
  23. The C language interface of the \fIOCI\fP is not particularly friendly.
  24. A number of functions accept redundant parameters,
  25. in order to be useful in a wide range of programming languages.
  26. The interface is not really suitable for \fIPerl\fP
  27. because it requires fixed addresses to be specified for receipt of data.
  28. A new interface was therefore created for \fBOraperl\fP.
  29.  
  30. The interface follows the idiom of the following seven tasks:
  31.  
  32. .in +5
  33. .ta .4i 4.4i
  34. .nf
  35. \fBTask        Interface\fP
  36.  
  37. \fB1\fP    log in to the database    \fIora_login\fP
  38. \fB2\fP    open a stream for an SQL statement    \fIora_open\fP
  39. \fB3\fP    modify the statement    \fIora_bind\fP
  40. \fB4\fP    get the data    \fIora_fetch\fP
  41. \fB5\fP    close the stream    \fIora_close\fP
  42. \fB6\fP    execute an SQL statement    \fIora_do\fP
  43. \fB7\fP    log off of the database    \fIora_logoff\fP
  44. .fi
  45. .in -5
  46.  
  47.  
  48. .ce 2
  49. \fBCursors\fP
  50. _______
  51.  
  52. The \fIOCI\fP communicates with the calling process via \fIcursor\fPs. 
  53. One cursor is required for each login (together with a host data area),
  54. and one for each SQL statement executed.
  55. To save the user the task of allocating cursors,
  56. \fBOraperl\fP allocates them automatically,
  57. and returns an identifier to the user
  58. to be supplied as a parameter to future function calls.
  59.  
  60. A set of functions (not directly accessible to the user)
  61. deals with the allocation and release of cursors.
  62.  
  63.  
  64. .ce 2
  65. \fBInformation from the Database\fP
  66. _____________________________
  67.  
  68. Each set of data retrieved from the database
  69. is returned to the user as an array.
  70. A program may determine the number of fields to be returned
  71. without actually accessing any data.
  72. This may be useful
  73. in a program which allows queries to be entered interactively.
  74.  
  75.  
  76. .ce 2
  77. \fBPublic Function Descriptions\fP
  78. ____________________________
  79.  
  80. Return values from functions are in the form of strings,
  81. with a null string being returned for an error.
  82.  
  83.  
  84. \fBora_version\fP
  85.  
  86. This function has nothing to do with the data interface;
  87. it simply prints the Oraperl version and copyright information,
  88. similar to Perl's \fB\-v\fP flag.
  89. It does not return a value.
  90.  
  91.  
  92. \fBora_login(database, name, password)\fP
  93.  
  94. Requests a cursor
  95. for use as a \fILogin Data Area\fP (\fIlda\fP)
  96. and then calls \fBOCI\ orlon\fP
  97. to log the user into the given \fIOracle\fP database
  98. under the name and password specified.
  99. It returns the address of the \fIlda\fP.
  100.  
  101.  
  102. \fBora_open(lda, stmt)\fP
  103.  
  104. Requests a cursor (\fIcsr\fP)
  105. and calls \fBOCI\ oopen\fP to connect it the the specified \fIlda\fP.
  106. It then calls \fBOCI\ osql3\fP to attach the SQL statement.
  107. If the statement does not contain any substitution variables,
  108. \fIora_open\fP calls \fBOCI\ oexec\fP to instruct \fIOracle\fP to execute it.
  109.  
  110. If these three steps succeed,
  111. \fBora_open\fP then makes successive calls to \fBOCI\ odsc\fP
  112. to determine the number and size of the fields which will be returned.
  113. It allocates memory for these fields within \fIcsr\fP
  114. and attaches them to the cursor using \fBOCI\ odefin\fP.
  115. It also attaches a return code field to each item,
  116. so that NULL data returns can be caught and treated sensibly.
  117. It returns the address of the \fIcsr\fP.
  118.  
  119.  
  120. \fBora_bind(csr, var, ...)\fP
  121.  
  122. Binds the specified \fIvar\fPs to the substitution variables
  123. in the SQL statement identified by \fIcsr\fP
  124. and calls \fBOCI\ oexec\fP to execute the resulting statement.
  125. Assumes that the substitution variables are \fB:1\fP, \fB:2\fP, \fB:3\fP, etc
  126. in the order that they appear in the \fBora_bind\fP call.
  127.  
  128.  
  129. \fBora_fetch(csr)\fP
  130.  
  131. In an array context,
  132. calls \fBOCI\ ofetch\fP with the specified \fIcsr\fP
  133. and returns an array with one element for each field returned.
  134. If any field in the database was NULL,
  135. and empty string will be returned.
  136. It is not possible to distinguish between empty and NULL fields.
  137. In a scalar context,
  138. returns the number of fields available from the query.
  139.  
  140.  
  141. \fBora_close(csr)\fP
  142.  
  143. Calls \fBOCI\ oclose\fP to release the \fIcsr\fP
  144. and then frees the memory allocated to it.
  145. The string \fBOK\fP is returned.
  146.  
  147.  
  148. \fBora_do(lda, stmt)\fP
  149.  
  150. This is equivalent to an \fBora_open\fP
  151. immediately followed by an \fBora_close\fP
  152. (in fact, that is how it is implemented)
  153. except that the user does not have to keep track
  154. of the \fIcsr\fP used.
  155. It is suitable for statements which do not return any data
  156. and which do not contain any substitution variables.
  157.  
  158.  
  159. \fBora_logoff(lda)\fP
  160.  
  161. Calls \fBOCI\ ologoff\fP to log off of \fIOracle\fP
  162. and then frees the memory allocated to \fIlda\fP.
  163. The string \fBOK\fP is returned.
  164.  
  165.  
  166. .ce 2
  167. \fBPublic Variable Descriptions\fP
  168. ____________________________
  169.  
  170. The variables are read\-only,
  171. since they refer to the status of \fIOracle\fP commands.
  172.  
  173.  
  174. \fB$ora_errno\fP
  175.  
  176. Contains the error number from the last \fBOCI\fP function executed.
  177.  
  178.  
  179. \fB$ora_errstr\fP
  180.  
  181. Contains the error message corresponding to the current value of $errno.
  182.  
  183.  
  184. .ce 2
  185. \fBPrivate Function Descriptions\fP
  186. _____________________________
  187.  
  188.  
  189. Functions private to \fBOraperl\fP
  190. deal with the allocation and release of cursors.
  191.  
  192. The definition of a cursor is extended from the \fIOracle\fP definition
  193. to include an \fIhda\fP (\fIHost Data Area\fP),
  194. space for the data returned from the database
  195. and space for return codes for each data field.
  196. Thus, \fIcsr\fPs and \fIlda\fPs have the same structure internally.
  197. All the cursors are held on a singly\-linked list.
  198.  
  199.  
  200. \fBora_free_data(csr)\fP
  201.  
  202. Releases the memory space reserved for data for the specified \fIcsr\fP.
  203.  
  204.  
  205. \fBora_getcursor()\fP
  206.  
  207. Allocates a new cursor and adds it to the list.
  208. It returns the address of the cursor.
  209.  
  210.  
  211. \fBora_getlda()\fP
  212.  
  213. Calls \fBora_getcursor\fP to allocate a new cursor,
  214. then allocates the \fIhda\fP
  215. to allow it to be used for logging into \fIOracle\fP.
  216. It returns the address of the cursor.
  217.  
  218.  
  219. \fBora_dropcursor(csr)\fP
  220.  
  221. Releases the memory associated with the specified cursor,
  222. and removes it from the list.
  223. It returns 1 if the cursor was successfully dropped,
  224. 0 otherwise.
  225.  
  226.  
  227. \fBora_droplda(lda)\fP
  228.  
  229. Calls \fBora_dropcursor\fP to release the cursor
  230. and passes back the return value.
  231. Only exists for completeness,
  232. but could be extended to verify that what it is dropping is an \fIlda\fP.
  233.  
  234.  
  235. \fBora_findcursor(csr)\fP
  236.  
  237. Searches the list looking for the specified \fIcsr\fP.
  238. It returns 1 if it was found, 0 otherwise.
  239.  
  240.  
  241. \fBcheck_csr(csr)\fP
  242.  
  243. Checks whether the address supplied corresponds to a valid data cursor
  244. (i.e. it exists in the list,
  245. its \fIhda\fP is not allocated,
  246. its \fIdata\fP area is allocated).
  247. It returns 1 for a valid cursor, 0 otherwise.
  248.  
  249.  
  250. \fBcheck_lda(lda)\fP
  251.  
  252. Checks whether the address supplied corresponds to a valid login cursor
  253. (i.e. it exists in the list,
  254. its \fIhda\fP is allocated,
  255. its \fIdata\fP area is not allocated).
  256. It returns 1 for a valid cursor, 0 otherwise.
  257.  
  258.  
  259. .ce 2
  260. \fBDebugging\fP
  261. _________
  262.  
  263. \fIPerl\fP includes support for runtime debugging via a \fB\-D\fP option
  264. which sets debugging flags.
  265. \fIOraperl\fP also allows runtime debugging by a separate but related mechanism.
  266.  
  267. Debugging is flag based.
  268. The following flags have significance for \fIOraperl\fP:
  269.  
  270. .in +5
  271. .ta 5
  272. .ti -5
  273. \0\08    \c
  274. Reports entry and exit to \fIOraperl\fP functions,
  275. including internal functions not directly available to \fIOraperl\fP scripts.
  276.  
  277. .ti -5
  278. \032    \c
  279. Reports conversions between strings and numerics.
  280. In the case of Oraperl, this only concerns the translation of cursor addresses
  281. into strings, and vice versa,
  282. since the data translations are performed by the Oracle software.
  283. However, it could be useful in tracing obscure bugs,
  284. if the \fIlda\fPs or \fIcsr\fPs returned by \fIOraperl\fP are unusable.
  285.  
  286. .ti -5
  287. 128    \c
  288. Reports use of \fImalloc\fP and \fIfree\fP
  289. to obtain cursors, login data areas, etc.
  290. .in -5
  291.  
  292. Debugging may be enabled in \fIOraperl\fP
  293. by defining either \fBDEBUGGING\fP or \fBPERL_DEBUGGING\fP during compilation.
  294. \fBPERL_DEBUGGING\fP may only be used
  295. if \fIPerl\fP was compiled with debugging enabled.
  296. It differs from \fBDEBUGGING\fP in that
  297. it arranges for the \fIOraperl\fP debugging flags to be initialised
  298. from the \fB\-D\fP option on the command line,
  299. if given.
  300.  
  301. If debugging is compiled into \fIOraperl\fP,
  302. the debugging flags may be accessed or set
  303. via the variable \fIora_debug\fP.
  304. This variable may be tested to determine whether debugging has been enabled;
  305. for example:
  306.  
  307. .nf
  308. .ti +5
  309. \fBdefined($ora_debug)\0||\0warn("oraperl debugging not enabled\en");\fP
  310. .fi
  311.