home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sources / misc / 4161 < prev    next >
Encoding:
Text File  |  1992-12-12  |  30.7 KB  |  1,129 lines

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: Kevin Stock <kstock@encore.com>
  4. Subject:  v34i021:  oraperl-v2 - Extensions to Perl to access Oracle database, Patch03
  5. Message-ID: <1992Dec12.200913.29773@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: 99b0ae8a2b00e4094c5bd93417a7d07d
  8. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  9. Organization: Sterling Software
  10. Date: Sat, 12 Dec 1992 20:09:13 GMT
  11. Approved: kent@sparky.imd.sterling.com
  12. Lines: 1115
  13.  
  14. Submitted-by: Kevin Stock <kstock@encore.com>
  15. Posting-number: Volume 34, Issue 21
  16. Archive-name: oraperl-v2/patch03
  17. Environment: Perl, Oracle with OCI, optionally Curses
  18. Patch-To: oraperl-v2: Volume 30, Issue 87-91
  19.  
  20. This is patch 3 to version 2 of Oraperl, a set of usersubs which
  21. allow Perl to access Oracle databases. You need Perl (v3.0.27 or
  22. better) and Oracle (including the Oracle Call Interface) to build
  23. Oraperl. If you can build Larry's Curseperl, then you can also
  24. build Coraperl, which is Oraperl with Curses.
  25.  
  26. Oraperl version 2 appeared as 5 postings in comp.sources.misc
  27. volume 30, issues 87 to 91. Patch 01 appeared shortly afterwards
  28. as issue 99, and Patch 02 as volume 32, issue 93.
  29.  
  30.   Principal changes:
  31.   ------------------
  32. * The functions &ora_bind() and &ora_do() now return a row-count
  33.   for successful statements. The return values are as follows:
  34.  
  35.     undef    for bad statements (eg, bad syntax)
  36.     'OK'    for good statements which affected no rows
  37.     count    for good statements which affected count rows
  38.  
  39.   This means that the standard idiom
  40.  
  41.     &ora_do($lda, $stmt) || die "$stmt failed - $ora_errstr\n";
  42.  
  43.   still works properly. However, if you tested the exact return
  44.   value from these functions, you will have to change your programs.
  45.  
  46. * The return type from malloc() can now be configured in Makefile.
  47.   The default is (char *).
  48.  
  49. * In &ora_do, a cursor was left dangling if oclose() failed. This is
  50.   no longer the case.
  51.  
  52.   Minor Changes:
  53.   --------------
  54. * examples/sql has been fixed:
  55.  
  56.   The new -c option allows the size of the fetch row cache to be set
  57.   The new -n option allows a string to be printed for NULL fields
  58.   The damage done by the change to &ora_titles() has been undone
  59.  
  60. * examples/japh has been added:
  61.  
  62.   This is a simple 'Just another Perl hacker' program, using a table to
  63.   store the information. A slightly modified version has been added to
  64.   testdir as well.
  65.  
  66. * examples/tabinfo has been modified
  67.  
  68.   the output format is slightly changed
  69.   it will now accept multiple table names and print the description of each
  70.  
  71.   What to do
  72.   ----------
  73. Unshar this file in your Oraperl source directory. This will create
  74. three new files:
  75.  
  76.     patch3
  77.     examples/japh
  78.     testdir/japh.pl
  79.  
  80. Apply the patch using:
  81.  
  82.     patch -p <patch3
  83.  
  84. then make, make test, optionally make coraperl, and make install.
  85.  
  86.     Kevin Stock
  87.     kstock@encore.com
  88.  
  89.  
  90. #!/bin/sh
  91. # This is a shell archive (produced by shar 3.49)
  92. # To extract the files from this archive, save it to a file, remove
  93. # everything above the "!/bin/sh" line above, and type "sh file_name".
  94. #
  95. # made 12/08/1992 15:53 UTC by kstock@mmcompta
  96. # Source directory /usr/local/src/cmd/oraperl-v2
  97. #
  98. # existing files will NOT be overwritten unless -c is specified
  99. #
  100. # This shar contains:
  101. # length  mode       name
  102. # ------ ---------- ------------------------------------------
  103. #  23409 -rw-r--r-- patch3
  104. #   1061 -rwxr-xr-x examples/japh
  105. #   1056 -rw-r--r-- testdir/japh.pl
  106. #
  107. # ============= patch3 ==============
  108. if test -f 'patch3' -a X"$1" != X"-c"; then
  109.     echo 'x - skipping patch3 (File already exists)'
  110. else
  111. echo 'x - extracting patch3 (Text)'
  112. sed 's/^X//' << 'SHAR_EOF' > 'patch3' &&
  113. X*** /user/mis/kstock/tmp/patchlevel.h    Tue Dec  8 16:45:52 1992
  114. X--- ./patchlevel.h    Tue Nov 17 10:23:44 1992
  115. X***************
  116. X*** 1,4 ****
  117. X  /* patchlevel.h */
  118. X  
  119. X  #define    VERSION        2
  120. X! #define    PATCHLEVEL    2
  121. X--- 1,4 ----
  122. X  /* patchlevel.h */
  123. X  
  124. X  #define    VERSION        2
  125. X! #define    PATCHLEVEL    3
  126. X*** /user/mis/kstock/tmp/Changes    Tue Dec  8 16:45:52 1992
  127. X--- ./Changes    Wed Dec  2 11:45:42 1992
  128. X***************
  129. X*** 4,9 ****
  130. X--- 4,17 ----
  131. X  Version 2
  132. X  =========
  133. X  
  134. X+ Patch 03
  135. X+ ========
  136. X+ Modify &ora_bind() and &ora_do() to return the row count
  137. X+ malloc() doesn't return a char * on all systems
  138. X+ A cursor was left dangling if the ora_close() within &ora_do failed
  139. X+ The change to &ora_titles() broke examples/sql
  140. X+ Added -n option to examples/sql to replace NULL fields with a string
  141. X+ 
  142. X  Patch 02
  143. X  ========
  144. X  Added a BUGS section to the manual page
  145. X*** /user/mis/kstock/tmp/Makefile    Tue Dec  8 16:42:57 1992
  146. X--- ./Makefile    Tue Nov 17 15:02:14 1992
  147. X***************
  148. X*** 53,58 ****
  149. X--- 53,62 ----
  150. X  # If your system library does not include strtoul, uncomment the next line
  151. X  STRTOUL    = strtoul.o
  152. X  #
  153. X+ # If your malloc() returns anything other than a char *, set the appropriate
  154. X+ # type here (don't include the *)
  155. X+ # MALLOC_PTR_TYPE=void
  156. X+ #
  157. X  # If you are using Perl v3 instead of v4, uncomment the next line
  158. X  # STR_2MORTAL    = -Dstr_2mortal=str_2static
  159. X  
  160. X*** /user/mis/kstock/tmp/Readme    Tue Dec  8 16:45:53 1992
  161. X--- ./Readme    Tue Nov 17 15:06:16 1992
  162. X***************
  163. X*** 25,31 ****
  164. X      DBUG_O        the debugging library, if debugging is required
  165. X      CACHE        default fetch cache size, if you want to change it
  166. X      BIND        if defined, do not pad empty bind values
  167. X!     STRTOUL        \_ system dependent - see Makefile for details
  168. X      STR_2MORTAL    /
  169. X      TESTDATA    database, username and password for testing Oraperl
  170. X  
  171. X--- 25,32 ----
  172. X      DBUG_O        the debugging library, if debugging is required
  173. X      CACHE        default fetch cache size, if you want to change it
  174. X      BIND        if defined, do not pad empty bind values
  175. X!     STRTOUL        \
  176. X!     MALLOC_PTR_TYPE     +- system dependent - see Makefile for details
  177. X      STR_2MORTAL    /
  178. X      TESTDATA    database, username and password for testing Oraperl
  179. X  
  180. X*** /user/mis/kstock/tmp/doc/oraperl.1    Tue Dec  8 16:45:53 1992
  181. X--- ./doc/oraperl.1    Wed Dec  2 11:37:46 1992
  182. X***************
  183. X*** 169,174 ****
  184. X--- 169,178 ----
  185. X  &ora_bind($csr, 70, 'marketing', undef);
  186. X  .if t .fi P
  187. X  
  188. X+ \fI&ora_bind()\fP returns an undefined value if an error occurred.
  189. X+ Otherwise, it returns the number of rows affected by the command
  190. X+ or the string \fB'OK'\fP if the command was successful but modified no rows.
  191. X+ 
  192. X  This function is equivalent to the \fIOCI obndrn\fP and \fIoexec\fP statements.
  193. X  
  194. X  The \fIOCI obndrn\fP function does not allow empty strings to be bound.
  195. X***************
  196. X*** 277,282 ****
  197. X--- 281,290 ----
  198. X  &ora_close(&ora_open($lda,\ $statement))\c
  199. X  .if t .ft P
  200. X  \&.
  201. X+ 
  202. X+ \fI&ora_do()\fP returns an undefined value if an error occurred.
  203. X+ Otherwise, it returns the number of rows affected by the command
  204. X+ or the string \fB'OK'\fP if the command was successful but modified no rows.
  205. X  .\"
  206. X  .SH "&ora_logoff($lda)"
  207. X  .\"
  208. X***************
  209. X*** 677,682 ****
  210. X--- 685,709 ----
  211. X  
  212. X  Debugging option \fB32\fP only reports internal string/numeric translations,
  213. X  not those performed on the data retrieved from the database.
  214. X+ 
  215. X+ When calling \fI&ora_open()\fP or \fI&ora_do()\fP with long SQL statements,
  216. X+ \fIPerl\fP's \fIHere Document\fP may be used to good effect for clarity.
  217. X+ 
  218. X+ For example:
  219. X+ 
  220. X+ .nf
  221. X+ .in +.5i
  222. X+ .if t .ft CW
  223. X+ $csr = &ora_open($lda, <<END_OF_QUERY, 10) || die $ora_errstr;
  224. X+ .in +.5i
  225. X+ select name, fname, telno from address_book
  226. X+ where lower(position) like '%director%'
  227. X+ order by name
  228. X+ .in -.5i
  229. X+ END_OF_QUERY
  230. X+ .in -.5i
  231. X+ .if t .ft P
  232. X+ .fi
  233. X  .SH SEE ALSO
  234. X  .nf
  235. X  \fIOracle\fP Documentation:
  236. X*** /user/mis/kstock/tmp/examples/Readme    Tue Dec  8 16:45:54 1992
  237. X--- ./examples/Readme    Wed Dec  2 10:56:23 1992
  238. X***************
  239. X*** 14,19 ****
  240. X--- 14,22 ----
  241. X          it using a format. It also illustrates how to recognise NULL
  242. X          fields.
  243. X  
  244. X+ japh        Just another Perl hacker, written in Oraperl
  245. X+         This is no one-liner, but it demonstrates a few things.
  246. X+ 
  247. X  mkdb.pl        Creates a database, puts some data into it, drops it. The nice
  248. X          thing about this is that it detects whether it is running under
  249. X          Oraperl or Coraperl, and changes its output accordingly. It
  250. X*** /user/mis/kstock/tmp/examples/bind.pl    Tue Dec  8 16:43:17 1992
  251. X--- ./examples/bind.pl    Wed Dec  2 11:48:15 1992
  252. X***************
  253. X*** 17,22 ****
  254. X--- 17,25 ----
  255. X      chop;
  256. X      &ora_bind($csr, $_)    || die $ora_errstr;
  257. X  
  258. X+     # Note that $phone is placed in brackets to give it array context
  259. X+     # Without them, &ora_fetch() returns the number of columns available
  260. X+ 
  261. X      if (($phone) = &ora_fetch($csr))
  262. X      {
  263. X          print "$phone\n";
  264. X*** /user/mis/kstock/tmp/examples/mkdb.pl    Tue Dec  8 16:45:55 1992
  265. X--- ./examples/mkdb.pl    Wed Dec  2 12:08:39 1992
  266. X***************
  267. X*** 50,56 ****
  268. X  
  269. X      sub during
  270. X      {
  271. X!         &addstr(sprintf("%2d   %-15s%3d\n", $lineno++, $name, $ext));
  272. X      }
  273. X  
  274. X      sub after
  275. X--- 50,56 ----
  276. X  
  277. X      sub during
  278. X      {
  279. X!         &addstr(sprintf("%2d   %-15s%3s\n", $lineno++, $name, $ext));
  280. X      }
  281. X  
  282. X      sub after
  283. X*** /user/mis/kstock/tmp/examples/sql    Tue Dec  8 16:43:05 1992
  284. X--- ./examples/sql    Wed Dec  2 11:21:51 1992
  285. X***************
  286. X*** 7,45 ****
  287. X  # Script to run an Oracle statement from the command line.
  288. X  # Written in response to <nirad.690285085@newdelphi> in alt.sources.wanted.
  289. X  #
  290. X! # Usage:
  291. X! #    sql [-#debug] [-bbase] [-ddelim] [-f|-h] [-lpage_len] name/pass stmt
  292. X  #
  293. X! #    -#debug            debugging control string
  294. X! #                MUST be first argument
  295. X! #    -b base            database to use (default $ENV{'ORACLE_SID'})
  296. X! #    -d delim        specifies the field delimiter (default TAB)
  297. X! #    -f            formatted output, similar to sqlplus
  298. X! #    -h            add headers, no formatting
  299. X! #    -l page_len        lines per page, only used by -f (default 60)
  300. X! #    name/pass        Oracle username and password
  301. X! #    stmt            Oracle statement to be executed
  302. X  #
  303. X  # Author:    Kevin Stock
  304. X  # Date:        18th November 1991
  305. X  #
  306. X  
  307. X  $ora_debug = shift if $ARGV[0] =~ /^-#/;
  308. X  
  309. X! $USAGE = "[-bbase] [-ddelim] [-f|-h] [-lpage_len] username/password statement";
  310. X  $, = "\t";            # default delimiter is a tab
  311. X  $\ = "\n";            # each record terminated with newline
  312. X  
  313. X  require 'getopts.pl';        # option parsing
  314. X! do Getopts('b:d:fhl:');
  315. X  die "$0: only one of -f and -h may be specified\n" if ($opt_f && $opt_h);
  316. X  
  317. X  $USER = shift;            # get the user name and password
  318. X  die "Usage: $0 $USAGE\n" unless $#ARGV >= 0;        # must have a statement
  319. X  
  320. X  $, = $opt_d if defined($opt_d);                # set column delimiter
  321. X  $= = $opt_l if defined($opt_l);                # set page length
  322. X- $ENV{'ORACLE_SID'} = $opt_b if defined($opt_b);        # set database
  323. X  
  324. X  die "ORACLE_SID not set\n" unless defined($ENV{'ORACLE_SID'});
  325. X  
  326. X--- 7,49 ----
  327. X  # Script to run an Oracle statement from the command line.
  328. X  # Written in response to <nirad.690285085@newdelphi> in alt.sources.wanted.
  329. X  #
  330. X! # Parameters (* = mandatory)
  331. X  #
  332. X! #    -#debug          debugging control string (must be first argument)
  333. X! #    -b base          database to use (default $ENV{'ORACLE_SID'})
  334. X! #    -c cache      SQL fetch cache size
  335. X! #    -d delim      specifies the field delimiter (default TAB)
  336. X! #    -f          formatted output, similar to sqlplus
  337. X! #    -h          add headers, no formatting
  338. X! #    -l page_len      lines per page, only used by -f (default 60)
  339. X! #    -n string      replace NULL fields by string
  340. X! #    name/pass    * Oracle username and password
  341. X! #    stmt        * Oracle statement to be executed
  342. X  #
  343. X  # Author:    Kevin Stock
  344. X  # Date:        18th November 1991
  345. X+ # Last change:    18th November 1992
  346. X  #
  347. X  
  348. X  $ora_debug = shift if $ARGV[0] =~ /^-#/;
  349. X  
  350. X! $USAGE = <<;
  351. X!     [-bbase] [-ccache] [-ddelim] [-f|-h] [-lpage_len] [-nstring] name/pass stmt
  352. X! 
  353. X  $, = "\t";            # default delimiter is a tab
  354. X  $\ = "\n";            # each record terminated with newline
  355. X  
  356. X  require 'getopts.pl';        # option parsing
  357. X! do Getopts('b:c:d:fhl:n:');
  358. X  die "$0: only one of -f and -h may be specified\n" if ($opt_f && $opt_h);
  359. X  
  360. X  $USER = shift;            # get the user name and password
  361. X  die "Usage: $0 $USAGE\n" unless $#ARGV >= 0;        # must have a statement
  362. X  
  363. X+ $ENV{'ORACLE_SID'} = $opt_b if defined($opt_b);        # set database
  364. X+ $ora_cache = $opt_c if defined($opt_c);            # set fetch cache
  365. X  $, = $opt_d if defined($opt_d);                # set column delimiter
  366. X  $= = $opt_l if defined($opt_l);                # set page length
  367. X  
  368. X  die "ORACLE_SID not set\n" unless defined($ENV{'ORACLE_SID'});
  369. X  
  370. X***************
  371. X*** 54,66 ****
  372. X  {
  373. X      if ($opt_f)            # formatted output
  374. X      {
  375. X!         @titles = &ora_titles($csr);
  376. X!         $format .= "format STDOUT_TOP =\n" . join($,, @titles) . "\n";
  377. X!         grep(tr//-/c, @titles);
  378. X!         $format .= join($,, @titles) . "\n.\n";
  379. X  
  380. X!         grep((s/^-/@/, tr/-/</), @titles);
  381. X!         $format .= "format STDOUT =\n" . join($,, @titles) . "\n";
  382. X          foreach $i (0 .. $nfields - 1)
  383. X          {
  384. X              $format .= "\$result[$i],";
  385. X--- 58,89 ----
  386. X  {
  387. X      if ($opt_f)            # formatted output
  388. X      {
  389. X!         # Build up format statements for the data
  390. X! 
  391. X!         # First, the header - a list of field names, formatted
  392. X!         # in columns of the appropriate width
  393. X! 
  394. X!         $fmt = '';
  395. X!         grep($fmt .= "%-${_}.${_}s|", &ora_lengths($csr));
  396. X!         chop $fmt;
  397. X!         $fmt = sprintf($fmt, &ora_titles($csr, 0));
  398. X!         $format .= "format STDOUT_TOP =\n" . $fmt . "\n";
  399. X! 
  400. X!         # Then underlines for the field names
  401. X  
  402. X!         $fmt =~ tr/|/-/c;
  403. X!         $fmt =~ tr/|/+/;
  404. X!         $format .= $fmt . "\n.\n";
  405. X! 
  406. X!         # Then for the data format, a @<<... field per column
  407. X! 
  408. X!         $fmt =~ tr/-+/<|/;
  409. X!         $fmt =~ s/(^|\|)</\1@/g;
  410. X!         $format .= "format STDOUT =\n" . $fmt . "\n";
  411. X! 
  412. X!         # Finally the variable associated with each column
  413. X!         # Why doesn't Perl let us specify an array here?
  414. X! 
  415. X          foreach $i (0 .. $nfields - 1)
  416. X          {
  417. X              $format .= "\$result[$i],";
  418. X***************
  419. X*** 72,78 ****
  420. X      }
  421. X      elsif ($opt_h)
  422. X      {
  423. X!         @titles = &ora_titles($csr);
  424. X          grep(s/  *$//, @titles);
  425. X          print @titles;
  426. X          grep(tr//-/c, @titles);
  427. X--- 95,103 ----
  428. X      }
  429. X      elsif ($opt_h)
  430. X      {
  431. X!         # Simple headers with underlines
  432. X! 
  433. X!         @titles = &ora_titles($csr, 0);
  434. X          grep(s/  *$//, @titles);
  435. X          print @titles;
  436. X          grep(tr//-/c, @titles);
  437. X***************
  438. X*** 81,86 ****
  439. X--- 106,112 ----
  440. X  
  441. X      while (@result = &ora_fetch($csr))
  442. X      {
  443. X+         grep(defined $_ || ($_ = $opt_n), @result) if $opt_n;
  444. X          ($opt_f) ? (write) : (print @result);
  445. X      }
  446. X      warn "$ora_errstr\n" if ($ora_errno != 0);
  447. X***************
  448. X*** 104,110 ****
  449. X  .nr % 0            \" start at page 1
  450. X  ';<<'.ex'; ############## From here on it's a standard manual page ############
  451. X  .ll 80
  452. X! .TH SQL L "18th November 1991"
  453. X  .ad
  454. X  .nh
  455. X  .SH NAME
  456. X--- 130,136 ----
  457. X  .nr % 0            \" start at page 1
  458. X  ';<<'.ex'; ############## From here on it's a standard manual page ############
  459. X  .ll 80
  460. X! .TH SQL L "18th November 1992"
  461. X  .ad
  462. X  .nh
  463. X  .SH NAME
  464. X***************
  465. X*** 112,120 ****
  466. X--- 138,148 ----
  467. X  .SH SYNOPSIS
  468. X  \fBsql\fP
  469. X  [\fB\-b\fP\fIbase\fP]
  470. X+ [\fB\-c\fP\fIcache\fP]
  471. X  [\fB\-d\fP\fIdelim\fP]
  472. X  [\fB\-f\fP|\fB\-h\fP]
  473. X  [\fB\-l\fP\fIpage_len\fP]
  474. X+ [\fB\-n\fP\fIstring\fP]
  475. X  \fIname\fP\fB/\fP\fIpassword\fP
  476. X  \fIstatement\fP
  477. X  .SH DESCRIPTION
  478. X***************
  479. X*** 129,134 ****
  480. X--- 157,170 ----
  481. X  If it is not given, the database specified by the environment variable
  482. X  \fBORACLE_SID\fP is used.
  483. X  
  484. X+ The \fB\-c\fP\fIcache\fP flag may be supplied to set the size of fetch cache
  485. X+ to be used. If it is not given, the system default is used.
  486. X+ 
  487. X+ If the \fB\-n\fP\fIstring\fP flag is supplied,
  488. X+ \fBNULL\fP fields (in the \fIOracle\fP sense)
  489. X+ will replaced in the output by \fIstring\fP.
  490. X+ Normally, they are left blank.
  491. X+ 
  492. X  The \fB\-f\fP and \fB\-h\fP flags may be used to modify the form of the output.
  493. X  Without either flag, no field headers are printed
  494. X  and fields are not padded.
  495. X***************
  496. X*** 136,153 ****
  497. X  field headers are added to the top of the output,
  498. X  but the format is otherwise unchanged.
  499. X  With the \fB\-f\fP flag,
  500. X! the output is formatted in a fashion similar to that used by \fIsqlplus\fP,
  501. X  except that all fields are left\-justified, regardless of their data type.
  502. X  Column headers are printed at the top of each page;
  503. X  a page is assumed to be 60 lines long,
  504. X  but this may be overridden with the \fB\-l\fP\fIpage_len\fP flag.
  505. X  
  506. X! Normally, fields are separated with tabs;
  507. X  this may be changed to any desired string (\fIdelim\fP)
  508. X  using the \fB\-d\fP flag.
  509. X  .SH ENVIRONMENT
  510. X  The environment variable \fBORACLE_SID\fP
  511. X! determines the Oracle database to be used.
  512. X  .SH DIAGNOSTICS
  513. X  .in +5
  514. X  .ti -5
  515. X--- 172,190 ----
  516. X  field headers are added to the top of the output,
  517. X  but the format is otherwise unchanged.
  518. X  With the \fB\-f\fP flag,
  519. X! the output is formatted in a tabular form similar to that used by \fIsqlplus\fP,
  520. X  except that all fields are left\-justified, regardless of their data type.
  521. X  Column headers are printed at the top of each page;
  522. X  a page is assumed to be 60 lines long,
  523. X  but this may be overridden with the \fB\-l\fP\fIpage_len\fP flag.
  524. X  
  525. X! Without the \fB\-f\fP flag, fields are separated with tabs;
  526. X  this may be changed to any desired string (\fIdelim\fP)
  527. X  using the \fB\-d\fP flag.
  528. X  .SH ENVIRONMENT
  529. X  The environment variable \fBORACLE_SID\fP
  530. X! determines the Oracle database to be used
  531. X! if the \fB\-b\fP\fIbase\fP flag is not supplied.
  532. X  .SH DIAGNOSTICS
  533. X  .in +5
  534. X  .ti -5
  535. X*** /user/mis/kstock/tmp/examples/tabinfo.pl    Tue Dec  8 16:45:59 1992
  536. X--- ./examples/tabinfo.pl    Thu Oct 15 09:57:19 1992
  537. X***************
  538. X*** 18,24 ****
  539. X  (($base = shift)    &&
  540. X   ($user = shift)    &&
  541. X   ($pass = shift)    &&
  542. X!  ($table = shift))    || die "Usage: $0 base user password table\n";
  543. X  
  544. X  # we need this for the table of datatypes
  545. X  #
  546. X--- 18,24 ----
  547. X  (($base = shift)    &&
  548. X   ($user = shift)    &&
  549. X   ($pass = shift)    &&
  550. X!  ($table = shift))    || die "Usage: $0 base user password table ...\n";
  551. X  
  552. X  # we need this for the table of datatypes
  553. X  #
  554. X***************
  555. X*** 28,53 ****
  556. X  Structure of @<<<<<<<<<<<<<<<<<<<<<<<
  557. X  $table
  558. X  
  559. X! Field name          | Length | Type | Type description
  560. X! --------------------+--------+------+-------------------------------------------
  561. X  .
  562. X  
  563. X  format STDOUT =
  564. X! @<<<<<<<<<<<<<<<<<<<| @>>>>> | @>>> | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  565. X  $name[$i], $length[$i], $type[$i], $ora_types{$type[$i]}
  566. X  .
  567. X  
  568. X  $lda = &ora_login($base, $user, $pass) || die $ora_errstr . "\n";
  569. X- $csr = &ora_open($lda, "select * from $table") || die $ora_errstr . "\n";
  570. X  
  571. X! (@name = &ora_titles($csr, 0)) || die $ora_errstr . "\n";
  572. X! (@length = &ora_lengths($csr)) || die $ora_errstr . "\n";
  573. X! (@type = &ora_types($csr)) || die $ora_errstr . "\n";
  574. X! 
  575. X! foreach $i (0 .. $#name)
  576. X  {
  577. X!     write;
  578. X! }
  579. X  
  580. X- &ora_close($csr);
  581. X  &ora_logoff($lda);
  582. X--- 28,60 ----
  583. X  Structure of @<<<<<<<<<<<<<<<<<<<<<<<
  584. X  $table
  585. X  
  586. X! Field name                                    | Length | Type | Type description
  587. X! ----------------------------------------------+--------+------+-----------------
  588. X  .
  589. X  
  590. X  format STDOUT =
  591. X! @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @>>>>> | @>>> | @<<<<<<<<<<<<<<<
  592. X  $name[$i], $length[$i], $type[$i], $ora_types{$type[$i]}
  593. X  .
  594. X  
  595. X  $lda = &ora_login($base, $user, $pass) || die $ora_errstr . "\n";
  596. X  
  597. X! do
  598. X  {
  599. X!     $csr = &ora_open($lda, "select * from $table") || die "$ora_errstr\n";
  600. X! 
  601. X!     (@name = &ora_titles($csr, 0)) || die $ora_errstr . "\n";
  602. X!     (@length = &ora_lengths($csr)) || die $ora_errstr . "\n";
  603. X!     (@type = &ora_types($csr)) || die $ora_errstr . "\n";
  604. X! 
  605. X!     foreach $i (0 .. $#name)
  606. X!     {
  607. X!         write;
  608. X!     }
  609. X! 
  610. X!     &ora_close($csr);
  611. X! 
  612. X!     $- = 0;
  613. X! } while ($table = shift);
  614. X  
  615. X  &ora_logoff($lda);
  616. X*** /user/mis/kstock/tmp/oracle.mus    Tue Dec  8 16:45:59 1992
  617. X--- ./oracle.mus    Tue Nov 17 11:27:43 1992
  618. X***************
  619. X*** 227,233 ****
  620. X      else {
  621. X          char *csr        = (char *) str_get(st[1]);
  622. X          char **vars        = (char **) malloc((items-1) * sizeof(char *));
  623. X!         int retval;
  624. X  
  625. X          if (vars == NULL)
  626. X          {
  627. X--- 227,233 ----
  628. X      else {
  629. X          char *csr        = (char *) str_get(st[1]);
  630. X          char **vars        = (char **) malloc((items-1) * sizeof(char *));
  631. X!         long retval;
  632. X  
  633. X          if (vars == NULL)
  634. X          {
  635. X***************
  636. X*** 252,265 ****
  637. X          free(vars);
  638. X          }
  639. X  
  640. X!         str_numset(st[0], (double) retval);
  641. X      }
  642. X      return sp;
  643. X  
  644. X! CASE    char *    ora_do
  645. X! I    char *    lda
  646. X! I    char *    stmt
  647. X! END
  648. X  
  649. X  CASE    char *    ora_close
  650. X  I    char *    csr
  651. X--- 252,284 ----
  652. X          free(vars);
  653. X          }
  654. X  
  655. X!         if (retval < 0)
  656. X!         str_set(st[0], (char *) NULL);
  657. X!         else if (retval == 0)
  658. X!         str_set(st[0], "OK");
  659. X!         else
  660. X!         str_numset(st[0], (double) retval);
  661. X      }
  662. X      return sp;
  663. X  
  664. X!     case US_ora_do:
  665. X!     if (items != 2)
  666. X!         fatal("Usage: &ora_do($lda, $stmt)");
  667. X!     else {
  668. X!         long retval;
  669. X!         char *    lda =        (char *)    str_get(st[1]);
  670. X!         char *    stmt =        (char *)    str_get(st[2]);
  671. X! 
  672. X!         retval = ora_do(lda, stmt);
  673. X! 
  674. X!         if (retval < 0L)
  675. X!         str_set(st[0], (char *) NULL);
  676. X!         else if (retval == 0L)
  677. X!         str_set(st[0], "OK");
  678. X!         else
  679. X!         str_numset(st[0], (double) retval);
  680. X!     }
  681. X!     return sp;
  682. X  
  683. X  CASE    char *    ora_close
  684. X  I    char *    csr
  685. X*** /user/mis/kstock/tmp/orafns.c    Tue Dec  8 16:46:00 1992
  686. X--- ./orafns.c    Tue Nov 17 11:39:08 1992
  687. X***************
  688. X*** 767,778 ****
  689. X   * binds actual values to the SQL statement associated with csr
  690. X   */
  691. X  
  692. X! int ora_bind(csr_s, vars, nitems)
  693. X  char *csr_s, **vars;
  694. X  int nitems;
  695. X  {
  696. X      int i;
  697. X      short null_flag = -1;
  698. X  #ifndef    NO_BIND_PADDING
  699. X      static char small_buf[2] = " ";
  700. X  #endif
  701. X--- 767,779 ----
  702. X   * binds actual values to the SQL statement associated with csr
  703. X   */
  704. X  
  705. X! long ora_bind(csr_s, vars, nitems)
  706. X  char *csr_s, **vars;
  707. X  int nitems;
  708. X  {
  709. X      int i;
  710. X      short null_flag = -1;
  711. X+     long rowcount;
  712. X  #ifndef    NO_BIND_PADDING
  713. X      static char small_buf[2] = " ";
  714. X  #endif
  715. X***************
  716. X*** 787,793 ****
  717. X      {
  718. X          ora_errno = ORAP_INVCSR;
  719. X          DBUG_PRINT("exit", ("not a csr"));
  720. X!         DBUG_RETURN(0);
  721. X      }
  722. X      else if (csr->varfields != nitems)
  723. X      {
  724. X--- 788,794 ----
  725. X      {
  726. X          ora_errno = ORAP_INVCSR;
  727. X          DBUG_PRINT("exit", ("not a csr"));
  728. X!         DBUG_RETURN(-1L);
  729. X      }
  730. X      else if (csr->varfields != nitems)
  731. X      {
  732. X***************
  733. X*** 794,800 ****
  734. X          ora_errno = ORAP_NUMVARS;
  735. X          DBUG_PRINT("exit", ("expected %d items, got %d",
  736. X              csr->varfields, nitems));
  737. X!         DBUG_RETURN(0);
  738. X      }
  739. X  
  740. X      for (i = 0 ; i < nitems ; i++)
  741. X--- 795,801 ----
  742. X          ora_errno = ORAP_NUMVARS;
  743. X          DBUG_PRINT("exit", ("expected %d items, got %d",
  744. X              csr->varfields, nitems));
  745. X!         DBUG_RETURN(-1L);
  746. X      }
  747. X  
  748. X      for (i = 0 ; i < nitems ; i++)
  749. X***************
  750. X*** 807,813 ****
  751. X              ora_errno = csr->csr->csrrc;
  752. X              DBUG_PRINT("exit", ("obndrn failed on field %d, <NULL>",
  753. X                  i + 1));
  754. X!             DBUG_RETURN(0);
  755. X          }
  756. X  
  757. X          DBUG_PRINT("info", ("obndrn %d, <NULL> OK", (i + 1), vars[i]));
  758. X--- 808,814 ----
  759. X              ora_errno = csr->csr->csrrc;
  760. X              DBUG_PRINT("exit", ("obndrn failed on field %d, <NULL>",
  761. X                  i + 1));
  762. X!             DBUG_RETURN(-1L);
  763. X          }
  764. X  
  765. X          DBUG_PRINT("info", ("obndrn %d, <NULL> OK", (i + 1), vars[i]));
  766. X***************
  767. X*** 827,833 ****
  768. X              ora_errno = csr->csr->csrrc;
  769. X              DBUG_PRINT("exit", ("obndrn failed on field %d, \"%s\"",
  770. X                  i + 1, vars[i]));
  771. X!             DBUG_RETURN(0);
  772. X          }
  773. X  
  774. X          DBUG_PRINT("info", ("obndrn %d, \"%s\" OK", (i + 1), vars[i]));
  775. X--- 828,834 ----
  776. X              ora_errno = csr->csr->csrrc;
  777. X              DBUG_PRINT("exit", ("obndrn failed on field %d, \"%s\"",
  778. X                  i + 1, vars[i]));
  779. X!             DBUG_RETURN(-1L);
  780. X          }
  781. X  
  782. X          DBUG_PRINT("info", ("obndrn %d, \"%s\" OK", (i + 1), vars[i]));
  783. X***************
  784. X*** 838,844 ****
  785. X      {
  786. X          ora_errno = csr->csr->csrrc;
  787. X          DBUG_PRINT("exit", ("oexec failed"));
  788. X!         DBUG_RETURN(0);
  789. X      }
  790. X  
  791. X      /* any cached data is now out of date, as is the end_of data flag */
  792. X--- 839,845 ----
  793. X      {
  794. X          ora_errno = csr->csr->csrrc;
  795. X          DBUG_PRINT("exit", ("oexec failed"));
  796. X!         DBUG_RETURN(-1L);
  797. X      }
  798. X  
  799. X      /* any cached data is now out of date, as is the end_of data flag */
  800. X***************
  801. X*** 845,852 ****
  802. X      csr->in_cache = 0;
  803. X      csr->end_of_data = 0;
  804. X  
  805. X!     DBUG_PRINT("exit", ("returning OK"));
  806. X!     DBUG_RETURN(1);
  807. X  }
  808. X  
  809. X  
  810. X--- 846,856 ----
  811. X      csr->in_cache = 0;
  812. X      csr->end_of_data = 0;
  813. X  
  814. X!     rowcount = csr->csr->csrrpc;
  815. X!     DBUG_PRINT("info", ("%ld rows processed", rowcount));
  816. X! 
  817. X!     DBUG_PRINT("exit", ("returning %ld", rowcount));
  818. X!     DBUG_RETURN(rowcount);
  819. X  }
  820. X  
  821. X  
  822. X***************
  823. X*** 858,868 ****
  824. X   * sets and executes the specified sql statement, without leaving a cursor open
  825. X   */
  826. X  
  827. X! char *ora_do(lda_s, stmt)
  828. X  char *lda_s;
  829. X  char *stmt;
  830. X  {
  831. X      char *csr_s;
  832. X  
  833. X      DBUG_ENTER("ora_do");
  834. X      DBUG_PRINT("entry", ("ora_do(%s, \"%s\")", lda_s, stmt));
  835. X--- 862,874 ----
  836. X   * sets and executes the specified sql statement, without leaving a cursor open
  837. X   */
  838. X  
  839. X! long ora_do(lda_s, stmt)
  840. X  char *lda_s;
  841. X  char *stmt;
  842. X  {
  843. X+     long rowcount;
  844. X      char *csr_s;
  845. X+     struct cursor *csr;
  846. X  
  847. X      DBUG_ENTER("ora_do");
  848. X      DBUG_PRINT("entry", ("ora_do(%s, \"%s\")", lda_s, stmt));
  849. X***************
  850. X*** 869,886 ****
  851. X  
  852. X      if ((csr_s = ora_open(lda_s, stmt)) == NULL)
  853. X      {
  854. X!         DBUG_PRINT("exit", ("ora_open failed"));
  855. X!         DBUG_RETURN(NULL);
  856. X      }
  857. X!     else if (ora_close(csr_s) == NULL)
  858. X      {
  859. X!         DBUG_PRINT("exit", ("ora_close failed"));
  860. X!         DBUG_RETURN(NULL);
  861. X      }
  862. X      else
  863. X      {
  864. X!         DBUG_PRINT("exit", ("command successful"));
  865. X!         DBUG_RETURN(OK);
  866. X      }
  867. X  
  868. X      /* NOTREACHED */
  869. X--- 875,901 ----
  870. X  
  871. X      if ((csr_s = ora_open(lda_s, stmt)) == NULL)
  872. X      {
  873. X!         DBUG_PRINT("exit", ("ora_open failed - returning -1"));
  874. X!         DBUG_RETURN(-1L);
  875. X      }
  876. X! 
  877. X!     csr = (struct cursor *) strtoul(csr_s, (char **) NULL, 0);
  878. X!     DBUG_PRINT("conv", ("string %s converted to address $#lx",
  879. X!         csr_s, (long) csr));
  880. X! 
  881. X!     rowcount = csr->csr->csrrpc;
  882. X!     DBUG_PRINT("info", ("%ld rows processed", rowcount));
  883. X! 
  884. X!     if (ora_close(csr_s) == NULL)
  885. X      {
  886. X!         ora_dropcursor(csr);
  887. X!         DBUG_PRINT("exit", ("ora_close failed - returning -1"));
  888. X!         DBUG_RETURN(-1L);
  889. X      }
  890. X      else
  891. X      {
  892. X!         DBUG_PRINT("exit", ("returning %ld", rowcount));
  893. X!         DBUG_RETURN(rowcount);
  894. X      }
  895. X  
  896. X      /* NOTREACHED */
  897. X*** /user/mis/kstock/tmp/orafns.h    Tue Dec  8 16:43:08 1992
  898. X--- ./orafns.h    Wed Dec  2 11:53:14 1992
  899. X***************
  900. X*** 14,33 ****
  901. X  
  902. X  void        ora_version();
  903. X  
  904. X! int        ora_bind(),
  905. X!         ora_fetch(),
  906. X          ora_titles();
  907. X  
  908. X  char        *ora_login(),
  909. X          *ora_open(),
  910. X          *ora_close(),
  911. X-         *ora_do(),
  912. X          *ora_logoff(),
  913. X          *ora_commit(),
  914. X          *ora_rollback(),
  915. X          *ora_autocommit();
  916. X  
  917. X  
  918. X  /* These functions are internal to the system, not for public consumption */
  919. X  
  920. X  int        ora_dropcursor(),
  921. X--- 14,34 ----
  922. X  
  923. X  void        ora_version();
  924. X  
  925. X! int        ora_fetch(),
  926. X          ora_titles();
  927. X  
  928. X  char        *ora_login(),
  929. X          *ora_open(),
  930. X          *ora_close(),
  931. X          *ora_logoff(),
  932. X          *ora_commit(),
  933. X          *ora_rollback(),
  934. X          *ora_autocommit();
  935. X  
  936. X+ long        ora_do(),
  937. X+         ora_bind();
  938. X  
  939. X+ 
  940. X  /* These functions are internal to the system, not for public consumption */
  941. X  
  942. X  int        ora_dropcursor(),
  943. X***************
  944. X*** 93,101 ****
  945. X  
  946. X  int        count_colons();
  947. X  unsigned long    strtoul();
  948. X! char        *getenv(), *malloc();
  949. X  void        my_setenv();
  950. X  
  951. X  
  952. X  /* variables accesible to the outside world */
  953. X  
  954. X--- 94,107 ----
  955. X  
  956. X  int        count_colons();
  957. X  unsigned long    strtoul();
  958. X! char        *getenv();
  959. X  void        my_setenv();
  960. X  
  961. X+ #ifndef    MALLOC_PTR_TYPE
  962. X+ #    define    MALLOC_PTR_TYPE    char
  963. X+ #endif
  964. X+ 
  965. X+ MALLOC_PTR_TYPE    *malloc();
  966. X  
  967. X  /* variables accesible to the outside world */
  968. X  
  969. X*** /user/mis/kstock/tmp/testdir/Standard-Results    Tue Dec  8 16:46:02 1992
  970. X--- ./testdir/Standard-Results    Wed Dec  2 11:54:55 1992
  971. X***************
  972. X*** 10,15 ****
  973. X--- 10,16 ----
  974. X  Only values up to 11 should appear.
  975. X  
  976. X  2 3 5 7 11 
  977. X+ just another Oraperl hacker, 
  978. X  2 fields, lengths 10, 40
  979. X      types 1, 2
  980. X      names NAME, EXT
  981. SHAR_EOF
  982. chmod 0644 patch3 ||
  983. echo 'restore of patch3 failed'
  984. Wc_c="`wc -c < 'patch3'`"
  985. test 23409 -eq "$Wc_c" ||
  986.     echo 'patch3: original size 23409, current size' "$Wc_c"
  987. fi
  988. # ============= examples/japh ==============
  989. if test ! -d 'examples'; then
  990.     echo 'x - creating directory examples'
  991.     mkdir 'examples'
  992. fi
  993. if test -f 'examples/japh' -a X"$1" != X"-c"; then
  994.     echo 'x - skipping examples/japh (File already exists)'
  995. else
  996. echo 'x - extracting examples/japh (Text)'
  997. sed 's/^X//' << 'SHAR_EOF' > 'examples/japh' &&
  998. X#!/usr/local/bin/oraperl
  999. X#
  1000. X# This is an example of how we could code a JAPH in Oraperl.
  1001. X#
  1002. X# Author:    Kevin Stock
  1003. X# Date:        1st December 1992
  1004. X#
  1005. X
  1006. X# supply debugging output if desired
  1007. X
  1008. X$ora_debug = shift if $ARGV[0] =~ /^-#/;
  1009. X
  1010. X# login to the database and create the table
  1011. X
  1012. X$lda = &ora_login('t', 'kstock', 'kstock') || die $ora_errstr;
  1013. X&ora_do($lda, <<) || die $ora_errstr;
  1014. X    create table japh (word char(7), posn number(1))
  1015. X
  1016. X# Loop to insert data into the table
  1017. X
  1018. X$csr = &ora_open($lda, <<) || die $ora_errstr;
  1019. X    insert into japh values(:1, :2)
  1020. X
  1021. Xwhile (<DATA>)
  1022. X{
  1023. X    chop;
  1024. X    &ora_bind($csr, split(':')) || warn "$_: $ora_errstr";
  1025. X}
  1026. X&ora_close($csr) || warn $ora_errstr;
  1027. X
  1028. X# Now retrieve the data, printing it word by word
  1029. X
  1030. X$csr = &ora_open($lda, <<) || die $ora_errstr;
  1031. X    select word from japh order by posn
  1032. X
  1033. Xwhile (($word) = &ora_fetch($csr))
  1034. X{
  1035. X    print "$word ";
  1036. X}
  1037. X&ora_close($csr) || warn $ora_errstr;
  1038. X
  1039. Xprint "\n";
  1040. X
  1041. X# delete the table
  1042. X
  1043. X&ora_do($lda, 'drop table japh') || warn $ora_errstr;
  1044. X&ora_logoff($lda) || die $ora_errstr;
  1045. X
  1046. X__END__
  1047. XOraperl:3
  1048. Xanother:2
  1049. Xhacker:4
  1050. Xjust:1
  1051. SHAR_EOF
  1052. chmod 0755 examples/japh ||
  1053. echo 'restore of examples/japh failed'
  1054. Wc_c="`wc -c < 'examples/japh'`"
  1055. test 1061 -eq "$Wc_c" ||
  1056.     echo 'examples/japh: original size 1061, current size' "$Wc_c"
  1057. fi
  1058. # ============= testdir/japh.pl ==============
  1059. if test ! -d 'testdir'; then
  1060.     echo 'x - creating directory testdir'
  1061.     mkdir 'testdir'
  1062. fi
  1063. if test -f 'testdir/japh.pl' -a X"$1" != X"-c"; then
  1064.     echo 'x - skipping testdir/japh.pl (File already exists)'
  1065. else
  1066. echo 'x - extracting testdir/japh.pl (Text)'
  1067. sed 's/^X//' << 'SHAR_EOF' > 'testdir/japh.pl' &&
  1068. X# supply debugging output if desired
  1069. X
  1070. X$ora_debug = shift if $ARGV[0] =~ /^-#/;
  1071. X
  1072. X$USAGE = "Usage: $0 database username password\n";
  1073. X
  1074. X$base = shift || die $USAGE;
  1075. X$name = shift || die $USAGE;
  1076. X$pass = shift || die $USAGE;
  1077. X
  1078. X# login to the database and create the table
  1079. X
  1080. X$lda = &ora_login($base, $name, $pass) || die $ora_errstr;
  1081. X&ora_do($lda, <<) || die $ora_errstr;
  1082. X    create table japh (word char(7), posn number(1))
  1083. X
  1084. X# Loop to insert data into the table
  1085. X
  1086. X$csr = &ora_open($lda, <<) || die $ora_errstr;
  1087. X    insert into japh values(:1, :2)
  1088. X
  1089. Xwhile (<DATA>)
  1090. X{
  1091. X    chop;
  1092. X    &ora_bind($csr, split(':')) || warn "$_: $ora_errstr";
  1093. X}
  1094. X&ora_close($csr) || warn $ora_errstr;
  1095. X
  1096. X# Now retrieve the data, printing it word by word
  1097. X
  1098. X$csr = &ora_open($lda, <<) || die $ora_errstr;
  1099. X    select word from japh order by posn
  1100. X
  1101. Xwhile (($word) = &ora_fetch($csr))
  1102. X{
  1103. X    print "$word ";
  1104. X}
  1105. X&ora_close($csr) || warn $ora_errstr;
  1106. X
  1107. Xprint "\n";
  1108. X
  1109. X# delete the table
  1110. X
  1111. X&ora_do($lda, 'drop table japh') || warn $ora_errstr;
  1112. X&ora_logoff($lda) || die $ora_errstr;
  1113. X
  1114. X__END__
  1115. XOraperl:3
  1116. Xanother:2
  1117. Xhacker,:4
  1118. Xjust:1
  1119. SHAR_EOF
  1120. chmod 0644 testdir/japh.pl ||
  1121. echo 'restore of testdir/japh.pl failed'
  1122. Wc_c="`wc -c < 'testdir/japh.pl'`"
  1123. test 1056 -eq "$Wc_c" ||
  1124.     echo 'testdir/japh.pl: original size 1056, current size' "$Wc_c"
  1125. fi
  1126. exit 0
  1127.  
  1128. exit 0 # Just in case...
  1129.