home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume43 / sybperl / part01 next >
Encoding:
Internet Message Format  |  1994-06-27  |  87.2 KB

  1. From: mpeppler@itf.ch (Michael Peppler)
  2. Newsgroups: comp.sources.misc
  3. Subject: v43i046:  sybperl - Sybase DB-library extensions to Perl, v1.011, Part01/02
  4. Date: 27 Jun 1994 16:13:09 -0500
  5. Organization: Sterling Software
  6. Sender: kent@sparky.sterling.com
  7. Approved: kent@sparky.sterling.com
  8. Message-ID: <csm-v43i046=sybperl.161248@sparky.sterling.com>
  9. X-Md4-Signature: ff5ffb78408ee15f219ae1bf64f3095c
  10.  
  11. Submitted-by: mpeppler@itf.ch (Michael Peppler)
  12. Posting-number: Volume 43, Issue 46
  13. Archive-name: sybperl/part01
  14. Environment: UNIX, Perl, Sybase
  15. Supersedes: sybperl: Volume 39, Issue 101-103
  16.  
  17. This is sybperl release 1.011
  18.    
  19.    Sybperl is an extension to Perl which implements a sub-set of
  20.    Sybase's DB-Library API. This enables you to write Perl scripts
  21.    that have direct access to one or several Sybase servers.
  22.  
  23.    Requirements: Perl ver 3.0.27 or higher (4.036 strongly suggested!).
  24.          Sybase DB-Library (aka Open Client), 4.0 or higher
  25.  
  26. Changes from release 1.009:
  27.  
  28.     1.011    Added &dbfreebuf().
  29.         Added &dbsetopt() (contributed by Tom Kimpton).
  30.         Added &DBSETLCHARSET() and &DBSETLNATLANG().
  31.         Made sure the password and username fields of the
  32.         LOGINREC are reset to NULL.
  33.         Retrieving non-ascii TEXT data did not work.
  34.         Reworked the man page a bit (hopefully to make it more
  35.         readable!)
  36.         Reworked the Makefile.
  37.         Changed the method of testing for DBlib version to
  38.         setting the numeric version in the Makefile and
  39.         testing the revision level in the code.
  40.     1.010   Changed the Copyright Notice to be in line with Perl's
  41.         distribution arrangements.
  42.         The OLD_SYBPERL define has been changed to AUTO_LOGIN
  43.         (which is a bit more explicit!).
  44.         eg/dbschema.pl now accepts a -s server parameter,
  45.         prompts for SA password, and correctly extracts
  46.         permissions for stored procs and views (thanks to Bill
  47.         Papp).
  48.         Casts of data retrieved via dbdata() are now done with
  49.         DBlibrary typedefs instead of standard C types.
  50.         The bug that prevented setting BCP_SETL() on the first
  51.         DBPROCESS opened has been corrected (thanks to Peter
  52.         Harrington).
  53.  
  54.         
  55. I am always interested in hearing comments and suggestions for
  56. improvements, and also porting attempts/problems/stories.
  57.  
  58.  
  59. Enjoy!
  60.  
  61. Michael
  62. --
  63. Michael Peppler                | mpeppler@itf.ch          | Sysadmin,
  64. ITF Management SA           |                          |   DBA,
  65. 13 Rue de la Fontaine       | Phone: (+4122) 312 1311  | Programmer
  66. CH-1204 Geneva, Switzerland | Fax:   (+4122) 312 1325  | & Trader...
  67. --------
  68. #! /bin/sh
  69. # This is a shell archive.  Remove anything before this line, then feed it
  70. # into a shell via "sh file" or similar.  To overwrite existing files,
  71. # type "sh file -c".
  72. # Contents:  README BUGS CHANGES Makefile PACKING.LST eg eg/README
  73. #   eg/capture.pl eg/dbschema.pl eg/dbtext.pl eg/report.pl eg/space.pl
  74. #   eg/sql.pl eg/test_dbmoney.pl lib lib/sybdb.ph lib/sybdb_redefs.pl
  75. #   lib/sybperl.pl patchlevel.h sybperl.1 t t/sbex.pl
  76. # Wrapped by kent@sparky on Mon Jun 27 16:09:47 1994
  77. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  78. echo If this archive is complete, you will see the following message:
  79. echo '          "shar: End of archive 1 (of 2)."'
  80. if test -f 'README' -a "${1}" != "-c" ; then 
  81.   echo shar: Will not clobber existing file \"'README'\"
  82. else
  83.   echo shar: Extracting \"'README'\" \(4126 characters\)
  84.   sed "s/^X//" >'README' <<'END_OF_FILE'
  85. X    @(#)README    1.6    6/8/94
  86. X    
  87. X                 Sybperl, version 1.0
  88. X                Patchlevel 11
  89. X
  90. X
  91. X
  92. X   Sybperl is an extension to Perl which implements a sub-set of
  93. X   Sybase's DB-Library API. This enables you to write Perl scripts
  94. X   that have direct access to one or several Sybase servers.
  95. X
  96. X   Requirements: Perl ver 3.0.27 or higher (4.036 strongly suggested!).
  97. X         Sybase DB-Library (aka Open Client), 4.0 or higher
  98. X
  99. X
  100. X   Compiling & Installing Sybperl:
  101. X   
  102. X   Unshar somewhere convenient, and edit Makefile to reflect your
  103. X   system setup. The following macros/defines may need to be set:
  104. X
  105. X       DBLIBVS          The version of your OpenClient library.
  106. X             Set it to the revision level of your copy of
  107. X             DBlibrary (eg DBlibrary version 4.2 set
  108. X             DBLIBVS=420).
  109. X       HAS_CALLBACK     This enables the use of Perl subroutines as
  110. X             DB-Library error & message handlers. This is
  111. X             a new feature of Perl 4.018, but it might
  112. X             work with earlier versions.
  113. X       AUTO_LOGIN      This allows sybperl to silently call
  114. X             dblogin()/dbopen() with default arguments if
  115. X             you omit to do so in the script. This saves a
  116. X             couple of keystrokes, which is nice for quick
  117. X             hacks :-)
  118. X       SET_VAL         If this macro is set, then attempts to set a
  119. X             Sybperl user-variable (such as
  120. X             $NO_MORE_RESULTS) will result in a fatal
  121. X             error. Otherwise such attempts are silently
  122. X             ignored.
  123. X       PACKAGE_BUG     There appears to be a weird bug when one
  124. X             calls usersubs from within multiple Perl
  125. X             packages. If you run into this problem, you
  126. X             can enable this macro (see also the BUGS
  127. X             file).
  128. X       UPERL         See the comments in the Makefile, and the
  129. X             BUGS file. The defaults should work.
  130. X       PERL_VERSION     Uncomment if you're using a Perl version
  131. X             earlier than 4.03
  132. X
  133. X   The Makefile will not attempt to build uperl.o if it can't find it.
  134. X
  135. X   You may also need to edit the lib/sybperl.pl file to addapt it to
  136. X   your environment.
  137. X
  138. X   There are some test scripts in the t directory which you can run to
  139. X   see if all is well, and to get an idea of what can be done with
  140. X   sybperl. There are also some example scripts in the 'eg' directory.
  141. X
  142. X   Sybperl was initially tested in the following environments:
  143. X
  144. X   Sun Sparc, SunOS 4.1.3, Sybase 4.9.2, Perl 4.036
  145. X   Sun 3/80, SunOS 4.0.3, Sybase 4.0.1, Perl 4.010
  146. X   Sun Sparc, SunOS 4.1, Sybase 4.2, Perl 4.010
  147. X   Pyramid MIServer 2/2, OSx V5.1a, Sybase 4.0, Perl 4.010
  148. X
  149. X   It is also known to run under Solaris 2.x, HP-UX, NeXT.
  150. X   
  151. X   I use sybperl daily in a production environment on a Sun network
  152. X   (Sun 4/65s and Axil HWS 310s) under SunOS 4.1.3, with Sybase
  153. X   version 4.9.2 and Perl 4.036
  154. X
  155. X   FTP site: Sybperl and other DBMS related extensions to Perl can be
  156. X   found on ftp.demon.co.uk:/pub/perl/db.
  157. X   
  158. X
  159. X   BUGS:
  160. X
  161. X   Both DBlibrary and Perl define a symbol named 'savestr', resulting
  162. X   in the Perl version being called from DBlibrary. See the BUGS file
  163. X   for ways to get around this problem.
  164. X
  165. X   Memory usage can also be a problem in certain cases. Again see the
  166. X   BUGS file for details.
  167. X   
  168. X
  169. X   My thanks go first and foremost to Larry for Perl, and to the
  170. X   following people for testing Sybperl, and suggesting
  171. X   improvements:
  172. X
  173. X   Teemu Torma            Brent Milnor
  174. X   Matthew Merzbacher        Eric Fifer
  175. X   Dan Banay            Mark Lawrence
  176. X   Jeffrey Wong            Wolfgang Richter
  177. X   Anders Ardo            Gijs Mos
  178. X   Minh Ton Ha            G. Roderick Singleton
  179. X   Peter Gutmann        Bill Papp
  180. X
  181. X
  182. X   Have fun using it and let me know of any improvements, problems,
  183. X   whatever...
  184. X
  185. X   Michael Peppler            mpeppler@itf.ch
  186. X   ITF Management SA            BIX:   mpeppler                         
  187. X   13 Rue de la Fontaine        Phone: (+4122) 312 1311  
  188. X   CH-1204 Geneva, Switzerland  Fax:   (+4122) 312 1322  
  189. X
  190. X   
  191. X
  192. X                   NOTICE - Warranty and Copyright
  193. X
  194. X           
  195. X   Sybperl is not a product of ITF Management. There is no warranty,
  196. X   and no official support.
  197. X
  198. X   It is Copyright 1991, 1992, 1993, 1994 Michael Peppler & ITF Management
  199. X   SA, but may be freely distributed under the same terms as Perl
  200. X   itself, that is, under the terms of either the GNU Public License
  201. X   or the Artistic License. 
  202. X
  203. END_OF_FILE
  204.   if test 4126 -ne `wc -c <'README'`; then
  205.     echo shar: \"'README'\" unpacked with wrong size!
  206.   fi
  207.   # end of 'README'
  208. fi
  209. if test -f 'BUGS' -a "${1}" != "-c" ; then 
  210.   echo shar: Will not clobber existing file \"'BUGS'\"
  211. else
  212.   echo shar: Extracting \"'BUGS'\" \(4649 characters\)
  213.   sed "s/^X//" >'BUGS' <<'END_OF_FILE'
  214. X    @(#)BUGS    1.3    10/4/93
  215. X    
  216. X    The Sybase DB-Library - Perl savestr() conflict
  217. X    ------------------------------------------------
  218. X
  219. X
  220. X    Ah! The joys of tying different packages together!
  221. X
  222. X    Both Perl and DB-Library have a function called savestr(). The
  223. X    DB-Library version is used in dbcmd() to add an SQL command to the
  224. X    list of commands pointed to by dpproc->dbcmdbuf, and in dbuse() as
  225. X    well. Now there are several ways to work around this problem.
  226. X
  227. X    1) Recompile Perl (specifically, uperl.o in the Perl source
  228. X       directory) with some suitable flags (eg -Dsavestr=p_savestr).
  229. X       This does not create any compatibility problems, but is a
  230. X       lengthy procedure.
  231. X
  232. X    2) Do something like:
  233. X       cc -c sybperl.c
  234. X       ld -r -o sybperl2.o sybperl.o -lsybdb
  235. X       [edit sybperl2.o and replace `_savestr' with something like `_savest1']
  236. X       cc -o sybperl uperl.o sybperl2.o
  237. X       This is not a bad solution, but won't work if you have shared
  238. X       library versions of libsybdb.a
  239. X
  240. X    3) Edit uperl.o and replace savestr with something else. This is
  241. X       the solution I've chosen as the default. It is relatively fast,
  242. X       does not rely on any internal knowledge of DB-Library, and does
  243. X       not require Perl to be recompiled.
  244. X
  245. X    The Makefile gives some information on how to achieve these
  246. X    different options.
  247. X       
  248. X    Thanks to Teemu Torma for providing the initial input on this problem.    
  249. X
  250. X
  251. X
  252. X    Sybperl Memory Usage
  253. X    --------------------
  254. X
  255. X    The general format of a Sybperl script usually looks somewhat like
  256. X    this:
  257. X
  258. X    #!/usr/local/bin/sybperl
  259. X
  260. X    &dbcmd( query text );
  261. X    &dbsqlexec;
  262. X    &dbresults;
  263. X
  264. X    while(@data = &dbnextrow)
  265. X    {
  266. X       process data
  267. X    }
  268. X
  269. X
  270. X    If you are using a version of Perl prior to release 4, patchlevel
  271. X    35, then this method will result in a rather important memory
  272. X    leak. There are two ways around this problem:
  273. X
  274. X    1) Upgrade to Perl 4, patchlevel 35 :-)
  275. X
  276. X    2) Write a subroutine that calls &dbnextrow and stores the returned
  277. X       array to a local variable, and which in turn returns that array to
  278. X       the main while() loop, like so:
  279. X
  280. X    sub getRow
  281. X    {
  282. X        local(@data);
  283. X
  284. X    @data = &dbnextrow;
  285. X
  286. X    @data;
  287. X    }
  288. X
  289. X    while(@data = &getRow)
  290. X    {
  291. X       etc.
  292. X    }
  293. X
  294. X
  295. X    This technique should keep the memory usage of Sybperl to a
  296. X    manageable level.
  297. X
  298. X
  299. X
  300. X    Perl packages / usersubs bug
  301. X    ----------------------------
  302. X
  303. X    The following is bug that was uncovered by Jeff Wong:
  304. X
  305. X------ begin excerpt -------
  306. X
  307. Xa: sybperl script z.pl has some *.pl required scripts.  Let's call
  308. X   them x.pl and y.pl for convenience.
  309. X
  310. Xb: z.pl looks like this (basic structure):
  311. X
  312. X   ...
  313. X   require "sybperl.pl";
  314. X   require "x.pl";
  315. X   require "y.pl";
  316. X   ...
  317. X
  318. Xc: x.pl looks like this (basic structure):
  319. X
  320. X   ...
  321. X   package x;
  322. X   ...
  323. X   < Sybperl functions with main package dereferencing, e.g. &main'dbcancel(), >
  324. X   < &main'dbcancel( $dbproc ), &main'dbnextrow(), ...                        >
  325. X   ...
  326. X   package main;
  327. X   ...
  328. X
  329. Xd: y.pl looks like x.pl or perhaps like other required packages (in format).
  330. X
  331. Xe: Bug surfaces in x.pl in that it suddenly cannot locate the sybperl
  332. X   functions.
  333. X
  334. XMy guess is that the bug is caused by the way that usersub functions
  335. Xare treated by the "require" and "package" operators.  I say this because:
  336. X
  337. X   - Usersub functions look very much like perl built-in functions, except that
  338. X     usersub functions require an ampersand character in front of their names.
  339. X
  340. X   - Built-in functions are global to all packages.
  341. X
  342. X   - Perl user-defined functions are local to the package which contains their
  343. X     name definition (i.e. where the namespace is).
  344. X
  345. X   - When I don't use the x.pl style package construct, the problem disappears.
  346. X
  347. X------ end excerpt -------
  348. X
  349. X
  350. X    The way around this bug is to compile Sybperl with the PACKAGE_BUG
  351. X    macro defined. When this is done, sybperl.pl creates a number of
  352. X    'glue' routines (see lib/sybdb_redefs.pl') which bypass the bug.
  353. X
  354. X    It's not the cleanest of solutions, but it works...
  355. X
  356. X    However, be aware of the Perl @_ array assignement problems if you
  357. X    call sybperl functions without a parameter list (as in &dbsqlexec;
  358. X    instead of &dbsqlexec($dbproc);). When calling Sybperl functions
  359. X    via the glue routines, the @_ array will default to the parameters
  360. X    passed to last previously called Perl subroutine if it's called
  361. X    without a parameter list. And that's almost certainly not what you
  362. X    want.
  363. X
  364. X    
  365. X
  366. X    
  367. X    Please let me know if you find any other problems with Sybperl so
  368. X    that I can look into it.
  369. X
  370. X    Thank you.
  371. X
  372. X    Michael Peppler    <mpeppler@itf.ch>
  373. X
  374. X
  375. END_OF_FILE
  376.   if test 4649 -ne `wc -c <'BUGS'`; then
  377.     echo shar: \"'BUGS'\" unpacked with wrong size!
  378.   fi
  379.   # end of 'BUGS'
  380. fi
  381. if test -f 'CHANGES' -a "${1}" != "-c" ; then 
  382.   echo shar: Will not clobber existing file \"'CHANGES'\"
  383. else
  384.   echo shar: Extracting \"'CHANGES'\" \(4437 characters\)
  385.   sed "s/^X//" >'CHANGES' <<'END_OF_FILE'
  386. X    @(#)CHANGES    1.10    6/8/94
  387. X
  388. X    
  389. X    Sybperl CHANGES:
  390. X    
  391. X    1.011    Added &dbfreebuf().
  392. X        Added &dbsetopt() (contributed by Tom Kimpton).
  393. X        Added &DBSETLCHARSET() and &DBSETLNATLANG().
  394. X        Made sure the password and username fields of the
  395. X        LOGINREC are reset to NULL.
  396. X        Retrieving non-ascii TEXT data did not work.
  397. X        Reworked the man page a bit (hopefully to make it more
  398. X        readable!)
  399. X        Reworked the Makefile.
  400. X        Changed the method of testing for DBlib version to
  401. X        setting the numeric version in the Makefile and
  402. X        testing the revision level in the code.
  403. X    1.010   Changed the Copyright Notice to be in line with Perl's
  404. X        distribution arrangements.
  405. X        The OLD_SYBPERL define has been changed to AUTO_LOGIN
  406. X        (which is a bit more explicit!).
  407. X        eg/dbschema.pl now accepts a -s server parameter,
  408. X        prompts for SA password, and correctly extracts
  409. X        permissions for stored procs and views (thanks to Bill
  410. X        Papp).
  411. X        Casts of data retrieved via dbdata() are now done with
  412. X        DBlibrary typedefs instead of standard C types.
  413. X        The bug that prevented setting BCP_SETL() on the first
  414. X        DBPROCESS opened has been corrected (thanks to Peter
  415. X        Harrington).
  416. X    1.009   The script name is now used to set the application
  417. X        name in sysprocesses via the DBSETLAPP() macro.
  418. X        Calling &dbsafestr() with three arguments would result
  419. X        in an erroneous fatal error message.
  420. X        Sybperl now sets the application name in sysprocesses
  421. X        (via DBSETLAPP()) to the name of the script that is
  422. X        running.
  423. X        Some problems with dbschema.pl which only showed up
  424. X        when PACKAGE_BUG is defined have been corrected.
  425. X    1.008   Added user settable variables to control whether
  426. X        Sybperl returns 'NULL' or Perl's 'undef' value on NULL
  427. X        values from a query, whether numeric results are kept
  428. X        in native format, and whether binary data should be
  429. X        preceded by '0x' (suggested by Steve Baumgarten).
  430. X        Actually made $DBstatus visible (it was documented but
  431. X        not usable up to now...).
  432. X        Passing an undef'd variable to &bcp_sendrow will cause
  433. X        a NULL value to be sent to the server for that column.
  434. X    1.007   Added &dbmny* calls and code to circumvent weird
  435. X        package/usub interaction bug, both contributed by Jeff
  436. X        Wong.
  437. X        Added &bcp_* calls.
  438. X        Added &dbretdata() call (returns an array, possibly
  439. X        associative, with the return parameters of a stored
  440. X        proc).
  441. X        Calls to any of the routines with an undefined
  442. X        DBPROCESS will now elicit a warning; previously, such
  443. X        calls defaulted to using the first (default)
  444. X        DBPROCESS.
  445. X        Data returned from queries is not converted to char
  446. X        unless its necessary - this applies mainly to types
  447. X        SYBFLOAT and SYBREAL which could loose some precision
  448. X        on being converted to a string via sprintf().
  449. X    1.006    Added contributed patches: &dbwritetext(),
  450. X        &dbsafestr() and a modified &dblogin().
  451. X        Added &dbhasretstats() and &dbretstatus(), as well as
  452. X        some calls to DBlib macros such as DBCMD(),
  453. X        DBMORECMD(), etc.
  454. X        Received a patch to eg/space.pl from Wolfgang Richter.
  455. X        Code that was defined to compile if BROKEN_DBCMD was
  456. X        defined has been removed. It was only a hack, making
  457. X        use of knowledge of the structure of the DBPROCESS
  458. X        data type.
  459. X        Added the possibility to return an associative array
  460. X        from &dbnextrow.
  461. X        Added support for new datatypes (SYBREAL, SYBDATETIME4).
  462. X        NULL values retrieved using &dbnextrow can be returned
  463. X        as 'undef' instead of 'NULL' (this is a compile-time
  464. X        option).
  465. X    1.005   Sybperl would core dump if you used a uninitialized
  466. X            DBPROCESS.
  467. X        A solution to the sometime pathological    memory usage
  468. X        observed when using a release of Perl lower than 4.035
  469. X        is also described in BUGS.
  470. X        &dblogin now returns -1 if the dblogin() or dbopen()
  471. X        calls fail.
  472. X        Added the possibility to login to a specific server
  473. X        without setting the DSQUERY environment variable.
  474. X        Added a script to extract the information regarding
  475. X        the database from the databases' system tables. See
  476. X        eg/dbschema.pl.
  477. X    1.004    Added support for Perl based error and message
  478. X        handlers (as made possible by Perl 4.018). Many Thanks
  479. X        to Teemu Torma for this code.
  480. X        Added limited support for SYBTEXT datatypes.
  481. X        Added &dbstrcpy() to retrieve the current command buffer.
  482. X        The DBPROCESS parameter to most &db*() calls can now
  483. X        be omitted: it will default to the first DBPROCESS
  484. X        opened (the one that is returned by &dblogin()).
  485. X        Added lib/sybdb.ph
  486. X        Added a couple of example scripts in eg/*.pl, courtesy
  487. X        of Gijs Mos (Thank You!).
  488. X    1.003    Base version.
  489. X
  490. END_OF_FILE
  491.   if test 4437 -ne `wc -c <'CHANGES'`; then
  492.     echo shar: \"'CHANGES'\" unpacked with wrong size!
  493.   fi
  494.   # end of 'CHANGES'
  495. fi
  496. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  497.   echo shar: Will not clobber existing file \"'Makefile'\"
  498. else
  499.   echo shar: Extracting \"'Makefile'\" \(3950 characters\)
  500.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  501. X#    @(#)Makefile    1.21    6/10/94
  502. X#
  503. X
  504. X# Configuration stuff:
  505. X
  506. X# Where is the Perl source tree located. This is needed to find the
  507. X# Perl include files, and uperl.o which sybperl needs to link with.
  508. XPERLSRC = /usr/local/src/perl
  509. X
  510. X# Where are the sybase .h files located
  511. XSYBINCS = /usr/local/sybase/include
  512. X
  513. X# Any other non-default directories that need to be searched ?
  514. XLOCINCS = .
  515. X
  516. X# Where are the Sybase libraries located
  517. XSYBLIBDIR = /usr/local/lib
  518. XSYBLIBS = -lsybdb
  519. X
  520. X# Any extra libraries needed?
  521. X# Solaris 2 needs -lsocket -lnsl
  522. X# HP-UX seems to need -ldbm
  523. XEXTRA_LIBS=
  524. X
  525. X# Where does the executable go
  526. XBINDIR = /usr/local/bin
  527. X
  528. X# Where do the lib/*.pl go
  529. XPERLLIB = /usr/local/lib/perl
  530. X
  531. X# where do we put the manual page
  532. XMANDIR = /usr/local/man
  533. XMANEXT = l
  534. X
  535. X
  536. X# The Perl/Sybase savestr() conflict.
  537. X# Both Perl and Sybase DB-Library have a function called savestr(),
  538. X# and this creates a problem when using functions such as dbcmd().
  539. X# There are several ways around this.
  540. X# You can:
  541. X#
  542. X#    - Recompile uperl.o with a -Dsavestr=psvestr (or something similar).
  543. X#    - Edit an existing uperl.o and change _savestr to _psvestr.
  544. X#
  545. X#
  546. X# To use the first option, you have to reconfigure & recompile Perl
  547. X# manually, and then set compile sybperl with the following line
  548. X# uncommented:
  549. X# UPERL = $(PERLSRC)/uperl.o
  550. X#
  551. X# The default is to use the second solution:
  552. XUPERL = uperl2.o
  553. X
  554. X# DBLIBVS: The DBlib version that you have. 
  555. X# Controls the inclusion of routines which are available
  556. X# only in more recent versions of DB library.
  557. XDBLIBVS = -DDBLIBVS=461
  558. X
  559. X# HAS_CALLBACK: This should be defined if you have Perl 4 patchlevel
  560. X# 18 or later. User defined error/message handlers in Perl are not
  561. X# possible if this is not defined, however.
  562. XHAS_CALLBACK= -DHAS_CALLBACK
  563. X
  564. X# AUTO_LOGIN: When this is turned on, automatic logging in to Sybase
  565. X# is enabled. 
  566. X# Otherwise, failing to call &dblogin is a fatal error.
  567. XAUTO_LOGIN= -DAUTO_LOGIN
  568. X
  569. X# SET_VAL: If this is set, then assigning a value to Sybperl's
  570. X# read-only variables is a fatal error. Normally, this would be
  571. X# silently ignored.
  572. X#SET_VAL = -DUSERVAL_SET_FATAL
  573. X
  574. X# PACKAGE_BUG: Controls whether code to circumvent a bug in Perl that
  575. X# shows up when calling usubs from within nested packages is included.
  576. X# See also the BUGS file.
  577. X#PACKAGE_BUG = -DPACKAGE_BUG
  578. X
  579. X# RINDEX: Does your system know rindex(), but not strrchr() ?
  580. X#RINDEX = -Dstrrchr=rindex
  581. X
  582. X# Uncomment this if you are compiling sybperl for Perl version 3.xx
  583. X# I strongly recommend that you get Perl 4.036 if it is at all
  584. X# available for your system!
  585. X# PERL_VERSION = -DVERSION3
  586. X
  587. X# Which compiler to use    
  588. XCC = gcc
  589. X
  590. XCFLAGS = -O2 -g
  591. XCPPFLAGS = -I$(PERLSRC) -I$(LOCINCS) -I$(SYBINCS) $(PERL_VERSION) \
  592. X        $(HAS_CALLBACK) $(AUTO_LOGIN) $(DBLIBVS) \
  593. X        $(SET_VAL) $(PACKAGE_BUG) $(RINDEX)
  594. X
  595. Xsybperl: $(UPERL) sybperl.o
  596. X    $(CC) $(CFLAGS) -L$(SYBLIBDIR) $(UPERL) sybperl.o $(SYBLIBS) $(EXTRA_LIBS) -lm -o sybperl
  597. X
  598. Xsybperl.o: sybperl.c
  599. X    $(CC) -c $(CFLAGS) $(CPPFLAGS) sybperl.c
  600. X
  601. X# Create uperl.o IF you wish to use the 2nd way of resolving the
  602. X# Perl/Sybase savestr conflict.
  603. X$(UPERL): $(PERLSRC)/uperl.o
  604. X    cp $(PERLSRC)/uperl.o $(UPERL)
  605. X    perl -p -i.bak -e 's/savestr/psvestr/g;' $(UPERL)
  606. X    rm -f $(UPERL).bak
  607. X
  608. X
  609. Xclean:
  610. X    rm -f sybperl *.o *~ core
  611. X
  612. Xinstall: sybperl
  613. X    install -s -m 755 sybperl $(BINDIR)
  614. X    cp lib/syb*.p? $(PERLLIB)
  615. X    cp sybperl.1 $(MANDIR)/man$(MANEXT)/sybperl.$(MANEXT)
  616. X
  617. Xshar:
  618. X    rm -f sybperl.shar
  619. X    shar.pl README PACKING.LST BUGS CHANGES Makefile sybperl.c \
  620. X    sybperl.1 patchlevel.h lib/sybperl.pl lib/sybdb.ph \
  621. X    lib/sybdb_redefs.pl t/sbex.pl \
  622. X    eg/sql.pl eg/space.pl eg/capture.pl eg/report.pl \
  623. X    eg/dbschema.pl eg/dbtext.pl eg/test_dbmoney.pl eg/README >sybperl.shar
  624. X
  625. X
  626. Xtar:
  627. X    rm -f sybperl.tar
  628. X    tar cvfB sybperl.tar README PACKING.LST BUGS CHANGES Makefile sybperl.c \
  629. X    sybperl.1 patchlevel.h lib/sybperl.pl lib/sybdb.ph \
  630. X    lib/sybdb_redefs.pl t/sbex.pl \
  631. X    eg/sql.pl eg/space.pl eg/capture.pl eg/report.pl \
  632. X    eg/dbschema.pl eg/dbtext.pl eg/test_dbmoney.pl eg/README
  633. X
  634. X
  635. X
  636. X
  637. X
  638. END_OF_FILE
  639.   if test 3950 -ne `wc -c <'Makefile'`; then
  640.     echo shar: \"'Makefile'\" unpacked with wrong size!
  641.   fi
  642.   # end of 'Makefile'
  643. fi
  644. if test -f 'PACKING.LST' -a "${1}" != "-c" ; then 
  645.   echo shar: Will not clobber existing file \"'PACKING.LST'\"
  646. else
  647.   echo shar: Extracting \"'PACKING.LST'\" \(1270 characters\)
  648.   sed "s/^X//" >'PACKING.LST' <<'END_OF_FILE'
  649. X    @(#)PACKING.LST    1.1    9/2/93
  650. X
  651. X    
  652. X    The Sybperl package should contain the following files:
  653. X
  654. X
  655. X        PACKING.LST        This file
  656. X        README        Read Me!
  657. X        BUGS        Perl/DB-library incompatibility description
  658. X        CHANGES
  659. X        Makefile
  660. X        sybperl.c        Sybperl source
  661. X        sybperl.1        Man page
  662. X        patchlevel.h
  663. X        t/sbex.pl        Example of sybperl script
  664. X        lib/sybperl.pl  A Perl library file.
  665. X        lib/sybdb.ph    Some of the DB-Library include files, run
  666. X                through h2ph.
  667. X        eg/space.pl        How much space does your sybase databases use?
  668. X        eg/capture.pl   Create a table extracted from /etc/passwd
  669. X        eg/report.pl    Report from table created by capture.pl
  670. X        eg/sql.pl        Utility routines used by the above example programs.
  671. X
  672. X        eg/dbtext.pl    Example of &dbwritetext() usage. This
  673. X                script will NOT work out of the box. Read
  674. X                the code to see what requires doing first.
  675. X        eg/test_dbmoney.pl
  676. X                    Example script using &dbmny*() calls.
  677. X
  678. X        eg/dbschema.pl  Create an Isql script that will to
  679. X                        recreate your database(s) structure (data
  680. X                types, tables, indexes, rules, defaults,
  681. X                views, triggers and stored procedures),
  682. X                extracting the information from the
  683. X                database's system tables.
  684. X
  685. END_OF_FILE
  686.   if test 1270 -ne `wc -c <'PACKING.LST'`; then
  687.     echo shar: \"'PACKING.LST'\" unpacked with wrong size!
  688.   fi
  689.   # end of 'PACKING.LST'
  690. fi
  691. if test ! -d 'eg' ; then
  692.     echo shar: Creating directory \"'eg'\"
  693.     mkdir 'eg'
  694. fi
  695. if test -f 'eg/README' -a "${1}" != "-c" ; then 
  696.   echo shar: Will not clobber existing file \"'eg/README'\"
  697. else
  698.   echo shar: Extracting \"'eg/README'\" \(1797 characters\)
  699.   sed "s/^X//" >'eg/README' <<'END_OF_FILE'
  700. X    @(#)README    1.5    8/31/93
  701. X
  702. X
  703. X    This directory contains a number of example scripts for Sybperl.
  704. X
  705. X
  706. X    
  707. X    space.pl        Report the space used by your database.
  708. X    capture.pl        Create a table with information from
  709. X            /etc/passwd.
  710. X    report.pl        Report information from the above table.
  711. X    sql.pl        Utility used by the above three scripts.
  712. X    dbschema.pl        Extract an Isql script to re-create a database
  713. X    dbtext.pl        A very simple example of usage of dbwritetext.
  714. X            Read the code before using!
  715. X    test_dbmoney.pl    Example script using dbmny* calls.
  716. X
  717. X
  718. X    
  719. X    Dbschema.pl Documentation:
  720. X    --------------------------
  721. X    
  722. X    This is a Sybperl script that extracts a Sybase database definition
  723. X    and creates an Isql script to rebuild the database.
  724. X
  725. X    dbschema.pl is NOT a production script, in the sense that it does
  726. X    not do ALL the necessary work. The script tries to do the right
  727. X    thing, but in certain cases (mainly where the owner of an object
  728. X    is not the DBO) it creates an invalid or incorrect Isql command. I
  729. X    have tried to detect these cases, and log them both to stdout and to a
  730. X    file, so that the script can be corrected.
  731. X    Please note also that dbschema.pl logs in to Sybase with the
  732. X    default (Unix) user id, and a NULL password. This behaviour is
  733. X    maybe not OK for your site.
  734. X
  735. X    Usage:
  736. X
  737. X        itf1% dbschema.pl -d excalibur -o excalibur.isql -v
  738. X
  739. X    Run dbschema on database 'excalibur', place the resulting script
  740. X    in 'excalibur.isql' (and the error log in 'excalibur.isql.log')
  741. X    and turn on verbose output on the console. The default database is
  742. X    'master', the default output file is 'script.isql'.
  743. X
  744. X
  745. X    I hope this will prove of some use, and I would be more than happy
  746. X    to hear of any improvements :-)
  747. X
  748. X
  749. X    Michael Peppler        mpeppler@itf.ch
  750. X
  751. END_OF_FILE
  752.   if test 1797 -ne `wc -c <'eg/README'`; then
  753.     echo shar: \"'eg/README'\" unpacked with wrong size!
  754.   fi
  755.   # end of 'eg/README'
  756. fi
  757. if test -f 'eg/capture.pl' -a "${1}" != "-c" ; then 
  758.   echo shar: Will not clobber existing file \"'eg/capture.pl'\"
  759. else
  760.   echo shar: Extracting \"'eg/capture.pl'\" \(1640 characters\)
  761.   sed "s/^X//" >'eg/capture.pl' <<'END_OF_FILE'
  762. X#! /usr/local/bin/sybperl
  763. X
  764. X#
  765. X#    @(#)capture.pl    1.1    6/24/92
  766. X#
  767. X
  768. Xrequire "sybperl.pl";
  769. Xrequire "sql.pl";
  770. X
  771. X#
  772. X# Log us in to Sybase.
  773. X#
  774. X$d = &dblogin;
  775. X
  776. X&sql($d, "set statistics io on");
  777. X&sql($d, "set statistics time on");
  778. X
  779. X#
  780. X# Count the number off password tables.
  781. X#
  782. X@results = &sql($d, '
  783. X        select count(*) from sysobjects
  784. X        where name = "password" and type = "U"'
  785. X       );
  786. X
  787. X#
  788. X# If there is none create it else truncate it.
  789. X#
  790. Xif(@results[0] == 0) {
  791. X    &sql($d, '
  792. X        create table password(
  793. X            username char(8),
  794. X            uid int,
  795. X            gid int,
  796. X            shell varchar(30),
  797. X            home varchar(30)
  798. X        )'
  799. X    );
  800. X    print "The password table has been created.\n";
  801. X} else {
  802. X    &sql($d, 'truncate table password');
  803. X    print "The password table already exists. Table truncated!\n";
  804. X};
  805. X
  806. X#
  807. X# Read the password entries and add them to the database.
  808. X#
  809. Xwhile (($n,$p,$u,$g,$q,$c,$gc,$d,$s)= getpwent) {
  810. X    print "Adding $n.\n";
  811. X    &sql($d, "
  812. X        insert password
  813. X        values(\"$n\", $u, $g, \"$s\", \"$d\")
  814. X        "
  815. X    );
  816. X};
  817. Xendpwent;
  818. X
  819. X#
  820. X# Count the number off group tables.
  821. X#
  822. X@results = &sql($d, '
  823. X        select count(*) from sysobjects
  824. X        where name = "groups" and type = "U"'
  825. X       );
  826. X
  827. X#
  828. X# If there is none create it else truncate it.
  829. X#
  830. Xif(@results[0] == 0) {
  831. X    &sql($d, '
  832. X        create table groups(
  833. X            groupname char(8),
  834. X            gid int
  835. X        )'
  836. X    );
  837. X    print "The groups table has been created.\n";
  838. X} else {
  839. X    &sql($d, 'truncate table groups');
  840. X    print "The groups table already exists. Table truncated!\n";
  841. X};
  842. X
  843. X#
  844. X# Read the group entries and add them to the database.
  845. X#
  846. Xwhile (($gn,$gp,$gg,$gm)= getgrent) {
  847. X    print "Adding group $gn.\n";
  848. X    &sql($d, "
  849. X        insert groups
  850. X        values(\"$gn\", $gg)
  851. X        "
  852. X    );
  853. X};
  854. Xendgrent;
  855. X
  856. END_OF_FILE
  857.   if test 1640 -ne `wc -c <'eg/capture.pl'`; then
  858.     echo shar: \"'eg/capture.pl'\" unpacked with wrong size!
  859.   fi
  860.   chmod +x 'eg/capture.pl'
  861.   # end of 'eg/capture.pl'
  862. fi
  863. if test -f 'eg/dbschema.pl' -a "${1}" != "-c" ; then 
  864.   echo shar: Will not clobber existing file \"'eg/dbschema.pl'\"
  865. else
  866.   echo shar: Extracting \"'eg/dbschema.pl'\" \(9982 characters\)
  867.   sed "s/^X//" >'eg/dbschema.pl' <<'END_OF_FILE'
  868. X#! /usr/local/bin/sybperl
  869. X#
  870. X#    @(#)dbschema.pl    1.11    2/22/94
  871. X#
  872. X#
  873. X# dbschema.pl    A script to extract a database structure from
  874. X#        a Sybase database
  875. X#
  876. X# Written by:    Michael Peppler (mpeppler@itf.ch)
  877. X# Last Modified:  22 Feb 1994
  878. X#
  879. X# Usage:    dbschema.pl -d database -o script.name -t pattern -s server -v
  880. X#            where   database is self-explanatory (default: master)
  881. X#                           script.name is the output file (default: script.isql)
  882. X#                           pattern is the pattern of object names (in sysobjects)
  883. X#                           that we will look at (default: %), and server is
  884. X#                the server to connect to (default, the value of $ENV{DSQUERY}).
  885. X#
  886. X#            -v turns on a verbose switch.
  887. X#
  888. X#    Changes:   11/18/93 - bpapp - Put in interactive SA password prompt
  889. X#               11/18/93 - bpapp - Get protection information for views and
  890. X#                                  stored procedures.
  891. X#        02/22/94 - mpeppler - Merge bpapp's changes with itf version
  892. X#
  893. X#------------------------------------------------------------------------------
  894. X
  895. X
  896. Xrequire 'sybperl.pl';
  897. Xrequire 'getopts.pl';
  898. Xrequire 'ctime.pl';
  899. X
  900. X@nul = ('not null','null');
  901. X
  902. Xselect(STDOUT); $| = 1;        # make unbuffered
  903. X
  904. Xdo Getopts('d:t:o:s:v');
  905. X
  906. X$opt_d = 'master' unless $opt_d;
  907. X$opt_o = 'script.isql' unless $opt_o;
  908. X$opt_t = '%' unless $opt_t;
  909. X$opt_s = $ENV{DSQUERY} unless $opt_s;
  910. X
  911. Xopen(SCRIPT, "> $opt_o") || die "Can't open $opt_o: $!\n";
  912. Xopen(LOG, "> $opt_o.log") || die "Can't open $opt_o.log: $!\n";
  913. X
  914. X#
  915. X# Log us in to Sybase as 'sa' and prompt for admin password.
  916. X#
  917. Xprint "\nAdministrative account password: ";
  918. Xsystem("stty -echo");
  919. Xchop($sapw = <>);
  920. Xsystem("stty echo");
  921. X
  922. X$dbproc = &dblogin("sa", $sapw, $opt_s);
  923. X&dbuse($dbproc, $opt_d);
  924. X
  925. Xchop($date = &ctime(time));
  926. X
  927. Xprint "dbschema.pl on Database $opt_d\n";
  928. X
  929. Xprint LOG "Error log from dbschema.pl on Database $opt_d on $date\n\n";
  930. Xprint LOG "The following objects cannot be reliably created from the script in $opt_o.
  931. XPlease correct the script to remove any inconsistencies.\n\n";
  932. X
  933. Xprint SCRIPT
  934. X    "/* This Isql script was generated by dbschema.pl on $date.
  935. X** The indexes need to be checked: column names & index names
  936. X** might be truncated!
  937. X*/\n";
  938. X
  939. Xprint SCRIPT "\nuse $opt_d\ngo\n"; # Change to the appropriate database
  940. X
  941. X
  942. X# first, Add the appropriate user data types:
  943. X#
  944. X
  945. Xprint "Add user-defined data types...";
  946. Xprint SCRIPT
  947. X    "/* Add user-defined data types: */\n\n";
  948. X
  949. X&dbcmd($dbproc, "select s.length, s.name, st.name,\n");
  950. X&dbcmd($dbproc, "       object_name(s.tdefault),\n");
  951. X&dbcmd($dbproc, "       object_name(s.domain)\n");
  952. X&dbcmd($dbproc, "from   $opt_d.dbo.systypes s, $opt_d.dbo.systypes st\n");
  953. X&dbcmd($dbproc, "where  st.type = s.type\n");
  954. X&dbcmd($dbproc, "and s.usertype > 100 and st.usertype < 100 and st.usertype != 18\n");
  955. X&dbsqlexec($dbproc);
  956. X&dbresults($dbproc);
  957. X
  958. X
  959. Xwhile((@dat = &dbnextrow($dbproc)))
  960. X{
  961. X    print SCRIPT "sp_addtype $dat[1],";
  962. X    if ($dat[2] =~ /char|binary/)
  963. X    {
  964. X        print SCRIPT "'$dat[2]($dat[0])'";
  965. X    }
  966. X    else
  967. X    {
  968. X        print SCRIPT "$dat[2]";
  969. X    }
  970. X    print SCRIPT "\ngo\n";
  971. X                # Now remeber the default & rule for later.
  972. X    $urule{$dat[1]} = $dat[4] if $dat[4] !~ /NULL/;
  973. X    $udflt{$dat[1]} = $dat[3] if $dat[3] !~ /NULL/;
  974. X}
  975. X
  976. Xprint "Done\n";
  977. X
  978. Xprint "Create rules...";
  979. Xprint SCRIPT
  980. X    "\n/* Now we add the rules... */\n\n";
  981. X
  982. X&getObj('Rule', 'R');
  983. Xprint "Done\n";
  984. X
  985. Xprint "Create defaults...";
  986. Xprint SCRIPT
  987. X    "\n/* Now we add the defaults... */\n\n";
  988. X
  989. X&getObj('Default', 'D');
  990. Xprint "Done\n";
  991. X
  992. Xprint "Bind rules & defaults to user data types...";
  993. Xprint SCRIPT "/* Bind rules & defaults to user data types... */\n\n";
  994. X
  995. Xwhile(($dat, $dflt)=each(%udflt))
  996. X{
  997. X    print SCRIPT "sp_bindefault $dflt, $dat\ngo\n";
  998. X}
  999. Xwhile(($dat, $rule) = each(%urule))
  1000. X{
  1001. X    print SCRIPT "sp_bindrule $rule, $dat\ngo\n";
  1002. X}
  1003. Xprint "Done\n";
  1004. X
  1005. Xprint "Create Tables & Indices...";
  1006. Xprint "\n" if $opt_v;
  1007. X
  1008. X&dbcmd($dbproc, "select o.name,u.name, o.id\n");
  1009. X&dbcmd($dbproc, "from $opt_d.dbo.sysobjects o, $opt_d.dbo.sysusers u\n");
  1010. X&dbcmd($dbproc, "where o.type = 'U' and o.name like '$opt_t' and u.uid = o.uid\n");
  1011. X&dbcmd($dbproc, "order by o.name\n");
  1012. X
  1013. X&dbsqlexec($dbproc);
  1014. X&dbresults($dbproc);
  1015. X
  1016. Xwhile((@dat = &dbnextrow($dbproc)))
  1017. X{
  1018. X    $_ = join('@', @dat);    # join the data together on a line
  1019. X    push(@tables,$_);        # and save it in a list
  1020. X}
  1021. X
  1022. X
  1023. Xforeach (@tables)        # For each line in the list
  1024. X{
  1025. X    @tab = split(/@/, $_);
  1026. X
  1027. X    print "Creating table $tab[0], owner $tab[1]\n" if $opt_v;
  1028. X
  1029. X    print SCRIPT "/* Start of description of table $tab[1].$tab[0] */\n\n";
  1030. X
  1031. X    &dbcmd($dbproc, "select Column_name = c.name, \n");
  1032. X    &dbcmd($dbproc, "       Type = t.name, \n");
  1033. X    &dbcmd($dbproc, "       Length = c.length, \n");
  1034. X    &dbcmd($dbproc, "       Nulls = convert(bit, (c.status & 8)),\n");
  1035. X    &dbcmd($dbproc, "       Default_name = object_name(c.cdefault),\n");
  1036. X    &dbcmd($dbproc, "       Rule_name = object_name(c.domain)\n");
  1037. X    &dbcmd($dbproc, "from   $opt_d.dbo.syscolumns c, $opt_d.dbo.systypes t\n");
  1038. X    &dbcmd($dbproc, "where  c.id = $tab[2]\n");
  1039. X    &dbcmd($dbproc, "and    c.usertype *= t.usertype\n");
  1040. X
  1041. X    &dbsqlexec($dbproc);
  1042. X    &dbresults($dbproc);
  1043. X
  1044. X    undef(%rule);
  1045. X    undef(%dflt);
  1046. X
  1047. X    print SCRIPT "\n\nCREATE TABLE $opt_d.$tab[1].$tab[0]\n ("; 
  1048. X    $first = 1;
  1049. X    while((@field = &dbnextrow($dbproc)))
  1050. X    {
  1051. X        print SCRIPT ",\n" if !$first;        # add a , and a \n if not first field in table
  1052. X        
  1053. X        print SCRIPT "\t$field[0] \t$field[1]";
  1054. X        print SCRIPT "($field[2])" if $field[1] =~ /char|bin/;
  1055. X        print SCRIPT " $nul[$field[3]]";
  1056. X    
  1057. X    $rule{"$tab[0].$field[0]"} = $field[5] if ($field[5] !~ /NULL/ && $urule{$field[1]} ne $field[5]);
  1058. X    $dflt{"$tab[0].$field[0]"} = $field[4] if ($field[4] !~ /NULL/ && $udflt{$field[1]} ne $field[4]);;
  1059. X        $first = 0 if $first;
  1060. X        
  1061. X    }
  1062. X    print SCRIPT " )\n";
  1063. X
  1064. X# now get the indexes...
  1065. X#
  1066. X
  1067. X    print "Indexes for table $tab[1].$tab[0]\n" if $opt_v;
  1068. X    
  1069. X    &dbcmd($dbproc, "sp_helpindex '$tab[1].$tab[0]'\n");
  1070. X
  1071. X    &dbsqlexec($dbproc);
  1072. X    &dbresults($dbproc);
  1073. X
  1074. X    while((@field = &dbnextrow($dbproc)))
  1075. X    {
  1076. X        print SCRIPT "\nCREATE ";
  1077. X        print SCRIPT "unique " if $field[1] =~ /unique/;
  1078. X        print SCRIPT "clustered " if $field[1] =~ /^clust/;
  1079. X        print SCRIPT "index $field[0]\n";
  1080. X        @col = split(/,/,$field[2]);
  1081. X        print SCRIPT "on $opt_d.$tab[1].$tab[0] (";
  1082. X        $first = 1;
  1083. X        foreach (@col)
  1084. X        {
  1085. X            print SCRIPT ", " if !$first;
  1086. X            $first = 0;
  1087. X            print SCRIPT "$_";
  1088. X        }
  1089. X        print SCRIPT ")\n";
  1090. X    }
  1091. X
  1092. X    &getPerms("$tab[1].$tab[0]");
  1093. X
  1094. X    print SCRIPT "go\n";
  1095. X
  1096. X    print "Bind rules & defaults to columns...\n" if $opt_v;
  1097. X    print SCRIPT "/* Bind rules & defaults to columns... */\n\n";
  1098. X
  1099. X    if($tab[1] ne 'dbo' && (keys(%dflt) || keys(%rule)))
  1100. X    {
  1101. X    print SCRIPT "/* The owner of the table is $tab[1].
  1102. X** I can't bind the rules/defaults to a table of which I am not the owner.
  1103. X** The procedures below will have to be run manualy by user $tab[1].
  1104. X*/";
  1105. X    print LOG "Defaults/Rules for $tab[1].$tab[0] could not be bound\n";
  1106. X    }
  1107. X
  1108. X    while(($dat, $dflt)=each(%dflt))
  1109. X    {
  1110. X    print SCRIPT "/* " if $tab[1] ne 'dbo';
  1111. X    print SCRIPT "sp_bindefault $dflt, '$dat'";
  1112. X    if($tab[1] ne 'dbo')
  1113. X    {
  1114. X        print SCRIPT " */\n";
  1115. X    }
  1116. X    else
  1117. X    {
  1118. X        print SCRIPT "\ngo\n";
  1119. X    }
  1120. X    }
  1121. X    while(($dat, $rule) = each(%rule))
  1122. X    {
  1123. X    print SCRIPT "/* " if $tab[1] ne 'dbo';
  1124. X    print SCRIPT "sp_bindrule $rule, '$dat'";
  1125. X    if($tab[1] ne 'dbo')
  1126. X    {
  1127. X        print SCRIPT " */\n";
  1128. X    }
  1129. X    else
  1130. X    {
  1131. X        print SCRIPT "\ngo\n";
  1132. X    }
  1133. X    }
  1134. X    print SCRIPT "\n/* End of description of table $tab[1].$tab[0] */\n";
  1135. X
  1136. X}
  1137. X
  1138. Xprint "Done\n";
  1139. X
  1140. X
  1141. X#
  1142. X# Now create any views that might exist
  1143. X#
  1144. X
  1145. Xprint "Create views...";
  1146. Xprint SCRIPT
  1147. X    "\n/* Now we add the views... */\n\n";
  1148. X
  1149. X&getObj('View', 'V');
  1150. X
  1151. Xprint "Done\n";
  1152. X
  1153. X#
  1154. X# Now create any stored procs that might exist
  1155. X#
  1156. X
  1157. Xprint "Create stored procs...";
  1158. Xprint SCRIPT
  1159. X    "\n/* Now we add the stored procedures... */\n\n";
  1160. X&getObj('Stored Proc', 'P');
  1161. X
  1162. Xprint "Done\n";
  1163. X
  1164. X#
  1165. X# Now create the triggers
  1166. X#
  1167. X
  1168. Xprint "Create triggers...";
  1169. Xprint SCRIPT
  1170. X    "\n/* Now we add the triggers... */\n\n";
  1171. X
  1172. X&getObj('Trigger', 'TR');
  1173. X
  1174. X
  1175. Xprint "Done\n";
  1176. X
  1177. Xprint "\nLooks like I'm all done!\n";
  1178. Xclose(SCRIPT);
  1179. Xclose(LOG);
  1180. X
  1181. X&dbexit;
  1182. X
  1183. X
  1184. Xsub getPerms
  1185. X{
  1186. X    local($obj) = $_[0];
  1187. X    local($ret, @dat, $act, $cnt);
  1188. X
  1189. X    &dbcmd($dbproc, "sp_helprotect '$obj'\n");
  1190. X    &dbsqlexec($dbproc);
  1191. X
  1192. X    $cnt = 0;
  1193. X    while(($ret = &dbresults($dbproc)) != $NO_MORE_RESULTS && $ret != $FAIL)
  1194. X    {
  1195. X    while(@dat = &dbnextrow($dbproc))
  1196. X    {
  1197. X        $act = 'to';
  1198. X        $act = 'from' if $dat[0] =~ /Revoke/;
  1199. X        print SCRIPT "$dat[0] $dat[1] on $obj $act $dat[2]\n";
  1200. X        ++$cnt;
  1201. X    }
  1202. X    }
  1203. X    $cnt;
  1204. X}
  1205. X
  1206. Xsub getObj
  1207. X{
  1208. X    local($objname, $obj) = @_;
  1209. X    local(@dat, @items, @vi, $found);
  1210. X    
  1211. X    &dbcmd($dbproc, "select o.name, u.name, o.id\n");
  1212. X    &dbcmd($dbproc, "from $opt_d.dbo.sysobjects o, $opt_d.dbo.sysusers u\n");
  1213. X    &dbcmd($dbproc, "where o.type = '$obj' and o.name like '$opt_t' and u.uid = o.uid\n");
  1214. X    &dbcmd($dbproc, "order by o.name\n");
  1215. X
  1216. X    &dbsqlexec($dbproc);
  1217. X    &dbresults($dbproc);
  1218. X
  1219. X    while((@dat = &dbnextrow($dbproc)))
  1220. X    {                # 
  1221. X    $_ = join('@', @dat);    # join the data together on a line
  1222. X    push(@items, $_);    # and save it in a list
  1223. X    }
  1224. X
  1225. X    foreach (@items)
  1226. X    {
  1227. X    @vi = split(/@/, $_);
  1228. X    $found = 0;
  1229. X
  1230. X    &dbcmd($dbproc, "select text from syscomments where id = $vi[2]");
  1231. X    &dbsqlexec($dbproc);
  1232. X    &dbresults($dbproc);
  1233. X    
  1234. X    print SCRIPT
  1235. X        "/* $objname $vi[0], owner $vi[1] */\n";
  1236. X
  1237. X    while(($text) = &dbnextrow($dbproc))
  1238. X    {
  1239. X        if(!$found && $vi[1] ne 'dbo')
  1240. X        {
  1241. X        ++$found if($text =~ /$vi[1]/);
  1242. X        }
  1243. X        print SCRIPT $text;
  1244. X    }
  1245. X    print SCRIPT "\ngo\n";
  1246. X    if(!$found && $vi[1] ne 'dbo')
  1247. X    {
  1248. X        print "**Warning**\n$objname $vi[0] has owner $vi[1]\nbut this is not mentioned in the CREATE PROC statement!!\n";
  1249. X        print LOG "$objname $vi[0] (owner $vi[1])\n";
  1250. X    }
  1251. X    if ($obj eq 'V' || $obj eq 'P')
  1252. X    {
  1253. X       &getPerms("$vi[0]") && print SCRIPT "go\n";
  1254. X    }
  1255. X
  1256. X    }
  1257. X}
  1258. X
  1259. X
  1260. END_OF_FILE
  1261.   if test 9982 -ne `wc -c <'eg/dbschema.pl'`; then
  1262.     echo shar: \"'eg/dbschema.pl'\" unpacked with wrong size!
  1263.   fi
  1264.   # end of 'eg/dbschema.pl'
  1265. fi
  1266. if test -f 'eg/dbtext.pl' -a "${1}" != "-c" ; then 
  1267.   echo shar: Will not clobber existing file \"'eg/dbtext.pl'\"
  1268. else
  1269.   echo shar: Extracting \"'eg/dbtext.pl'\" \(738 characters\)
  1270.   sed "s/^X//" >'eg/dbtext.pl' <<'END_OF_FILE'
  1271. X#  Script which demonstrates dbwrite routine.
  1272. X#
  1273. X#  In isql do something like:
  1274. X#       create table text_table (t_index int, the_text text)
  1275. X#
  1276. X#    @(#)dbtext.pl    1.1    8/31/93
  1277. X#
  1278. X
  1279. Xrequire "sybperl.pl";
  1280. Xrequire "sql.pl";
  1281. X
  1282. X$d = &dblogin;
  1283. X$d2 = &dbopen;
  1284. X
  1285. X&sql ($d, 'delete from text_table');
  1286. X&sql ($d, 'insert into text_table (t_index, the_text) values (5,"")');
  1287. X
  1288. X
  1289. X&dbcmd($d,'select the_text, t_index from text_table where t_index = 5');
  1290. X&dbsqlexec($d);                         # execute sql
  1291. X
  1292. X&dbresults($d);
  1293. X@data = &dbnextrow($d);
  1294. X
  1295. X&dbwritetext ($d2, "text_table.the_text", $d, 1, "This is text which was added with Sybperl");
  1296. X
  1297. X@result = &sql($d,'select t_index, the_text from text_table where t_index = 5');
  1298. X
  1299. Xprint @result, "\n";
  1300. X
  1301. X&dbclose($d);
  1302. X
  1303. END_OF_FILE
  1304.   if test 738 -ne `wc -c <'eg/dbtext.pl'`; then
  1305.     echo shar: \"'eg/dbtext.pl'\" unpacked with wrong size!
  1306.   fi
  1307.   # end of 'eg/dbtext.pl'
  1308. fi
  1309. if test -f 'eg/report.pl' -a "${1}" != "-c" ; then 
  1310.   echo shar: Will not clobber existing file \"'eg/report.pl'\"
  1311. else
  1312.   echo shar: Extracting \"'eg/report.pl'\" \(753 characters\)
  1313.   sed "s/^X//" >'eg/report.pl' <<'END_OF_FILE'
  1314. X#! /usr/local/bin/sybperl
  1315. X
  1316. X#
  1317. X#    @(#)report.pl    1.1    6/24/92
  1318. X#
  1319. X
  1320. Xrequire "sybperl.pl";
  1321. Xrequire "sql.pl";
  1322. X
  1323. X#
  1324. X# Log us in to Sybase.
  1325. X#
  1326. X$d = &dblogin;
  1327. X
  1328. X#
  1329. X# define the format
  1330. X#
  1331. Xformat top=
  1332. X             PASSWORD FILE
  1333. XLogin      Uid Group      Shell                   Home directory
  1334. X-------- ----- ---------- ----------------------- ----------------------
  1335. X. 
  1336. Xformat stdout=
  1337. X@<<<<<<< @>>>> @<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<
  1338. X$n,      $u,   $gn,       $s,                     $d
  1339. X. 
  1340. X
  1341. X#
  1342. X# See if everything is there.
  1343. X#
  1344. X@results = &sql($d, '
  1345. X    select username, uid, isnull(groupname,convert(char,p.gid)), shell, home
  1346. X    from password p, groups g
  1347. X    where    p.gid *= g.gid
  1348. X    order by uid
  1349. X    ');
  1350. Xforeach $x (@results) {
  1351. X    ($n,$u,$gn,$s,$d) = split("~",$x);
  1352. X    write;
  1353. X}
  1354. X
  1355. END_OF_FILE
  1356.   if test 753 -ne `wc -c <'eg/report.pl'`; then
  1357.     echo shar: \"'eg/report.pl'\" unpacked with wrong size!
  1358.   fi
  1359.   chmod +x 'eg/report.pl'
  1360.   # end of 'eg/report.pl'
  1361. fi
  1362. if test -f 'eg/space.pl' -a "${1}" != "-c" ; then 
  1363.   echo shar: Will not clobber existing file \"'eg/space.pl'\"
  1364. else
  1365.   echo shar: Extracting \"'eg/space.pl'\" \(1494 characters\)
  1366.   sed "s/^X//" >'eg/space.pl' <<'END_OF_FILE'
  1367. X#! /usr/local/bin/sybperl
  1368. X#
  1369. X#    @(#)space.pl    1.2    4/2/93
  1370. X
  1371. Xrequire "sybperl.pl";
  1372. Xrequire "sql.pl";
  1373. X
  1374. X#
  1375. X# Log us in to Sybase.
  1376. X#
  1377. Xprint "Name of Sybase server: ";
  1378. X$server = <>; chop($server);
  1379. Xif($server ne '')
  1380. X{
  1381. X    $ENV{'DSQUERY'} = $server;
  1382. X}
  1383. Xelse
  1384. X{
  1385. X    $server = $ENV{'DSQUERY'};
  1386. X}
  1387. X
  1388. Xprint "Administrative account password: ";
  1389. Xeval `stty -echo`;
  1390. X$sapw = <>; chop($sapw);
  1391. Xeval `stty echo`;
  1392. X
  1393. X$d = &dblogin("sa", $sapw);
  1394. X
  1395. X
  1396. X$server = $server . '.';
  1397. X
  1398. X
  1399. X&sql($d, "use master");
  1400. X@dbs = &sql($d, "select name from sysdatabases order by name");
  1401. X
  1402. Xforeach $n (@dbs) {
  1403. X    &sql($d, "use $n");
  1404. X    $x = join('~', &sql($d, 'sp_spaceused'));
  1405. X    $x =~ s/ //g;
  1406. X    $x =~ s/MB|KB//g;
  1407. X    ($name, $size, $res, $data, $index, $free ) = split("~",$x);
  1408. X    $unused = $size * 1024 - $res;
  1409. X    write;
  1410. X    $ts += $size;
  1411. X    $tr += $res;
  1412. X    $td += $data;
  1413. X    $ti += $index;
  1414. X    $tf += $free;
  1415. X}
  1416. X
  1417. Xprint '-' x 78, "\n"; 
  1418. X$name = 'TOTAL';
  1419. X$size = $ts;
  1420. X$res = $tr;
  1421. X$data = $td;
  1422. X$index = $ti;
  1423. X$free = $tf;
  1424. X$unused = $size * 1024 - $res;
  1425. Xwrite;
  1426. X
  1427. Xformat top=
  1428. XSpace usage per database for server @<<<<<<<<<<<<<<<
  1429. X                    $server
  1430. XName             Size    Reserved       Data      Index       Free     Unused
  1431. X             (MB)        (KB)       (KB)       (KB)       (KB)       (KB)
  1432. X-----------------------------------------------------------------------------
  1433. X. 
  1434. Xformat stdout=
  1435. X@<<<<<<<<<  @>>>>>>>>  @>>>>>>>>>  @>>>>>>>>  @>>>>>>>>  @>>>>>>>>  @>>>>>>>>
  1436. X$name,      $size,     $res,       $data,     $index,    $free,     $unused
  1437. X. 
  1438. X
  1439. X
  1440. END_OF_FILE
  1441.   if test 1494 -ne `wc -c <'eg/space.pl'`; then
  1442.     echo shar: \"'eg/space.pl'\" unpacked with wrong size!
  1443.   fi
  1444.   chmod +x 'eg/space.pl'
  1445.   # end of 'eg/space.pl'
  1446. fi
  1447. if test -f 'eg/sql.pl' -a "${1}" != "-c" ; then 
  1448.   echo shar: Will not clobber existing file \"'eg/sql.pl'\"
  1449. else
  1450.   echo shar: Extracting \"'eg/sql.pl'\" \(1736 characters\)
  1451.   sed "s/^X//" >'eg/sql.pl' <<'END_OF_FILE'
  1452. X#
  1453. X#    @(#)sql.pl    1.2    8/9/93
  1454. X#
  1455. X
  1456. Xsub sql {
  1457. X    local($db,$sql,$sep)=@_;            # local copy parameters
  1458. X
  1459. X    $sep = '~' unless $sep;            # provide default for sep
  1460. X
  1461. X    @res = ();                    # clear result array
  1462. X
  1463. X    &dbcmd($db,$sql);                # pass sql to server
  1464. X    &dbsqlexec($db);                # execute sql
  1465. X
  1466. X    while(&dbresults($db) != $NO_MORE_RESULTS) {    # copy all results
  1467. X    while (@data = &dbnextrow($db)) {
  1468. X        push(@res,join($sep,@data));
  1469. X    }
  1470. X    }
  1471. X
  1472. X    @res;                    # return the result array
  1473. X}
  1474. X
  1475. X
  1476. X# Message and error handlers.
  1477. X
  1478. Xsub sql_message_handler
  1479. X{
  1480. X    local ($db, $message, $state, $severity, $text, $server, $procedure, $line)
  1481. X    = @_;
  1482. X
  1483. X    if ($severity > 0)
  1484. X    {
  1485. X    print ("Sybase message ", $message, ", Severity ", $severity,
  1486. X           ", state ", $state);
  1487. X    print ("\nServer `", $server, "'") if defined ($server);
  1488. X    print ("\nProcedure `", $procedure, "'") if defined ($procedure);
  1489. X    print ("\nLine ", $line) if defined ($line);
  1490. X    print ("\n    ", $text, "\n\n");
  1491. X
  1492. X# &dbstrcpy returns the command buffer.
  1493. X
  1494. X    local ($lineno) = 1;    # 
  1495. X    foreach $row (split (/\n/, &dbstrcpy ($db)))
  1496. X    {
  1497. X        print (sprintf ("%5d", $lineno ++), "> ", $row, "\n");
  1498. X    }
  1499. X    }
  1500. X    elsif ($message == 0)
  1501. X    {
  1502. X    print ($text, "\n");
  1503. X    }
  1504. X    
  1505. X    0;
  1506. X}
  1507. X
  1508. Xsub sql_error_handler {
  1509. X    # Check the error code to see if we should report this.
  1510. X    if ($_[2] != &SYBESMSG) {
  1511. X    local ($db, $severity, $error, $os_error, $error_msg, $os_error_msg)
  1512. X        = @_;
  1513. X    print ("Sybase error: ", $error_msg, "\n");
  1514. X    print ("OS Error: ", $os_error_msg, "\n") if defined ($os_error_msg);
  1515. X    }
  1516. X
  1517. X    &INT_CANCEL;
  1518. X}
  1519. X
  1520. X
  1521. Xif( defined(&dbmsghandle))    # Is this a modern version of sybperl? ;-)
  1522. X{
  1523. X    &dbmsghandle ("sql_message_handler"); # Some user defined error handlers
  1524. X    &dberrhandle ("sql_error_handler");
  1525. X}
  1526. X
  1527. X
  1528. X1;
  1529. X
  1530. END_OF_FILE
  1531.   if test 1736 -ne `wc -c <'eg/sql.pl'`; then
  1532.     echo shar: \"'eg/sql.pl'\" unpacked with wrong size!
  1533.   fi
  1534.   # end of 'eg/sql.pl'
  1535. fi
  1536. if test -f 'eg/test_dbmoney.pl' -a "${1}" != "-c" ; then 
  1537.   echo shar: Will not clobber existing file \"'eg/test_dbmoney.pl'\"
  1538. else
  1539.   echo shar: Extracting \"'eg/test_dbmoney.pl'\" \(5455 characters\)
  1540.   sed "s/^X//" >'eg/test_dbmoney.pl' <<'END_OF_FILE'
  1541. X#! /usr/local/bin/sybperl
  1542. X
  1543. X#    @(#)test_dbmoney.pl    1.3    6/1/94
  1544. X#
  1545. X
  1546. Xunshift(@INC, "../lib");    # to use the uninstalled require'd files
  1547. Xrequire "sybperl.pl";
  1548. Xrequire "getopts.pl";
  1549. X
  1550. X( !defined( $FALSE )) && ( $FALSE = 0 );
  1551. X( !defined( $TRUE ))  && ( $TRUE  = 1 );
  1552. X
  1553. X&Getopts( 'S:' );
  1554. X
  1555. Xif ( defined( $opt_S )) {
  1556. X   $server = $opt_S;
  1557. X}
  1558. Xelse {
  1559. X   $server = $ENV{ 'DSQUERY' };
  1560. X}
  1561. X
  1562. X$tty_test = system( "/bin/tty -s" ) / 256;
  1563. X
  1564. X(( $tty_test == 0 ) || ( $tty_test == 1 )) ||
  1565. X   die "Invalid options were specified to /bin/tty: $!\n";
  1566. X
  1567. Xif ( $tty_test == 0 ) {  # tty device attached to STDIN
  1568. X   system( "/bin/stty -echo" );
  1569. X   print "SA password: ";
  1570. X   $sybupw = scalar( <STDIN> );
  1571. X   system( "/bin/stty echo" );
  1572. X   print "\n";
  1573. X}
  1574. Xelse {
  1575. X   $sybupw = scalar( <STDIN> );
  1576. X}
  1577. X
  1578. Xchop $sybupw;
  1579. X
  1580. X$dbproc = &dblogin( "sa", $sybupw, $server );
  1581. X
  1582. X&dbuse( "master" );
  1583. X
  1584. X$money1 = '4.89';
  1585. X$money2 = '8.56';
  1586. X$money3 = '*';
  1587. X
  1588. Xprintf( "money1 = %.4f, money2 = %.4f\n", $money1, $money2 );
  1589. X
  1590. X($status, $money3) = &dbmnyzero( );
  1591. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1592. X
  1593. X($status, $money3) = &dbmnyinc( $money3 );
  1594. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1595. X($status, $money3) = &dbmnyinc( $money3 );
  1596. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1597. X($status, $money3) = &dbmnyinc( $money3 );
  1598. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1599. X($status, $money3) = &dbmnyinc( $money3 );
  1600. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1601. X
  1602. X$money3 = '0.0001';
  1603. X($status, $money3) = &dbmnyscale( $money3, 100, 1 );
  1604. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1605. X
  1606. X( $money3, $money4 ) = ( '0.0001', '0.0002' );
  1607. X($status, $money3) = &dbmnyadd( $money4, $money3 );
  1608. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1609. X
  1610. X$money3 = '0.0004'; $money4 = '0.0003'; $money5 = '0.0005';
  1611. X$money6 = '0.0004';
  1612. Xprintf( "status = %d, money3 = %.4f, money4 = %.4f\n",
  1613. X    &dbmnycmp( $money3, $money4 ), $money3, $money4 );
  1614. Xprintf( "status = %d, money3 = %.4f, money5 = %.4f\n",
  1615. X    &dbmnycmp( $money3, $money5 ), $money3, $money5 );
  1616. Xprintf( "status = %d, money3 = %.4f, money6 = %.4f\n",
  1617. X    &dbmnycmp( $money3, $money6 ), $money3, $money6 );
  1618. Xprintf( "status = %d, money4 = %.4f, money5 = %.4f\n",
  1619. X    &dbmnycmp( $money4, $money5 ), $money4, $money5 );
  1620. Xprintf( "status = %d, money4 = %.4f, money6 = %.4f\n",
  1621. X    &dbmnycmp( $money4, $money6 ), $money4, $money6 );
  1622. Xprintf( "status = %d, money5 = %.4f, money6 = %.4f\n",
  1623. X    &dbmnycmp( $money5, $money6 ), $money5, $money6 );
  1624. X
  1625. X($status, $money3) = &dbmnyadd( $money1, $money2 );
  1626. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1627. X
  1628. X($status, $money3) = &dbmnysub( $money1, $money2 );
  1629. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1630. X
  1631. X($status, $money3) = &dbmnydivide( $money3, $money2 );
  1632. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1633. X
  1634. X($status, $money4) = &dbmnymaxneg( );
  1635. Xprintf( "status = %d, money4 = %.4f\n", $status, $money4 );
  1636. X
  1637. X($status, $money3) = &dbmnymaxpos( );
  1638. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1639. X
  1640. X($status, $money4) = &dbmnyzero( );
  1641. X
  1642. X@tbal = ( '4.89', '8.92', '7.77', '11.11', '0.01' );
  1643. X
  1644. Xfor ( $cntr = 0 ; $cntr <= $#tbal ; $cntr++ ) {
  1645. X  printf( "Item %d - %s\n", $cntr, $tbal[ $cntr ] );
  1646. X  ($status, $money4) = &dbmnyadd( $tbal[ $cntr ], $money4 );
  1647. X}
  1648. X
  1649. Xprintf( "status = %d, total = %.4f\n", $status, $money4 );
  1650. X
  1651. X$cntr = $#tbal + 1;
  1652. X
  1653. X($status, $money4) = &dbmnydivide( $money4, "$cntr" );
  1654. Xprintf( "status = %d, avg = %.4f\n", $status, $money4 );
  1655. X
  1656. Xprint "-------------------------\n";
  1657. X
  1658. X$money1 = '4.89';
  1659. X$money2 = '8.56';
  1660. X$money3 = '*';
  1661. X
  1662. Xprintf( "money1 = %.4f, money2 = %.4f\n", $money1, $money2 );
  1663. X
  1664. X($status, $money3) = &dbmny4zero( );
  1665. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1666. X
  1667. X( $money3, $money4 ) = ( '0.0001', '0.0002' );
  1668. X($status, $money3) = &dbmny4add( $money3, $money4 );
  1669. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1670. X
  1671. X$money3 = '0.0004'; $money4 = '0.0003'; $money5 = '0.0005';
  1672. X$money6 = '0.0004';
  1673. Xprintf( "status = %d, money3 = %.4f, money4 = %.4f\n",
  1674. X    &dbmny4cmp( $money3, $money4 ), $money3, $money4 );
  1675. Xprintf( "status = %d, money3 = %.4f, money5 = %.4f\n",
  1676. X    &dbmny4cmp( $money3, $money5 ), $money3, $money5 );
  1677. Xprintf( "status = %d, money3 = %.4f, money6 = %.4f\n",
  1678. X    &dbmny4cmp( $money3, $money6 ), $money3, $money6 );
  1679. Xprintf( "status = %d, money4 = %.4f, money5 = %.4f\n",
  1680. X    &dbmny4cmp( $money4, $money5 ), $money4, $money5 );
  1681. Xprintf( "status = %d, money4 = %.4f, money6 = %.4f\n",
  1682. X    &dbmny4cmp( $money4, $money6 ), $money4, $money6 );
  1683. Xprintf( "status = %d, money5 = %.4f, money6 = %.4f\n",
  1684. X    &dbmny4cmp( $money5, $money6 ), $money5, $money6 );
  1685. X
  1686. X($status, $money3) = &dbmny4add( $money1, $money2 );
  1687. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1688. X
  1689. X($status, $money3) = &dbmny4sub( $money1, $money2 );
  1690. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1691. X
  1692. X($status, $money3) = &dbmny4divide( $money3, $money2 );
  1693. Xprintf( "status = %d, money3 = %.4f\n", $status, $money3 );
  1694. X
  1695. X($status, $money4) = &dbmny4zero( $money4 );
  1696. X
  1697. X@tbal = ( '4.89', '8.92', '7.77', '11.11', '0.01' );
  1698. X
  1699. Xfor ( $cntr = 0 ; $cntr <= $#tbal ; $cntr++ ) {
  1700. X  printf( "Item %d - %s\n", $cntr, $tbal[ $cntr ] );
  1701. X  ($status, $money4) = &dbmny4add( $tbal[ $cntr ], $money4 );
  1702. X}
  1703. X
  1704. Xprintf( "status = %d, total = %.4f\n", $status, $money4 );
  1705. X
  1706. X$cntr = $#tbal + 1;
  1707. X
  1708. X($status, $money4) = &dbmny4divide( $money4, "$cntr" );
  1709. Xprintf( "status = %d, avg = %.4f\n", $status, $money4 );
  1710. X
  1711. X&dbclose;
  1712. X
  1713. X&dbexit;
  1714. X
  1715. Xexit( $STDEXIT );
  1716. X
  1717. END_OF_FILE
  1718.   if test 5455 -ne `wc -c <'eg/test_dbmoney.pl'`; then
  1719.     echo shar: \"'eg/test_dbmoney.pl'\" unpacked with wrong size!
  1720.   fi
  1721.   # end of 'eg/test_dbmoney.pl'
  1722. fi
  1723. if test ! -d 'lib' ; then
  1724.     echo shar: Creating directory \"'lib'\"
  1725.     mkdir 'lib'
  1726. fi
  1727. if test -f 'lib/sybdb.ph' -a "${1}" != "-c" ; then 
  1728.   echo shar: Will not clobber existing file \"'lib/sybdb.ph'\"
  1729. else
  1730.   echo shar: Extracting \"'lib/sybdb.ph'\" \(5260 characters\)
  1731.   sed "s/^X//" >'lib/sybdb.ph' <<'END_OF_FILE'
  1732. X;#    @(#)sybdb.ph    1.2    8/30/93
  1733. X;#
  1734. X;#
  1735. X
  1736. Xsub SYBESYNC {20001;}
  1737. Xsub SYBEFCON {20002;}
  1738. Xsub SYBETIME {20003;}
  1739. Xsub SYBEREAD {20004;}
  1740. Xsub SYBEBUFL {20005;}
  1741. Xsub SYBEWRIT {20006;}
  1742. Xsub SYBEVMS {20007;}
  1743. Xsub SYBESOCK {20008;}
  1744. Xsub SYBECONN {20009;}
  1745. Xsub SYBEMEM {20010;}
  1746. Xsub SYBEDBPS {20011;}
  1747. Xsub SYBEINTF {20012;}
  1748. Xsub SYBEUHST {20013;}
  1749. Xsub SYBEPWD {20014;}
  1750. Xsub SYBEOPIN {20015;}
  1751. Xsub SYBEINLN {20016;}
  1752. Xsub SYBESEOF {20017;}
  1753. Xsub SYBESMSG {20018;}
  1754. Xsub SYBERPND {20019;}
  1755. Xsub SYBEBTOK {20020;}
  1756. Xsub SYBEITIM {20021;}
  1757. Xsub SYBEOOB {20022;}
  1758. Xsub SYBEBTYP {20023;}
  1759. Xsub SYBEBNCR {20024;}
  1760. Xsub SYBEIICL {20025;}
  1761. Xsub SYBECNOR {20026;}
  1762. Xsub SYBENPRM {20027;}
  1763. Xsub SYBEUVDT {20028;}
  1764. Xsub SYBEUFDT {20029;}
  1765. Xsub SYBEWAID {20030;}
  1766. Xsub SYBECDNS {20031;}
  1767. Xsub SYBEABNC {20032;}
  1768. Xsub SYBEABMT {20033;}
  1769. Xsub SYBEABNP {20034;}
  1770. Xsub SYBEAAMT {20035;}
  1771. Xsub SYBENXID {20036;}
  1772. Xsub SYBERXID {20037;}
  1773. Xsub SYBEICN {20038;}
  1774. Xsub SYBENMOB {20039;}
  1775. Xsub SYBEAPUT {20040;}
  1776. Xsub SYBEASNL {20041;}
  1777. Xsub SYBENTLL {20042;}
  1778. Xsub SYBEASUL {20043;}
  1779. Xsub SYBERDNR {20044;}
  1780. Xsub SYBENSIP {20045;}
  1781. Xsub SYBEABNV {20046;}
  1782. Xsub SYBEDDNE {20047;}
  1783. Xsub SYBECUFL {20048;}
  1784. Xsub SYBECOFL {20049;}
  1785. Xsub SYBECSYN {20050;}
  1786. Xsub SYBECLPR {20051;}
  1787. Xsub SYBECNOV {20052;}
  1788. Xsub SYBERDCN {20053;}
  1789. Xsub SYBESFOV {20054;}
  1790. Xsub SYBEUNT {20055;}
  1791. Xsub SYBECLOS {20056;}
  1792. Xsub SYBEUAVE {20057;}
  1793. Xsub SYBEUSCT {20058;}
  1794. Xsub SYBEEQVA {20059;}
  1795. Xsub SYBEUDTY {20060;}
  1796. Xsub SYBETSIT {20061;}
  1797. Xsub SYBEAUTN {20062;}
  1798. Xsub SYBEBDIO {20063;}
  1799. Xsub SYBEBCNT {20064;}
  1800. Xsub SYBEIFNB {20065;}
  1801. Xsub SYBETTS {20066;}
  1802. Xsub SYBEKBCO {20067;}
  1803. Xsub SYBEBBCI {20068;}
  1804. Xsub SYBEKBCI {20069;}
  1805. Xsub SYBEBCRE {20070;}
  1806. Xsub SYBETPTN {20071;}
  1807. Xsub SYBEBCWE {20072;}
  1808. Xsub SYBEBCNN {20073;}
  1809. Xsub SYBEBCOR {20074;}
  1810. Xsub SYBEBCIS {20075;}
  1811. Xsub SYBEBCPI {20076;}
  1812. Xsub SYBEBCPN {20077;}
  1813. Xsub SYBEBCPB {20078;}
  1814. Xsub SYBEVDPT {20079;}
  1815. Xsub SYBEBIVI {20080;}
  1816. Xsub SYBEBCBC {20081;}
  1817. Xsub SYBEBCFO {20082;}
  1818. Xsub SYBEBCVH {20083;}
  1819. Xsub SYBEBCUO {20084;}
  1820. Xsub SYBEBCUC {20085;}
  1821. Xsub SYBEBUOE {20086;}
  1822. Xsub SYBEBUCE {20087;}
  1823. Xsub SYBEBWEF {20088;}
  1824. Xsub SYBEASTF {20089;}
  1825. Xsub SYBEUACS {20090;}
  1826. Xsub SYBEASEC {20091;}
  1827. Xsub SYBETMTD {20092;}
  1828. Xsub SYBENTTN {20093;}
  1829. Xsub SYBEDNTI {20094;}
  1830. Xsub SYBEBTMT {20095;}
  1831. Xsub SYBEORPF {20096;}
  1832. Xsub SYBEUVBF {20097;}
  1833. Xsub SYBEBUOF {20098;}
  1834. Xsub SYBEBUCF {20099;}
  1835. Xsub SYBEBRFF {20100;}
  1836. Xsub SYBEBWFF {20101;}
  1837. Xsub SYBEBUDF {20102;}
  1838. Xsub SYBEBIHC {20103;}
  1839. Xsub SYBEBEOF {20104;}
  1840. Xsub SYBEBCNL {20105;}
  1841. Xsub SYBEBCSI {20106;}
  1842. Xsub SYBEBCIT {20107;}
  1843. Xsub SYBEBCSA {20108;}
  1844. Xsub SYBENULL {20109;}
  1845. Xsub SYBEUNAM {20110;}
  1846. Xsub SYBEBCRO {20111;}
  1847. Xsub SYBEMPLL {20112;}
  1848. Xsub SYBERPIL {20113;}
  1849. Xsub SYBERPUL {20114;}
  1850. Xsub SYBEUNOP {20115;}
  1851. Xsub SYBECRNC {20116;}
  1852. Xsub SYBERTCC {20117;}
  1853. Xsub SYBERTSC {20118;}
  1854. Xsub SYBEUCRR {20119;}
  1855. Xsub SYBERPNA {20120;}
  1856. Xsub SYBEOPNA {20121;}
  1857. Xsub SYBEFGTL {20122;}
  1858. Xsub SYBECWLL {20123;}
  1859. Xsub SYBEUFDS {20124;}
  1860. Xsub SYBEUCPT {20125;}
  1861. Xsub SYBETMCF {20126;}
  1862. Xsub SYBEAICF {20127;}
  1863. Xsub SYBEADST {20128;}
  1864. Xsub SYBEALTT {20129;}
  1865. Xsub SYBEAPCT {20130;}
  1866. Xsub SYBEXOCI {20131;}
  1867. Xsub SYBEFSHD {20132;}
  1868. Xsub SYBEAOLF {20133;}
  1869. Xsub SYBEARDI {20134;}
  1870. Xsub SYBEURCI {20135;}
  1871. Xsub SYBEARDL {20136;}
  1872. Xsub SYBEURMI {20137;}
  1873. Xsub SYBEUREM {20138;}
  1874. Xsub SYBEURES {20139;}
  1875. Xsub SYBEUREI {20140;}
  1876. Xsub SYBEOREN {20141;}
  1877. Xsub SYBEISOI {20142;}
  1878. Xsub SYBEIDCL {20143;}
  1879. Xsub SYBEIMCL {20144;}
  1880. Xsub SYBEIFCL {20145;}
  1881. Xsub SYBEUTDS {20146;}
  1882. Xsub SYBEBUFF {20147;}
  1883. Xsub SYBEACNV {20148;}
  1884. Xsub SYBEDPOR {20149;}
  1885. Xsub SYBENDC {20150;}
  1886. Xsub SYBEMVOR {20151;}
  1887. Xsub SYBEDVOR {20152;}
  1888. Xsub SYBENBVP {20153;}
  1889. Xsub SYBESPID {20154;}
  1890. Xsub SYBENDTP {20155;}
  1891. Xsub SYBEXTN {20156;}
  1892. Xsub SYBEXTDN {20157;}
  1893. Xsub SYBEXTSN {20158;}
  1894. Xsub SYBENUM {20159;}
  1895. Xsub SYBETYPE {20160;}
  1896. Xsub SYBEGENOS {20161;}
  1897. Xsub SYBEPAGE {20162;}
  1898. Xsub SYBEOPTNO {20163;}
  1899. Xsub SYBEETD {20164;}
  1900. Xsub SYBERTYPE {20165;}
  1901. Xsub SYBERFILE {20166;}
  1902. Xsub SYBEFMODE {20167;}
  1903. Xsub SYBESLCT {20168;}
  1904. Xsub SYBEZTXT {20169;}
  1905. Xsub SYBENTST {20170;}
  1906. Xsub SYBEOSSL {20171;}
  1907. Xsub SYBEESSL {20172;}
  1908. Xsub SYBENLNL {20173;}
  1909. Xsub SYBENHAN {20174;}
  1910. Xsub SYBENBUF {20175;}
  1911. Xsub SYBENULP {20176;}
  1912. Xsub SYBENOTI {20177;}
  1913. Xsub SYBEEVOP {20178;}
  1914. Xsub SYBENEHA {20179;}
  1915. Xsub SYBETRAN {20180;}
  1916. Xsub SYBEEVST {20181;}
  1917. Xsub SYBEEINI {20182;}
  1918. Xsub SYBEECRT {20183;}
  1919. Xsub SYBEECAN {20184;}
  1920. Xsub SYBEEUNR {20185;}
  1921. Xsub SYBERPCS {20186;}
  1922. Xsub SYBETPAR {20187;}
  1923. Xsub SYBETEXS {20188;}
  1924. Xsub SYBETRAC {20189;}
  1925. Xsub SYBETRAS {20190;}
  1926. Xsub SYBEPRTF {20191;}
  1927. Xsub SYBETRSN {20192;}
  1928. Xsub SYBEBPKS {20193;}
  1929. Xsub SYBEIPV {20194;}
  1930. Xsub SYBEMOV {20195;}
  1931. Xsub SYBEDIVZ {20196;}
  1932. Xsub SYBEASTL {20197;}
  1933. Xsub SYBESEFA {20198;}
  1934. Xsub SYBEPOLL {20199;}
  1935. Xsub SYBENOEV {20200;}
  1936. Xsub SYBEBADPK {20201;}
  1937. Xsub DBERRCOUNT {201;}
  1938. X
  1939. X# sybperl standard definitions (and some new additions)
  1940. X#
  1941. X# From sybfront.h
  1942. X#
  1943. X
  1944. X# sybperl standard definitions (and some new additions)
  1945. X#
  1946. X# From sybdb.h
  1947. X#
  1948. X
  1949. X# sybperl standard definitions (and some new additions)
  1950. X#
  1951. X# From syberror.h
  1952. X#
  1953. X
  1954. X# Other definitions (optional)
  1955. X#
  1956. X# From sybdb.h
  1957. X#
  1958. Xsub DBSINGLE {0;}
  1959. Xsub DBDOUBLE {1;}
  1960. Xsub DBBOTH {2;}
  1961. Xsub DBXLATE_XOK {0;}
  1962. Xsub DBXLATE_XOF {1;}
  1963. Xsub DBXLATE_XPAT {2;}
  1964. Xsub DBRESULT {1;}
  1965. Xsub DBNOTIFICATION {2;}
  1966. Xsub DBTIMEOUT {3;}
  1967. Xsub DBINTERRUPT {4;}
  1968. Xsub DBMAXMNYSYM {5;}
  1969. Xsub DBMAXECLEN {8;}
  1970. Xsub DBMAXESLEN {256;}
  1971. Xsub DBMAXCPYRTLEN {512;}
  1972. Xsub DBTDS_UNKNOWN {0;}
  1973. Xsub DBTDS_2_0 {1;}
  1974. Xsub DBTDS_3_4 {2;}
  1975. Xsub DBTDS_4_0 {3;}
  1976. Xsub DBTDS_4_2 {4;}
  1977. Xsub DBTDS_4_6 {5;}
  1978. X
  1979. X
  1980. Xsub SUCCEED {1;}
  1981. Xsub FAIL {0;}
  1982. X
  1983. Xsub INT_EXIT {0;}
  1984. Xsub INT_CONTINUE {1;}
  1985. Xsub INT_CANCEL {2;}
  1986. X
  1987. X1;
  1988. X
  1989. END_OF_FILE
  1990.   if test 5260 -ne `wc -c <'lib/sybdb.ph'`; then
  1991.     echo shar: \"'lib/sybdb.ph'\" unpacked with wrong size!
  1992.   fi
  1993.   # end of 'lib/sybdb.ph'
  1994. fi
  1995. if test -f 'lib/sybdb_redefs.pl' -a "${1}" != "-c" ; then 
  1996.   echo shar: Will not clobber existing file \"'lib/sybdb_redefs.pl'\"
  1997. else
  1998.   echo shar: Extracting \"'lib/sybdb_redefs.pl'\" \(9685 characters\)
  1999.   sed "s/^X//" >'lib/sybdb_redefs.pl' <<'END_OF_FILE'
  2000. X#    @(#)sybdb_redefs.pl    1.3    6/10/94
  2001. X#
  2002. X# Adapted from Jeff Wongs version.
  2003. X# sybdb_redefs.pl - sybperl redefinitions to defeat weird package/user-defined
  2004. X#                   built-in subroutine bug.
  2005. X#
  2006. X# mpeppler 09/06/94, V1.6 - add &dbsetopt, &DBSETLNATLANG, &DBSETLCHARSET.
  2007. X# mpeppler 12/05/94, V1.5 - add &dbfreebuf (1.011)
  2008. X# jtw, 09/06/93, V1.4 - defer omission of $dbproc for all routines
  2009. X# jtw, 09/06/93, V1.3 - add OpenClient R4.6.1 money routines
  2010. X# jtw, 14/05/93, V1.2 - change argument test in &dbnextrow to == 0
  2011. X# jtw, 13/05/93, V1.1 - synchronise with sybperl V1.6
  2012. X# jtw, 18/03/93, V1.0 - original
  2013. X#
  2014. X#
  2015. Xpackage main;
  2016. X
  2017. Xsub dblogin {
  2018. X   local( @param_array ) = @_;
  2019. X   local( $dbproc );
  2020. X
  2021. X   $dbproc = &dbLOGIN( @param_array );
  2022. X
  2023. X   return $dbproc;
  2024. X}
  2025. X
  2026. Xsub dbopen {
  2027. X   local( $server ) = @_;
  2028. X   local( $dbproc );
  2029. X
  2030. X   $dbproc = &dbOPEN( $server );
  2031. X
  2032. X   return $dbproc;
  2033. X}
  2034. X
  2035. Xsub dbclose {
  2036. X   local( $dbproc ) = @_;
  2037. X   local( $ret );
  2038. X
  2039. X   $ret = &dbCLOSE( $dbproc );
  2040. X
  2041. X   return $ret;
  2042. X}
  2043. X
  2044. Xsub dbcmd {
  2045. X   local( @param_array ) = @_;
  2046. X   local( $ret );
  2047. X
  2048. X   $ret = &dbCMD( @param_array );
  2049. X
  2050. X   return $ret;
  2051. X}
  2052. X
  2053. Xsub dbsqlexec {
  2054. X   local( $dbproc ) = @_;
  2055. X   local( $ret );
  2056. X
  2057. X   $ret = &dbSQLEXEC( $dbproc );
  2058. X
  2059. X   return $ret;
  2060. X}
  2061. X
  2062. Xsub dbresults {
  2063. X   local( $dbproc ) = @_;
  2064. X   local( $ret );
  2065. X
  2066. X   $ret = &dbRESULTS( $dbproc );
  2067. X
  2068. X   return $ret;
  2069. X}
  2070. X
  2071. Xsub dbnextrow {
  2072. X   local( @param_array ) = @_;
  2073. X   local( @dvec, %avec );
  2074. X
  2075. X   if (( $#param_array     == 1 )  &&
  2076. X       ( $param_array[ 1 ] != 0 ))    {  # associative array
  2077. X      %avec = &dbNEXTROW( @param_array );
  2078. X
  2079. X      return %avec;
  2080. X   }
  2081. X   else {  # normal array
  2082. X      @dvec = &dbNEXTROW( @param_array );
  2083. X
  2084. X      return @dvec;
  2085. X   }
  2086. X}
  2087. X
  2088. Xsub dbcancel {
  2089. X   local( $dbproc ) = @_;
  2090. X   local( $ret );
  2091. X
  2092. X   $ret = &dbCANCEL( $dbproc );
  2093. X
  2094. X   return $ret;
  2095. X}
  2096. X
  2097. Xsub dbcanquery {
  2098. X   local( $dbproc ) = @_;
  2099. X   local( $ret );
  2100. X
  2101. X   $ret = &dbCANQUERY( $dbproc );
  2102. X
  2103. X   return $ret;
  2104. X}
  2105. X
  2106. Xsub dbfreebuf {
  2107. X   local( $dbproc ) = @_;
  2108. X   local( $ret );
  2109. X
  2110. X   $ret = &dbFREEBUF( $dbproc );
  2111. X
  2112. X   return $ret;
  2113. X}
  2114. X
  2115. Xsub dbsetopt {
  2116. X   local( @param_array ) = @_;
  2117. X   local( $ret );
  2118. X
  2119. X   $ret = &dbSETOPT( @param_array );
  2120. X
  2121. X   return $ret;
  2122. X}
  2123. X
  2124. Xsub dbexit {
  2125. X   &dbEXIT;
  2126. X}
  2127. X
  2128. Xsub dbuse {
  2129. X   local( @param_array ) = @_;
  2130. X   local( $ret );
  2131. X
  2132. X   $ret = &dbUSE( @param_array );
  2133. X
  2134. X   return $ret;
  2135. X}
  2136. X
  2137. Xsub dberrhandle {
  2138. X   local( $handler ) = @_;
  2139. X   local( $old_handler );
  2140. X
  2141. X   $old_handler = &dbERRHANDLE( $handler );
  2142. X
  2143. X   return $old_handler;
  2144. X}
  2145. X
  2146. Xsub dbmsghandle {
  2147. X   local( $handler ) = @_;
  2148. X   local( $old_handler );
  2149. X
  2150. X   $old_handler = &dbMSGHANDLE( $handler );
  2151. X
  2152. X   return $old_handler;
  2153. X}
  2154. X
  2155. Xsub dbstrcpy {
  2156. X   local( $dbproc ) = @_;
  2157. X   local( $string );
  2158. X
  2159. X   $string = &dbSTRCPY( $dbproc );
  2160. X
  2161. X   return $string;
  2162. X}
  2163. X
  2164. Xsub dbsafestr {
  2165. X   local( @param_array ) = @_;
  2166. X   local( $string );
  2167. X
  2168. X   $string = &dbSAFESTR( @param_array );
  2169. X
  2170. X   return $string;
  2171. X}
  2172. X
  2173. Xsub dbwritetext {
  2174. X   local( @param_array ) = @_;
  2175. X   local( $status );
  2176. X
  2177. X   $status = &dbWRITETEXT( @param_array );
  2178. X
  2179. X   return $status;
  2180. X}
  2181. X
  2182. Xsub DBSETLCHARSET {
  2183. X   local( @param_array ) = @_;
  2184. X   local( $status );
  2185. X
  2186. X   $status = &dbSETLCHARSET( @param_array );
  2187. X
  2188. X   return $status;
  2189. X}
  2190. X
  2191. Xsub DBSETLNATLANG {
  2192. X   local( @param_array ) = @_;
  2193. X   local( $status );
  2194. X
  2195. X   $status = &dbSETLNATLANG( @param_array );
  2196. X
  2197. X   return $status;
  2198. X}
  2199. X
  2200. Xsub DBCURCMD {
  2201. X   local( $dbproc ) = @_;
  2202. X   local( $cmd_no );
  2203. X
  2204. X   $cmd_no = &dbCURCMD( $dbproc );
  2205. X
  2206. X   return $cmd_no;
  2207. X}
  2208. X
  2209. Xsub DBCURROW {
  2210. X   local( $dbproc ) = @_;
  2211. X   local( $row_no );
  2212. X
  2213. X   $row_no = &dbCURROW( $dbproc );
  2214. X
  2215. X   return $row_no;
  2216. X}
  2217. X
  2218. Xsub DBMORECMDS {
  2219. X   local( $dbproc ) = @_;
  2220. X   local( $status );
  2221. X
  2222. X   $status = &dbMORECMDS( $dbproc );
  2223. X
  2224. X   return $status;
  2225. X}
  2226. X
  2227. Xsub DBCMDROW {
  2228. X   local( $dbproc ) = @_;
  2229. X   local( $status );
  2230. X
  2231. X   $status = &dbCMDROW( $dbproc );
  2232. X
  2233. X   return $status;
  2234. X}
  2235. X
  2236. Xsub DBROWS {
  2237. X   local( $dbproc ) = @_;
  2238. X   local( $status );
  2239. X
  2240. X   $status = &dbROWS( $dbproc );
  2241. X
  2242. X   return $status;
  2243. X}
  2244. X
  2245. Xsub DBCOUNT {
  2246. X   local( $dbproc ) = @_;
  2247. X   local( $no_rows );
  2248. X
  2249. X   $no_rows = &dbCOUNT( $dbproc );
  2250. X
  2251. X   return $no_rows;
  2252. X}
  2253. X
  2254. Xsub dbhasretstat {
  2255. X   local( $dbproc ) = @_;
  2256. X   local( $status );
  2257. X
  2258. X   $status = &dbHASRETSTAT( $dbproc );
  2259. X
  2260. X   return $status;
  2261. X}
  2262. X
  2263. Xsub dbretstatus {
  2264. X   local( $dbproc ) = @_;
  2265. X   local( $status );
  2266. X
  2267. X   $status = &dbRETSTATUS( $dbproc );
  2268. X
  2269. X   return $status;
  2270. X}
  2271. X
  2272. Xsub dbmny4add {
  2273. X   local( @param_array ) = @_;
  2274. X   local( @status );
  2275. X
  2276. X   @status = &dbMNY4ADD( @param_array );
  2277. X
  2278. X   return @status;
  2279. X}
  2280. X
  2281. Xsub dbmny4cmp {
  2282. X   local( @param_array ) = @_;
  2283. X   local( $status );
  2284. X
  2285. X   $status = &dbMNY4CMP( @param_array );
  2286. X
  2287. X   return $status;
  2288. X}
  2289. X
  2290. Xsub dbmny4divide {
  2291. X   local( @param_array ) = @_;
  2292. X   local( @status );
  2293. X
  2294. X   @status = &dbMNY4DIVIDE( @param_array );
  2295. X
  2296. X   return @status;
  2297. X}
  2298. X
  2299. Xsub dbmny4minus {
  2300. X   local( @param_array ) = @_;
  2301. X   local( @status );
  2302. X
  2303. X   @status = &dbMNY4MINUS( @param_array );
  2304. X
  2305. X   return @status;
  2306. X}
  2307. X
  2308. Xsub dbmny4mul {
  2309. X   local( @param_array ) = @_;
  2310. X   local( @status );
  2311. X   
  2312. X   @status = &dbMNY4MUL( @param_array );
  2313. X
  2314. X   return @status;
  2315. X}
  2316. X
  2317. Xsub dbmny4sub {
  2318. X   local( @param_array ) = @_;
  2319. X   local( @status );
  2320. X
  2321. X   @status = &dbMNY4SUB( @param_array );
  2322. X
  2323. X   return @status;
  2324. X}
  2325. X
  2326. Xsub dbmny4zero {
  2327. X   local( @param_array ) = @_;
  2328. X   local( @status );
  2329. X
  2330. X   @status = &dbMNY4ZERO( @param_array );
  2331. X
  2332. X   return @status;
  2333. X}
  2334. X
  2335. Xsub dbmnyadd {
  2336. X   local( @param_array ) = @_;
  2337. X   local( @status );
  2338. X
  2339. X   @status = &dbMNYADD( @param_array );
  2340. X
  2341. X   return @status;
  2342. X}
  2343. X
  2344. Xsub dbmnycmp {
  2345. X   local( @param_array ) = @_;
  2346. X   local( $status );
  2347. X
  2348. X   $status = &dbMNYCMP( @param_array );
  2349. X
  2350. X   return $status;
  2351. X}
  2352. X
  2353. Xsub dbmnydivide {
  2354. X   local( @param_array ) = @_;
  2355. X   local( @status );
  2356. X
  2357. X   @status = &dbMNYDIVIDE( @param_array );
  2358. X
  2359. X   return @status;
  2360. X}
  2361. X
  2362. Xsub dbmnyminus {
  2363. X   local( @param_array ) = @_;
  2364. X   local( @status );
  2365. X
  2366. X   @status = &dbMNYMINUS( @param_aray );
  2367. X
  2368. X   return @status;
  2369. X}
  2370. X
  2371. Xsub dbmnymul {
  2372. X   local( @param_array ) = @_;
  2373. X   local( @status );
  2374. X
  2375. X   @status = &dbMNYMUL( @param_array );
  2376. X
  2377. X   return @status;
  2378. X}
  2379. X
  2380. Xsub dbmnysub {
  2381. X   local( @param_array ) = @_;
  2382. X   local( @status );
  2383. X
  2384. X   @status = &dbMNYSUB( @param_array );
  2385. X
  2386. X   return @status;
  2387. X}
  2388. X
  2389. Xsub dbmnyzero {
  2390. X   local( @param_array ) = @_;
  2391. X   local( @status );
  2392. X
  2393. X   @status = &dbMNYZERO( @param_array );
  2394. X
  2395. X   return @status;
  2396. X}
  2397. X
  2398. Xsub dbmnydec {
  2399. X   local( @param_array ) = @_;
  2400. X   local( @status );
  2401. X
  2402. X   @status = &dbMNYDEC( @param_array );
  2403. X
  2404. X   return @status;
  2405. X}
  2406. X
  2407. Xsub dbmnydown {
  2408. X   local( @param_array ) = @_;
  2409. X   local( @status );
  2410. X
  2411. X   @status = &dbMNYDOWN( @param_array );
  2412. X
  2413. X   return @status;
  2414. X}
  2415. X
  2416. Xsub dbmnyinc {
  2417. X   local( @param_array ) = @_;
  2418. X   local( @status );
  2419. X
  2420. X   @status = &dbMNYINC( @param_array );
  2421. X
  2422. X   return @status;
  2423. X}
  2424. X
  2425. Xsub dbmnyinit {
  2426. X   local( @param_array ) = @_;
  2427. X   local( @status );
  2428. X
  2429. X   @status = &dbMNYINIT( @param_array );
  2430. X
  2431. X   return @status;
  2432. X}
  2433. X
  2434. Xsub dbmnymaxneg {
  2435. X   local( @param_array ) = @_;
  2436. X   local( @status );
  2437. X
  2438. X   @status = &dbMNYMAXNEG( @param_array );
  2439. X
  2440. X   return @status;
  2441. X}
  2442. X
  2443. Xsub dbmnymaxpos {
  2444. X   local( @param_array ) = @_;
  2445. X   local( @status );
  2446. X
  2447. X   @status = &dbMNYMAXPOS( @param_array );
  2448. X
  2449. X   return @status;
  2450. X}
  2451. X
  2452. Xsub dbmnyndigit {
  2453. X   local( @param_array ) = @_;
  2454. X   local( @status );
  2455. X
  2456. X   @status = &dbMNYNDIGIT( @param_array );
  2457. X
  2458. X   return @array;
  2459. X}
  2460. X
  2461. Xsub dbmnyscale {
  2462. X   local( @param_array ) = @_;
  2463. X   local( @status );
  2464. X
  2465. X   @status = &dbMNYSCALE( @param_array );
  2466. X
  2467. X   return @status;
  2468. X}
  2469. X
  2470. Xsub dbcoltype
  2471. X{
  2472. X    local( @param_array ) = @_;
  2473. X    local( $status );
  2474. X
  2475. X    $status = &dbCOLTYPE( @param_array );
  2476. X
  2477. X    return $status;
  2478. X}
  2479. X
  2480. Xsub dbcolname
  2481. X{
  2482. X    local( @param_array ) = @_;
  2483. X    local( $status );
  2484. X
  2485. X    $status = &dbCOLNAME( @param_array );
  2486. X
  2487. X    return $status;
  2488. X}
  2489. X
  2490. Xsub dbcollen
  2491. X{
  2492. X    local( @param_array ) = @_;
  2493. X    local( $status );
  2494. X
  2495. X    $status = &dbCOLLEN( @param_array );
  2496. X
  2497. X    return $status;
  2498. X}
  2499. X
  2500. Xsub dbnumcols
  2501. X{
  2502. X    local( @param_array ) = @_;
  2503. X    local( $status );
  2504. X
  2505. X    $status = &dbNUMCOLS( @param_array );
  2506. X
  2507. X    return $status;
  2508. X}
  2509. X
  2510. Xsub dbrecftos
  2511. X{
  2512. X    local( @param_array ) = @_;
  2513. X    local( $status );
  2514. X
  2515. X    $status = &dbRECFTOS( @param_array );
  2516. X
  2517. X    return $status;
  2518. X}
  2519. X
  2520. Xsub BCP_SETL
  2521. X{
  2522. X    local( @param_array ) = @_;
  2523. X    local( $status );
  2524. X
  2525. X    $status = &bcp_SETL( @param_array );
  2526. X
  2527. X    return $status;
  2528. X}
  2529. X
  2530. Xsub bcp_getl
  2531. X{
  2532. X    local( @param_array ) = @_;
  2533. X    local( $status );
  2534. X
  2535. X    $status = &bcp_GETL( @param_array );
  2536. X
  2537. X    return $status;
  2538. X}
  2539. X
  2540. Xsub bcp_init
  2541. X{
  2542. X    local( @param_array ) = @_;
  2543. X    local( $status );
  2544. X
  2545. X    $status = &bcp_INIT( @param_array );
  2546. X
  2547. X    return $status;
  2548. X}
  2549. X
  2550. Xsub bcp_meminit
  2551. X{
  2552. X    local( @param_array ) = @_;
  2553. X    local( $status );
  2554. X
  2555. X    $status = &bcp_MEMINIT( @param_array );
  2556. X
  2557. X    return $status;
  2558. X}
  2559. X
  2560. Xsub bcp_sendrow
  2561. X{
  2562. X    local( @param_array ) = @_;
  2563. X    local( $status );
  2564. X
  2565. X    $status = &bcp_SENDROW( @param_array );
  2566. X
  2567. X    return $status;
  2568. X}
  2569. X
  2570. Xsub bcp_batch
  2571. X{
  2572. X    local( @param_array ) = @_;
  2573. X    local( $status );
  2574. X
  2575. X    $status = &bcp_BATCH( @param_array );
  2576. X
  2577. X    return $status;
  2578. X}
  2579. X
  2580. Xsub bcp_done
  2581. X{
  2582. X    local( @param_array ) = @_;
  2583. X    local( $status );
  2584. X
  2585. X    $status = &bcp_DONE( @param_array );
  2586. X
  2587. X    return $status;
  2588. X}
  2589. X
  2590. Xsub bcp_control
  2591. X{
  2592. X    local( @param_array ) = @_;
  2593. X    local( $status );
  2594. X
  2595. X    $status = &bcp_CONTROL( @param_array );
  2596. X
  2597. X    return $status;
  2598. X}
  2599. X
  2600. Xsub bcp_columns
  2601. X{
  2602. X    local( @param_array ) = @_;
  2603. X    local( $status );
  2604. X
  2605. X    $status = &bcp_COLUMNS( @param_array );
  2606. X
  2607. X    return $status;
  2608. X}
  2609. X
  2610. Xsub bcp_colfmt
  2611. X{
  2612. X    local( @param_array ) = @_;
  2613. X    local( $status );
  2614. X
  2615. X    $status = &bcp_COLFMT( @param_array );
  2616. X
  2617. X    return $status;
  2618. X}
  2619. X
  2620. Xsub bcp_exec
  2621. X{
  2622. X    local( @param_array ) = @_;
  2623. X    local( $status );
  2624. X
  2625. X    $status = &bcp_EXEC( @param_array );
  2626. X
  2627. X    return $status;
  2628. X}
  2629. X
  2630. Xsub bcp_readfmt
  2631. X{
  2632. X    local( @param_array ) = @_;
  2633. X    local( $status );
  2634. X
  2635. X    $status = &bcp_READFMT( @param_array );
  2636. X
  2637. X    return $status;
  2638. X}
  2639. X
  2640. Xsub bcp_writefmt
  2641. X{
  2642. X    local( @param_array ) = @_;
  2643. X    local( $status );
  2644. X
  2645. X    $status = &bcp_WRITEFMT( @param_array );
  2646. X
  2647. X    return $status;
  2648. X}
  2649. X
  2650. X# ----- end of sybdb_redefs.pl -----
  2651. X
  2652. X1;
  2653. X
  2654. END_OF_FILE
  2655.   if test 9685 -ne `wc -c <'lib/sybdb_redefs.pl'`; then
  2656.     echo shar: \"'lib/sybdb_redefs.pl'\" unpacked with wrong size!
  2657.   fi
  2658.   # end of 'lib/sybdb_redefs.pl'
  2659. fi
  2660. if test -f 'lib/sybperl.pl' -a "${1}" != "-c" ; then 
  2661.   echo shar: Will not clobber existing file \"'lib/sybperl.pl'\"
  2662. else
  2663.   echo shar: Extracting \"'lib/sybperl.pl'\" \(1865 characters\)
  2664.   sed "s/^X//" >'lib/sybperl.pl' <<'END_OF_FILE'
  2665. X;#     @(#)sybperl.pl    1.5    9/23/93
  2666. X
  2667. X;# This file, when interpreted, sets the appropriate environment
  2668. X;# variables for Sybase's use DB-Library & isql.
  2669. X;#
  2670. X;# usage:
  2671. X;#    require 'sybperl.pl';
  2672. X;#
  2673. X;# We don't set the environment if it is already set.
  2674. X
  2675. Xrequire 'sybdb.ph';
  2676. X
  2677. X$ENV{'SYBASE'} = "/usr/local/sybase" unless $ENV{'SYBASE'};
  2678. X$ENV{'DSQUERY'}= "SYBASE" unless $ENV{'DSQUERY'};
  2679. X$ENV{'PATH'}="$ENV{'PATH'}:$ENV{'SYBASE'}/bin" unless $ENV{'PATH'} =~ /$ENV{'SYBASE'}/;
  2680. X
  2681. X# Message and error handlers.
  2682. X
  2683. Xsub message_handler
  2684. X{
  2685. X    local ($db, $message, $state, $severity, $text, $server, $procedure, $line)
  2686. X    = @_;
  2687. X
  2688. X    if ($severity > 0)
  2689. X    {
  2690. X    print STDERR ("Sybase message ", $message, ", Severity ", $severity,
  2691. X           ", state ", $state);
  2692. X    print STDERR ("\nServer `", $server, "'") if defined ($server);
  2693. X    print STDERR ("\nProcedure `", $procedure, "'") if defined ($procedure);
  2694. X    print STDERR ("\nLine ", $line) if defined ($line);
  2695. X    print STDERR ("\n    ", $text, "\n\n");
  2696. X
  2697. X# &dbstrcpy returns the command buffer.
  2698. X
  2699. X    local ($lineno) = 1;    # 
  2700. X    foreach $row (split (/\n/, &dbstrcpy ($db)))
  2701. X    {
  2702. X        print STDERR (sprintf ("%5d", $lineno ++), "> ", $row, "\n");
  2703. X    }
  2704. X    }
  2705. X    elsif ($message == 0)
  2706. X    {
  2707. X    print STDERR ($text, "\n");
  2708. X    }
  2709. X    
  2710. X    0;
  2711. X}
  2712. X
  2713. Xsub error_handler {
  2714. X    # Check the error code to see if we should report this.
  2715. X    if ($_[2] != &SYBESMSG) {
  2716. X    local ($db, $severity, $error, $os_error, $error_msg, $os_error_msg)
  2717. X        = @_;
  2718. X    print STDERR ("Sybase error: ", $error_msg, "\n");
  2719. X    print STDERR ("OS Error: ", $os_error_msg, "\n") if defined ($os_error_msg);
  2720. X    }
  2721. X
  2722. X    &INT_CANCEL;
  2723. X}
  2724. X
  2725. X
  2726. Xif( defined(&dbmsghandle))    # Is this a modern version of sybperl? ;-)
  2727. X{
  2728. X    &dbmsghandle ("message_handler"); # Some user defined error handlers
  2729. X    &dberrhandle ("error_handler");
  2730. X}
  2731. X
  2732. X
  2733. Xif (defined($SybPackageBug) && $SybPackageBug == 1)
  2734. X{
  2735. X    require 'sybdb_redefs.pl';
  2736. X}
  2737. X
  2738. X
  2739. X1;
  2740. X
  2741. END_OF_FILE
  2742.   if test 1865 -ne `wc -c <'lib/sybperl.pl'`; then
  2743.     echo shar: \"'lib/sybperl.pl'\" unpacked with wrong size!
  2744.   fi
  2745.   # end of 'lib/sybperl.pl'
  2746. fi
  2747. if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  2748.   echo shar: Will not clobber existing file \"'patchlevel.h'\"
  2749. else
  2750.   echo shar: Extracting \"'patchlevel.h'\" \(81 characters\)
  2751.   sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
  2752. X
  2753. X/*     @(#)patchlevel.h    1.5    5/12/94     */
  2754. X
  2755. X#define VERSION 1
  2756. X#define PATCHLEVEL 11
  2757. X
  2758. X
  2759. END_OF_FILE
  2760.   if test 81 -ne `wc -c <'patchlevel.h'`; then
  2761.     echo shar: \"'patchlevel.h'\" unpacked with wrong size!
  2762.   fi
  2763.   # end of 'patchlevel.h'
  2764. fi
  2765. if test -f 'sybperl.1' -a "${1}" != "-c" ; then 
  2766.   echo shar: Will not clobber existing file \"'sybperl.1'\"
  2767. else
  2768.   echo shar: Extracting \"'sybperl.1'\" \(11205 characters\)
  2769.   sed "s/^X//" >'sybperl.1' <<'END_OF_FILE'
  2770. X.\".po 4
  2771. X.\"    @(#)sybperl.1    1.6    6/8/94
  2772. X.TH SYBPERL 1 "25 May 1994"
  2773. X.ad
  2774. X.nh
  2775. X.SH NAME
  2776. Xsybperl \- Perl access to Sybase databases
  2777. X.SH SYNOPSIS
  2778. X.nf
  2779. X$ret     = &dbcancel([$dbproc])
  2780. X$ret     = &dbcanquery([$dbproc])
  2781. X$ret     = &dbcmd([$dbproc,] $sql_cmd)
  2782. X       &dbclose([$dbproc])
  2783. X$len     = &dbcollen([$dbproc], $colid)
  2784. X$name    = &dbcolname([$dbproc], $colid)
  2785. X$type    = &dbcoltype([$dbproc], $colid)
  2786. X$ret     = &dberrhandle($handler)
  2787. X$ret     = &dbexit()
  2788. X$ret     = &dbfreebuf([$dbproc])
  2789. X$status  = &dbhasretstat([$dbproc])
  2790. X$dbproc  = &dblogin([$user[, $pwd[, $server]]])
  2791. X$ret     = &dbmsghandle($handler)
  2792. X@data    = &dbnextrow([$dbproc [, $doAssoc]])
  2793. X$count   = &dbnumcols([$dbproc])
  2794. X$dbproc1 = &dbopen([$server])
  2795. X$ret     = &dbresults([$dbproc])
  2796. X@data    = &dbretdata([$dbproc [, $doAssoc]])
  2797. X$status  = &dbretstatus([$dbproc])
  2798. X$string  = &dbsafestr($dbproc, $instring [,$quote_char])
  2799. X$ret       = &dbsetopt($dbproc, $option, $char_param [,$int_param])
  2800. X$ret     = &dbsqlexec([$dbproc])
  2801. X$string  = &dbstrcpy([$dbproc])
  2802. X$ret     = &dbuse([$dbproc,] $database)
  2803. X$status  = &dbwritetext($dbproc_1, $col_name, $dbproc_2, $select_col, $text)
  2804. X$ret     = &DBCURCMD([$dbproc])
  2805. X$status  = &DBMORECMD([$dbproc])
  2806. X$status  = &DBCMDROW([$dbproc])
  2807. X$status  = $DBROWS([$dbproc])
  2808. X$ret     = $DBCOUNT([$dbproc])
  2809. X$ret     = $DBSETLCHARSET(char-set)
  2810. X$ret     = $DBSETLNATLANG(language)
  2811. X
  2812. X($status, $sum)    = &dbmny4add([$dbproc,] $m1, $m2)
  2813. X$status        = &dbmny4cmp([$dbproc,] $m1, $m2)
  2814. X($status, $quotient)    = &dbmny4divide([$dbproc,] $m1, $m2)
  2815. X($status, $dest)    = &dbmny4minus([$dbproc,] $source)
  2816. X($status, $product)    = &dbmny4mul([$dbproc,] $m1, $m2)
  2817. X($status, $difference)    = &dbmny4sub([$dbproc,] $m1, $m2)
  2818. X($status, $ret)    = &dbmny4zero([$dbproc])
  2819. X($status, $sum)    = &dbmnyadd([$dbproc,] $m1, $m2)
  2820. X$status        = &dbmnycmp([$dbproc,] $m1, $m2)
  2821. X($status, $ret)    = &dbmnydec([$dbproc,] $m1)
  2822. X($status, $quotient)    = &dbmnydivide([$dbproc,] $m1, $m2)
  2823. X($status, $ret, $remainder) = &dbmnydown([$dbproc,] $m1, $divisor)
  2824. X($status, $ret)    = &dbmnyinc([$dbproc,] $m1)
  2825. X($status, $ret, $remain)    = &dbmnyinit([$dbproc,] $m1, $trim)
  2826. X($status, $ret)        = &dbmnymaxneg([$dbproc])
  2827. X($status, $ret)        = &dbmnymaxpos([$dbproc])
  2828. X($status, $dest) = &dbmnyminus([$dbproc,] $source)
  2829. X($status, $product)    = &dbmnymul([$dbproc,] $m1, $m2)
  2830. X($status, $m1, $digits, $remain)    = &dbmnyndigit([$dbproc,] $m1)
  2831. X($status, $ret)        = &dbmnyscale([$dbproc,] $m1, $multiplier,
  2832. X                $addend)
  2833. X($status, $difference)    = &dbmnysub([$dbproc,] $m1, $m2)
  2834. X($status, $ret)    = &dbmnyzero([$dbproc])
  2835. X
  2836. X$status    = &BCP_SETL($state)
  2837. X$status = &bcp_getl;
  2838. X$status = &bcp_init([$dbproc,] $tblname, $hostfile, $errfile, $dir)
  2839. X$status = &bcp_meminit([$dbproc,] $numcols)
  2840. X$status = &bcp_sendrow($dbproc, $col1, $col2, ...)
  2841. X$status = &bcp_batch([$dbproc])
  2842. X$status = &bcp_done([$dbproc])
  2843. X$status = &bcp_control([$dbproc,] $field, $value)
  2844. X$status = &bcp_columns([$dbproc,] $host_columns)
  2845. X$status = &bcp_colfmt([$dbproc,] $host_column, $host_type,
  2846. X              $host_prefixlen, $host_collen, $host_term,
  2847. X              $host_termlen, $table_colnum)
  2848. X($status, $rows_copied) = &bcp_exec([$dbproc])
  2849. X$status = &bcp_readfmt([$dbproc,] $filename)
  2850. X$status = &bcp_writefmt([$dbproc,] $filename)
  2851. X
  2852. X$SUCCEED        $MORE_ROWS            $EXCEPTION    $EXPROGRAM
  2853. X$FAIL            $REG_ROW            $EXSIGNAL    $EXSERVER
  2854. X$NO_MORE_ROWS    $BUF_FULL            $EXINFO    $EXCOMM
  2855. X$NO_MORE_RESULTS    $NO_MORE_PARAMS        $EXDBLIB    $EXTIME
  2856. X$ComputeId        $DBSAVE            $EXFORMS    $EXFATAL
  2857. X$DBstatus        $DBNOSAVE            $EXUSER
  2858. X$SybperlVer        $DBNOERR            $EXLOOKUP
  2859. X$STDEXIT        $DB_PASSTHRU_MORE    $EXSCREENIO
  2860. X$ERREXIT        $DB_PASSTHRU_EOM        $EXCLIPBOARD
  2861. X$INT_EXIT        $DBNOPROC            $EXNONFATAL
  2862. X$INT_CONTINUE                    $EXCONVERSION
  2863. X$INT_CANCEL                        $EXRESOURCE
  2864. X$INT_TIMEOUT                        $EXCONSISTENCY
  2865. X$DB_IN        $DB_OUT
  2866. X$BCPMAXERRS    $BCPFIRST    $BCPLAST    $BCPBATCH
  2867. X$DBTRUE        $DBFALSE
  2868. X$SybPackageBug
  2869. X$dbNullIsUndef    $dbKeepNumeric    $dbBin0x
  2870. X.fi
  2871. X.SH DESCRIPTION
  2872. X\fBSybperl\fP is a version of \fIPerl\fP which has been extended (via
  2873. Xthe \fIusersubs\fP feature) to allow access to \fISybase\fP databases.
  2874. X
  2875. X\fBSybperl\fP maps a subset of the \fISybase
  2876. XDB-Library\fP API to \fIPerl\fP. The usage of these functions is the same
  2877. Xas in \fIDB-Library\fP, unless specifically noted.
  2878. X
  2879. X\fBDifferences with DB-Library:\fP
  2880. X
  2881. X\fB&dblogin\fP takes 3 optional arguements (the userid, the
  2882. Xpassword and the server to connect to). These default to the Unix
  2883. Xuserid, the null password and the default server (from the DSQUERY
  2884. Xenvironment variable).
  2885. X
  2886. X\fB&dblogin\fP returns a \fBDBPROCESS\fP, not a \fBLOGINREC\fP. This
  2887. Xsimplifies the call to open a connection to a Sybase dataserver
  2888. Xsomewhat. If the login fails for any reason \fB&dblogin\fP returns -1.
  2889. X\fB&dblogin\fP can be called multiple times to login to different
  2890. Xservers, or to login as several users simultaneously.
  2891. X
  2892. XFurther \fBDBPROCESSes\fP can be opened using
  2893. X\fB&dbopen([$server])\fP, using the login information from the
  2894. Xlast call to \fB&dblogin()\fP. The number of simultaneous DBPROCESSes
  2895. Xis limited to 25 (This can be changed by altering a #define in sybperl.c).
  2896. X
  2897. XThe \fB$dbproc\fP parameter used by most subroutines is optional,
  2898. Xand defaults to the DBPROCESS returned
  2899. Xby the first call to \fB&dblogin\fP (exceptions: \fB&dbsafestr()\fP,
  2900. X\fB&dbwritetext()\fP and \fB&bcp_sendrow()\fP require explicit \fB$dbproc\fP parameters.)
  2901. X
  2902. X\fB&dbnextrow\fP returns an array of formatted data, based on the
  2903. Xdatatype of the corresponding columns. \fB&dbnextrow\fP sets the
  2904. Xvariable \fB$ComputeId\fP when the result row is a computed row (the
  2905. Xresult of a \fIcompute by\fP clause). If the optional \fB$doAssoc\fP
  2906. Xparameter is non-zero \fB&dbnextrow\fP returns an
  2907. Xassociative array keyed on the column name of each returned field. If
  2908. Xthe column name is null (as for example in the case of an aggregate),
  2909. Xthen \fB&dbnextrow\fP assigns a column name based on the column number.
  2910. X
  2911. X\fB&dbretdata\fP returns an array of the parameters
  2912. Xdeclared as \fBOUTput\fP in an \fBEXEC\fP stored procedure statement.
  2913. XIf the ooptional \fB$doAssoc\fP parameter is non-zero, then an
  2914. Xassociative array keyed on the name of the parameters is returned
  2915. X(again, if the parameters are unnamed, the key is based on the
  2916. Xparamter number). A single call will
  2917. Xreturn all the parameters for the last \fBEXEC\fP statement.
  2918. X
  2919. X\fB&dbsafestr\fP takes a string literal ' or " as the third [optional] argument
  2920. Xand means \fBDBSINGLE\fP or \fBDBDOUBLE\fP, respectively.
  2921. XOmission of the third argument means \fBDBBOTH\fP.
  2922. X
  2923. XIn order to simplify its use somewhat, the calling sequence of
  2924. X\fB&dbwritetext\fP has been changed. \fI$select_proc\fP and
  2925. X\fI$select_col\fP are the dbproc and column number of a currently
  2926. Xactive query. Logging is always off.
  2927. X
  2928. XNote that all DBMONEY routines which in the C version take pointers to
  2929. Xarguments (in order to return values) return these values in an array
  2930. Xinstead (eg: status = dbmnyadd(dbproc, m1, m2, result) becomes
  2931. X($status, $result) = &dbmnyadd($dbproc, $m1, $m2))
  2932. X
  2933. XCopying data from program variables into a Sybase table using BCP has
  2934. Xbeen implemented in a slightly different manner. Instead of using
  2935. Xbcp_bind(), you need to call &bcp_meminit() to determine the number of
  2936. Xcolumns that will be sent to the server, and the call &bcp_sendrow()
  2937. Xwith the data for each row (see \fBEXAMPLES\fP, below). Passing
  2938. X\fBundef\fP as one of the data
  2939. Xvalues will result in a \fBNULL\fP value being sent to the server for
  2940. Xthat column.
  2941. X
  2942. X\fBVariables:\fP
  2943. X
  2944. X\fBSybperl\fP defines a number of Read-Only variables, and three
  2945. XRead-Write variables. Most of the variables correspond to #define's in
  2946. Xthe \fIOpenClient\fP include files (see the Sybase documentation for
  2947. Xmore information).
  2948. X
  2949. XThe \fBSybperl\fP specific variables are:
  2950. X
  2951. X\fB$ComputeId\fP \- Set by \fB&dbnextrow\fP when it processes a
  2952. X\fIcompute row\fP as opposed to a normal results row.
  2953. X.br
  2954. X\fB$DBstatus\fP \- The status returned by the last call to
  2955. X\fBdbnextrow()\fP.
  2956. X.br
  2957. X\fB$SybperlVer\fP \- The Sybperl release version.
  2958. X.br
  2959. X\fB$SybPackageBug\fP \- Set to TRUE if \fBSybperl\fP was compiled with
  2960. Xthe option to circumvent a bug in \fBPerl's\fP implementation of
  2961. Xpackages. This variable is undefined otherwise.
  2962. X.br
  2963. X\fB$dbNullIsUndef\fP \- This variable controls whether NULL values
  2964. Xreturned from a query will be returned as the string '\fINULL\fP' (the
  2965. Xdefault) or as the \fBPerl\fP \fIundef\fP value.
  2966. X.br
  2967. X\fB$dbKeepNumeric\fP \- This variable controls whether numeric
  2968. Xdatatypes returned by queries are converted to strings (the default)
  2969. Xor left in native format.
  2970. X.br
  2971. X\fB$dbBin0x\fP \- This variable controls whether variables of type
  2972. X\fBSYBBINARY\fP are returned with a leading \fB0x\fP or not (the
  2973. Xdefault).
  2974. X
  2975. XThese last three variables are all boolean.
  2976. X
  2977. X.SH "UNIMPLEMENTED FEATURES"
  2978. X
  2979. X\fB&dbfcmd\fP is not implemented, but can be emulated by using
  2980. X\fIsprintf\fP as in \fI&dbcmd($dbproc, sprintf("%d", $num_val))\;\fP
  2981. X
  2982. X.SH EXAMPLES
  2983. X
  2984. XUsing &dbretdata():
  2985. X
  2986. X.nf
  2987. X    &dbcmd($dbproc, "declare @data int\n");
  2988. X    &dbcmd($dbproc, "exec my_stored_proc @data out\n");
  2989. X    &dbsqlexec($dbproc);
  2990. X    &dbresults($dbproc);
  2991. X    while(&dbnextrow($dbproc))
  2992. X    {
  2993. X        ;    # empty loop...
  2994. X    }
  2995. X    ($ret) = &dbretdata($dbproc);
  2996. X.fi
  2997. X
  2998. XDoing a Bulk Copy from program variables into a Sybase table:
  2999. X
  3000. X.nf
  3001. X    &BCP_SETL($DBTRUE);
  3002. X    $dbproc = &dblogin;
  3003. X    &bcp_init($dbproc, "test.dbo.t2", '', 'bcp.err', $DB_IN);
  3004. X    &bcp_meminit($dbproc, 3);   # we wish to copy three columns into
  3005. X                    # the 't2' table
  3006. X    while(<>)
  3007. X    {
  3008. X        chop;
  3009. X        @dat = split(' ', $_);
  3010. X        &bcp_sendrow($dbproc, @dat);
  3011. X    }
  3012. X    $ret = &bcp_done($dbproc);
  3013. X.fi
  3014. X
  3015. X
  3016. X
  3017. X.SH OPTIONS
  3018. X
  3019. XSee the \fIPerl(1)\fP manual page.
  3020. X
  3021. X.SH BUGS
  3022. X
  3023. XMemory usage can become very large in certain conditions when
  3024. Xusing a version of Perl prior to 4.035. This
  3025. Xcan be circumvented - see the BUGS file in the Sybperl distribution.
  3026. X
  3027. XIf \fB&dbnextrow\fP encounters a datatype that it does not know about,
  3028. Xit tries to convert it to SYBCHAR, and to store it in a 256 byte
  3029. Xbuffer - without checking for overflow.
  3030. X
  3031. XThe handling of multiple logins isn't really clean. A call to
  3032. X\fB&dblogin\fP sets the values for the User name and Password. These
  3033. Xvalues are remembered - and used in calls to \fB&dbopen\fP - until
  3034. Xthey are changed in a new call to \fB&dblogin()\fP. It is possible to
  3035. Xavoid the use of \fB&dbopen\fP alltogether, and simply call
  3036. X\fB&dblogin\fP each time a new \fBDBPROCESS\fP is required.
  3037. X
  3038. XThis man page only covers \fBdifferences\fP between \fBsybperl\fP's
  3039. Ximplementation of the API and \fBDBlibrary\fP itself. A form of
  3040. Xtutorial in using \fBsybperl\fP is probably needed.
  3041. X
  3042. X.SH FILES
  3043. X
  3044. X\fI$PERLLIB/sybperl.pl\fP should be called in all \fBsybperl\fP
  3045. Xscripts to set the correct environment variables used by DB-Library.
  3046. XA sample \fI$PERLLIB/sybdb.ph\fP is provided with sybperl. You may
  3047. Xwant to use \fBh2ph\fP to add definitions to this file.
  3048. X
  3049. X.SH "SEE ALSO"
  3050. X
  3051. X\fIPerl(1L), Sybase Open Client DB Library Reference Manual, h2ph(1L).\fP
  3052. X
  3053. X.SH AUTHOR
  3054. X
  3055. X.nf
  3056. XMichael Peppler, ITF Management SA \- mpeppler@itf.ch
  3057. X.fi
  3058. XJeffrey Wong (jtw@comdyn.cdsyd.oz.au) contributed the
  3059. XOpenClient R4.6.1 DBMONEY routines
  3060. XBrent Milnor (brent@oceania.com) contributed &dbwritetext().
  3061. XEric Fifer (egf@sbi.com) contributed corrections to the
  3062. X&dblogin()/&dbopen() sequence.
  3063. XMark Lawrence (mark@drd.com) contributed &dbsafestr().
  3064. XMichael Bloom (mb@tti.com) contributed code to handle SYBIMAGE data.
  3065. XDon Preuss (donp@niaid.nih.gov) contributed the &dbcolXXX() calls.
  3066. X
  3067. END_OF_FILE
  3068.   if test 11205 -ne `wc -c <'sybperl.1'`; then
  3069.     echo shar: \"'sybperl.1'\" unpacked with wrong size!
  3070.   fi
  3071.   # end of 'sybperl.1'
  3072. fi
  3073. if test ! -d 't' ; then
  3074.     echo shar: Creating directory \"'t'\"
  3075.     mkdir 't'
  3076. fi
  3077. if test -f 't/sbex.pl' -a "${1}" != "-c" ; then 
  3078.   echo shar: Will not clobber existing file \"'t/sbex.pl'\"
  3079. else
  3080.   echo shar: Extracting \"'t/sbex.pl'\" \(5086 characters\)
  3081.   sed "s/^X//" >'t/sbex.pl' <<'END_OF_FILE'
  3082. X#!../sybperl
  3083. X
  3084. X
  3085. X@nul = ('not null','null');
  3086. X@sysdb = ('master', 'model', 'tempdb');
  3087. X
  3088. Xunshift(@INC, '../lib');
  3089. X
  3090. Xrequire "sybperl.pl";
  3091. X
  3092. Xprint "Sybperl version $SybperlVer\n\n";
  3093. Xprint "PACKAGE_BUG is defined - sybdb_redefs.pl has been loaded\n" if (defined($SybPackageBug) && $SybPackageBug == 1);
  3094. X
  3095. Xprint "This script tests some of sybperl's functions, and prints out\n";
  3096. Xprint "description of the databases that are defined in your Sybase\n";
  3097. Xprint "dataserver.\n\n";
  3098. X
  3099. X
  3100. X$dbproc = &dblogin("sa");    # Login to sybase
  3101. X&dbmsghandle ("message_handler"); # Some user defined error handlers
  3102. X&dberrhandle ("error_handler");
  3103. X
  3104. X$dbproc2 = &dbopen;        # Get a second dbprocess, so that we can select from several
  3105. X                                # chanels simultaneously. We could code things so that this
  3106. X                # feature is unnecessary, but it's good to exercise it.
  3107. X
  3108. X                # First, find out what databases exist:
  3109. X&dbcmd($dbproc, "select name from sysdatabases order by crdate\n");
  3110. X&dbsqlexec($dbproc);
  3111. X&dbresults($dbproc);
  3112. X
  3113. Xdatabase: while((@db = &dbnextrow($dbproc)))
  3114. X{
  3115. X    foreach $nm (@sysdb)
  3116. X    {
  3117. X    if($db[0] =~ /$nm/)
  3118. X    {
  3119. X        print "'$db[0]' is a system database\n";
  3120. X        next database;
  3121. X    }
  3122. X    }
  3123. X    print "Finding user tables in user database $db[0]...";
  3124. X
  3125. X    &dbcmd($dbproc2, "select o.name, u.name, o.id\n"); # 
  3126. X    &dbcmd($dbproc2, "from $db[0].dbo.sysobjects o, $db[0].dbo.sysusers u\n");
  3127. X    &dbcmd($dbproc2, "where o.type = 'U' and u.uid = o.uid\n");
  3128. X    &dbcmd($dbproc2, "order by o.name\n");
  3129. X
  3130. X    &dbsqlexec($dbproc2);
  3131. X    &dbresults($dbproc2);
  3132. X
  3133. X    while((@dat = &dbnextrow($dbproc2)))
  3134. X    {
  3135. X    $tab = join('@', @dat);    # Save the information
  3136. X    push(@tables, $tab);    # for later use...
  3137. X    }
  3138. X    print "Done.\n";
  3139. X
  3140. X    print "Finding user defined datatypes in database $db[0]...\n";
  3141. X
  3142. X    &dbcmd($dbproc2, "select s.length,substring(s.name,1,30),substring(st.name,1,30)\n");
  3143. X    &dbcmd($dbproc2, "from $db[0].dbo.systypes s, $db[0].dbo.systypes st\n");
  3144. X    &dbcmd($dbproc2, "where  st.type = s.type\n");
  3145. X    &dbcmd($dbproc2, "and s.usertype > 100 and st.usertype < 100 and st.usertype != 18\n");
  3146. X    &dbsqlexec($dbproc2);
  3147. X    &dbresults($dbproc2);
  3148. X
  3149. X    while((@dat = &dbnextrow($dbproc2)))
  3150. X    {
  3151. X    print "sp_addtype $dat[1],";
  3152. X    if ($dat[2] =~ /char|binary/)
  3153. X    {
  3154. X        print "'$dat[2]($dat[0])'";
  3155. X    }
  3156. X    else
  3157. X    {
  3158. X        print "$dat[2]";
  3159. X    }
  3160. X    print "\n";
  3161. X
  3162. X    }
  3163. X    print "Done.\n";
  3164. X
  3165. X    print "Now we find the table definition for each user table\nin database $db[0]...\n";
  3166. X
  3167. X    foreach $ln (@tables)        # For each line in the list
  3168. X    {
  3169. X    @tab = split('@',$ln);
  3170. X
  3171. X    &dbcmd($dbproc2, "select Column_name = c.name, \n");
  3172. X    &dbcmd($dbproc2, "       Type = t.name, \n");
  3173. X    &dbcmd($dbproc2, "       Length = c.length, \n");
  3174. X    &dbcmd($dbproc2, "       Nulls = convert(bit, (c.status & 8))\n");
  3175. X    &dbcmd($dbproc2, "from   $db[0].dbo.syscolumns c, $db[0].dbo.systypes t\n");
  3176. X    &dbcmd($dbproc2, "where  c.id = $tab[2]\n");
  3177. X    &dbcmd($dbproc2, "and    c.usertype *= t.usertype\n");
  3178. X    
  3179. X    &dbsqlexec($dbproc2);
  3180. X    &dbresults($dbproc2);
  3181. X
  3182. X    print "\nTABLE $db[0].$tab[1].$tab[0]\n ("; 
  3183. X    $first = 1;
  3184. X    while((@field = &dbnextrow($dbproc2)))
  3185. X    {
  3186. X        print ",\n" if !$first;        # add a , and a \n if not first field in table
  3187. X        
  3188. X        print "\t$field[0] \t$field[1]";
  3189. X        print "($field[2])" if $field[1] =~ /char|bin/;
  3190. X        print " $nul[$field[3]]";
  3191. X
  3192. X        $first = 0 if $first;
  3193. X    }
  3194. X    print " )\n";
  3195. X
  3196. X# now get the indexes...
  3197. X#
  3198. X    print "\nIndexes on $db[0].$tab[1].$tab[0]...\n\n";
  3199. X    &dbuse($dbproc2, $db[0]);
  3200. X    &dbcmd($dbproc2, "sp_helpindex '$tab[1].$tab[0]'\n");
  3201. X
  3202. X    &dbsqlexec($dbproc2);
  3203. X    &dbresults($dbproc2);
  3204. X
  3205. X    while((@field = &dbnextrow($dbproc2)))
  3206. X    {
  3207. X        print "unique " if $field[1] =~ /unique/;
  3208. X        print "clustered " if $field[1] =~ /^clust/;
  3209. X        print "index $field[0]\n";
  3210. X        @col = split(/,/,$field[2]);
  3211. X        print "on $db[0].$tab[1].$tab[0] (";
  3212. X        $first = 1;
  3213. X        foreach $ln1 (@col)
  3214. X        {
  3215. X        print ", " if !$first;
  3216. X        $first = 0;
  3217. X        print "$ln1";
  3218. X        }
  3219. X        print ")\n";
  3220. X    }
  3221. X    print "\nDone.\n";
  3222. X    }
  3223. X    &dbuse($dbproc2, "master");
  3224. X    @tables = ();
  3225. X}
  3226. X
  3227. X&dbexit;
  3228. X
  3229. X
  3230. X# Message and error handlers.
  3231. X
  3232. Xsub message_handler
  3233. X{
  3234. X    local ($db, $message, $state, $severity, $text, $server, $procedure, $line)
  3235. X    = @_;
  3236. X
  3237. X    if ($severity > 0)
  3238. X    {
  3239. X    print ("Sybase message ", $message, ", Severity ", $severity,
  3240. X           ", state ", $state);
  3241. X    print ("\nServer `", $server, "'") if defined ($server);
  3242. X    print ("\nProcedure `", $procedure, "'") if defined ($procedure);
  3243. X    print ("\nLine ", $line) if defined ($line);
  3244. X    print ("\n    ", $text, "\n\n");
  3245. X
  3246. X# &dbstrcpy returns the command buffer.
  3247. X
  3248. X    local ($lineno) = 1;    # 
  3249. X    foreach $row (split (/\n/, &dbstrcpy ($db)))
  3250. X    {
  3251. X        print (sprintf ("%5d", $lineno ++), "> ", $row, "\n");
  3252. X    }
  3253. X    }
  3254. X    elsif ($message == 0)
  3255. X    {
  3256. X    print ($text, "\n");
  3257. X    }
  3258. X    
  3259. X    0;
  3260. X}
  3261. X
  3262. Xsub error_handler {
  3263. X    # Check the error code to see if we should report this.
  3264. X    if ($_[2] != &SYBESMSG) {
  3265. X    local ($db, $severity, $error, $os_error, $error_msg, $os_error_msg)
  3266. X        = @_;
  3267. X    print ("Sybase error: ", $error_msg, "\n");
  3268. X    print ("OS Error: ", $os_error_msg, "\n") if defined ($os_error_msg);
  3269. X    }
  3270. X
  3271. X    &INT_CANCEL;
  3272. X}
  3273. X
  3274. X
  3275. X
  3276. END_OF_FILE
  3277.   if test 5086 -ne `wc -c <'t/sbex.pl'`; then
  3278.     echo shar: \"'t/sbex.pl'\" unpacked with wrong size!
  3279.   fi
  3280.   chmod +x 't/sbex.pl'
  3281.   # end of 't/sbex.pl'
  3282. fi
  3283. echo shar: End of archive 1 \(of 2\).
  3284. cp /dev/null ark1isdone
  3285. MISSING=""
  3286. for I in 1 2 ; do
  3287.     if test ! -f ark${I}isdone ; then
  3288.     MISSING="${MISSING} ${I}"
  3289.     fi
  3290. done
  3291. if test "${MISSING}" = "" ; then
  3292.     echo You have unpacked both archives.
  3293.     rm -f ark[1-9]isdone
  3294. else
  3295.     echo You still must unpack the following archives:
  3296.     echo "        " ${MISSING}
  3297. fi
  3298. exit 0
  3299. exit 0 # Just in case...
  3300.