home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume39 / sybperl / part03 < prev    next >
Encoding:
Text File  |  1993-09-25  |  50.1 KB  |  2,102 lines

  1. Newsgroups: comp.sources.misc
  2. From: mpeppler@itf.ch (Michael Peppler)
  3. Subject: v39i103:  sybperl - Sybase DB-library extensions to Perl, v1.8, Part03/03
  4. Message-ID: <1993Sep25.182700.13480@sparky.sterling.com>
  5. X-Md4-Signature: d56d0ee00ff4b44f14863b8fea79a4f9
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Sat, 25 Sep 1993 18:27:00 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: mpeppler@itf.ch (Michael Peppler)
  12. Posting-number: Volume 39, Issue 103
  13. Archive-name: sybperl/part03
  14. Environment: UNIX, Perl, Sybase
  15. Supersedes: sybperl: Volume 37, Issue 33-34
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # Contents:  BUGS CHANGES PACKING.LST eg/README eg/capture.pl
  22. #   eg/dbtext.pl eg/space.pl eg/sql.pl eg/test_dbmoney.pl lib/sybdb.ph
  23. #   lib/sybdb_redefs.pl lib/sybperl.pl t/sbex.pl
  24. # Wrapped by kent@sparky on Sat Sep 25 13:16:00 1993
  25. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  26. echo If this archive is complete, you will see the following message:
  27. echo '          "shar: End of archive 3 (of 3)."'
  28. if test -f 'BUGS' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'BUGS'\"
  30. else
  31.   echo shar: Extracting \"'BUGS'\" \(4516 characters\)
  32.   sed "s/^X//" >'BUGS' <<'END_OF_FILE'
  33. X    @(#)BUGS    1.1    9/2/93
  34. X    
  35. X    The Sybase DB-Library - Perl savestr() conflict
  36. X    ------------------------------------------------
  37. X
  38. X
  39. X    Ah! The joys of tying different packages together!
  40. X
  41. X    Both Perl and DB-Library have a function called savestr(). The
  42. X    DB-Library version is used in dbcmd() to add an SQL command to the
  43. X    list of commands pointed to by dpproc->dbcmdbuf, and in dbuse() as
  44. X    well. Now there are several ways to work around this problem.
  45. X
  46. X    1) Compile sybperl.c with -DBROKEN_DBCMD. I've written some code
  47. X       that emulates calls to dbcmd() and dbuse(). This works OK on my
  48. X       machine/OS/Version of Perl/Version of DBlib, but it relies on
  49. X       the internal storing method used by DBlib, and that might
  50. X       change in the future.
  51. X
  52. X    2) Recompile Perl (specifically, uperl.o in the Perl source
  53. X       directory) with some suitable flags (eg -Dsavestr=p_savestr).
  54. X       This does not create any compatibility problems, but is a
  55. X       lengthy procedure.
  56. X
  57. X    3) Do something like:
  58. X       cc -c sybperl.c
  59. X       ld -r -o sybperl2.o sybperl.o -lsybdb
  60. X       [edit sybperl2.o and replace `_savestr' with something like `_savest1']
  61. X       cc -o sybperl uperl.o sybperl2.o
  62. X       This is not a bad solution, but won't work if you have shared
  63. X       library versions of libsybdb.a
  64. X
  65. X    4) Edit uperl.o and replace savestr with something else. This is
  66. X       the solution I've chosen as the default. It is relatively fast,
  67. X       does not rely on any internal knowledge of DB-Library, and does
  68. X       not require Perl to be recompiled.
  69. X
  70. X    The Makefile gives some information on how to achieve these
  71. X    different options.
  72. X       
  73. X    Thanks to Teemu Torma for providing the initial input on this problem.    
  74. X
  75. X
  76. X
  77. X    Sybperl Memory Usage
  78. X    --------------------
  79. X
  80. X    The general format of a Sybperl script usually looks somewhat like
  81. X    this:
  82. X
  83. X    #!/usr/local/bin/sybperl
  84. X
  85. X    &dbcmd( query text );
  86. X    &dbsqlexec;
  87. X    &dbresults;
  88. X
  89. X    while(@data = &dbnextrow)
  90. X    {
  91. X       process data
  92. X    }
  93. X
  94. X
  95. X    If you are using a version of Perl prior to release 4, patchlevel
  96. X    35, then this method will result in a rather important memory
  97. X    leak. There are two ways around this problem:
  98. X
  99. X    1) Upgrade to Perl 4, patchlevel 35 :-)
  100. X
  101. X    2) Write a subroutine that calls &dbnextrow and stores the returned
  102. X       array to a local variable, and which in turn returns that array to
  103. X       the main while() loop, like so:
  104. X
  105. X    sub getRow
  106. X    {
  107. X        local(@data);
  108. X
  109. X    @data = &dbnextrow;
  110. X
  111. X    @data;
  112. X    }
  113. X
  114. X    while(@data = &getRow)
  115. X    {
  116. X       etc.
  117. X    }
  118. X
  119. X
  120. X    This technique should keep the memory usage of Sybperl to a
  121. X    manageable level.
  122. X
  123. X
  124. X
  125. X    Perl packages / usersubs bug
  126. X    ----------------------------
  127. X
  128. X    The following is bug that was uncovered by Jeff Wong:
  129. X
  130. X------ begin excerpt -------
  131. X
  132. Xa: sybperl script z.pl has some *.pl required scripts.  Let's call
  133. X   them x.pl and y.pl for convenience.
  134. X
  135. Xb: z.pl looks like this (basic structure):
  136. X
  137. X   ...
  138. X   require "sybperl.pl";
  139. X   require "x.pl";
  140. X   require "y.pl";
  141. X   ...
  142. X
  143. Xc: x.pl looks like this (basic structure):
  144. X
  145. X   ...
  146. X   package x;
  147. X   ...
  148. X   < Sybperl functions with main package dereferencing, e.g. &main'dbcancel(), >
  149. X   < &main'dbcancel( $dbproc ), &main'dbnextrow(), ...                        >
  150. X   ...
  151. X   package main;
  152. X   ...
  153. X
  154. Xd: y.pl looks like x.pl or perhaps like other required packages (in format).
  155. X
  156. Xe: Bug surfaces in x.pl in that it suddenly cannot locate the sybperl
  157. X   functions.
  158. X
  159. XMy guess is that the bug is caused by the way that usersub functions
  160. Xare treated by the "require" and "package" operators.  I say this because:
  161. X
  162. X   - Usersub functions look very much like perl built-in functions, except that
  163. X     usersub functions require an ampersand character in front of their names.
  164. X
  165. X   - Built-in functions are global to all packages.
  166. X
  167. X   - Perl user-defined functions are local to the package which contains their
  168. X     name definition (i.e. where the namespace is).
  169. X
  170. X   - When I don't use the x.pl style package construct, the problem disappears.
  171. X
  172. X------ end excerpt -------
  173. X
  174. X
  175. X    The way around this bug is to compile Sybperl with the PACKAGE_BUG
  176. X    macro defined. When this is done, sybperl.pl creates a number of
  177. X    'glue' routines (see lib/sybdb_redefs.pl') which bypass the bug.
  178. X
  179. X    It's not the cleanest of solutions, but it works...
  180. X
  181. X
  182. X
  183. X    
  184. X    Please let me know if you find any other problems with Sybperl so
  185. X    that I can look into it.
  186. X
  187. X    Thank you.
  188. X
  189. X    Michael Peppler    <mpeppler@itf.ch>
  190. X
  191. X
  192. END_OF_FILE
  193.   if test 4516 -ne `wc -c <'BUGS'`; then
  194.     echo shar: \"'BUGS'\" unpacked with wrong size!
  195.   fi
  196.   # end of 'BUGS'
  197. fi
  198. if test -f 'CHANGES' -a "${1}" != "-c" ; then 
  199.   echo shar: Will not clobber existing file \"'CHANGES'\"
  200. else
  201.   echo shar: Extracting \"'CHANGES'\" \(2925 characters\)
  202.   sed "s/^X//" >'CHANGES' <<'END_OF_FILE'
  203. X    @(#)CHANGES    1.4    9/7/93
  204. X
  205. X    
  206. X    Sybperl CHANGES:
  207. X
  208. X    1.008   Added user settable variables to control whether
  209. X        Sybperl returns 'NULL' or Perl's 'undef' value on NULL
  210. X        values from a query, whether numeric results are kept
  211. X        in native format, and whether binary data should be
  212. X        preceded by '0x' (suggested by Steve Baumgartner).
  213. X        Actually made $DBstatus visible (it was documented but
  214. X        not usable up to now...).
  215. X        Passing an undef'd variable to &bcp_sendrow will cause
  216. X        a NULL value to be sent to the server for that column.
  217. X    1.007   Added &dbmny* calls and code to circumvent weird
  218. X        package/usub interaction bug, both contributed by Jeff
  219. X        Wong.
  220. X        Added &bcp_* calls.
  221. X        Added &dbretdata() call (returns an array, possibly
  222. X        associative, with the return parameters of a stored
  223. X        proc).
  224. X        Calls to any of the routines with an undefined
  225. X        DBPROCESS will now elicit a warning; previously, such
  226. X        calls defaulted to using the first (default)
  227. X        DBPROCESS.
  228. X        Data returned from queries is not converted to char
  229. X        unless its necessary - this applies mainly to types
  230. X        SYBFLOAT and SYBREAL which could loose some precision
  231. X        on being converted to a string via sprintf().
  232. X    1.006    Added contributed patches: &dbwritetext(),
  233. X        &dbsafestr() and a modified &dblogin().
  234. X        Added &dbhasretstats() and &dbretstatus(), as well as
  235. X        some calls to DBlib macros such as DBCMD(),
  236. X        DBMORECMD(), etc.
  237. X        Received a patch to eg/space.pl from Wolfgang Richter.
  238. X        Code that was defined to compile if BROKEN_DBCMD was
  239. X        defined has been removed. It was only a hack, making
  240. X        use of knowledge of the structure of the DBPROCESS
  241. X        data type.
  242. X        Added the possibility to return an associative array
  243. X        from &dbnextrow.
  244. X        Added support for new datatypes (SYBREAL, SYBDATETIME4).
  245. X        NULL values retrieved using &dbnextrow can be returned
  246. X        as 'undef' instead of 'NULL' (this is a compile-time
  247. X        option).
  248. X    1.005   Sybperl would core dump if you used a uninitialized
  249. X            DBPROCESS.
  250. X        A solution to the sometime pathological    memory usage
  251. X        observed when using a release of Perl lower than 4.035
  252. X        is also described in BUGS.
  253. X        &dblogin now returns -1 if the dblogin() or dbopen()
  254. X        calls fail.
  255. X        Added the possibility to login to a specific server
  256. X        without setting the DSQUERY environment variable.
  257. X        Added a script to extract the information regarding
  258. X        the database from the databases' system tables. See
  259. X        eg/dbschema.pl.
  260. X    1.004    Added support for Perl based error and message
  261. X        handlers (as made possible by Perl 4.018). Many Thanks
  262. X        to Teemu Torma for this code.
  263. X        Added limited support for SYBTEXT datatypes.
  264. X        Added &dbstrcpy() to retrieve the current command buffer.
  265. X        The DBPROCESS parameter to most &db*() calls can now
  266. X        be omitted: it will default to the first DBPROCESS
  267. X        opened (the one that is returned by &dblogin()).
  268. X        Added lib/sybdb.ph
  269. X        Added a couple of example scripts in eg/*.pl, courtesy
  270. X        of Gijs Mos (Thank You!).
  271. X    1.003    Base version.
  272. X
  273. END_OF_FILE
  274.   if test 2925 -ne `wc -c <'CHANGES'`; then
  275.     echo shar: \"'CHANGES'\" unpacked with wrong size!
  276.   fi
  277.   # end of 'CHANGES'
  278. fi
  279. if test -f 'PACKING.LST' -a "${1}" != "-c" ; then 
  280.   echo shar: Will not clobber existing file \"'PACKING.LST'\"
  281. else
  282.   echo shar: Extracting \"'PACKING.LST'\" \(1270 characters\)
  283.   sed "s/^X//" >'PACKING.LST' <<'END_OF_FILE'
  284. X    @(#)PACKING.LST    1.1    9/2/93
  285. X
  286. X    
  287. X    The Sybperl package should contain the following files:
  288. X
  289. X
  290. X        PACKING.LST        This file
  291. X        README        Read Me!
  292. X        BUGS        Perl/DB-library incompatibility description
  293. X        CHANGES
  294. X        Makefile
  295. X        sybperl.c        Sybperl source
  296. X        sybperl.1        Man page
  297. X        patchlevel.h
  298. X        t/sbex.pl        Example of sybperl script
  299. X        lib/sybperl.pl  A Perl library file.
  300. X        lib/sybdb.ph    Some of the DB-Library include files, run
  301. X                through h2ph.
  302. X        eg/space.pl        How much space does your sybase databases use?
  303. X        eg/capture.pl   Create a table extracted from /etc/passwd
  304. X        eg/report.pl    Report from table created by capture.pl
  305. X        eg/sql.pl        Utility routines used by the above example programs.
  306. X
  307. X        eg/dbtext.pl    Example of &dbwritetext() usage. This
  308. X                script will NOT work out of the box. Read
  309. X                the code to see what requires doing first.
  310. X        eg/test_dbmoney.pl
  311. X                    Example script using &dbmny*() calls.
  312. X
  313. X        eg/dbschema.pl  Create an Isql script that will to
  314. X                        recreate your database(s) structure (data
  315. X                types, tables, indexes, rules, defaults,
  316. X                views, triggers and stored procedures),
  317. X                extracting the information from the
  318. X                database's system tables.
  319. X
  320. END_OF_FILE
  321.   if test 1270 -ne `wc -c <'PACKING.LST'`; then
  322.     echo shar: \"'PACKING.LST'\" unpacked with wrong size!
  323.   fi
  324.   # end of 'PACKING.LST'
  325. fi
  326. if test -f 'eg/README' -a "${1}" != "-c" ; then 
  327.   echo shar: Will not clobber existing file \"'eg/README'\"
  328. else
  329.   echo shar: Extracting \"'eg/README'\" \(1797 characters\)
  330.   sed "s/^X//" >'eg/README' <<'END_OF_FILE'
  331. X    @(#)README    1.5    8/31/93
  332. X
  333. X
  334. X    This directory contains a number of example scripts for Sybperl.
  335. X
  336. X
  337. X    
  338. X    space.pl        Report the space used by your database.
  339. X    capture.pl        Create a table with information from
  340. X            /etc/passwd.
  341. X    report.pl        Report information from the above table.
  342. X    sql.pl        Utility used by the above three scripts.
  343. X    dbschema.pl        Extract an Isql script to re-create a database
  344. X    dbtext.pl        A very simple example of usage of dbwritetext.
  345. X            Read the code before using!
  346. X    test_dbmoney.pl    Example script using dbmny* calls.
  347. X
  348. X
  349. X    
  350. X    Dbschema.pl Documentation:
  351. X    --------------------------
  352. X    
  353. X    This is a Sybperl script that extracts a Sybase database definition
  354. X    and creates an Isql script to rebuild the database.
  355. X
  356. X    dbschema.pl is NOT a production script, in the sense that it does
  357. X    not do ALL the necessary work. The script tries to do the right
  358. X    thing, but in certain cases (mainly where the owner of an object
  359. X    is not the DBO) it creates an invalid or incorrect Isql command. I
  360. X    have tried to detect these cases, and log them both to stdout and to a
  361. X    file, so that the script can be corrected.
  362. X    Please note also that dbschema.pl logs in to Sybase with the
  363. X    default (Unix) user id, and a NULL password. This behaviour is
  364. X    maybe not OK for your site.
  365. X
  366. X    Usage:
  367. X
  368. X        itf1% dbschema.pl -d excalibur -o excalibur.isql -v
  369. X
  370. X    Run dbschema on database 'excalibur', place the resulting script
  371. X    in 'excalibur.isql' (and the error log in 'excalibur.isql.log')
  372. X    and turn on verbose output on the console. The default database is
  373. X    'master', the default output file is 'script.isql'.
  374. X
  375. X
  376. X    I hope this will prove of some use, and I would be more than happy
  377. X    to hear of any improvements :-)
  378. X
  379. X
  380. X    Michael Peppler        mpeppler@itf.ch
  381. X
  382. END_OF_FILE
  383.   if test 1797 -ne `wc -c <'eg/README'`; then
  384.     echo shar: \"'eg/README'\" unpacked with wrong size!
  385.   fi
  386.   # end of 'eg/README'
  387. fi
  388. if test -f 'eg/capture.pl' -a "${1}" != "-c" ; then 
  389.   echo shar: Will not clobber existing file \"'eg/capture.pl'\"
  390. else
  391.   echo shar: Extracting \"'eg/capture.pl'\" \(1640 characters\)
  392.   sed "s/^X//" >'eg/capture.pl' <<'END_OF_FILE'
  393. X#! /usr/local/bin/sybperl
  394. X
  395. X#
  396. X#    @(#)capture.pl    1.1    6/24/92
  397. X#
  398. X
  399. Xrequire "sybperl.pl";
  400. Xrequire "sql.pl";
  401. X
  402. X#
  403. X# Log us in to Sybase.
  404. X#
  405. X$d = &dblogin;
  406. X
  407. X&sql($d, "set statistics io on");
  408. X&sql($d, "set statistics time on");
  409. X
  410. X#
  411. X# Count the number off password tables.
  412. X#
  413. X@results = &sql($d, '
  414. X        select count(*) from sysobjects
  415. X        where name = "password" and type = "U"'
  416. X       );
  417. X
  418. X#
  419. X# If there is none create it else truncate it.
  420. X#
  421. Xif(@results[0] == 0) {
  422. X    &sql($d, '
  423. X        create table password(
  424. X            username char(8),
  425. X            uid int,
  426. X            gid int,
  427. X            shell varchar(30),
  428. X            home varchar(30)
  429. X        )'
  430. X    );
  431. X    print "The password table has been created.\n";
  432. X} else {
  433. X    &sql($d, 'truncate table password');
  434. X    print "The password table already exists. Table truncated!\n";
  435. X};
  436. X
  437. X#
  438. X# Read the password entries and add them to the database.
  439. X#
  440. Xwhile (($n,$p,$u,$g,$q,$c,$gc,$d,$s)= getpwent) {
  441. X    print "Adding $n.\n";
  442. X    &sql($d, "
  443. X        insert password
  444. X        values(\"$n\", $u, $g, \"$s\", \"$d\")
  445. X        "
  446. X    );
  447. X};
  448. Xendpwent;
  449. X
  450. X#
  451. X# Count the number off group tables.
  452. X#
  453. X@results = &sql($d, '
  454. X        select count(*) from sysobjects
  455. X        where name = "groups" and type = "U"'
  456. X       );
  457. X
  458. X#
  459. X# If there is none create it else truncate it.
  460. X#
  461. Xif(@results[0] == 0) {
  462. X    &sql($d, '
  463. X        create table groups(
  464. X            groupname char(8),
  465. X            gid int
  466. X        )'
  467. X    );
  468. X    print "The groups table has been created.\n";
  469. X} else {
  470. X    &sql($d, 'truncate table groups');
  471. X    print "The groups table already exists. Table truncated!\n";
  472. X};
  473. X
  474. X#
  475. X# Read the group entries and add them to the database.
  476. X#
  477. Xwhile (($gn,$gp,$gg,$gm)= getgrent) {
  478. X    print "Adding group $gn.\n";
  479. X    &sql($d, "
  480. X        insert groups
  481. X        values(\"$gn\", $gg)
  482. X        "
  483. X    );
  484. X};
  485. Xendgrent;
  486. X
  487. END_OF_FILE
  488.   if test 1640 -ne `wc -c <'eg/capture.pl'`; then
  489.     echo shar: \"'eg/capture.pl'\" unpacked with wrong size!
  490.   fi
  491.   chmod +x 'eg/capture.pl'
  492.   # end of 'eg/capture.pl'
  493. fi
  494. if test -f 'eg/dbtext.pl' -a "${1}" != "-c" ; then 
  495.   echo shar: Will not clobber existing file \"'eg/dbtext.pl'\"
  496. else
  497.   echo shar: Extracting \"'eg/dbtext.pl'\" \(738 characters\)
  498.   sed "s/^X//" >'eg/dbtext.pl' <<'END_OF_FILE'
  499. X#  Script which demonstrates dbwrite routine.
  500. X#
  501. X#  In isql do something like:
  502. X#       create table text_table (t_index int, the_text text)
  503. X#
  504. X#    @(#)dbtext.pl    1.1    8/31/93
  505. X#
  506. X
  507. Xrequire "sybperl.pl";
  508. Xrequire "sql.pl";
  509. X
  510. X$d = &dblogin;
  511. X$d2 = &dbopen;
  512. X
  513. X&sql ($d, 'delete from text_table');
  514. X&sql ($d, 'insert into text_table (t_index, the_text) values (5,"")');
  515. X
  516. X
  517. X&dbcmd($d,'select the_text, t_index from text_table where t_index = 5');
  518. X&dbsqlexec($d);                         # execute sql
  519. X
  520. X&dbresults($d);
  521. X@data = &dbnextrow($d);
  522. X
  523. X&dbwritetext ($d2, "text_table.the_text", $d, 1, "This is text which was added with Sybperl");
  524. X
  525. X@result = &sql($d,'select t_index, the_text from text_table where t_index = 5');
  526. X
  527. Xprint @result, "\n";
  528. X
  529. X&dbclose($d);
  530. X
  531. END_OF_FILE
  532.   if test 738 -ne `wc -c <'eg/dbtext.pl'`; then
  533.     echo shar: \"'eg/dbtext.pl'\" unpacked with wrong size!
  534.   fi
  535.   # end of 'eg/dbtext.pl'
  536. fi
  537. if test -f 'eg/space.pl' -a "${1}" != "-c" ; then 
  538.   echo shar: Will not clobber existing file \"'eg/space.pl'\"
  539. else
  540.   echo shar: Extracting \"'eg/space.pl'\" \(1494 characters\)
  541.   sed "s/^X//" >'eg/space.pl' <<'END_OF_FILE'
  542. X#! /usr/local/bin/sybperl
  543. X#
  544. X#    @(#)space.pl    1.2    4/2/93
  545. X
  546. Xrequire "sybperl.pl";
  547. Xrequire "sql.pl";
  548. X
  549. X#
  550. X# Log us in to Sybase.
  551. X#
  552. Xprint "Name of Sybase server: ";
  553. X$server = <>; chop($server);
  554. Xif($server ne '')
  555. X{
  556. X    $ENV{'DSQUERY'} = $server;
  557. X}
  558. Xelse
  559. X{
  560. X    $server = $ENV{'DSQUERY'};
  561. X}
  562. X
  563. Xprint "Administrative account password: ";
  564. Xeval `stty -echo`;
  565. X$sapw = <>; chop($sapw);
  566. Xeval `stty echo`;
  567. X
  568. X$d = &dblogin("sa", $sapw);
  569. X
  570. X
  571. X$server = $server . '.';
  572. X
  573. X
  574. X&sql($d, "use master");
  575. X@dbs = &sql($d, "select name from sysdatabases order by name");
  576. X
  577. Xforeach $n (@dbs) {
  578. X    &sql($d, "use $n");
  579. X    $x = join('~', &sql($d, 'sp_spaceused'));
  580. X    $x =~ s/ //g;
  581. X    $x =~ s/MB|KB//g;
  582. X    ($name, $size, $res, $data, $index, $free ) = split("~",$x);
  583. X    $unused = $size * 1024 - $res;
  584. X    write;
  585. X    $ts += $size;
  586. X    $tr += $res;
  587. X    $td += $data;
  588. X    $ti += $index;
  589. X    $tf += $free;
  590. X}
  591. X
  592. Xprint '-' x 78, "\n"; 
  593. X$name = 'TOTAL';
  594. X$size = $ts;
  595. X$res = $tr;
  596. X$data = $td;
  597. X$index = $ti;
  598. X$free = $tf;
  599. X$unused = $size * 1024 - $res;
  600. Xwrite;
  601. X
  602. Xformat top=
  603. XSpace usage per database for server @<<<<<<<<<<<<<<<
  604. X                    $server
  605. XName             Size    Reserved       Data      Index       Free     Unused
  606. X             (MB)        (KB)       (KB)       (KB)       (KB)       (KB)
  607. X-----------------------------------------------------------------------------
  608. X. 
  609. Xformat stdout=
  610. X@<<<<<<<<<  @>>>>>>>>  @>>>>>>>>>  @>>>>>>>>  @>>>>>>>>  @>>>>>>>>  @>>>>>>>>
  611. X$name,      $size,     $res,       $data,     $index,    $free,     $unused
  612. X. 
  613. X
  614. X
  615. END_OF_FILE
  616.   if test 1494 -ne `wc -c <'eg/space.pl'`; then
  617.     echo shar: \"'eg/space.pl'\" unpacked with wrong size!
  618.   fi
  619.   chmod +x 'eg/space.pl'
  620.   # end of 'eg/space.pl'
  621. fi
  622. if test -f 'eg/sql.pl' -a "${1}" != "-c" ; then 
  623.   echo shar: Will not clobber existing file \"'eg/sql.pl'\"
  624. else
  625.   echo shar: Extracting \"'eg/sql.pl'\" \(1736 characters\)
  626.   sed "s/^X//" >'eg/sql.pl' <<'END_OF_FILE'
  627. X#
  628. X#    @(#)sql.pl    1.2    8/9/93
  629. X#
  630. X
  631. Xsub sql {
  632. X    local($db,$sql,$sep)=@_;            # local copy parameters
  633. X
  634. X    $sep = '~' unless $sep;            # provide default for sep
  635. X
  636. X    @res = ();                    # clear result array
  637. X
  638. X    &dbcmd($db,$sql);                # pass sql to server
  639. X    &dbsqlexec($db);                # execute sql
  640. X
  641. X    while(&dbresults($db) != $NO_MORE_RESULTS) {    # copy all results
  642. X    while (@data = &dbnextrow($db)) {
  643. X        push(@res,join($sep,@data));
  644. X    }
  645. X    }
  646. X
  647. X    @res;                    # return the result array
  648. X}
  649. X
  650. X
  651. X# Message and error handlers.
  652. X
  653. Xsub sql_message_handler
  654. X{
  655. X    local ($db, $message, $state, $severity, $text, $server, $procedure, $line)
  656. X    = @_;
  657. X
  658. X    if ($severity > 0)
  659. X    {
  660. X    print ("Sybase message ", $message, ", Severity ", $severity,
  661. X           ", state ", $state);
  662. X    print ("\nServer `", $server, "'") if defined ($server);
  663. X    print ("\nProcedure `", $procedure, "'") if defined ($procedure);
  664. X    print ("\nLine ", $line) if defined ($line);
  665. X    print ("\n    ", $text, "\n\n");
  666. X
  667. X# &dbstrcpy returns the command buffer.
  668. X
  669. X    local ($lineno) = 1;    # 
  670. X    foreach $row (split (/\n/, &dbstrcpy ($db)))
  671. X    {
  672. X        print (sprintf ("%5d", $lineno ++), "> ", $row, "\n");
  673. X    }
  674. X    }
  675. X    elsif ($message == 0)
  676. X    {
  677. X    print ($text, "\n");
  678. X    }
  679. X    
  680. X    0;
  681. X}
  682. X
  683. Xsub sql_error_handler {
  684. X    # Check the error code to see if we should report this.
  685. X    if ($_[2] != &SYBESMSG) {
  686. X    local ($db, $severity, $error, $os_error, $error_msg, $os_error_msg)
  687. X        = @_;
  688. X    print ("Sybase error: ", $error_msg, "\n");
  689. X    print ("OS Error: ", $os_error_msg, "\n") if defined ($os_error_msg);
  690. X    }
  691. X
  692. X    &INT_CANCEL;
  693. X}
  694. X
  695. X
  696. Xif( defined(&dbmsghandle))    # Is this a modern version of sybperl? ;-)
  697. X{
  698. X    &dbmsghandle ("sql_message_handler"); # Some user defined error handlers
  699. X    &dberrhandle ("sql_error_handler");
  700. X}
  701. X
  702. X
  703. X1;
  704. X
  705. END_OF_FILE
  706.   if test 1736 -ne `wc -c <'eg/sql.pl'`; then
  707.     echo shar: \"'eg/sql.pl'\" unpacked with wrong size!
  708.   fi
  709.   # end of 'eg/sql.pl'
  710. fi
  711. if test -f 'eg/test_dbmoney.pl' -a "${1}" != "-c" ; then 
  712.   echo shar: Will not clobber existing file \"'eg/test_dbmoney.pl'\"
  713. else
  714.   echo shar: Extracting \"'eg/test_dbmoney.pl'\" \(5481 characters\)
  715.   sed "s/^X//" >'eg/test_dbmoney.pl' <<'END_OF_FILE'
  716. X#! /usr/local/bin/sybperl
  717. X
  718. X#    @(#)test_dbmoney.pl    1.1    8/31/93
  719. X#
  720. X
  721. Xunshift(@INC, "../lib");    # to use the uninstalled require'd files
  722. Xrequire "sybperl.pl";
  723. Xrequire "getopts.pl";
  724. X
  725. X( !defined( $FALSE )) && ( $FALSE = 0 );
  726. X( !defined( $TRUE ))  && ( $TRUE  = 1 );
  727. X
  728. X&Getopts( 'S:' );
  729. X
  730. Xif ( defined( $opt_S )) {
  731. X   $server = $opt_S;
  732. X}
  733. Xelse {
  734. X   $server = $ENV{ 'DSQUERY' };
  735. X}
  736. X
  737. X$tty_test = system( "/bin/tty -s" ) / 256;
  738. X
  739. X(( $tty_test == 0 ) || ( $tty_test == 1 )) ||
  740. X   die "Invalid options were specified to /bin/tty: $!\n";
  741. X
  742. Xif ( $tty_test == 0 ) {  # tty device attached to STDIN
  743. X   system( "/bin/stty -echo" );
  744. X   print "SA password: ";
  745. X   $sybupw = scalar( <STDIN> );
  746. X   system( "/bin/stty echo" );
  747. X   print "\n";
  748. X}
  749. Xelse {
  750. X   $sybupw = scalar( <STDIN> );
  751. X}
  752. X
  753. Xchop $sybupw;
  754. X
  755. X$dbproc = &dblogin( "sa", $sybupw, $server );
  756. X
  757. X&dbuse( "master" );
  758. X
  759. X$money1 = '4.89';
  760. X$money2 = '8.56';
  761. X$money3 = '*';
  762. X
  763. Xprintf( "money1 = %.4f, money2 = %.4f\n", $money1, $money2 );
  764. X
  765. X($status, $money3) = &dbmnyzero( $money3 );
  766. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  767. X
  768. X($status, $money3) = &dbmnyinc( $money3 );
  769. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  770. X($status, $money3) = &dbmnyinc( $money3 );
  771. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  772. X($status, $money3) = &dbmnyinc( $money3 );
  773. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  774. X($status, $money3) = &dbmnyinc( $money3 );
  775. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  776. X
  777. X$money3 = '0.0001';
  778. X($status, $money3) = &dbmnyscale( $money3, 100, 1 );
  779. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  780. X
  781. X( $money3, $money4 ) = ( '0.0001', '0.0002' );
  782. X($status, $money3) = &dbmnyadd( $money3, $money4, $money3 );
  783. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  784. X
  785. X$money3 = '0.0004'; $money4 = '0.0003'; $money5 = '0.0005';
  786. X$money6 = '0.0004';
  787. Xprintf( "status = %d, money3 = %.4f, money4 = %.4f\n",
  788. X    &dbmnycmp( $money3, $money4 ), $money3, $money4 );
  789. Xprintf( "status = %d, money3 = %.4f, money5 = %.4f\n",
  790. X    &dbmnycmp( $money3, $money5 ), $money3, $money5 );
  791. Xprintf( "status = %d, money3 = %.4f, money6 = %.4f\n",
  792. X    &dbmnycmp( $money3, $money6 ), $money3, $money6 );
  793. Xprintf( "status = %d, money4 = %.4f, money5 = %.4f\n",
  794. X    &dbmnycmp( $money4, $money5 ), $money4, $money5 );
  795. Xprintf( "status = %d, money4 = %.4f, money6 = %.4f\n",
  796. X    &dbmnycmp( $money4, $money6 ), $money4, $money6 );
  797. Xprintf( "status = %d, money5 = %.4f, money6 = %.4f\n",
  798. X    &dbmnycmp( $money5, $money6 ), $money5, $money6 );
  799. X
  800. X($status, $money3) = &dbmnyadd( $money1, $money2 );
  801. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  802. X
  803. X($status, $money3) = &dbmnysub( $money1, $money2 );
  804. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  805. X
  806. X($status, $money3) = &dbmnydivide( $money3, $money2 );
  807. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  808. X
  809. X($status, $money4) = &dbmnymaxneg( );
  810. Xprintf( "status = %d, money4 = %.4f\n", $status, $money4 );
  811. X
  812. X($status, $money3) = &dbmnymaxpos( );
  813. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  814. X
  815. X($status, $money4) = &dbmnyzero( );
  816. X
  817. X@tbal = ( '4.89', '8.92', '7.77', '11.11', '0.01' );
  818. X
  819. Xfor ( $cntr = 0 ; $cntr <= $#tbal ; $cntr++ ) {
  820. X  printf( "Item %d - %s\n", $cntr, $tbal[ $cntr ] );
  821. X  ($status, $money4) = &dbmnyadd( $tbal[ $cntr ], $money4 );
  822. X}
  823. X
  824. Xprintf( "status = %d, total = %.4f\n", $status, $money4 );
  825. X
  826. X$cntr = $#tbal + 1;
  827. X
  828. X($status, $money4) = &dbmnydivide( $money4, "$cntr" );
  829. Xprintf( "status = %d, avg = %.4f\n", $status, $money4 );
  830. X
  831. Xprint "-------------------------\n";
  832. X
  833. X$money1 = '4.89';
  834. X$money2 = '8.56';
  835. X$money3 = '*';
  836. X
  837. Xprintf( "money1 = %.4f, money2 = %.4f\n", $money1, $money2 );
  838. X
  839. X($status, $money3) = &dbmny4zero( $money3 );
  840. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  841. X
  842. X( $money3, $money4 ) = ( '0.0001', '0.0002' );
  843. X($status, $money3) = &dbmny4add( $money3, $money4 );
  844. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  845. X
  846. X$money3 = '0.0004'; $money4 = '0.0003'; $money5 = '0.0005';
  847. X$money6 = '0.0004';
  848. Xprintf( "status = %d, money3 = %.4f, money4 = %.4f\n",
  849. X    &dbmny4cmp( $money3, $money4 ), $money3, $money4 );
  850. Xprintf( "status = %d, money3 = %.4f, money5 = %.4f\n",
  851. X    &dbmny4cmp( $money3, $money5 ), $money3, $money5 );
  852. Xprintf( "status = %d, money3 = %.4f, money6 = %.4f\n",
  853. X    &dbmny4cmp( $money3, $money6 ), $money3, $money6 );
  854. Xprintf( "status = %d, money4 = %.4f, money5 = %.4f\n",
  855. X    &dbmny4cmp( $money4, $money5 ), $money4, $money5 );
  856. Xprintf( "status = %d, money4 = %.4f, money6 = %.4f\n",
  857. X    &dbmny4cmp( $money4, $money6 ), $money4, $money6 );
  858. Xprintf( "status = %d, money5 = %.4f, money6 = %.4f\n",
  859. X    &dbmny4cmp( $money5, $money6 ), $money5, $money6 );
  860. X
  861. X($status, $money3) = &dbmny4add( $money1, $money2 );
  862. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  863. X
  864. X($status, $money3) = &dbmny4sub( $money1, $money2 );
  865. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  866. X
  867. X($status, $money3) = &dbmny4divide( $money3, $money2 );
  868. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  869. X
  870. X($status, $money4) = &dbmny4zero( $money4 );
  871. X
  872. X@tbal = ( '4.89', '8.92', '7.77', '11.11', '0.01' );
  873. X
  874. Xfor ( $cntr = 0 ; $cntr <= $#tbal ; $cntr++ ) {
  875. X  printf( "Item %d - %s\n", $cntr, $tbal[ $cntr ] );
  876. X  ($status, $money4) = &dbmny4add( $tbal[ $cntr ], $money4 );
  877. X}
  878. X
  879. Xprintf( "status = %d, total = %.4f\n", $status, $money4 );
  880. X
  881. X$cntr = $#tbal + 1;
  882. X
  883. X($status, $money4) = &dbmny4divide( $money4, "$cntr" );
  884. Xprintf( "status = %d, avg = %.4f\n", $status, $money4 );
  885. X
  886. X&dbclose;
  887. X
  888. X&dbexit;
  889. X
  890. Xexit( $STDEXIT );
  891. X
  892. END_OF_FILE
  893.   if test 5481 -ne `wc -c <'eg/test_dbmoney.pl'`; then
  894.     echo shar: \"'eg/test_dbmoney.pl'\" unpacked with wrong size!
  895.   fi
  896.   # end of 'eg/test_dbmoney.pl'
  897. fi
  898. if test -f 'lib/sybdb.ph' -a "${1}" != "-c" ; then 
  899.   echo shar: Will not clobber existing file \"'lib/sybdb.ph'\"
  900. else
  901.   echo shar: Extracting \"'lib/sybdb.ph'\" \(5260 characters\)
  902.   sed "s/^X//" >'lib/sybdb.ph' <<'END_OF_FILE'
  903. X;#    @(#)sybdb.ph    1.2    8/30/93
  904. X;#
  905. X;#
  906. X
  907. Xsub SYBESYNC {20001;}
  908. Xsub SYBEFCON {20002;}
  909. Xsub SYBETIME {20003;}
  910. Xsub SYBEREAD {20004;}
  911. Xsub SYBEBUFL {20005;}
  912. Xsub SYBEWRIT {20006;}
  913. Xsub SYBEVMS {20007;}
  914. Xsub SYBESOCK {20008;}
  915. Xsub SYBECONN {20009;}
  916. Xsub SYBEMEM {20010;}
  917. Xsub SYBEDBPS {20011;}
  918. Xsub SYBEINTF {20012;}
  919. Xsub SYBEUHST {20013;}
  920. Xsub SYBEPWD {20014;}
  921. Xsub SYBEOPIN {20015;}
  922. Xsub SYBEINLN {20016;}
  923. Xsub SYBESEOF {20017;}
  924. Xsub SYBESMSG {20018;}
  925. Xsub SYBERPND {20019;}
  926. Xsub SYBEBTOK {20020;}
  927. Xsub SYBEITIM {20021;}
  928. Xsub SYBEOOB {20022;}
  929. Xsub SYBEBTYP {20023;}
  930. Xsub SYBEBNCR {20024;}
  931. Xsub SYBEIICL {20025;}
  932. Xsub SYBECNOR {20026;}
  933. Xsub SYBENPRM {20027;}
  934. Xsub SYBEUVDT {20028;}
  935. Xsub SYBEUFDT {20029;}
  936. Xsub SYBEWAID {20030;}
  937. Xsub SYBECDNS {20031;}
  938. Xsub SYBEABNC {20032;}
  939. Xsub SYBEABMT {20033;}
  940. Xsub SYBEABNP {20034;}
  941. Xsub SYBEAAMT {20035;}
  942. Xsub SYBENXID {20036;}
  943. Xsub SYBERXID {20037;}
  944. Xsub SYBEICN {20038;}
  945. Xsub SYBENMOB {20039;}
  946. Xsub SYBEAPUT {20040;}
  947. Xsub SYBEASNL {20041;}
  948. Xsub SYBENTLL {20042;}
  949. Xsub SYBEASUL {20043;}
  950. Xsub SYBERDNR {20044;}
  951. Xsub SYBENSIP {20045;}
  952. Xsub SYBEABNV {20046;}
  953. Xsub SYBEDDNE {20047;}
  954. Xsub SYBECUFL {20048;}
  955. Xsub SYBECOFL {20049;}
  956. Xsub SYBECSYN {20050;}
  957. Xsub SYBECLPR {20051;}
  958. Xsub SYBECNOV {20052;}
  959. Xsub SYBERDCN {20053;}
  960. Xsub SYBESFOV {20054;}
  961. Xsub SYBEUNT {20055;}
  962. Xsub SYBECLOS {20056;}
  963. Xsub SYBEUAVE {20057;}
  964. Xsub SYBEUSCT {20058;}
  965. Xsub SYBEEQVA {20059;}
  966. Xsub SYBEUDTY {20060;}
  967. Xsub SYBETSIT {20061;}
  968. Xsub SYBEAUTN {20062;}
  969. Xsub SYBEBDIO {20063;}
  970. Xsub SYBEBCNT {20064;}
  971. Xsub SYBEIFNB {20065;}
  972. Xsub SYBETTS {20066;}
  973. Xsub SYBEKBCO {20067;}
  974. Xsub SYBEBBCI {20068;}
  975. Xsub SYBEKBCI {20069;}
  976. Xsub SYBEBCRE {20070;}
  977. Xsub SYBETPTN {20071;}
  978. Xsub SYBEBCWE {20072;}
  979. Xsub SYBEBCNN {20073;}
  980. Xsub SYBEBCOR {20074;}
  981. Xsub SYBEBCIS {20075;}
  982. Xsub SYBEBCPI {20076;}
  983. Xsub SYBEBCPN {20077;}
  984. Xsub SYBEBCPB {20078;}
  985. Xsub SYBEVDPT {20079;}
  986. Xsub SYBEBIVI {20080;}
  987. Xsub SYBEBCBC {20081;}
  988. Xsub SYBEBCFO {20082;}
  989. Xsub SYBEBCVH {20083;}
  990. Xsub SYBEBCUO {20084;}
  991. Xsub SYBEBCUC {20085;}
  992. Xsub SYBEBUOE {20086;}
  993. Xsub SYBEBUCE {20087;}
  994. Xsub SYBEBWEF {20088;}
  995. Xsub SYBEASTF {20089;}
  996. Xsub SYBEUACS {20090;}
  997. Xsub SYBEASEC {20091;}
  998. Xsub SYBETMTD {20092;}
  999. Xsub SYBENTTN {20093;}
  1000. Xsub SYBEDNTI {20094;}
  1001. Xsub SYBEBTMT {20095;}
  1002. Xsub SYBEORPF {20096;}
  1003. Xsub SYBEUVBF {20097;}
  1004. Xsub SYBEBUOF {20098;}
  1005. Xsub SYBEBUCF {20099;}
  1006. Xsub SYBEBRFF {20100;}
  1007. Xsub SYBEBWFF {20101;}
  1008. Xsub SYBEBUDF {20102;}
  1009. Xsub SYBEBIHC {20103;}
  1010. Xsub SYBEBEOF {20104;}
  1011. Xsub SYBEBCNL {20105;}
  1012. Xsub SYBEBCSI {20106;}
  1013. Xsub SYBEBCIT {20107;}
  1014. Xsub SYBEBCSA {20108;}
  1015. Xsub SYBENULL {20109;}
  1016. Xsub SYBEUNAM {20110;}
  1017. Xsub SYBEBCRO {20111;}
  1018. Xsub SYBEMPLL {20112;}
  1019. Xsub SYBERPIL {20113;}
  1020. Xsub SYBERPUL {20114;}
  1021. Xsub SYBEUNOP {20115;}
  1022. Xsub SYBECRNC {20116;}
  1023. Xsub SYBERTCC {20117;}
  1024. Xsub SYBERTSC {20118;}
  1025. Xsub SYBEUCRR {20119;}
  1026. Xsub SYBERPNA {20120;}
  1027. Xsub SYBEOPNA {20121;}
  1028. Xsub SYBEFGTL {20122;}
  1029. Xsub SYBECWLL {20123;}
  1030. Xsub SYBEUFDS {20124;}
  1031. Xsub SYBEUCPT {20125;}
  1032. Xsub SYBETMCF {20126;}
  1033. Xsub SYBEAICF {20127;}
  1034. Xsub SYBEADST {20128;}
  1035. Xsub SYBEALTT {20129;}
  1036. Xsub SYBEAPCT {20130;}
  1037. Xsub SYBEXOCI {20131;}
  1038. Xsub SYBEFSHD {20132;}
  1039. Xsub SYBEAOLF {20133;}
  1040. Xsub SYBEARDI {20134;}
  1041. Xsub SYBEURCI {20135;}
  1042. Xsub SYBEARDL {20136;}
  1043. Xsub SYBEURMI {20137;}
  1044. Xsub SYBEUREM {20138;}
  1045. Xsub SYBEURES {20139;}
  1046. Xsub SYBEUREI {20140;}
  1047. Xsub SYBEOREN {20141;}
  1048. Xsub SYBEISOI {20142;}
  1049. Xsub SYBEIDCL {20143;}
  1050. Xsub SYBEIMCL {20144;}
  1051. Xsub SYBEIFCL {20145;}
  1052. Xsub SYBEUTDS {20146;}
  1053. Xsub SYBEBUFF {20147;}
  1054. Xsub SYBEACNV {20148;}
  1055. Xsub SYBEDPOR {20149;}
  1056. Xsub SYBENDC {20150;}
  1057. Xsub SYBEMVOR {20151;}
  1058. Xsub SYBEDVOR {20152;}
  1059. Xsub SYBENBVP {20153;}
  1060. Xsub SYBESPID {20154;}
  1061. Xsub SYBENDTP {20155;}
  1062. Xsub SYBEXTN {20156;}
  1063. Xsub SYBEXTDN {20157;}
  1064. Xsub SYBEXTSN {20158;}
  1065. Xsub SYBENUM {20159;}
  1066. Xsub SYBETYPE {20160;}
  1067. Xsub SYBEGENOS {20161;}
  1068. Xsub SYBEPAGE {20162;}
  1069. Xsub SYBEOPTNO {20163;}
  1070. Xsub SYBEETD {20164;}
  1071. Xsub SYBERTYPE {20165;}
  1072. Xsub SYBERFILE {20166;}
  1073. Xsub SYBEFMODE {20167;}
  1074. Xsub SYBESLCT {20168;}
  1075. Xsub SYBEZTXT {20169;}
  1076. Xsub SYBENTST {20170;}
  1077. Xsub SYBEOSSL {20171;}
  1078. Xsub SYBEESSL {20172;}
  1079. Xsub SYBENLNL {20173;}
  1080. Xsub SYBENHAN {20174;}
  1081. Xsub SYBENBUF {20175;}
  1082. Xsub SYBENULP {20176;}
  1083. Xsub SYBENOTI {20177;}
  1084. Xsub SYBEEVOP {20178;}
  1085. Xsub SYBENEHA {20179;}
  1086. Xsub SYBETRAN {20180;}
  1087. Xsub SYBEEVST {20181;}
  1088. Xsub SYBEEINI {20182;}
  1089. Xsub SYBEECRT {20183;}
  1090. Xsub SYBEECAN {20184;}
  1091. Xsub SYBEEUNR {20185;}
  1092. Xsub SYBERPCS {20186;}
  1093. Xsub SYBETPAR {20187;}
  1094. Xsub SYBETEXS {20188;}
  1095. Xsub SYBETRAC {20189;}
  1096. Xsub SYBETRAS {20190;}
  1097. Xsub SYBEPRTF {20191;}
  1098. Xsub SYBETRSN {20192;}
  1099. Xsub SYBEBPKS {20193;}
  1100. Xsub SYBEIPV {20194;}
  1101. Xsub SYBEMOV {20195;}
  1102. Xsub SYBEDIVZ {20196;}
  1103. Xsub SYBEASTL {20197;}
  1104. Xsub SYBESEFA {20198;}
  1105. Xsub SYBEPOLL {20199;}
  1106. Xsub SYBENOEV {20200;}
  1107. Xsub SYBEBADPK {20201;}
  1108. Xsub DBERRCOUNT {201;}
  1109. X
  1110. X# sybperl standard definitions (and some new additions)
  1111. X#
  1112. X# From sybfront.h
  1113. X#
  1114. X
  1115. X# sybperl standard definitions (and some new additions)
  1116. X#
  1117. X# From sybdb.h
  1118. X#
  1119. X
  1120. X# sybperl standard definitions (and some new additions)
  1121. X#
  1122. X# From syberror.h
  1123. X#
  1124. X
  1125. X# Other definitions (optional)
  1126. X#
  1127. X# From sybdb.h
  1128. X#
  1129. Xsub DBSINGLE {0;}
  1130. Xsub DBDOUBLE {1;}
  1131. Xsub DBBOTH {2;}
  1132. Xsub DBXLATE_XOK {0;}
  1133. Xsub DBXLATE_XOF {1;}
  1134. Xsub DBXLATE_XPAT {2;}
  1135. Xsub DBRESULT {1;}
  1136. Xsub DBNOTIFICATION {2;}
  1137. Xsub DBTIMEOUT {3;}
  1138. Xsub DBINTERRUPT {4;}
  1139. Xsub DBMAXMNYSYM {5;}
  1140. Xsub DBMAXECLEN {8;}
  1141. Xsub DBMAXESLEN {256;}
  1142. Xsub DBMAXCPYRTLEN {512;}
  1143. Xsub DBTDS_UNKNOWN {0;}
  1144. Xsub DBTDS_2_0 {1;}
  1145. Xsub DBTDS_3_4 {2;}
  1146. Xsub DBTDS_4_0 {3;}
  1147. Xsub DBTDS_4_2 {4;}
  1148. Xsub DBTDS_4_6 {5;}
  1149. X
  1150. X
  1151. Xsub SUCCEED {1;}
  1152. Xsub FAIL {0;}
  1153. X
  1154. Xsub INT_EXIT {0;}
  1155. Xsub INT_CONTINUE {1;}
  1156. Xsub INT_CANCEL {2;}
  1157. X
  1158. X1;
  1159. X
  1160. END_OF_FILE
  1161.   if test 5260 -ne `wc -c <'lib/sybdb.ph'`; then
  1162.     echo shar: \"'lib/sybdb.ph'\" unpacked with wrong size!
  1163.   fi
  1164.   # end of 'lib/sybdb.ph'
  1165. fi
  1166. if test -f 'lib/sybdb_redefs.pl' -a "${1}" != "-c" ; then 
  1167.   echo shar: Will not clobber existing file \"'lib/sybdb_redefs.pl'\"
  1168. else
  1169.   echo shar: Extracting \"'lib/sybdb_redefs.pl'\" \(9041 characters\)
  1170.   sed "s/^X//" >'lib/sybdb_redefs.pl' <<'END_OF_FILE'
  1171. X#    @(#)sybdb_redefs.pl    1.2    8/31/93
  1172. X#
  1173. X# Adapted from Jeff Wongs version.
  1174. X# sybdb_redefs.pl - sybperl redefinitions to defeat weird package/user-defined
  1175. X#                   built-in subroutine bug.
  1176. X#
  1177. X# jtw, 09/06/93, V1.4 - defer omission of $dbproc for all routines
  1178. X# jtw, 09/06/93, V1.3 - add OpenClient R4.6.1 money routines
  1179. X# jtw, 14/05/93, V1.2 - change argument test in &dbnextrow to == 0
  1180. X# jtw, 13/05/93, V1.1 - synchronise with sybperl V1.6
  1181. X# jtw, 18/03/93, V1.0 - original
  1182. X#
  1183. X#
  1184. Xpackage main;
  1185. X
  1186. Xsub dblogin {
  1187. X   local( @param_array ) = @_;
  1188. X   local( $dbproc );
  1189. X
  1190. X   $dbproc = &dbLOGIN( @param_array );
  1191. X
  1192. X   return $dbproc;
  1193. X}
  1194. X
  1195. Xsub dbopen {
  1196. X   local( $server ) = @_;
  1197. X   local( $dbproc );
  1198. X
  1199. X   $dbproc = &dbOPEN( $server );
  1200. X
  1201. X   return $dbproc;
  1202. X}
  1203. X
  1204. Xsub dbclose {
  1205. X   local( $dbproc ) = @_;
  1206. X   local( $ret );
  1207. X
  1208. X   $ret = &dbCLOSE( $dbproc );
  1209. X
  1210. X   return $ret;
  1211. X}
  1212. X
  1213. Xsub dbcmd {
  1214. X   local( @param_array ) = @_;
  1215. X   local( $ret );
  1216. X
  1217. X   $ret = &dbCMD( @param_array );
  1218. X
  1219. X   return $ret;
  1220. X}
  1221. X
  1222. Xsub dbsqlexec {
  1223. X   local( $dbproc ) = @_;
  1224. X   local( $ret );
  1225. X
  1226. X   $ret = &dbSQLEXEC( $dbproc );
  1227. X
  1228. X   return $ret;
  1229. X}
  1230. X
  1231. Xsub dbresults {
  1232. X   local( $dbproc ) = @_;
  1233. X   local( $ret );
  1234. X
  1235. X   $ret = &dbRESULTS( $dbproc );
  1236. X
  1237. X   return $ret;
  1238. X}
  1239. X
  1240. Xsub dbnextrow {
  1241. X   local( @param_array ) = @_;
  1242. X   local( @dvec, %avec );
  1243. X
  1244. X   if (( $#param_array     == 1 )  &&
  1245. X       ( $param_array[ 1 ] != 0 ))    {  # associative array
  1246. X      %avec = &dbNEXTROW( @param_array );
  1247. X
  1248. X      return %avec;
  1249. X   }
  1250. X   else {  # normal array
  1251. X      @dvec = &dbNEXTROW( @param_array );
  1252. X
  1253. X      return @dvec;
  1254. X   }
  1255. X}
  1256. X
  1257. Xsub dbcancel {
  1258. X   local( $dbproc ) = @_;
  1259. X   local( $ret );
  1260. X
  1261. X   $ret = &dbCANCEL( $dbproc );
  1262. X
  1263. X   return $ret;
  1264. X}
  1265. X
  1266. Xsub dbcanquery {
  1267. X   local( $dbproc ) = @_;
  1268. X   local( $ret );
  1269. X
  1270. X   $ret = &dbCANQUERY( $dbproc );
  1271. X
  1272. X   return $ret;
  1273. X}
  1274. X
  1275. Xsub dbexit {
  1276. X   &dbEXIT;
  1277. X}
  1278. X
  1279. Xsub dbuse {
  1280. X   local( @param_array ) = @_;
  1281. X   local( $ret );
  1282. X
  1283. X   $ret = &dbUSE( @param_array );
  1284. X
  1285. X   return $ret;
  1286. X}
  1287. X
  1288. Xsub dberrhandle {
  1289. X   local( $handler ) = @_;
  1290. X   local( $old_handler );
  1291. X
  1292. X   $old_handler = &dbERRHANDLE( $handler );
  1293. X
  1294. X   return $old_handler;
  1295. X}
  1296. X
  1297. Xsub dbmsghandle {
  1298. X   local( $handler ) = @_;
  1299. X   local( $old_handler );
  1300. X
  1301. X   $old_handler = &dbMSGHANDLE( $handler );
  1302. X
  1303. X   return $old_handler;
  1304. X}
  1305. X
  1306. Xsub dbstrcpy {
  1307. X   local( $dbproc ) = @_;
  1308. X   local( $string );
  1309. X
  1310. X   $string = &dbSTRCPY( $dbproc );
  1311. X
  1312. X   return $string;
  1313. X}
  1314. X
  1315. Xsub dbsafestr {
  1316. X   local( @param_array ) = @_;
  1317. X   local( $string );
  1318. X
  1319. X   $string = &dbSAFESTR( @param_array );
  1320. X
  1321. X   return $string;
  1322. X}
  1323. X
  1324. Xsub dbwritetext {
  1325. X   local( @param_array ) = @_;
  1326. X   local( $status );
  1327. X
  1328. X   $status = &dbWRITETEXT( @param_array );
  1329. X
  1330. X   return $status;
  1331. X}
  1332. X
  1333. Xsub DBCURCMD {
  1334. X   local( $dbproc ) = @_;
  1335. X   local( $cmd_no );
  1336. X
  1337. X   $cmd_no = &dbCURCMD( $dbproc );
  1338. X
  1339. X   return $cmd_no;
  1340. X}
  1341. X
  1342. Xsub DBCURROW {
  1343. X   local( $dbproc ) = @_;
  1344. X   local( $row_no );
  1345. X
  1346. X   $row_no = &dbCURROW( $dbproc );
  1347. X
  1348. X   return $row_no;
  1349. X}
  1350. X
  1351. Xsub DBMORECMDS {
  1352. X   local( $dbproc ) = @_;
  1353. X   local( $status );
  1354. X
  1355. X   $status = &dbMORECMDS( $dbproc );
  1356. X
  1357. X   return $status;
  1358. X}
  1359. X
  1360. Xsub DBCMDROW {
  1361. X   local( $dbproc ) = @_;
  1362. X   local( $status );
  1363. X
  1364. X   $status = &dbCMDROW( $dbproc );
  1365. X
  1366. X   return $status;
  1367. X}
  1368. X
  1369. Xsub DBROWS {
  1370. X   local( $dbproc ) = @_;
  1371. X   local( $status );
  1372. X
  1373. X   $status = &dbROWS( $dbproc );
  1374. X
  1375. X   return $status;
  1376. X}
  1377. X
  1378. Xsub DBCOUNT {
  1379. X   local( $dbproc ) = @_;
  1380. X   local( $no_rows );
  1381. X
  1382. X   $no_rows = &dbCOUNT( $dbproc );
  1383. X
  1384. X   return $no_rows;
  1385. X}
  1386. X
  1387. Xsub dbhasretstat {
  1388. X   local( $dbproc ) = @_;
  1389. X   local( $status );
  1390. X
  1391. X   $status = &dbHASRETSTAT( $dbproc );
  1392. X
  1393. X   return $status;
  1394. X}
  1395. X
  1396. Xsub dbretstatus {
  1397. X   local( $dbproc ) = @_;
  1398. X   local( $status );
  1399. X
  1400. X   $status = &dbRETSTATUS( $dbproc );
  1401. X
  1402. X   return $status;
  1403. X}
  1404. X
  1405. Xsub dbmny4add {
  1406. X   local( @param_array ) = @_;
  1407. X   local( @status );
  1408. X
  1409. X   @status = &dbMNY4ADD( @param_array );
  1410. X
  1411. X   return @status;
  1412. X}
  1413. X
  1414. Xsub dbmny4cmp {
  1415. X   local( @param_array ) = @_;
  1416. X   local( $status );
  1417. X
  1418. X   $status = &dbMNY4CMP( @param_array );
  1419. X
  1420. X   return $status;
  1421. X}
  1422. X
  1423. Xsub dbmny4divide {
  1424. X   local( @param_array ) = @_;
  1425. X   local( @status );
  1426. X
  1427. X   @status = &dbMNY4DIVIDE( @param_array );
  1428. X
  1429. X   return @status;
  1430. X}
  1431. X
  1432. Xsub dbmny4minus {
  1433. X   local( @param_array ) = @_;
  1434. X   local( @status );
  1435. X
  1436. X   @status = &dbMNY4MINUS( @param_array );
  1437. X
  1438. X   return @status;
  1439. X}
  1440. X
  1441. Xsub dbmny4mul {
  1442. X   local( @param_array ) = @_;
  1443. X   local( @status );
  1444. X   
  1445. X   @status = &dbMNY4MUL( @param_array );
  1446. X
  1447. X   return @status;
  1448. X}
  1449. X
  1450. Xsub dbmny4sub {
  1451. X   local( @param_array ) = @_;
  1452. X   local( @status );
  1453. X
  1454. X   @status = &dbMNY4SUB( @param_array );
  1455. X
  1456. X   return @status;
  1457. X}
  1458. X
  1459. Xsub dbmny4zero {
  1460. X   local( @param_array ) = @_;
  1461. X   local( @status );
  1462. X
  1463. X   @status = &dbMNY4ZERO( @param_array );
  1464. X
  1465. X   return @status;
  1466. X}
  1467. X
  1468. Xsub dbmnyadd {
  1469. X   local( @param_array ) = @_;
  1470. X   local( @status );
  1471. X
  1472. X   @status = &dbMNYADD( @param_array );
  1473. X
  1474. X   return @status;
  1475. X}
  1476. X
  1477. Xsub dbmnycmp {
  1478. X   local( @param_array ) = @_;
  1479. X   local( $status );
  1480. X
  1481. X   $status = &dbMNYCMP( @param_array );
  1482. X
  1483. X   return $status;
  1484. X}
  1485. X
  1486. Xsub dbmnydivide {
  1487. X   local( @param_array ) = @_;
  1488. X   local( @status );
  1489. X
  1490. X   @status = &dbMNYDIVIDE( @param_array );
  1491. X
  1492. X   return @status;
  1493. X}
  1494. X
  1495. Xsub dbmnyminus {
  1496. X   local( @param_array ) = @_;
  1497. X   local( @status );
  1498. X
  1499. X   @status = &dbMNYMINUS( @param_aray );
  1500. X
  1501. X   return @status;
  1502. X}
  1503. X
  1504. Xsub dbmnymul {
  1505. X   local( @param_array ) = @_;
  1506. X   local( @status );
  1507. X
  1508. X   @status = &dbMNYMUL( @param_array );
  1509. X
  1510. X   return @status;
  1511. X}
  1512. X
  1513. Xsub dbmnysub {
  1514. X   local( @param_array ) = @_;
  1515. X   local( @status );
  1516. X
  1517. X   @status = &dbMNYSUB( @param_array );
  1518. X
  1519. X   return @status;
  1520. X}
  1521. X
  1522. Xsub dbmnyzero {
  1523. X   local( @param_array ) = @_;
  1524. X   local( @status );
  1525. X
  1526. X   @status = &dbMNYZERO( @param_array );
  1527. X
  1528. X   return @status;
  1529. X}
  1530. X
  1531. Xsub dbmnydec {
  1532. X   local( @param_array ) = @_;
  1533. X   local( @status );
  1534. X
  1535. X   @status = &dbMNYDEC( @param_array );
  1536. X
  1537. X   return @status;
  1538. X}
  1539. X
  1540. Xsub dbmnydown {
  1541. X   local( @param_array ) = @_;
  1542. X   local( @status );
  1543. X
  1544. X   @status = &dbMNYDOWN( @param_array );
  1545. X
  1546. X   return @status;
  1547. X}
  1548. X
  1549. Xsub dbmnyinc {
  1550. X   local( @param_array ) = @_;
  1551. X   local( @status );
  1552. X
  1553. X   @status = &dbMNYINC( @param_array );
  1554. X
  1555. X   return @status;
  1556. X}
  1557. X
  1558. Xsub dbmnyinit {
  1559. X   local( @param_array ) = @_;
  1560. X   local( @status );
  1561. X
  1562. X   @status = &dbMNYINIT( @param_array );
  1563. X
  1564. X   return @status;
  1565. X}
  1566. X
  1567. Xsub dbmnymaxneg {
  1568. X   local( @param_array ) = @_;
  1569. X   local( @status );
  1570. X
  1571. X   @status = &dbMNYMAXNEG( @param_array );
  1572. X
  1573. X   return @status;
  1574. X}
  1575. X
  1576. Xsub dbmnymaxpos {
  1577. X   local( @param_array ) = @_;
  1578. X   local( @status );
  1579. X
  1580. X   @status = &dbMNYMAXPOS( @param_array );
  1581. X
  1582. X   return @status;
  1583. X}
  1584. X
  1585. Xsub dbmnyndigit {
  1586. X   local( @param_array ) = @_;
  1587. X   local( @status );
  1588. X
  1589. X   @status = &dbMNYNDIGIT( @param_array );
  1590. X
  1591. X   return @array;
  1592. X}
  1593. X
  1594. Xsub dbmnyscale {
  1595. X   local( @param_array ) = @_;
  1596. X   local( @status );
  1597. X
  1598. X   @status = &dbMNYSCALE( @param_array );
  1599. X
  1600. X   return @status;
  1601. X}
  1602. X
  1603. Xsub dbcoltype
  1604. X{
  1605. X    local( @param_array ) = @_;
  1606. X    local( $status );
  1607. X
  1608. X    $status = &dbCOLTYPE( @param_array );
  1609. X
  1610. X    return $status;
  1611. X}
  1612. X
  1613. Xsub dbcolname
  1614. X{
  1615. X    local( @param_array ) = @_;
  1616. X    local( $status );
  1617. X
  1618. X    $status = &dbCOLNAME( @param_array );
  1619. X
  1620. X    return $status;
  1621. X}
  1622. X
  1623. Xsub dbcollen
  1624. X{
  1625. X    local( @param_array ) = @_;
  1626. X    local( $status );
  1627. X
  1628. X    $status = &dbCOLLEN( @param_array );
  1629. X
  1630. X    return $status;
  1631. X}
  1632. X
  1633. Xsub dbnumcols
  1634. X{
  1635. X    local( @param_array ) = @_;
  1636. X    local( $status );
  1637. X
  1638. X    $status = &dbNUMCOLS( @param_array );
  1639. X
  1640. X    return $status;
  1641. X}
  1642. X
  1643. Xsub dbrecftos
  1644. X{
  1645. X    local( @param_array ) = @_;
  1646. X    local( $status );
  1647. X
  1648. X    $status = &dbRECFTOS( @param_array );
  1649. X
  1650. X    return $status;
  1651. X}
  1652. X
  1653. Xsub BCP_SETL
  1654. X{
  1655. X    local( @param_array ) = @_;
  1656. X    local( $status );
  1657. X
  1658. X    $status = &bcp_SETL( @param_array );
  1659. X
  1660. X    return $status;
  1661. X}
  1662. X
  1663. Xsub bcp_getl
  1664. X{
  1665. X    local( @param_array ) = @_;
  1666. X    local( $status );
  1667. X
  1668. X    $status = &bcp_GETL( @param_array );
  1669. X
  1670. X    return $status;
  1671. X}
  1672. X
  1673. Xsub bcp_init
  1674. X{
  1675. X    local( @param_array ) = @_;
  1676. X    local( $status );
  1677. X
  1678. X    $status = &bcp_INIT( @param_array );
  1679. X
  1680. X    return $status;
  1681. X}
  1682. X
  1683. Xsub bcp_meminit
  1684. X{
  1685. X    local( @param_array ) = @_;
  1686. X    local( $status );
  1687. X
  1688. X    $status = &bcp_MEMINIT( @param_array );
  1689. X
  1690. X    return $status;
  1691. X}
  1692. X
  1693. Xsub bcp_sendrow
  1694. X{
  1695. X    local( @param_array ) = @_;
  1696. X    local( $status );
  1697. X
  1698. X    $status = &bcp_SNEDROW( @param_array );
  1699. X
  1700. X    return $status;
  1701. X}
  1702. X
  1703. Xsub bcp_batch
  1704. X{
  1705. X    local( @param_array ) = @_;
  1706. X    local( $status );
  1707. X
  1708. X    $status = &bcp_BATCH( @param_array );
  1709. X
  1710. X    return $status;
  1711. X}
  1712. X
  1713. Xsub bcp_done
  1714. X{
  1715. X    local( @param_array ) = @_;
  1716. X    local( $status );
  1717. X
  1718. X    $status = &bcp_DONE( @param_array );
  1719. X
  1720. X    return $status;
  1721. X}
  1722. X
  1723. Xsub bcp_control
  1724. X{
  1725. X    local( @param_array ) = @_;
  1726. X    local( $status );
  1727. X
  1728. X    $status = &bcp_CONTROL( @param_array );
  1729. X
  1730. X    return $status;
  1731. X}
  1732. X
  1733. Xsub bcp_columns
  1734. X{
  1735. X    local( @param_array ) = @_;
  1736. X    local( $status );
  1737. X
  1738. X    $status = &bcp_COLUMNS( @param_array );
  1739. X
  1740. X    return $status;
  1741. X}
  1742. X
  1743. Xsub bcp_colfmt
  1744. X{
  1745. X    local( @param_array ) = @_;
  1746. X    local( $status );
  1747. X
  1748. X    $status = &bcp_COLFMT( @param_array );
  1749. X
  1750. X    return $status;
  1751. X}
  1752. X
  1753. Xsub bcp_exec
  1754. X{
  1755. X    local( @param_array ) = @_;
  1756. X    local( $status );
  1757. X
  1758. X    $status = &bcp_EXEC( @param_array );
  1759. X
  1760. X    return $status;
  1761. X}
  1762. X
  1763. Xsub bcp_readfmt
  1764. X{
  1765. X    local( @param_array ) = @_;
  1766. X    local( $status );
  1767. X
  1768. X    $status = &bcp_READFMT( @param_array );
  1769. X
  1770. X    return $status;
  1771. X}
  1772. X
  1773. Xsub bcp_writefmt
  1774. X{
  1775. X    local( @param_array ) = @_;
  1776. X    local( $status );
  1777. X
  1778. X    $status = &bcp_writefmt( @param_array );
  1779. X
  1780. X    return $status;
  1781. X}
  1782. X
  1783. X# ----- end of sybdb_redefs.pl -----
  1784. X
  1785. X1;
  1786. X
  1787. END_OF_FILE
  1788.   if test 9041 -ne `wc -c <'lib/sybdb_redefs.pl'`; then
  1789.     echo shar: \"'lib/sybdb_redefs.pl'\" unpacked with wrong size!
  1790.   fi
  1791.   # end of 'lib/sybdb_redefs.pl'
  1792. fi
  1793. if test -f 'lib/sybperl.pl' -a "${1}" != "-c" ; then 
  1794.   echo shar: Will not clobber existing file \"'lib/sybperl.pl'\"
  1795. else
  1796.   echo shar: Extracting \"'lib/sybperl.pl'\" \(1865 characters\)
  1797.   sed "s/^X//" >'lib/sybperl.pl' <<'END_OF_FILE'
  1798. X;#     @(#)sybperl.pl    1.5    9/23/93
  1799. X
  1800. X;# This file, when interpreted, sets the appropriate environment
  1801. X;# variables for Sybase's use DB-Library & isql.
  1802. X;#
  1803. X;# usage:
  1804. X;#    require 'sybperl.pl';
  1805. X;#
  1806. X;# We don't set the environment if it is already set.
  1807. X
  1808. Xrequire 'sybdb.ph';
  1809. X
  1810. X$ENV{'SYBASE'} = "/usr/local/sybase" unless $ENV{'SYBASE'};
  1811. X$ENV{'DSQUERY'}= "SYBASE" unless $ENV{'DSQUERY'};
  1812. X$ENV{'PATH'}="$ENV{'PATH'}:$ENV{'SYBASE'}/bin" unless $ENV{'PATH'} =~ /$ENV{'SYBASE'}/;
  1813. X
  1814. X# Message and error handlers.
  1815. X
  1816. Xsub message_handler
  1817. X{
  1818. X    local ($db, $message, $state, $severity, $text, $server, $procedure, $line)
  1819. X    = @_;
  1820. X
  1821. X    if ($severity > 0)
  1822. X    {
  1823. X    print STDERR ("Sybase message ", $message, ", Severity ", $severity,
  1824. X           ", state ", $state);
  1825. X    print STDERR ("\nServer `", $server, "'") if defined ($server);
  1826. X    print STDERR ("\nProcedure `", $procedure, "'") if defined ($procedure);
  1827. X    print STDERR ("\nLine ", $line) if defined ($line);
  1828. X    print STDERR ("\n    ", $text, "\n\n");
  1829. X
  1830. X# &dbstrcpy returns the command buffer.
  1831. X
  1832. X    local ($lineno) = 1;    # 
  1833. X    foreach $row (split (/\n/, &dbstrcpy ($db)))
  1834. X    {
  1835. X        print STDERR (sprintf ("%5d", $lineno ++), "> ", $row, "\n");
  1836. X    }
  1837. X    }
  1838. X    elsif ($message == 0)
  1839. X    {
  1840. X    print STDERR ($text, "\n");
  1841. X    }
  1842. X    
  1843. X    0;
  1844. X}
  1845. X
  1846. Xsub error_handler {
  1847. X    # Check the error code to see if we should report this.
  1848. X    if ($_[2] != &SYBESMSG) {
  1849. X    local ($db, $severity, $error, $os_error, $error_msg, $os_error_msg)
  1850. X        = @_;
  1851. X    print STDERR ("Sybase error: ", $error_msg, "\n");
  1852. X    print STDERR ("OS Error: ", $os_error_msg, "\n") if defined ($os_error_msg);
  1853. X    }
  1854. X
  1855. X    &INT_CANCEL;
  1856. X}
  1857. X
  1858. X
  1859. Xif( defined(&dbmsghandle))    # Is this a modern version of sybperl? ;-)
  1860. X{
  1861. X    &dbmsghandle ("message_handler"); # Some user defined error handlers
  1862. X    &dberrhandle ("error_handler");
  1863. X}
  1864. X
  1865. X
  1866. Xif (defined($SybPackageBug) && $SybPackageBug == 1)
  1867. X{
  1868. X    require 'sybdb_redefs.pl';
  1869. X}
  1870. X
  1871. X
  1872. X1;
  1873. X
  1874. END_OF_FILE
  1875.   if test 1865 -ne `wc -c <'lib/sybperl.pl'`; then
  1876.     echo shar: \"'lib/sybperl.pl'\" unpacked with wrong size!
  1877.   fi
  1878.   # end of 'lib/sybperl.pl'
  1879. fi
  1880. if test -f 't/sbex.pl' -a "${1}" != "-c" ; then 
  1881.   echo shar: Will not clobber existing file \"'t/sbex.pl'\"
  1882. else
  1883.   echo shar: Extracting \"'t/sbex.pl'\" \(4966 characters\)
  1884.   sed "s/^X//" >'t/sbex.pl' <<'END_OF_FILE'
  1885. X#!../sybperl
  1886. X
  1887. X
  1888. X@nul = ('not null','null');
  1889. X@sysdb = ('master', 'model', 'tempdb');
  1890. X
  1891. Xunshift(@INC, '../lib');
  1892. X
  1893. Xrequire "sybperl.pl";
  1894. X
  1895. Xprint "Sybperl version $SybperlVer\n\n";
  1896. X
  1897. Xprint "This script tests some of sybperl's functions, and prints out\n";
  1898. Xprint "description of the databases that are defined in your Sybase\n";
  1899. Xprint "dataserver.\n\n";
  1900. X
  1901. X
  1902. X$dbproc = &dblogin("sa");    # Login to sybase
  1903. X&dbmsghandle ("message_handler"); # Some user defined error handlers
  1904. X&dberrhandle ("error_handler");
  1905. X
  1906. X$dbproc2 = &dbopen;        # Get a second dbprocess, so that we can select from several
  1907. X                                # chanels simultaneously. We could code things so that this
  1908. X                # feature is unnecessary, but it's good to exercise it.
  1909. X
  1910. X                # First, find out what databases exist:
  1911. X&dbcmd($dbproc, "select name from sysdatabases order by crdate\n");
  1912. X&dbsqlexec($dbproc);
  1913. X&dbresults($dbproc);
  1914. X
  1915. Xdatabase: while((@db = &dbnextrow($dbproc)))
  1916. X{
  1917. X    foreach $nm (@sysdb)
  1918. X    {
  1919. X    if($db[0] =~ /$nm/)
  1920. X    {
  1921. X        print "'$db[0]' is a system database\n";
  1922. X        next database;
  1923. X    }
  1924. X    }
  1925. X    print "Finding user tables in user database $db[0]...";
  1926. X
  1927. X    &dbcmd($dbproc2, "select o.name, u.name, o.id\n"); # 
  1928. X    &dbcmd($dbproc2, "from $db[0].dbo.sysobjects o, $db[0].dbo.sysusers u\n");
  1929. X    &dbcmd($dbproc2, "where o.type = 'U' and u.uid = o.uid\n");
  1930. X    &dbcmd($dbproc2, "order by o.name\n");
  1931. X
  1932. X    &dbsqlexec($dbproc2);
  1933. X    &dbresults($dbproc2);
  1934. X
  1935. X    while((@dat = &dbnextrow($dbproc2)))
  1936. X    {
  1937. X    $tab = join('@', @dat);    # Save the information
  1938. X    push(@tables, $tab);    # for later use...
  1939. X    }
  1940. X    print "Done.\n";
  1941. X
  1942. X    print "Finding user defined datatypes in database $db[0]...\n";
  1943. X
  1944. X    &dbcmd($dbproc2, "select s.length,substring(s.name,1,30),substring(st.name,1,30)\n");
  1945. X    &dbcmd($dbproc2, "from $db[0].dbo.systypes s, $db[0].dbo.systypes st\n");
  1946. X    &dbcmd($dbproc2, "where  st.type = s.type\n");
  1947. X    &dbcmd($dbproc2, "and s.usertype > 100 and st.usertype < 100 and st.usertype != 18\n");
  1948. X    &dbsqlexec($dbproc2);
  1949. X    &dbresults($dbproc2);
  1950. X
  1951. X    while((@dat = &dbnextrow($dbproc2)))
  1952. X    {
  1953. X    print "sp_addtype $dat[1],";
  1954. X    if ($dat[2] =~ /char|binary/)
  1955. X    {
  1956. X        print "'$dat[2]($dat[0])'";
  1957. X    }
  1958. X    else
  1959. X    {
  1960. X        print "$dat[2]";
  1961. X    }
  1962. X    print "\n";
  1963. X
  1964. X    }
  1965. X    print "Done.\n";
  1966. X
  1967. X    print "Now we find the table definition for each user table\nin database $db[0]...\n";
  1968. X
  1969. X    foreach $ln (@tables)        # For each line in the list
  1970. X    {
  1971. X    @tab = split('@',$ln);
  1972. X
  1973. X    &dbcmd($dbproc2, "select Column_name = c.name, \n");
  1974. X    &dbcmd($dbproc2, "       Type = t.name, \n");
  1975. X    &dbcmd($dbproc2, "       Length = c.length, \n");
  1976. X    &dbcmd($dbproc2, "       Nulls = convert(bit, (c.status & 8))\n");
  1977. X    &dbcmd($dbproc2, "from   $db[0].dbo.syscolumns c, $db[0].dbo.systypes t\n");
  1978. X    &dbcmd($dbproc2, "where  c.id = $tab[2]\n");
  1979. X    &dbcmd($dbproc2, "and    c.usertype *= t.usertype\n");
  1980. X    
  1981. X    &dbsqlexec($dbproc2);
  1982. X    &dbresults($dbproc2);
  1983. X
  1984. X    print "\nTABLE $db[0].$tab[1].$tab[0]\n ("; 
  1985. X    $first = 1;
  1986. X    while((@field = &dbnextrow($dbproc2)))
  1987. X    {
  1988. X        print ",\n" if !$first;        # add a , and a \n if not first field in table
  1989. X        
  1990. X        print "\t$field[0] \t$field[1]";
  1991. X        print "($field[2])" if $field[1] =~ /char|bin/;
  1992. X        print " $nul[$field[3]]";
  1993. X
  1994. X        $first = 0 if $first;
  1995. X    }
  1996. X    print " )\n";
  1997. X
  1998. X# now get the indexes...
  1999. X#
  2000. X    print "\nIndexes on $db[0].$tab[0].$tab[1]...\n\n";
  2001. X    &dbuse($dbproc2, $db[0]);
  2002. X    &dbcmd($dbproc2, "sp_helpindex '$tab[1].$tab[0]'\n");
  2003. X
  2004. X    &dbsqlexec($dbproc2);
  2005. X    &dbresults($dbproc2);
  2006. X
  2007. X    while((@field = &dbnextrow($dbproc2)))
  2008. X    {
  2009. X        print "unique " if $field[1] =~ /unique/;
  2010. X        print "clustered " if $field[1] =~ /^clust/;
  2011. X        print "index $field[0]\n";
  2012. X        @col = split(/,/,$field[2]);
  2013. X        print "on $db[0].$tab[1].$tab[0] (";
  2014. X        $first = 1;
  2015. X        foreach $ln1 (@col)
  2016. X        {
  2017. X        print ", " if !$first;
  2018. X        $first = 0;
  2019. X        print "$ln1";
  2020. X        }
  2021. X        print ")\n";
  2022. X    }
  2023. X    print "\nDone.\n";
  2024. X    }
  2025. X    &dbuse($dbproc2, "master");
  2026. X    @tables = ();
  2027. X}
  2028. X
  2029. X&dbexit;
  2030. X
  2031. X
  2032. X# Message and error handlers.
  2033. X
  2034. Xsub message_handler
  2035. X{
  2036. X    local ($db, $message, $state, $severity, $text, $server, $procedure, $line)
  2037. X    = @_;
  2038. X
  2039. X    if ($severity > 0)
  2040. X    {
  2041. X    print ("Sybase message ", $message, ", Severity ", $severity,
  2042. X           ", state ", $state);
  2043. X    print ("\nServer `", $server, "'") if defined ($server);
  2044. X    print ("\nProcedure `", $procedure, "'") if defined ($procedure);
  2045. X    print ("\nLine ", $line) if defined ($line);
  2046. X    print ("\n    ", $text, "\n\n");
  2047. X
  2048. X# &dbstrcpy returns the command buffer.
  2049. X
  2050. X    local ($lineno) = 1;    # 
  2051. X    foreach $row (split (/\n/, &dbstrcpy ($db)))
  2052. X    {
  2053. X        print (sprintf ("%5d", $lineno ++), "> ", $row, "\n");
  2054. X    }
  2055. X    }
  2056. X    elsif ($message == 0)
  2057. X    {
  2058. X    print ($text, "\n");
  2059. X    }
  2060. X    
  2061. X    0;
  2062. X}
  2063. X
  2064. Xsub error_handler {
  2065. X    # Check the error code to see if we should report this.
  2066. X    if ($_[2] != &SYBESMSG) {
  2067. X    local ($db, $severity, $error, $os_error, $error_msg, $os_error_msg)
  2068. X        = @_;
  2069. X    print ("Sybase error: ", $error_msg, "\n");
  2070. X    print ("OS Error: ", $os_error_msg, "\n") if defined ($os_error_msg);
  2071. X    }
  2072. X
  2073. X    &INT_CANCEL;
  2074. X}
  2075. X
  2076. X
  2077. X
  2078. END_OF_FILE
  2079.   if test 4966 -ne `wc -c <'t/sbex.pl'`; then
  2080.     echo shar: \"'t/sbex.pl'\" unpacked with wrong size!
  2081.   fi
  2082.   chmod +x 't/sbex.pl'
  2083.   # end of 't/sbex.pl'
  2084. fi
  2085. echo shar: End of archive 3 \(of 3\).
  2086. cp /dev/null ark3isdone
  2087. MISSING=""
  2088. for I in 1 2 3 ; do
  2089.     if test ! -f ark${I}isdone ; then
  2090.     MISSING="${MISSING} ${I}"
  2091.     fi
  2092. done
  2093. if test "${MISSING}" = "" ; then
  2094.     echo You have unpacked all 3 archives.
  2095.     rm -f ark[1-9]isdone
  2096. else
  2097.     echo You still must unpack the following archives:
  2098.     echo "        " ${MISSING}
  2099. fi
  2100. exit 0
  2101. exit 0 # Just in case...
  2102.