home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume27 / oraperl / patch05 next >
Encoding:
Text File  |  1992-01-06  |  41.4 KB  |  1,494 lines

  1. Newsgroups: comp.sources.misc
  2. From: kstock@encore.com (Kevin Stock)
  3. Subject:  v27i067:  oraperl - Extensions to Perl to access Oracle databases, Patch05
  4. Message-ID: <1992Jan6.160506.8880@sparky.imd.sterling.com>
  5. X-Md4-Signature: 42382a781566e670d17d5e98a1e8ded1
  6. Date: Mon, 6 Jan 1992 16:05:06 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: kstock@encore.com (Kevin Stock)
  10. Posting-number: Volume 27, Issue 67
  11. Archive-name: oraperl/patch05
  12. Environment: Perl, Oracle, Pro*C, optionally Curses
  13. Patch-To: oraperl: Volume 18, Issue 10
  14.  
  15. This is Patch 05 for Oraperl, a set of usersubs which allow Perl to
  16. access Oracle databases. You need Perl (v3.0.27 or better) and Oracle
  17. (including the Oracle Call Interface) to build Oraperl. If you can
  18. build Larry's Curseperl, then you can also buld Coraperl, which is
  19. Oraperl with Curses.
  20.  
  21. Oraperl appeared in comp.sources.misc as follows:
  22.  
  23.     v18i010        original
  24.     v20i097        patch 01
  25.     v22i058        patch 02
  26.     v25i035, 036    patch 03
  27.     v26i036        patch 04
  28.  
  29.  
  30.             Details of Patch 05
  31.             -------------------
  32.  
  33.   Additions
  34.   ---------
  35. Christian Holzbaur (christian@ai.univie.ac.at) sent me routines for
  36. commit and rollback, which I have added to the distribution. If you
  37. don't know what commit and rollback do, try out the commit.pl script.
  38. Thanks, Christian.
  39.  
  40. A new sample script, bind.pl, shows how ora_bind() and ora_fetch()
  41. can be combined to to perform a simple but effiecient table lookup.
  42.  
  43. A new function, ora_titles() has been added to allow a program to
  44. determine the titles of the columns fetched. See the sql script for
  45. an example of how this may be used.
  46.  
  47.   General
  48.   -------
  49. Improved error checking for ora_close and ora_logoff. In particular,
  50. note that if these functions fail, the specified csr or lda is now
  51. _not_ released, so you can still use them if you want to try to fix
  52. the problem.
  53.  
  54.   What to do
  55.   ----------
  56. Unshar this message somewhere convenient. This will create the
  57. following files:
  58.  
  59.     Patch05        the patch
  60.     bind.pl        sample script for ora_bind
  61.     commit.pl    sample script for commit and rollback
  62.  
  63. Apply the patch, then recompile.
  64.  
  65. Please let me know if you have any problems with this patch or with
  66. Oraperl in general. Any bug fixes, additions, suggestions or other
  67. comments are welcome.
  68.  
  69.  
  70.     Kevin
  71.     kstock@encore.com, kstock@gouldfr.encore.fr
  72.  
  73.  
  74. #!/bin/sh
  75. # This is a shell archive (produced by shar 3.49)
  76. # To extract the files from this archive, save it to a file, remove
  77. # everything above the "!/bin/sh" line above, and type "sh file_name".
  78. #
  79. # made 01/02/1992 15:41 UTC by kstock@mmcompta
  80. # Source directory /usr/local/src/cmd/oraperl
  81. #
  82. # existing files will NOT be overwritten unless -c is specified
  83. #
  84. # This shar contains:
  85. # length  mode       name
  86. # ------ ---------- ------------------------------------------
  87. #  34887 -rw-r--r-- Patch05
  88. #    520 -rw-r--r-- bind.pl
  89. #   1266 -rw-r--r-- commit.pl
  90. #
  91. # ============= Patch05 ==============
  92. if test -f 'Patch05' -a X"$1" != X"-c"; then
  93.     echo 'x - skipping Patch05 (File already exists)'
  94. else
  95. echo 'x - extracting Patch05 (Text)'
  96. sed 's/^X//' << 'SHAR_EOF' > 'Patch05' &&
  97. Xdiff -c orig/patchlevel.h ./patchlevel.h
  98. XPrereq: 4
  99. X*** orig/patchlevel.h    Thu Jan  2 16:22:08 1992
  100. X--- ./patchlevel.h    Fri Dec 27 16:30:02 1991
  101. X***************
  102. X*** 1,3 ****
  103. X  /* patchlevel.h */
  104. X  
  105. X! #define    PATCHLEVEL    4
  106. X--- 1,3 ----
  107. X  /* patchlevel.h */
  108. X  
  109. X! #define    PATCHLEVEL    5
  110. Xdiff -c orig/CHANGES ./CHANGES
  111. X*** orig/CHANGES    Thu Jan  2 16:22:08 1992
  112. X--- ./CHANGES    Thu Jan  2 14:29:27 1992
  113. X***************
  114. X*** 38,40 ****
  115. X--- 38,47 ----
  116. X  Added a strtoul() function
  117. X  Separated the clean and realclean/clobber targets
  118. X  Cleaned up a few bits and pieces - shouldn't make any difference
  119. X+ 
  120. X+ Patch 05
  121. X+ ========
  122. X+ Added functions for commit and rollback, plus commit.pl to demonstrate them
  123. X+ Added a function to get the column titles, modified sql command to use it
  124. X+ Added the bind.pl script
  125. X+ Improved error handling for ora_close and ora_logoff
  126. Xdiff -c orig/Makefile ./Makefile
  127. X*** orig/Makefile    Thu Jan  2 16:22:09 1992
  128. X--- ./Makefile    Thu Jan  2 15:41:11 1992
  129. X***************
  130. X*** 49,55 ****
  131. X  HDRS        = patchlevel.h orafns.h
  132. X  DEFS        = $(STRTOL) $(PUTENV) $(STR_2MORTAL)
  133. X  
  134. X! CFLAGS        = $(DEBUG) -I$(SRC) $(GLOBINCS) $(LOCINCS) $(DEFS) -O
  135. X  
  136. X  oraperl: $(SRC)/uperl.o $(OOBJS)
  137. X      $(CC) -o oraperl $(SRC)/uperl.o $(OOBJS)            \
  138. X--- 49,55 ----
  139. X  HDRS        = patchlevel.h orafns.h
  140. X  DEFS        = $(STRTOL) $(PUTENV) $(STR_2MORTAL)
  141. X  
  142. X! CFLAGS        = $(DEBUG) -I$(SRC) $(GLOBINCS) $(LOCINCS) $(DEFS) # -O
  143. X  
  144. X  oraperl: $(SRC)/uperl.o $(OOBJS)
  145. X      $(CC) -o oraperl $(SRC)/uperl.o $(OOBJS)            \
  146. X***************
  147. X*** 59,67 ****
  148. X      $(CC) -o coraperl $(SRC)/uperl.o $(COBJS) $(SRC)/usub/curses.o    \
  149. X            -lm $(OCILIB) $(NETLIBS) $(ORALIBS) $(CLIBS) $(LIBS) $(CURSELIB)
  150. X  
  151. X! cusersub.o:    usersub.c
  152. X      @rm -f cusersub.c
  153. X      ln usersub.c cusersub.c
  154. X      $(CC) -c $(CFLAGS) -DCURSES cusersub.c
  155. X  
  156. X  oracle.c: $(SRC)/usub/mus oracle.mus
  157. X--- 59,69 ----
  158. X      $(CC) -o coraperl $(SRC)/uperl.o $(COBJS) $(SRC)/usub/curses.o    \
  159. X            -lm $(OCILIB) $(NETLIBS) $(ORALIBS) $(CLIBS) $(LIBS) $(CURSELIB)
  160. X  
  161. X! cusersub.c:    usersub.c
  162. X      @rm -f cusersub.c
  163. X      ln usersub.c cusersub.c
  164. X+ 
  165. X+ cusersub.o:    cusersub.c
  166. X      $(CC) -c $(CFLAGS) -DCURSES cusersub.c
  167. X  
  168. X  oracle.c: $(SRC)/usub/mus oracle.mus
  169. Xdiff -c orig/README ./README
  170. X*** orig/README    Thu Jan  2 16:22:09 1992
  171. X--- ./README    Fri Dec 27 16:50:07 1991
  172. X***************
  173. X*** 20,26 ****
  174. X      DEBUG        -DDEBUGGING, -DPERL_DEBUGGING or leave blank;
  175. X              see orafns.h for an explanation
  176. X      PUTENV        \ 
  177. X!     STRTOL         +- system dependent - see Makefile for details
  178. X      STR_2MORTAL    /
  179. X  
  180. X  As well as oraperl, you can also type "make coraperl" to create a version
  181. X--- 20,26 ----
  182. X      DEBUG        -DDEBUGGING, -DPERL_DEBUGGING or leave blank;
  183. X              see orafns.h for an explanation
  184. X      PUTENV        \ 
  185. X!     STRTOUL         +- system dependent - see Makefile for details
  186. X      STR_2MORTAL    /
  187. X  
  188. X  As well as oraperl, you can also type "make coraperl" to create a version
  189. X***************
  190. X*** 49,54 ****
  191. X--- 49,56 ----
  192. X      strtoul.c    for systems which don't have strtoul(3)
  193. X  
  194. X  Examples
  195. X+     bind.pl        use of ora_bind and ora_fetch for table lookup
  196. X+     commit.pl    using commit and rollback
  197. X      debug-p        tests to see if debugging is available
  198. X      ex.pl        simple example of Oraperl functions
  199. X      mkdb.pl        more extensive example, using curses if available
  200. Xdiff -c orig/ex.pl ./ex.pl
  201. X*** orig/ex.pl    Thu Jan  2 16:19:13 1992
  202. X--- ./ex.pl    Thu Nov 28 16:18:43 1991
  203. X***************
  204. X*** 1,4 ****
  205. X! format top =
  206. X         Name                           Phone
  207. X         ====                           =====
  208. X  .
  209. X--- 1,4 ----
  210. X! format STDOUT_TOP =
  211. X         Name                           Phone
  212. X         ====                           =====
  213. X  .
  214. Xdiff -c orig/mkdb.pl ./mkdb.pl
  215. X*** orig/mkdb.pl    Thu Jan  2 16:22:10 1992
  216. X--- ./mkdb.pl    Fri Dec 27 16:27:24 1991
  217. X***************
  218. X*** 13,18 ****
  219. X--- 13,21 ----
  220. X  # make sure that we really are running (c)oraperl
  221. X  die ("You should use oraperl, not perl\n") unless defined &ora_login;
  222. X  
  223. X+ # get debugging & error codes
  224. X+ require('oraperl.ph');
  225. X+ 
  226. X  # Arrange to use curses functions if they're available.
  227. X  # (This is just showing off)
  228. X  
  229. X***************
  230. X*** 59,67 ****
  231. X      eval <<'____END_OF_PLAIN_STUFF';
  232. X  
  233. X      $curses = 0;
  234. X!     $ora_debug = 8;
  235. X  
  236. X!     format top =
  237. X             Name         Ext
  238. X             ====         ===
  239. X  .
  240. X--- 62,70 ----
  241. X      eval <<'____END_OF_PLAIN_STUFF';
  242. X  
  243. X      $curses = 0;
  244. X!     $ora_debug = $ODBG_EXEC | $ODBG_MALLOC;
  245. X  
  246. X!     format STDOUT_TOP =
  247. X             Name         Ext
  248. X             ====         ===
  249. X  .
  250. X***************
  251. X*** 99,107 ****
  252. X      do after();
  253. X  }
  254. X  
  255. X- # get debugging & error codes
  256. X- require('oraperl.ph');
  257. X- 
  258. X  # set these as strings to make the code more readable
  259. X  $CREATE = "create table tryit (name char(10), ext number(3))";
  260. X  $INSERT = "insert into tryit values (:1, :2)";
  261. X--- 102,107 ----
  262. X***************
  263. X*** 111,117 ****
  264. X  
  265. X  # create the database
  266. X  
  267. X! $lda = &ora_login("t", "kstock", "kstock")    || die $ora_errstr;
  268. X  &ora_do($lda, $CREATE)                || die $ora_errstr;
  269. X  
  270. X  # put some data into it
  271. X--- 111,117 ----
  272. X  
  273. X  # create the database
  274. X  
  275. X! $lda = &ora_login('t', 'kstock', 'kstock')    || die $ora_errstr;
  276. X  &ora_do($lda, $CREATE)                || die $ora_errstr;
  277. X  
  278. X  # put some data into it
  279. X***************
  280. X*** 151,155 ****
  281. X  angela:208
  282. X  larry:424
  283. X  catherine:201
  284. X! randall:306
  285. X  arnold:305
  286. X--- 151,155 ----
  287. X  angela:208
  288. X  larry:424
  289. X  catherine:201
  290. X! randal:306
  291. X  arnold:305
  292. Xdiff -c orig/oracle.mus ./oracle.mus
  293. X*** orig/oracle.mus    Thu Jan  2 16:22:10 1992
  294. X--- ./oracle.mus    Thu Jan  2 11:00:31 1992
  295. X***************
  296. X*** 29,39 ****
  297. X--- 29,42 ----
  298. X      US_ora_version,
  299. X      US_ora_login,
  300. X      US_ora_open,
  301. X+     US_ora_titles,
  302. X      US_ora_bind,
  303. X      US_ora_fetch,
  304. X      US_ora_close,
  305. X      US_ora_do,
  306. X      US_ora_logoff,
  307. X+     US_ora_commit,
  308. X+     US_ora_rollback,
  309. X  };
  310. X  
  311. X  static int usersub();
  312. X***************
  313. X*** 60,70 ****
  314. X--- 63,76 ----
  315. X      make_usub("ora_version",    US_ora_version,    usersub, filename);
  316. X      make_usub("ora_login",    US_ora_login,    usersub, filename);
  317. X      make_usub("ora_open",    US_ora_open,    usersub, filename);
  318. X+     make_usub("ora_titles",    US_ora_titles,    usersub, filename);
  319. X      make_usub("ora_bind",    US_ora_bind,    usersub, filename);
  320. X      make_usub("ora_fetch",    US_ora_fetch,    usersub, filename);
  321. X      make_usub("ora_close",    US_ora_close,    usersub, filename);
  322. X      make_usub("ora_do",        US_ora_do,    usersub, filename);
  323. X      make_usub("ora_logoff",    US_ora_logoff,    usersub, filename);
  324. X+     make_usub("ora_commit",    US_ora_commit,    usersub, filename);
  325. X+     make_usub("ora_rollback",    US_ora_rollback,usersub, filename);
  326. X  };
  327. X  
  328. X  
  329. X***************
  330. X*** 95,100 ****
  331. X--- 101,124 ----
  332. X  I    char *    stmt
  333. X  END
  334. X  
  335. X+     case US_ora_titles:
  336. X+     if (items != 1) {
  337. X+         fatal("Usage: @array = &ora_titles($csr)");
  338. X+     } else {
  339. X+         char *csr        = (char *) str_get(st[1]);
  340. X+         int  retval;
  341. X+ 
  342. X+         retval = ora_titles(csr);
  343. X+         astore(stack, sp + retval, Nullstr);
  344. X+         st = stack->ary_array + sp;
  345. X+         for (i = 0 ; i < retval ; i++) {
  346. X+         tmps = ora_result[i];
  347. X+         st[i] = str_2mortal(str_make(tmps, strlen(tmps)));
  348. X+         }
  349. X+         return sp + retval - 1;
  350. X+     }
  351. X+     /* NOTREACHED */
  352. X+ 
  353. X      case US_ora_fetch:
  354. X      if (items != 1) {
  355. X          if (curcsv->wantarray)
  356. X***************
  357. X*** 166,171 ****
  358. X--- 190,203 ----
  359. X  END
  360. X  
  361. X  CASE    char *    ora_logoff
  362. X+ I    char *    lda
  363. X+ END
  364. X+ 
  365. X+ CASE    char *    ora_commit
  366. X+ I    char *    lda
  367. X+ END  
  368. X+ 
  369. X+ CASE    char *    ora_rollback
  370. X  I    char *    lda
  371. X  END
  372. X  
  373. Xdiff -c orig/orafns.c ./orafns.c
  374. X*** orig/orafns.c    Thu Jan  2 16:22:11 1992
  375. X--- ./orafns.c    Thu Jan  2 11:52:39 1992
  376. X***************
  377. X*** 252,259 ****
  378. X      DEBUG(8, 1, (fprintf(stderr,
  379. X          "ora_open(%s, \"%s\")\n", lda_s, stmt)));
  380. X      DEBUG(32, 0, (fprintf(stderr,
  381. X!         "ora_open: string \"%s\" converted to lda %#lx\n",
  382. X!         lda_s, lda)));
  383. X  
  384. X      if (check_lda(lda) == 0)
  385. X      {
  386. X--- 252,258 ----
  387. X      DEBUG(8, 1, (fprintf(stderr,
  388. X          "ora_open(%s, \"%s\")\n", lda_s, stmt)));
  389. X      DEBUG(32, 0, (fprintf(stderr,
  390. X!         "ora_open: string \"%s\" converted to lda %#lx\n", lda_s, lda)));
  391. X  
  392. X      if (check_lda(lda) == 0)
  393. X      {
  394. X***************
  395. X*** 336,341 ****
  396. X--- 335,352 ----
  397. X              "ora_open: got rcode array %d items %d bytes at %#lx\n",
  398. X              i, i * sizeof(short), (long) csr->rcode)));
  399. X  
  400. X+         if ((csr->len = (short *) malloc(i * sizeof(short))) == NULL)
  401. X+         {
  402. X+             (void) ora_dropcursor(csr);
  403. X+             DEBUG((8 | 128), -1, (fputs(
  404. X+                 "ora_open: out of memory\n", stderr)));
  405. X+             ora_errno = ORAP_NOMEM;
  406. X+             return((char *) NULL);
  407. X+         }
  408. X+         DEBUG(128, 0, (fprintf(stderr,
  409. X+             "ora_open: got len array %d items %d bytes at %#lx\n",
  410. X+             i, i * sizeof(short), (long) csr->len)));
  411. X+ 
  412. X          csr->nfields = i;
  413. X  
  414. X          for (i = 0 ; i < csr->nfields ; i++)
  415. X***************
  416. X*** 360,365 ****
  417. X--- 371,377 ----
  418. X              odefin(csr->csr, i + 1, csr->data[i], dsize + 1, 5, 0,
  419. X                  (short *) 0, (char *) 0, 0, 0, (short *) 0,
  420. X                  &(csr->rcode[i]));
  421. X+             csr->len[i] = dsize;
  422. X          }
  423. X      }
  424. X      else
  425. X***************
  426. X*** 379,384 ****
  427. X--- 391,458 ----
  428. X  }
  429. X  
  430. X  
  431. X+ /* ora_titles(csr)
  432. X+  *
  433. X+  * returns the column headers for the query referenced by csr
  434. X+  */
  435. X+ 
  436. X+ int ora_titles(csr_s)
  437. X+ char *csr_s;
  438. X+ {
  439. X+     int i;
  440. X+     short len;
  441. X+     struct cursor *csr = (struct cursor *)strtoul(csr_s, (char **) NULL, 0);
  442. X+ 
  443. X+     DEBUG(8, 1, (fprintf(stderr, "ora_titles(%s)\n", csr_s)));
  444. X+     DEBUG(32, 0, (fprintf(stderr,
  445. X+         "ora_titles: string \"%s\" converted to csr %#lx\n", csr_s, csr)));
  446. X+ 
  447. X+     if (check_csr(csr) == 0)
  448. X+     {
  449. X+         DEBUG(8, -1, (fputs("ora_titles: not a csr\n", stderr)));
  450. X+         ora_errno = ORAP_INVCSR;
  451. X+         return(0);
  452. X+     }
  453. X+     else if (csr->nfields == 0)
  454. X+     {
  455. X+         DEBUG(8, -1, (fputs("ora_titles: nothing to return\n",stderr)));
  456. X+         ora_errno = ORAP_NODATA;
  457. X+         return(0);
  458. X+     }
  459. X+ 
  460. X+     for (i = 0 ; i < csr->nfields ; i++)
  461. X+     {
  462. X+         len = csr->len[i];
  463. X+         oname(csr->csr, i + 1, (char *) -1, (short *) -1,
  464. X+               csr->data[i], &len);
  465. X+         csr->data[i][csr->len[i]] = '\0';
  466. X+     }
  467. X+ 
  468. X+ #ifdef    DEBUGGING
  469. X+     /* NOTE: use the DEBUG macro for printing even here in case
  470. X+      *     the debug output format is changed later
  471. X+      */
  472. X+ 
  473. X+     if (ora_debug & 8)
  474. X+     {
  475. X+         DEBUG(8, 0, (fputs("ora_titles: returning titles:\n", stderr)));
  476. X+         for (i = 0 ; i < csr->nfields ; i++)
  477. X+         {
  478. X+             DEBUG(8, 0, (fprintf(stderr,
  479. X+                 "ora_titles: field %4d title \"%s\"\n",
  480. X+                 i, csr->data[i])));
  481. X+         }
  482. X+     }
  483. X+ #endif
  484. X+ 
  485. X+     DEBUG(8, -1, (fprintf(stderr,
  486. X+         "ora_titles: returning %d items\n", csr->nfields)));
  487. X+     ora_result = csr->data;
  488. X+     ora_errno = 0;
  489. X+     return(csr->nfields);
  490. X+ }
  491. X+ 
  492. X+ 
  493. X  /* ora_fetch(csr)
  494. X   *
  495. X   * returns the next set of data from the cursor
  496. X***************
  497. X*** 390,400 ****
  498. X      int i;
  499. X      struct cursor *csr = (struct cursor *)strtoul(csr_s, (char **) NULL, 0);
  500. X  
  501. X!     DEBUG(8, 1, (fprintf(stderr,
  502. X!         "ora_fetch(%s)\n", csr_s)));
  503. X      DEBUG(32, 0, (fprintf(stderr,
  504. X!         "ora_fetch: string \"%s\" converted to csr %#lx\n",
  505. X!         csr_s, csr)));
  506. X  
  507. X      if (check_csr(csr) == 0)
  508. X      {
  509. X--- 464,472 ----
  510. X      int i;
  511. X      struct cursor *csr = (struct cursor *)strtoul(csr_s, (char **) NULL, 0);
  512. X  
  513. X!     DEBUG(8, 1, (fprintf(stderr, "ora_fetch(%s)\n", csr_s)));
  514. X      DEBUG(32, 0, (fprintf(stderr,
  515. X!         "ora_fetch: string \"%s\" converted to csr %#lx\n", csr_s, csr)));
  516. X  
  517. X      if (check_csr(csr) == 0)
  518. X      {
  519. X***************
  520. X*** 464,469 ****
  521. X--- 536,542 ----
  522. X          }
  523. X      }
  524. X  #endif
  525. X+ 
  526. X      DEBUG(8, -1, (fprintf(stderr,
  527. X          "ora_fetch: returning %d items\n", csr->nfields)));
  528. X      ora_result = csr->data;
  529. X***************
  530. X*** 546,553 ****
  531. X  {
  532. X      char *csr_s;
  533. X  
  534. X!     DEBUG(8, 1, (fprintf(stderr,
  535. X!         "ora_do(%s, \"%s\")\n", lda_s, stmt)));
  536. X  
  537. X      if ((csr_s = ora_open(lda_s, stmt)) == NULL)
  538. X      {
  539. X--- 619,625 ----
  540. X  {
  541. X      char *csr_s;
  542. X  
  543. X!     DEBUG(8, 1, (fprintf(stderr, "ora_do(%s, \"%s\")\n", lda_s, stmt)));
  544. X  
  545. X      if ((csr_s = ora_open(lda_s, stmt)) == NULL)
  546. X      {
  547. X***************
  548. X*** 582,589 ****
  549. X  
  550. X      DEBUG(8, 1, (fprintf(stderr, "ora_close(%s)\n", csr_s)));
  551. X      DEBUG(32, 0, (fprintf(stderr,
  552. X!         "ora_close: string \"%s\" converted to csr %#lx\n",
  553. X!         csr_s, csr)));
  554. X  
  555. X      if (check_csr(csr) == 0)
  556. X      {
  557. X--- 654,660 ----
  558. X  
  559. X      DEBUG(8, 1, (fprintf(stderr, "ora_close(%s)\n", csr_s)));
  560. X      DEBUG(32, 0, (fprintf(stderr,
  561. X!         "ora_close: string \"%s\" converted to csr %#lx\n", csr_s, csr)));
  562. X  
  563. X      if (check_csr(csr) == 0)
  564. X      {
  565. X***************
  566. X*** 592,603 ****
  567. X          return(NULL);
  568. X      }
  569. X  
  570. X!     oclose(csr->csr);
  571. X!     ora_errno = csr->csr->csrrc;
  572. X!     (void) ora_dropcursor(csr);
  573. X! 
  574. X!     DEBUG(8, -1, (fputs("ora_close: returning OK\n", stderr)));
  575. X!     return(OK);
  576. X  }
  577. X  
  578. X  
  579. X--- 663,680 ----
  580. X          return(NULL);
  581. X      }
  582. X  
  583. X!     if (oclose(csr->csr) != 0)
  584. X!     {
  585. X!         ora_errno = csr->csr->csrrc;
  586. X!         DEBUG(8, -1, (fputs("ora_close: oclose failed\n", stderr)));
  587. X!         return(NULL);
  588. X!     }
  589. X!     else
  590. X!     {
  591. X!         (void) ora_dropcursor(csr);
  592. X!         DEBUG(8, -1, (fputs("ora_close: returning OK\n", stderr)));
  593. X!         return(OK);
  594. X!     }
  595. X  }
  596. X  
  597. X  
  598. X***************
  599. X*** 613,620 ****
  600. X  
  601. X      DEBUG(8, 1, (fprintf(stderr, "ora_logoff(%s)\n", lda_s)));
  602. X      DEBUG(32, 0, (fprintf(stderr,
  603. X!         "ora_logoff: string \"%s\" converted to lda %#lx\n",
  604. X!         lda_s, lda)));
  605. X  
  606. X      if (check_lda(lda) == 0)
  607. X      {
  608. X--- 690,696 ----
  609. X  
  610. X      DEBUG(8, 1, (fprintf(stderr, "ora_logoff(%s)\n", lda_s)));
  611. X      DEBUG(32, 0, (fprintf(stderr,
  612. X!         "ora_logoff: string \"%s\" converted to lda %#lx\n", lda_s, lda)));
  613. X  
  614. X      if (check_lda(lda) == 0)
  615. X      {
  616. X***************
  617. X*** 623,632 ****
  618. X          return(NULL);
  619. X      }
  620. X  
  621. X!     ologof(lda->csr);
  622. X!     ora_errno = lda->csr->csrrc;
  623. X!     (void) ora_droplda(lda);
  624. X  
  625. X!     DEBUG(8, -1, (fputs("ora_logoff: returning OK\n", stderr)));
  626. X!     return(OK);
  627. X  }
  628. X--- 699,784 ----
  629. X          return(NULL);
  630. X      }
  631. X  
  632. X!     if (ologof(lda->csr) != 0)
  633. X!     {
  634. X!         ora_errno = lda->csr->csrrc;
  635. X!         DEBUG(8, -1, (fputs("ora_logoff: ologoff failed\n", stderr)));
  636. X!         return(NULL);
  637. X!     }
  638. X!     else
  639. X!     {
  640. X!         (void) ora_droplda(lda);
  641. X!         DEBUG(8, -1, (fputs("ora_logoff: returning OK\n", stderr)));
  642. X!         return(OK);
  643. X!     }
  644. X! }
  645. X! 
  646. X! 
  647. X! /* ora_commit(lda)
  648. X!  *
  649. X!  * Commits all pending transactions on the specified lda.
  650. X!  */
  651. X! 
  652. X! char *ora_commit(lda_s)
  653. X! char *lda_s;
  654. X! {
  655. X!     struct cursor *lda = (struct cursor *)strtoul(lda_s, (char **) NULL, 0);
  656. X! 
  657. X!     DEBUG(8, 1, (fprintf(stderr, "ora_commit(%s)\n", lda_s)));
  658. X!     DEBUG(32, 0, (fprintf(stderr,
  659. X!         "ora_commit: string \"%s\" converted to lda %#lx\n", lda_s, lda)));
  660. X! 
  661. X!     if (check_lda(lda) == 0)
  662. X!     {
  663. X!         DEBUG(8, -1, (fputs("ora_commit: not an lda\n", stderr)));
  664. X!         ora_errno = ORAP_INVLDA;
  665. X!         return(NULL);
  666. X!     }
  667. X! 
  668. X!     if (ocom(lda->csr) != 0)
  669. X!     {
  670. X!         ora_errno = lda->csr->csrrc;
  671. X!         DEBUG(8, -1, (fputs("ora_commit: ocom failed\n", stderr)));
  672. X!         return(NULL);
  673. X!     }
  674. X!     else
  675. X!     {
  676. X!         DEBUG(8, -1, (fputs("ora_commit: returning OK\n", stderr)));
  677. X!         return(OK);
  678. X!     }
  679. X! }
  680. X! 
  681. X! 
  682. X! /* ora_rollback(lda)
  683. X!  *
  684. X!  * rollbacks all pending transactions on the specified lda.
  685. X!  */
  686. X! 
  687. X! char *ora_rollback(lda_s)
  688. X! char *lda_s;
  689. X! {
  690. X!     struct cursor *lda = (struct cursor *)strtoul(lda_s, (char **) NULL, 0);
  691. X  
  692. X!     DEBUG(8, 1, (fprintf(stderr, "ora_rollback(%s)\n", lda_s)));
  693. X!     DEBUG(32, 0, (fprintf(stderr,
  694. X!        "ora_rollback: string \"%s\" converted to lda %#lx\n", lda_s, lda)));
  695. X! 
  696. X!     if (check_lda(lda) == 0)
  697. X!     {
  698. X!         DEBUG(8, -1, (fputs("ora_rollback: not an lda\n", stderr)));
  699. X!         ora_errno = ORAP_INVLDA;
  700. X!         return(NULL);
  701. X!     }
  702. X! 
  703. X!     if (orol(lda->csr) != 0)
  704. X!     {
  705. X!         ora_errno = lda->csr->csrrc;
  706. X!         DEBUG(8, -1, (fputs("ora_rollback: orol failed\n", stderr)));
  707. X!         return(NULL);
  708. X!     }
  709. X!     else
  710. X!     {
  711. X!         DEBUG(8, -1, (fputs("ora_rollback: returning OK\n", stderr)));
  712. X!         return(OK);
  713. X!     }
  714. X  }
  715. Xdiff -c orig/orafns.h ./orafns.h
  716. X*** orig/orafns.h    Thu Jan  2 16:22:11 1992
  717. X--- ./orafns.h    Thu Jan  2 11:07:44 1992
  718. X***************
  719. X*** 18,27 ****
  720. X          *ora_open(),
  721. X          *ora_close(),
  722. X          *ora_do(),
  723. X!         *ora_logoff();
  724. X  
  725. X  int        ora_bind(),
  726. X!         ora_fetch();
  727. X  
  728. X  
  729. X  /* These functions are internal to the system, not for public consumption */
  730. X--- 18,30 ----
  731. X          *ora_open(),
  732. X          *ora_close(),
  733. X          *ora_do(),
  734. X!         *ora_logoff(),
  735. X!         *ora_commit(),
  736. X!         *ora_rollback();
  737. X  
  738. X  int        ora_bind(),
  739. X!         ora_fetch(),
  740. X!         ora_titles();
  741. X  
  742. X  
  743. X  /* These functions are internal to the system, not for public consumption */
  744. X***************
  745. X*** 70,76 ****
  746. X      struct    csrdef    *csr;
  747. X      char        *hda,        /* used if this cursor is an lda     */
  748. X              **data;        /* used to receive database contents */
  749. X!     short        *rcode;        /* used to receive fetch error codes */
  750. X      int        nfields,    /* number of fields to retrieve         */
  751. X              varfields;    /* number of modifiable variables    */
  752. X      struct    cursor    *next;        /* list pointer                 */
  753. X--- 73,80 ----
  754. X      struct    csrdef    *csr;
  755. X      char        *hda,        /* used if this cursor is an lda     */
  756. X              **data;        /* used to receive database contents */
  757. X!     short        *rcode,        /* used to receive fetch error codes */
  758. X!             *len;        /* used to receive field lengths     */
  759. X      int        nfields,    /* number of fields to retrieve         */
  760. X              varfields;    /* number of modifiable variables    */
  761. X      struct    cursor    *next;        /* list pointer                 */
  762. Xdiff -c orig/oraperl.1 ./oraperl.1
  763. X*** orig/oraperl.1    Thu Jan  2 16:22:15 1992
  764. X--- ./oraperl.1    Thu Jan  2 11:03:36 1992
  765. X***************
  766. X*** 12,19 ****
  767. X--- 12,22 ----
  768. X  
  769. X  $lda = &ora_login($database, $name, $password)
  770. X  $csr = &ora_open($lda, $stmt)
  771. X+ &ora_titles($csr)
  772. X  &ora_bind($csr, $var, ...)
  773. X  &ora_fetch($csr)
  774. X+ &ora_commit($lda)
  775. X+ &ora_rollback($lda)
  776. X  &ora_close($csr)
  777. X  &ora_do($lda, $stmt)
  778. X  &ora_logoff($lda)
  779. X***************
  780. X*** 54,59 ****
  781. X--- 57,70 ----
  782. X  is only suitable for statements which do not return data
  783. X  or contain substitution variables.
  784. X  
  785. X+ A program may determine the field titles of an executed query
  786. X+ by calling the \fIora_titles\fP.
  787. X+ This function takes a single parameter,
  788. X+ a statement identifier (obtained from \fIora_open\fP)
  789. X+ indicating the query for which the titles are required.
  790. X+ The titles are returned as an array of strings,
  791. X+ one for each column.
  792. X+ 
  793. X  If the SQL statement contains substitution variables
  794. X  \fIora_bind\fP is used to assign values to them.
  795. X  This function takes a statement identifier (obtained from \fIora_open\fP)
  796. X***************
  797. X*** 77,82 ****
  798. X--- 88,99 ----
  799. X  Every \fIora_open\fP call should have a corresponding \fIora_close\fP,
  800. X  even if it did not return any data.
  801. X  
  802. X+ Modifications to a database
  803. X+ may be committed or rolled back
  804. X+ using the \fIora_commit\fP and \fIora_rollback\fP functions.
  805. X+ These functions take a single parameter,
  806. X+ a login identifier obtained from \fIora_login\fP.
  807. X+ 
  808. X  When the program no longer needs to access a given database,
  809. X  the login identifier should be released using the \fIora_logoff\fP function.
  810. X  This function returns the string \fBOK\fP.
  811. X***************
  812. X*** 191,201 ****
  813. X  are supported.
  814. X  .SH NOTES
  815. X  In keeping with the philosophy of \fIPerl\fP,
  816. X! there is no pre-defined limit to the number of simultaneous logins
  817. X  or SQL statements which may be active,
  818. X  nor to the number of data fields which may be returned by a query.
  819. X  The only limits are those imposed by the amount of memory available,
  820. X  or by \fIOracle\fP.
  821. X  
  822. X  Debugging option \fB32\fP only reports internal string/numeric translations,
  823. X  not those performed on the data retrieved from the database.
  824. X--- 208,226 ----
  825. X  are supported.
  826. X  .SH NOTES
  827. X  In keeping with the philosophy of \fIPerl\fP,
  828. X! there is no pre\-defined limit to the number of simultaneous logins
  829. X  or SQL statements which may be active,
  830. X  nor to the number of data fields which may be returned by a query.
  831. X  The only limits are those imposed by the amount of memory available,
  832. X  or by \fIOracle\fP.
  833. X+ 
  834. X+ Since the parameter to \fIora_commit\fP and \fIora_rollback\fP
  835. X+ is a login identifier and not a statement identifier,
  836. X+ \fIall\fP work associated with that login identifier
  837. X+ will be commited or rolled back simultaneously.
  838. X+ If you wish to be able to commit or roll back individual statements
  839. X+ you will have to call \fIora_login\fP multiple times
  840. X+ to obtain a login identifier for each statement.
  841. X  
  842. X  Debugging option \fB32\fP only reports internal string/numeric translations,
  843. X  not those performed on the data retrieved from the database.
  844. Xdiff -c orig/oraperl.doc ./oraperl.doc
  845. X*** orig/oraperl.doc    Thu Jan  2 16:22:05 1992
  846. X--- ./oraperl.doc    Thu Jan  2 11:03:45 1992
  847. X***************
  848. X*** 27,33 ****
  849. X  because it requires fixed addresses to be specified for receipt of data.
  850. X  A new interface was therefore created for \fBOraperl\fP.
  851. X  
  852. X! The interface follows the idiom of the following seven tasks:
  853. X  
  854. X  .in +5
  855. X  .ta .4i 4.4i
  856. X--- 27,33 ----
  857. X  because it requires fixed addresses to be specified for receipt of data.
  858. X  A new interface was therefore created for \fBOraperl\fP.
  859. X  
  860. X! The interface follows the idiom of the following tasks:
  861. X  
  862. X  .in +5
  863. X  .ta .4i 4.4i
  864. X***************
  865. X*** 34,46 ****
  866. X  .nf
  867. X  \fBTask        Interface\fP
  868. X  
  869. X! \fB1\fP    log in to the database    \fIora_login\fP
  870. X! \fB2\fP    open a stream for an SQL statement    \fIora_open\fP
  871. X! \fB3\fP    modify the statement    \fIora_bind\fP
  872. X! \fB4\fP    get the data    \fIora_fetch\fP
  873. X! \fB5\fP    close the stream    \fIora_close\fP
  874. X! \fB6\fP    execute an SQL statement    \fIora_do\fP
  875. X! \fB7\fP    log off of the database    \fIora_logoff\fP
  876. X  .fi
  877. X  .in -5
  878. X  
  879. X--- 34,50 ----
  880. X  .nf
  881. X  \fBTask        Interface\fP
  882. X  
  883. X! \fB\01\fP    log in to the database    \fIora_login\fP
  884. X! \fB\02\fP    open a stream for an SQL statement    \fIora_open\fP
  885. X! \fB\03\fP    retrieve the column names    \fIora_titles\fP
  886. X! \fB\04\fP    modify the statement    \fIora_bind\fP
  887. X! \fB\05\fP    get the data    \fIora_fetch\fP
  888. X! \fB\06\fP    close the stream    \fIora_close\fP
  889. X! \fB\07\fP    execute an SQL statement    \fIora_do\fP
  890. X! \fB\08\fP    commit the work done to a database    \fIora_commit\fP
  891. X! \fB\09\fP    roll back the work done to a database    \fIora_rollback\fP
  892. X! \fB10\fP    log off of the database    \fIora_logoff\fP
  893. X! 
  894. X  .fi
  895. X  .in -5
  896. X  
  897. X***************
  898. X*** 57,62 ****
  899. X--- 61,74 ----
  900. X  and returns an identifier to the user
  901. X  to be supplied as a parameter to future function calls.
  902. X  
  903. X+ \fBOraperl\fP's notion of a cursor is an extension of the \fIOCI\fP cursor.
  904. X+ An \fIOraperl\fP cursor contains an \fIOCI\fP cursor
  905. X+ together with other fields as required.
  906. X+ A cursor returned by the \fIora_login\fP function
  907. X+ also includes a host data area.
  908. X+ A cursor returned by the \fIora_open\fP function
  909. X+ also includes space for returned data and other status information.
  910. X+ 
  911. X  A set of functions (not directly accessible to the user)
  912. X  deals with the allocation and release of cursors.
  913. X  
  914. X***************
  915. X*** 117,122 ****
  916. X--- 129,141 ----
  917. X  It returns the address of the \fIcsr\fP.
  918. X  
  919. X  
  920. X+ \fBora_titles(csr)\fP
  921. X+ 
  922. X+ Returnes an array contain the field names associated with the query
  923. X+ identified by \fIcsr\fP.
  924. X+ This may be useful in programs which allow the user to specify a query.
  925. X+ 
  926. X+ 
  927. X  \fBora_bind(csr, var, ...)\fP
  928. X  
  929. X  Binds the specified \fIvar\fPs to the substitution variables
  930. X***************
  931. X*** 154,159 ****
  932. X--- 173,190 ----
  933. X  of the \fIcsr\fP used.
  934. X  It is suitable for statements which do not return any data
  935. X  and which do not contain any substitution variables.
  936. X+ 
  937. X+ 
  938. X+ \fBora_commit(lda)\fP
  939. X+ 
  940. X+ Calls \fBOCI\ ocom\fP to commit the work done under the given \fIlda\fP.
  941. X+ The string \fBOK\fP is returned.
  942. X+ 
  943. X+ 
  944. X+ \fBora_rollback(lda)\fP
  945. X+ 
  946. X+ Calls \fBOCI\ orol\fP to roll back the work done under the given \fIlda\fP.
  947. X+ The string \fBOK\fP is returned.
  948. X  
  949. X  
  950. X  \fBora_logoff(lda)\fP
  951. Xdiff -c orig/oraperl.ph ./oraperl.ph
  952. X*** orig/oraperl.ph    Thu Jan  2 16:19:32 1992
  953. X--- ./oraperl.ph    Fri Dec 27 16:03:04 1991
  954. X***************
  955. X*** 1,6 ****
  956. X  # oraperl.ph
  957. X  #
  958. X! # Various defines which may be useful in oraperl programs
  959. X  #
  960. X  # Author:    Kevin Stock
  961. X  # Date:        28th October 1991
  962. X--- 1,6 ----
  963. X  # oraperl.ph
  964. X  #
  965. X! # Various constants which may be useful in oraperl programs
  966. X  #
  967. X  # Author:    Kevin Stock
  968. X  # Date:        28th October 1991
  969. Xdiff -c orig/oraperl.ref ./oraperl.ref
  970. X*** orig/oraperl.ref    Thu Jan  2 16:22:05 1992
  971. X--- ./oraperl.ref    Thu Jan  2 15:45:15 1992
  972. X***************
  973. X*** 2,54 ****
  974. X  .\"
  975. X  .nf
  976. X  .\"
  977. X! .vs 10
  978. X! .ps 10
  979. X! \fBOraperl Quick Reference\fP
  980. X  .ps 8
  981. X  .sp 2
  982. X- .ps 10
  983. X  \fBOraperl Functions\fP
  984. X! .ps 8
  985. X  .in +2m
  986. X! .sp
  987. X  .ti -2m
  988. X  \fB&ora_version\fP
  989. X  Displays version and copyright information for Oraperl.
  990. X! .sp
  991. X  .ti -2m
  992. X  \fB$lda = &ora_login($database, $name, $password)\fP
  993. X  Logs into the specified database with the name and password given.
  994. X  Returns an \fIlda\fP for use with \fIora_open()\fP.
  995. X! .sp
  996. X  .ti -2m
  997. X  \fB$csr = &ora_open($lda, $statement)\fP
  998. X  Associates the given SQL statement in the database identified by $lda.
  999. X  Executes it if it contains no substitution variables.
  1000. X  Returns a \fIcsr\fP for use with \fIora_fetch()\fP.
  1001. X! .sp
  1002. X  .ti -2m
  1003. X  \fB&ora_bind($csr, $var, ...)\fP
  1004. X  Binds the given values to the substition variables in the SQL statement
  1005. X  associated with $csr, and executes the resulting statement.
  1006. X! .sp
  1007. X  .ti -2m
  1008. X! \fB$n = &ora_fetch($csr)\fP
  1009. X  Returns the number of fields available from the query.
  1010. X! .sp
  1011. X  .ti -2m
  1012. X! \fB@ary = &ora_fetch($csr)\fP
  1013. X  Retrieves the (next) output data from the statement identified by $csr.
  1014. X! .sp
  1015. X  .ti -2m
  1016. X  \fB&ora_close($csr)\fP
  1017. X  Finishes the SQL statement identified by $csr.
  1018. X! .sp
  1019. X  .ti -2m
  1020. X  \fB&ora_do($lda, $stmt)\fP
  1021. X  Equivalent to \fI&ora_close\fP(\fI&ora_open(...))\fP
  1022. X  for statements which have no substitution variables and do not return data.
  1023. X! .sp
  1024. X  .ti -2m
  1025. X  \fB&ora_logoff($lda)\fP
  1026. X  Logs out of the database identified by $lda.
  1027. X--- 2,64 ----
  1028. X  .\"
  1029. X  .nf
  1030. X  .\"
  1031. X! .vs 8
  1032. X  .ps 8
  1033. X+ \fBOraperl Quick Reference\fP
  1034. X  .sp 2
  1035. X  \fBOraperl Functions\fP
  1036. X! .ps 6
  1037. X  .in +2m
  1038. X! 
  1039. X  .ti -2m
  1040. X  \fB&ora_version\fP
  1041. X  Displays version and copyright information for Oraperl.
  1042. X! 
  1043. X  .ti -2m
  1044. X  \fB$lda = &ora_login($database, $name, $password)\fP
  1045. X  Logs into the specified database with the name and password given.
  1046. X  Returns an \fIlda\fP for use with \fIora_open()\fP.
  1047. X! 
  1048. X  .ti -2m
  1049. X  \fB$csr = &ora_open($lda, $statement)\fP
  1050. X  Associates the given SQL statement in the database identified by $lda.
  1051. X  Executes it if it contains no substitution variables.
  1052. X  Returns a \fIcsr\fP for use with \fIora_fetch()\fP.
  1053. X! 
  1054. X! .ti -2m
  1055. X! \fB@ary = &ora_titles($csr)\fP
  1056. X! Returns the column names associated with the query.
  1057. X! 
  1058. X  .ti -2m
  1059. X  \fB&ora_bind($csr, $var, ...)\fP
  1060. X  Binds the given values to the substition variables in the SQL statement
  1061. X  associated with $csr, and executes the resulting statement.
  1062. X! 
  1063. X  .ti -2m
  1064. X! \fB$n = &ora_fetch($csr)\fP    \fI(NB: Scalar context)\fP
  1065. X  Returns the number of fields available from the query.
  1066. X! 
  1067. X  .ti -2m
  1068. X! \fB@ary = &ora_fetch($csr)\fP    \fI(NB: Array context)\fP
  1069. X  Retrieves the (next) output data from the statement identified by $csr.
  1070. X! 
  1071. X  .ti -2m
  1072. X  \fB&ora_close($csr)\fP
  1073. X  Finishes the SQL statement identified by $csr.
  1074. X! 
  1075. X  .ti -2m
  1076. X  \fB&ora_do($lda, $stmt)\fP
  1077. X  Equivalent to \fI&ora_close\fP(\fI&ora_open(...))\fP
  1078. X  for statements which have no substitution variables and do not return data.
  1079. X! 
  1080. X! .ti -2m
  1081. X! \fB&ora_commit($lda)\fP
  1082. X! Commits the work performed under the login identified by $lda.
  1083. X! 
  1084. X! .ti -2m
  1085. X! \fB&ora_rollback($lda)\fP
  1086. X! Rolls back the work performed under the login identified by $lda.
  1087. X! 
  1088. X  .ti -2m
  1089. X  \fB&ora_logoff($lda)\fP
  1090. X  Logs out of the database identified by $lda.
  1091. X***************
  1092. X*** 56,67 ****
  1093. X  .sp 2
  1094. X  .ps 10
  1095. X  \fBOraperl Variables\fP
  1096. X! .sp
  1097. X  .ps 8
  1098. X  .ti -2m
  1099. X  \fB$ora_errno\fP  (read only)
  1100. X  Contains the error code from the last funtion call.
  1101. X! .sp
  1102. X  .ti -2m
  1103. X  \fB$ora_errstr\fP  (read only)
  1104. X  Contains the error message corresponding to $ora_errno.
  1105. X--- 66,77 ----
  1106. X  .sp 2
  1107. X  .ps 10
  1108. X  \fBOraperl Variables\fP
  1109. X! 
  1110. X  .ps 8
  1111. X  .ti -2m
  1112. X  \fB$ora_errno\fP  (read only)
  1113. X  Contains the error code from the last funtion call.
  1114. X! 
  1115. X  .ti -2m
  1116. X  \fB$ora_errstr\fP  (read only)
  1117. X  Contains the error message corresponding to $ora_errno.
  1118. Xdiff -c orig/sql ./sql
  1119. X*** orig/sql    Thu Jan  2 16:19:37 1992
  1120. X--- ./sql    Thu Jan  2 14:21:26 1992
  1121. X***************
  1122. X*** 2,29 ****
  1123. X  'di';
  1124. X  'ig00';
  1125. X  #
  1126. X! # sql [-ddelim] username/password statement
  1127. X  #
  1128. X  # Script to run an Oracle statement from the command line.
  1129. X  # Written in response to <nirad.690285085@newdelphi> in alt.sources.wanted.
  1130. X  #
  1131. X! # Author:    Kevin Stock
  1132. X  # Date:        18th November 1991
  1133. X  #
  1134. X  
  1135. X  # $ora_debug = 8;        # if you want to see what's happenning
  1136. X  
  1137. X  $, = "\t";            # default delimiter is a tab
  1138. X  $\ = "\n";            # each record terminated with newline
  1139. X  
  1140. X! if ($ARGV[0] =~ /^-d(.*)/)    # allows the delimiter to be empty
  1141. X! {
  1142. X!     $, = $1;
  1143. X!     shift;
  1144. X! }
  1145. X  
  1146. X  $USER = shift;            # get the user name and password
  1147. X! die "Usage: $0 sql [-ddelim] username/password statement\n" unless $#ARGV >= 0;
  1148. X  
  1149. X  # log into the database and execute the statement
  1150. X  
  1151. X--- 2,45 ----
  1152. X  'di';
  1153. X  'ig00';
  1154. X  #
  1155. X! # sql
  1156. X  #
  1157. X  # Script to run an Oracle statement from the command line.
  1158. X  # Written in response to <nirad.690285085@newdelphi> in alt.sources.wanted.
  1159. X  #
  1160. X! # Usage:
  1161. X! #    sql [-bbase] [-ddelim] [-f|-h] [-lpage_len] username/password statement
  1162. X! #
  1163. X! #    -b base            database to use (default $ENV{'ORACLE_SID'})
  1164. X! #    -d delim        specifies the field delimiter (default TAB)
  1165. X! #    -f            formatted output, similar to sqlplus
  1166. X! #    -h            add headers, no formatting
  1167. X! #    -l page_len        lines per page, only used by -f (default 60)
  1168. X! #    username/password    Oracle username and password
  1169. X! #    statement        Oracle statement to be executed
  1170. X! #
  1171. X! # Author:        Kevin Stock
  1172. X  # Date:        18th November 1991
  1173. X  #
  1174. X  
  1175. X  # $ora_debug = 8;        # if you want to see what's happenning
  1176. X  
  1177. X+ $USAGE = "[-bbase] [-ddelim] [-f|-h] [-lpage_len] username/password statement";
  1178. X  $, = "\t";            # default delimiter is a tab
  1179. X  $\ = "\n";            # each record terminated with newline
  1180. X  
  1181. X! require 'getopts.pl';        # option parsing
  1182. X! do Getopts('b:d:fhl:');
  1183. X! die "$0: only one of -f and -h may be specified\n" if ($opt_f && $opt_h);
  1184. X! 
  1185. X! $, = $opt_d if defined($opt_d);                # set column delimiter
  1186. X! $= = $opt_l if defined($opt_l);                # set page length
  1187. X! $ENV{'ORACLE_SID'} = $opt_b if defined($opt_b);        # set database
  1188. X  
  1189. X+ die "ORACLE_SID not set\n" unless defined($ENV{'ORACLE_SID'});
  1190. X+ 
  1191. X  $USER = shift;            # get the user name and password
  1192. X! die "Usage: $0 $USAGE\n" unless $#ARGV >= 0;
  1193. X  
  1194. X  # log into the database and execute the statement
  1195. X  
  1196. X***************
  1197. X*** 32,42 ****
  1198. X  
  1199. X  # print out any information which comes back
  1200. X  
  1201. X! if (&ora_fetch($csr) > 0)    # does the statement return data?
  1202. X  {
  1203. X      while (@result = &ora_fetch($csr))
  1204. X      {
  1205. X!         print @result;
  1206. X      }
  1207. X      warn "$ora_errstr\n" if ($ora_errno != 0);
  1208. X  }
  1209. X--- 48,85 ----
  1210. X  
  1211. X  # print out any information which comes back
  1212. X  
  1213. X! if (($nfields = &ora_fetch($csr)) > 0)    # does the statement return data?
  1214. X  {
  1215. X+     if ($opt_f)            # formatted output
  1216. X+     {
  1217. X+         @titles = &ora_titles($csr);
  1218. X+         $format .= "format STDOUT_TOP =\n" . join($,, @titles) . "\n";
  1219. X+         grep(tr//-/c, @titles);
  1220. X+         $format .= join($,, @titles) . "\n.\n";
  1221. X+ 
  1222. X+         grep((s/^-/@/, tr/-/</), @titles);
  1223. X+         $format .= "format STDOUT =\n" . join($,, @titles) . "\n";
  1224. X+         foreach $i (0 .. $nfields - 1)
  1225. X+         {
  1226. X+             $format .= "\$result[$i],";
  1227. X+         }
  1228. X+         chop $format;        # remove extraneous comma
  1229. X+         $format .= "\n.\n";
  1230. X+ 
  1231. X+         eval($format);
  1232. X+     }
  1233. X+     elsif ($opt_h)
  1234. X+     {
  1235. X+         @titles = &ora_titles($csr);
  1236. X+         grep(s/  *$//, @titles);
  1237. X+         print @titles;
  1238. X+         grep(tr//-/c, @titles);
  1239. X+         print @titles;
  1240. X+     }
  1241. X+ 
  1242. X      while (@result = &ora_fetch($csr))
  1243. X      {
  1244. X!         ($opt_f) ? (write) : (print @result);
  1245. X      }
  1246. X      warn "$ora_errstr\n" if ($ora_errno != 0);
  1247. X  }
  1248. X***************
  1249. X*** 65,79 ****
  1250. X  .SH NAME
  1251. X  sql \- execute an Oracle SQL statement from the command line
  1252. X  .SH SYNOPSIS
  1253. X! \fBsql\fP [\fB\-d\fP\fIdelim\fP] \fIname\fP\fB/\fP\fIpassword\fP \fIstatement\fP
  1254. X  .SH DESCRIPTION
  1255. X  .I Sql
  1256. X  connects to an Oracle database
  1257. X  using the \fIname/password\fP supplied
  1258. X  and executes the given SQL \fIstatement\fP
  1259. X! returning the result
  1260. X! (without column headers)
  1261. X  on its standard output.
  1262. X  Normally, fields are separated with tabs;
  1263. X  this may be changed to any desired string (\fIdelim\fP)
  1264. X  using the \fB\-d\fP flag.
  1265. X--- 108,145 ----
  1266. X  .SH NAME
  1267. X  sql \- execute an Oracle SQL statement from the command line
  1268. X  .SH SYNOPSIS
  1269. X! \fBsql\fP
  1270. X! [\fB-b\fP\fIbase\fP]
  1271. X! [\fB\-d\fP\fIdelim\fP]
  1272. X! [\fB\-f\fP|\fB\-h\fP]
  1273. X! [\fB-l\fP\fIpage_len\fP]
  1274. X! \fIname\fP\fB/\fP\fIpassword\fP
  1275. X! \fIstatement\fP
  1276. X  .SH DESCRIPTION
  1277. X  .I Sql
  1278. X  connects to an Oracle database
  1279. X  using the \fIname/password\fP supplied
  1280. X  and executes the given SQL \fIstatement\fP
  1281. X! displaying the result
  1282. X  on its standard output.
  1283. X+ 
  1284. X+ The \fB-b\fP\fIbase\fP flag may be supplied to specify the database to be used.
  1285. X+ If it is not given, the database specified by the environment variable
  1286. X+ \fBORACLE_SID\fP is used.
  1287. X+ 
  1288. X+ The \fB\-f\fP and \fB\-h\fP flags may be used to modify the form of the output.
  1289. X+ Without either flag, no field headers are printed
  1290. X+ and fields are not padded.
  1291. X+ With the \fB\-h\fP flag,
  1292. X+ field headers are added to the top of the output,
  1293. X+ but the format is otherwise unchanged.
  1294. X+ With the \fB\-f\fP flag,
  1295. X+ the output is formatted in a fashion similar to that used by \fIsqlplus\fP,
  1296. X+ except that all fields are left\-justified, regardless of their data type.
  1297. X+ Column headers are printed at the top of each page;
  1298. X+ a page is assumed to be 60 lines long,
  1299. X+ but this may be overridden with the \fB\-l\fP\fIpage_len\fP flag.
  1300. X+ 
  1301. X  Normally, fields are separated with tabs;
  1302. X  this may be changed to any desired string (\fIdelim\fP)
  1303. X  using the \fB\-d\fP flag.
  1304. X***************
  1305. X*** 81,94 ****
  1306. X  The environment variable \fBORACLE_SID\fP
  1307. X  determines the Oracle database to be used.
  1308. X  .SH DIAGNOSTICS
  1309. X! The only diagnostic generated by \fIsql\fP is a usage message.
  1310. X  However, you may also encounter
  1311. X! error messages from Oraperl (unlikely) or Oracle (more common).
  1312. X  See the \fIOracle Error Messages and Codes Manual\fP for details.
  1313. X  .SH NOTES
  1314. X  This program is only intended for use from the command line.
  1315. X  If you use it within a shell script
  1316. X! then you should consider rewriting it in Oraperl
  1317. X  to use Perl's text manipulation and formatting commands.
  1318. X  .SH "SEE ALSO"
  1319. X  \fISQL Language Reference Manual\fP
  1320. X--- 147,176 ----
  1321. X  The environment variable \fBORACLE_SID\fP
  1322. X  determines the Oracle database to be used.
  1323. X  .SH DIAGNOSTICS
  1324. X! .in +5
  1325. X! .ti -5
  1326. X! \fBonly one of -f and -h may be specified\fP
  1327. X! .br
  1328. X! the \fB-f\fP and \fB-h\fP options are mutually exclusive,
  1329. X! but both were specified
  1330. X! 
  1331. X! .ti -5
  1332. X! \fBORACLE_SID not set\fP
  1333. X! .br
  1334. X! the \fB-b\fP\fIbase\fP option was not supplied,
  1335. X! and the \fBORACLE_SID\fP environment variable was not set,
  1336. X! so \fIsql\fP cannot work out which database to open
  1337. X! 
  1338. X! .in -5
  1339. X! The only other diagnostics generated by \fIsql\fP are usage messages,
  1340. X! which should be self\-explanatory.
  1341. X  However, you may also encounter
  1342. X! error messages from Oraperl (unlikely) or from Oracle (more common).
  1343. X  See the \fIOracle Error Messages and Codes Manual\fP for details.
  1344. X  .SH NOTES
  1345. X  This program is only intended for use from the command line.
  1346. X  If you use it within a shell script
  1347. X! then you should consider rewriting your script in Oraperl
  1348. X  to use Perl's text manipulation and formatting commands.
  1349. X  .SH "SEE ALSO"
  1350. X  \fISQL Language Reference Manual\fP
  1351. X***************
  1352. X*** 98,103 ****
  1353. X  .SH AUTHOR
  1354. X  Kevin Stock,
  1355. X  .if t .ft C
  1356. X! <kstock@gouldfr.encore.fr, kstock@encore.com>
  1357. X  .if t .ft P
  1358. X  .ex
  1359. X--- 180,185 ----
  1360. X  .SH AUTHOR
  1361. X  Kevin Stock,
  1362. X  .if t .ft C
  1363. X! <kstock@encore.com>
  1364. X  .if t .ft P
  1365. X  .ex
  1366. SHAR_EOF
  1367. chmod 0644 Patch05 ||
  1368. echo 'restore of Patch05 failed'
  1369. Wc_c="`wc -c < 'Patch05'`"
  1370. test 34887 -eq "$Wc_c" ||
  1371.     echo 'Patch05: original size 34887, current size' "$Wc_c"
  1372. fi
  1373. # ============= bind.pl ==============
  1374. if test -f 'bind.pl' -a X"$1" != X"-c"; then
  1375.     echo 'x - skipping bind.pl (File already exists)'
  1376. else
  1377. echo 'x - extracting bind.pl (Text)'
  1378. sed 's/^X//' << 'SHAR_EOF' > 'bind.pl' &&
  1379. X#!./oraperl
  1380. X#
  1381. X# bind.pl
  1382. X#
  1383. X# This shows how the ora_bind function may be used to implement a
  1384. X# simple lookup script.
  1385. X
  1386. X# $ora_debug = 8;
  1387. X
  1388. X$lda = &ora_login('t', 'kstock', 'kstock')
  1389. X    || die $ora_errstr;
  1390. X$csr = &ora_open($lda, 'select phone from telno where name = :1')
  1391. X    || die $ora_errstr;
  1392. X
  1393. Xwhile(<STDIN>)
  1394. X{
  1395. X    chop;
  1396. X    &ora_bind($csr, $_)    || die $ora_errstr;
  1397. X
  1398. X    if (($phone) = &ora_fetch($csr))
  1399. X    {
  1400. X        print "$phone\n";
  1401. X    }
  1402. X    else
  1403. X    {
  1404. X        die $ora_errstr if $ora_errno;
  1405. X        print "unknown\n";
  1406. X    }
  1407. X}
  1408. X
  1409. X&ora_close($csr);
  1410. X&ora_logoff($lda);
  1411. SHAR_EOF
  1412. chmod 0644 bind.pl ||
  1413. echo 'restore of bind.pl failed'
  1414. Wc_c="`wc -c < 'bind.pl'`"
  1415. test 520 -eq "$Wc_c" ||
  1416.     echo 'bind.pl: original size 520, current size' "$Wc_c"
  1417. fi
  1418. # ============= commit.pl ==============
  1419. if test -f 'commit.pl' -a X"$1" != X"-c"; then
  1420.     echo 'x - skipping commit.pl (File already exists)'
  1421. else
  1422. echo 'x - extracting commit.pl (Text)'
  1423. sed 's/^X//' << 'SHAR_EOF' > 'commit.pl' &&
  1424. X#!./oraperl
  1425. X#
  1426. X# commit.pl
  1427. X#
  1428. X# Simple example of using commit and rollback.
  1429. X
  1430. X$lda = &ora_login('t', 'kstock', 'kstock') || die "$ora_errstr\n";
  1431. X&ora_do($lda, 'create table primes (prime number)') || die "$ora_errstr\n";
  1432. X
  1433. X$csr = &ora_open($lda, 'insert into primes values(:1)') || die "$ora_errstr\n";
  1434. Xprint 'creating table';
  1435. Xwhile (<DATA>)
  1436. X{
  1437. X    chop;
  1438. X    print " $_";
  1439. X    &ora_bind($csr, $_) || die "$_: $ora_errstr\n";
  1440. X    (print ' committing ', &ora_commit($lda)) if $_ == 11;
  1441. X}
  1442. X&ora_close($csr) || die "$ora_errstr\n";
  1443. X
  1444. Xprint "\n\nReading table for the first time\n\n";
  1445. X$csr = &ora_open($lda, 'select prime from primes') || die "$ora_errstr\n";
  1446. Xwhile (($prime) = &ora_fetch($csr))
  1447. X{
  1448. X    print "$prime ";
  1449. X}
  1450. Xdie "$ora_errstr\n" if $ora_errno;
  1451. X&ora_close($csr) || die "$ora_errstr\n";
  1452. X
  1453. Xprint "\n\nRolling back ", &ora_rollback($lda), "\n\n";
  1454. X
  1455. Xprint "Attempting to read data for the second time.\n";
  1456. Xprint "Only values up to 11 should appear.\n\n";
  1457. X$csr = &ora_open($lda, 'select prime from primes') || die "$ora_errstr\n";
  1458. Xwhile (($prime) = &ora_fetch($csr))
  1459. X{
  1460. X    print "$prime ";
  1461. X}
  1462. Xdie "$ora_errstr\n" if $ora_errno;
  1463. X&ora_close($csr) || die "$ora_errstr\n";
  1464. X
  1465. X&ora_do($lda, 'drop table primes') || die "$ora_errstr\n";
  1466. X&ora_logoff($lda);
  1467. Xprint "\n"
  1468. X__END__
  1469. X2
  1470. X3
  1471. X5
  1472. X7
  1473. X11
  1474. X13
  1475. X17
  1476. X19
  1477. X23
  1478. X29
  1479. SHAR_EOF
  1480. chmod 0644 commit.pl ||
  1481. echo 'restore of commit.pl failed'
  1482. Wc_c="`wc -c < 'commit.pl'`"
  1483. test 1266 -eq "$Wc_c" ||
  1484.     echo 'commit.pl: original size 1266, current size' "$Wc_c"
  1485. fi
  1486. exit 0
  1487.  
  1488. exit 0 # Just in case...
  1489. -- 
  1490. Kent Landfield                   INTERNET: kent@IMD.Sterling.COM
  1491. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1492. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1493. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1494.