#! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'CHANGES' <<'END_OF_FILE' XChanges from 1.1 to 1.2 X X$isql_code evaluates to a string error message when evaluated in a Xstring context, to a number in a numeric context. X XSupport for Byte and Text (Blobs), on insert and select, but not on Xupdate :--( X XParamaterised statements (`?'s in string statements). Undef values Xequate to nulls if supplied as separate parameters. Blobs are also Xpassed in this way. X XNew function &isql_titles($cid) returns an array of column names Xassociated with the open cursor $cid or the number of fields in a Xscalar context. X Xminor bug fix re. execute `sometimes' freeing a database statement. X XAdded a man page. X XChanged error on ``too many open cursors'' from -104 (too many open files) Xto -276 (cursor not found). X XAdded &isql_databases() - returns list of databases. X XNew variable $isql_attrib replaces $isql_maxcursors. X X&isql_open() now accepts non-select statements and returns a Xstatement id which can be executued using &isql_execute($id), with Xoptional parameters (&isql_execute() still accepts string statements Xto execute immediately, after parameter substitution). X XNew function &isql_type($id) returns the type of a statement id created Xby &isql_open(), as a string. For example 'SELECT'. X XNew function &isql_columns($id) returns a list of the data types associated Xwith the $id. X X&isql_fetch() can now accept a string select statement - opens a cursor, Xfetches the first row, closes the cursor, and returns the row. X XNew variable $isql_autoclose if set non-zero automatically closes select Xcursors on reaching last row. X XRenamed Winthrop Chans isql script to sql (apologies in advance) and Xextended it somewhat to demo 1.2 features (and to be more useful). X Xadded &isql_statement($cid) - returns associated statement. X Xadded $isql_database - current database name. X $isql_transactions - true if database has transactions. X $isql_ansi - true if database is mode ANSI X $isql_online - true if database is OnLine X XAdded a super-fast :-) finderr.pl library module to replace the Xrather slow informix supplied script. END_OF_FILE if test 2043 -ne `wc -c <'CHANGES'`; then echo shar: \"'CHANGES'\" unpacked with wrong size! fi # end of 'CHANGES' fi if test -f 'LICENSE' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'LICENSE'\" else echo shar: Extracting \"'LICENSE'\" \(17982 characters\) sed "s/^X//" >'LICENSE' <<'END_OF_FILE' X GNU GENERAL PUBLIC LICENSE X Version 2, June 1991 X X Copyright (C) 1989, 1991 Free Software Foundation, Inc. X 675 Mass Ave, Cambridge, MA 02139, USA X Everyone is permitted to copy and distribute verbatim copies X of this license document, but changing it is not allowed. X X Preamble X X The licenses for most software are designed to take away your Xfreedom to share and change it. By contrast, the GNU General Public XLicense is intended to guarantee your freedom to share and change free Xsoftware--to make sure the software is free for all its users. This XGeneral Public License applies to most of the Free Software XFoundation's software and to any other program whose authors commit to Xusing it. (Some other Free Software Foundation software is covered by Xthe GNU Library General Public License instead.) You can apply it to Xyour programs, too. X X When we speak of free software, we are referring to freedom, not Xprice. Our General Public Licenses are designed to make sure that you Xhave the freedom to distribute copies of free software (and charge for Xthis service if you wish), that you receive source code or can get it Xif you want it, that you can change the software or use pieces of it Xin new free programs; and that you know you can do these things. X X To protect your rights, we need to make restrictions that forbid Xanyone to deny you these rights or to ask you to surrender the rights. XThese restrictions translate to certain responsibilities for you if you Xdistribute copies of the software, or if you modify it. X X For example, if you distribute copies of such a program, whether Xgratis or for a fee, you must give the recipients all the rights that Xyou have. You must make sure that they, too, receive or can get the Xsource code. And you must show them these terms so they know their Xrights. X X We protect your rights with two steps: (1) copyright the software, and X(2) offer you this license which gives you legal permission to copy, Xdistribute and/or modify the software. X X Also, for each author's protection and ours, we want to make certain Xthat everyone understands that there is no warranty for this free Xsoftware. If the software is modified by someone else and passed on, we Xwant its recipients to know that what they have is not the original, so Xthat any problems introduced by others will not reflect on the original Xauthors' reputations. X X Finally, any free program is threatened constantly by software Xpatents. We wish to avoid the danger that redistributors of a free Xprogram will individually obtain patent licenses, in effect making the Xprogram proprietary. To prevent this, we have made it clear that any Xpatent must be licensed for everyone's free use or not licensed at all. X X The precise terms and conditions for copying, distribution and Xmodification follow. X X GNU GENERAL PUBLIC LICENSE X TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION X X 0. This License applies to any program or other work which contains Xa notice placed by the copyright holder saying it may be distributed Xunder the terms of this General Public License. The "Program", below, Xrefers to any such program or work, and a "work based on the Program" Xmeans either the Program or any derivative work under copyright law: Xthat is to say, a work containing the Program or a portion of it, Xeither verbatim or with modifications and/or translated into another Xlanguage. (Hereinafter, translation is included without limitation in Xthe term "modification".) Each licensee is addressed as "you". X XActivities other than copying, distribution and modification are not Xcovered by this License; they are outside its scope. The act of Xrunning the Program is not restricted, and the output from the Program Xis covered only if its contents constitute a work based on the XProgram (independent of having been made by running the Program). XWhether that is true depends on what the Program does. X X 1. You may copy and distribute verbatim copies of the Program's Xsource code as you receive it, in any medium, provided that you Xconspicuously and appropriately publish on each copy an appropriate Xcopyright notice and disclaimer of warranty; keep intact all the Xnotices that refer to this License and to the absence of any warranty; Xand give any other recipients of the Program a copy of this License Xalong with the Program. X XYou may charge a fee for the physical act of transferring a copy, and Xyou may at your option offer warranty protection in exchange for a fee. X X 2. You may modify your copy or copies of the Program or any portion Xof it, thus forming a work based on the Program, and copy and Xdistribute such modifications or work under the terms of Section 1 Xabove, provided that you also meet all of these conditions: X X a) You must cause the modified files to carry prominent notices X stating that you changed the files and the date of any change. X X b) You must cause any work that you distribute or publish, that in X whole or in part contains or is derived from the Program or any X part thereof, to be licensed as a whole at no charge to all third X parties under the terms of this License. X X c) If the modified program normally reads commands interactively X when run, you must cause it, when started running for such X interactive use in the most ordinary way, to print or display an X announcement including an appropriate copyright notice and a X notice that there is no warranty (or else, saying that you provide X a warranty) and that users may redistribute the program under X these conditions, and telling the user how to view a copy of this X License. (Exception: if the Program itself is interactive but X does not normally print such an announcement, your work based on X the Program is not required to print an announcement.) X XThese requirements apply to the modified work as a whole. If Xidentifiable sections of that work are not derived from the Program, Xand can be reasonably considered independent and separate works in Xthemselves, then this License, and its terms, do not apply to those Xsections when you distribute them as separate works. But when you Xdistribute the same sections as part of a whole which is a work based Xon the Program, the distribution of the whole must be on the terms of Xthis License, whose permissions for other licensees extend to the Xentire whole, and thus to each and every part regardless of who wrote it. X XThus, it is not the intent of this section to claim rights or contest Xyour rights to work written entirely by you; rather, the intent is to Xexercise the right to control the distribution of derivative or Xcollective works based on the Program. X XIn addition, mere aggregation of another work not based on the Program Xwith the Program (or with a work based on the Program) on a volume of Xa storage or distribution medium does not bring the other work under Xthe scope of this License. X X 3. You may copy and distribute the Program (or a work based on it, Xunder Section 2) in object code or executable form under the terms of XSections 1 and 2 above provided that you also do one of the following: X X a) Accompany it with the complete corresponding machine-readable X source code, which must be distributed under the terms of Sections X 1 and 2 above on a medium customarily used for software interchange; or, X X b) Accompany it with a written offer, valid for at least three X years, to give any third party, for a charge no more than your X cost of physically performing source distribution, a complete X machine-readable copy of the corresponding source code, to be X distributed under the terms of Sections 1 and 2 above on a medium X customarily used for software interchange; or, X X c) Accompany it with the information you received as to the offer X to distribute corresponding source code. (This alternative is X allowed only for noncommercial distribution and only if you X received the program in object code or executable form with such X an offer, in accord with Subsection b above.) X XThe source code for a work means the preferred form of the work for Xmaking modifications to it. For an executable work, complete source Xcode means all the source code for all modules it contains, plus any Xassociated interface definition files, plus the scripts used to Xcontrol compilation and installation of the executable. However, as a Xspecial exception, the source code distributed need not include Xanything that is normally distributed (in either source or binary Xform) with the major components (compiler, kernel, and so on) of the Xoperating system on which the executable runs, unless that component Xitself accompanies the executable. X XIf distribution of executable or object code is made by offering Xaccess to copy from a designated place, then offering equivalent Xaccess to copy the source code from the same place counts as Xdistribution of the source code, even though third parties are not Xcompelled to copy the source along with the object code. X X 4. You may not copy, modify, sublicense, or distribute the Program Xexcept as expressly provided under this License. Any attempt Xotherwise to copy, modify, sublicense or distribute the Program is Xvoid, and will automatically terminate your rights under this License. XHowever, parties who have received copies, or rights, from you under Xthis License will not have their licenses terminated so long as such Xparties remain in full compliance. X X 5. You are not required to accept this License, since you have not Xsigned it. However, nothing else grants you permission to modify or Xdistribute the Program or its derivative works. These actions are Xprohibited by law if you do not accept this License. Therefore, by Xmodifying or distributing the Program (or any work based on the XProgram), you indicate your acceptance of this License to do so, and Xall its terms and conditions for copying, distributing or modifying Xthe Program or works based on it. X X 6. Each time you redistribute the Program (or any work based on the XProgram), the recipient automatically receives a license from the Xoriginal licensor to copy, distribute or modify the Program subject to Xthese terms and conditions. You may not impose any further Xrestrictions on the recipients' exercise of the rights granted herein. XYou are not responsible for enforcing compliance by third parties to Xthis License. X X 7. If, as a consequence of a court judgment or allegation of patent Xinfringement or for any other reason (not limited to patent issues), Xconditions are imposed on you (whether by court order, agreement or Xotherwise) that contradict the conditions of this License, they do not Xexcuse you from the conditions of this License. If you cannot Xdistribute so as to satisfy simultaneously your obligations under this XLicense and any other pertinent obligations, then as a consequence you Xmay not distribute the Program at all. For example, if a patent Xlicense would not permit royalty-free redistribution of the Program by Xall those who receive copies directly or indirectly through you, then Xthe only way you could satisfy both it and this License would be to Xrefrain entirely from distribution of the Program. X XIf any portion of this section is held invalid or unenforceable under Xany particular circumstance, the balance of the section is intended to Xapply and the section as a whole is intended to apply in other Xcircumstances. X XIt is not the purpose of this section to induce you to infringe any Xpatents or other property right claims or to contest validity of any Xsuch claims; this section has the sole purpose of protecting the Xintegrity of the free software distribution system, which is Ximplemented by public license practices. Many people have made Xgenerous contributions to the wide range of software distributed Xthrough that system in reliance on consistent application of that Xsystem; it is up to the author/donor to decide if he or she is willing Xto distribute software through any other system and a licensee cannot Ximpose that choice. X XThis section is intended to make thoroughly clear what is believed to Xbe a consequence of the rest of this License. X X 8. If the distribution and/or use of the Program is restricted in Xcertain countries either by patents or by copyrighted interfaces, the Xoriginal copyright holder who places the Program under this License Xmay add an explicit geographical distribution limitation excluding Xthose countries, so that distribution is permitted only in or among Xcountries not thus excluded. In such case, this License incorporates Xthe limitation as if written in the body of this License. X X 9. The Free Software Foundation may publish revised and/or new versions Xof the General Public License from time to time. Such new versions will Xbe similar in spirit to the present version, but may differ in detail to Xaddress new problems or concerns. X XEach version is given a distinguishing version number. If the Program Xspecifies a version number of this License which applies to it and "any Xlater version", you have the option of following the terms and conditions Xeither of that version or of any later version published by the Free XSoftware Foundation. If the Program does not specify a version number of Xthis License, you may choose any version ever published by the Free Software XFoundation. X X 10. If you wish to incorporate parts of the Program into other free Xprograms whose distribution conditions are different, write to the author Xto ask for permission. For software which is copyrighted by the Free XSoftware Foundation, write to the Free Software Foundation; we sometimes Xmake exceptions for this. Our decision will be guided by the two goals Xof preserving the free status of all derivatives of our free software and Xof promoting the sharing and reuse of software generally. X X NO WARRANTY X X 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, XREPAIR OR CORRECTION. X X 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE XPOSSIBILITY OF SUCH DAMAGES. X X END OF TERMS AND CONDITIONS X X Appendix: How to Apply These Terms to Your New Programs X X If you develop a new program, and you want it to be of the greatest Xpossible use to the public, the best way to achieve this is to make it Xfree software which everyone can redistribute and change under these terms. X X To do so, attach the following notices to the program. It is safest Xto attach them to the start of each source file to most effectively Xconvey the exclusion of warranty; and each file should have at least Xthe "copyright" line and a pointer to where the full notice is found. X X X Copyright (C) 19yy X X This program is free software; you can redistribute it and/or modify X it under the terms of the GNU General Public License as published by X the Free Software Foundation; either version 2 of the License, or X (at your option) any later version. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X X You should have received a copy of the GNU General Public License X along with this program; if not, write to the Free Software X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X XAlso add information on how to contact you by electronic and paper mail. X XIf the program is interactive, make it output a short notice like this Xwhen it starts in an interactive mode: X X Gnomovision version 69, Copyright (C) 19yy name of author X Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. X This is free software, and you are welcome to redistribute it X under certain conditions; type `show c' for details. X XThe hypothetical commands `show w' and `show c' should show the appropriate Xparts of the General Public License. Of course, the commands you use may Xbe called something other than `show w' and `show c'; they could even be Xmouse-clicks or menu items--whatever suits your program. X XYou should also get your employer (if you work as a programmer) or your Xschool, if any, to sign a "copyright disclaimer" for the program, if Xnecessary. Here is a sample; alter the names: X X Yoyodyne, Inc., hereby disclaims all copyright interest in the program X `Gnomovision' (which makes passes at compilers) written by James Hacker. X X , 1 April 1989 X Ty Coon, President of Vice X XThis General Public License does not permit incorporating your program into Xproprietary programs. If your program is a subroutine library, you may Xconsider it more useful to permit linking proprietary applications with the Xlibrary. If this is what you want to do, use the GNU Library General XPublic License instead of this License. END_OF_FILE if test 17982 -ne `wc -c <'LICENSE'`; then echo shar: \"'LICENSE'\" unpacked with wrong size! fi # end of 'LICENSE' fi if test -f 'MANIFEST' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'MANIFEST'\" else echo shar: Extracting \"'MANIFEST'\" \(160 characters\) sed "s/^X//" >'MANIFEST' <<'END_OF_FILE' XCHANGES XLICENSE XMANIFEST XMakefile XREADME Xsql Xfinderr.pl Xfinderr Xisqlmus.mus Xisqlperl.h Xisqlperl.pec Xpec2ec Xmkstype Xtestisql Xusersub.c Xisqlperl.man Xisqlperl.doc END_OF_FILE if test 160 -ne `wc -c <'MANIFEST'`; then echo shar: \"'MANIFEST'\" unpacked with wrong size! fi # end of 'MANIFEST' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(8408 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' X# $Id: Makefile,v 1.19 1993/12/08 18:54:30 bill Exp $ X# X# Makefile config for isqlperl X# X# This file is part of the isqlperl system X# Copyright (C) 1993 William Hails X# X# This program is free software; you can redistribute it and/or modify X# it under the terms of the GNU General Public License as published by X# the Free Software Foundation; either version 2 of the License, or X# (at your option) any later version. X# X# This program is distributed in the hope that it will be useful, X# but WITHOUT ANY WARRANTY; without even the implied warranty of X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X# GNU General Public License for more details. X# X# You should have received a copy of the GNU General Public License X# along with this program; if not, write to the Free Software X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X# X# You can email me as bill@tardis.co.uk, or write to Bill Hails, CLI X# connect Ltd., 19, Quarry Street, Guildford, Surrey, GU1 3UY. England. X# X# $Log: Makefile,v $ X# Revision 1.19 1993/12/08 18:54:30 bill X# added -DNOSTRDUP option X# X# Revision 1.18 1993/12/08 17:40:11 bill X# clean removes sqldone X# X# Revision 1.17 1993/12/08 17:13:48 bill X# clean removes *.bak X# X# Revision 1.16 1993/12/08 16:37:14 bill X# also installs finderr X# X# Revision 1.15 1993/12/08 16:04:05 bill X# made much more configurable, and added an install target. X# X# Revision 1.14 1993/11/23 18:33:58 bill X# does RCSCLEAN if -d RCS X# X# Revision 1.13 1993/11/23 17:19:51 bill X# made more cofigured/configurable X# X# Revision 1.12 1993/11/18 18:14:29 bill X# added comments to config and added NOGETDBS variable X# X# Revision 1.11 1993/11/17 18:28:10 bill X# replaced with old makefile X# X# Revision 1.9 1993/10/28 11:43:37 bill X# 1.2 alpha release X# X# Revision 1.8 1993/10/06 18:32:43 bill X# new DEFINE_V4PLUS macro X# X# Revision 1.7 1993/09/16 20:27:05 bill X# explicitly give perl the mus script in case it doesn't point X# to the right perl in its #! line X# X# Revision 1.6 1993/09/16 18:19:30 bill X# applied wchan's patch X# X# Revision 1.5 1993/09/13 19:15:35 bill X# applied wchan's patches X# X# Revision 1.4 1993/09/05 22:55:46 bill X# clean target wasn't quite right X# X# Revision 1.3 1993/09/05 22:11:09 bill X# added license X# X# Revision 1.2 1993/09/05 20:32:39 bill X# tidied up X# X# Revision 1.1 1993/09/05 19:52:21 bill X# Initial revision X# X X################################# X# what C compiler you want to use X################################# X XCC=gcc X#CC=cc X X X################################# X# where your perl headers (*.h) are X################################# X XPERLDIR=/usr/sysop/perl X X X################################# X# where your uperl.o file is X################################# X XUPERLOBJ=$(PERLDIR)/uperl.o X X X################################# X# where your mus script is X################################# X XMUS=$(PERLDIR)/usub/mus X X X################################# X# the informix root directory X################################# X XINFORMIXDIR=/usr/informix X X X################################# X# the library informix uses to X# link its esql/c binaries, X# plus a library to resolve X# unresolved references from X# the (undocumented) Informix X# sqgetdbs() function to X# compact() and frmcmpr() (also X# undocumented). You can look X# in your $INFORMIXDIR/bin/esqlc X# script to see which library it X# uses X################################# X XILIBS=-lsql4 -lsace X#ILIBS=-lsql -l4gl -lforms X X X################################# X# *UN* comment this if you can't X# get around the unresolved X# references from the esql/c library X################################# X X# NOGETDBS=-DNOGETDBS X X X################################# X# other libraries needed by perl X################################# X XOTHERLIBS=-lX11 -lyp -lrpc -linet -lnsl_s -ldbm -lPW -lmalloc -lm -lx -lc_s X X X################################# X# other include directories needed by perl X################################# X XOTHERINC=-I/usr/include/rpcsvc -I/usr/include/X11 X X X################################# X# ENGINE should be one of SE, TURBO X# or ONLINE. This actually specifies X# the kind of Informix *library* you X# are linking. X# TURBO provides the least functionality X# (early Informix versions), X# ONLINE the most. X################################# X XENGINE=ONLINE X X X################################# X# Any additional flags you want to use X################################# X XFLAGS=-g -DDEBUGGING -Disc386 X X X################################# X# Comment this out if you *don't* X# have esql/c version 4.10 or higher X# (this has no effect if your engine X# library is TURBO) X################################# X XDEFINE_V410PLUS=-DHAS_V410PLUS X X X################################# X# the maximum number of cursors and statement ids X# that can be open at any one time. I believe that X# Informix imposes a limit of around 64, but I may be X# mistaken. X################################# X XMAXCURSORS=20 X X X################################# X# What you want to call the final executable X# isqlperl is recommended X################################# X XTARGET=isqlperl X X X################################# X# What you want to use to produce X# .c files from .ec files X################################# X XESQL=$(INFORMIXDIR)/bin/esql X# ESQL=$(INFORMIXDIR)/bin/c4gl X X X################################# X# *UN* comment this if you don't X# have the bzero(3) function X################################# X X# NOBZERO=-DNOBZERO X X X################################# X# *UN* comment this if you don't X# have the strdup(3) function X################################# X X# NOSTRDUP=-DNOSTRDUP X X X################################# X# where you want isqlperl X# installed X################################# X XINSTALLBIN=/usr/local/bin X X X################################# X# where you want the man page X# installed X################################# X XINSTALLMAN=/usr/local/catman/u_man/man1 X X X################################# X# what suffix you want for the X# man page X################################# X XMANSUFFIX=1 X X X################################# X# whether you want to install the X# pre-formatted manual (isqlperl.doc) X# or the [tn]roff source (isqlperl.man) X################################# X XMANPAGE=isqlperl.doc X X X################################# X# where your perl library (of .pl X# files) is X################################# X XPERLLIB=/usr/local/lib/perl X X X################################# X# set this to `cp' if you want X# to install the `sql' interpreter X# and the super-fast :-) finderr X# script, X# or to `true' if you do not X################################# X XMAYINSTALL=cp X X X################################################################### X# END OF CONFIG X################################################################### X XINFOINC=$(INFORMIXDIR)/incl X XINFOLIB=$(INFORMIXDIR)/lib X XINC=-I$(PERLDIR) $(OTHERINC) -I$(INFOINC) X XCPPFLAGS=$(FLAGS) -D$(ENGINE) $(NOGETDBS) $(NOBZERO) $(NOSTRDUP) \ X$(DEFINE_V410PLUS) $(INC) X XLIBS=$(ILIBS) $(OTHERLIBS) X XOBJS=usersub.o isqlperl.o X X# If your make objects, you can remove this line, which is for GNU Make: X.PHONY: all install clean X Xall: $(TARGET) sqldone X X$(TARGET): $(UPERLOBJ) $(OBJS) X $(CC) -g $(UPERLOBJ) $(OBJS) -L$(INFOLIB) $(LIBS) -o $(TARGET) X Xusersub.o: usersub.c X $(CC) -c $(CPPFLAGS) usersub.c X Xisqlperl.o: isqlperl.c isqlmus.c sqlstype.c isqlperl.h X $(CC) -c $(CPPFLAGS) isqlperl.c X Xisqlperl.c: isqlperl.ec X esql -e isqlperl.ec X Xisqlperl.ec: isqlperl.pec pec2ec X rm -f $@ X perl ./pec2ec $(MAXCURSORS) isqlperl.pec > $@ X Xisqlmus.c: isqlmus.mus $(MUS) X rm -f $@ X perl $(MUS) isqlmus.mus > $@ X Xsqlstype.c: $(INFOINC)/sqlstype.h mkstype X rm -f $@ X perl mkstype $(INFOINC)/sqlstype.h > $@ X Xsqldone: sql finderr X mv sql sql.bak X sed 's,^#!.*,#!$(INSTALLBIN)/$(TARGET),' sql.bak > sql X mv finderr finderr.bak X sed 's,^#!.*,#!$(INSTALLBIN)/$(TARGET),' finderr.bak > finderr X touch sqldone X Xinstall: all X cp $(TARGET) $(INSTALLBIN)/$(TARGET) X chmod 755 $(INSTALLBIN)/$(TARGET) X cp $(MANPAGE) $(INSTALLMAN)/$(TARGET).$(MANSUFFIX) X chmod 744 $(INSTALLMAN)/$(TARGET).$(MANSUFFIX) X $(MAYINSTALL) sql $(INSTALLBIN)/sql X -chmod 755 $(INSTALLBIN)/sql X $(MAYINSTALL) finderr $(INSTALLBIN)/finderr X -chmod 755 $(INSTALLBIN)/finderr X $(MAYINSTALL) finderr.pl $(PERLLIB)/finderr.pl X -chmod 744 $(PERLLIB)/finderr.pl X Xclean: X rm -f *.o *.bak core isqlperl.c isqlperl.ec isqlmus.c \ X sqlstype.c $(TARGET) sqldone X if [ -d RCS ] ; then rcsclean ; fi END_OF_FILE if test 8408 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'README' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'README'\" else echo shar: Extracting \"'README'\" \(2587 characters\) sed "s/^X//" >'README' <<'END_OF_FILE' X$Id: README,v 1.12 1993/12/08 16:05:23 bill Exp $ X X This file is part of the isqlperl system. X X (c) Copyright 1993 by William Hails X All rights reserved. X X This program is free software; you can redistribute it and/or modify X it under the terms of the GNU General Public License as published by X the Free Software Foundation. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X X You should have received a copy of the GNU General Public License X along with this program; if not, write to the Free Software X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X X You can email me as bill@tardis.co.uk or write to William Hails, CLI X Connect Ltd., 19, Quarry Street, Guildford, Surrey, GU1 3UY. England. X X XIsqlperl is a perl interface to Informix databases, implemented as a set Xof usub extensions to perl. X XSee the file CHANGES for facilities and features new with this release. XSee the man page (isqlperl.man, pre-formatted as isqlperl.doc) for Xdocumentation. X XThis is only a temporary measure, isqlperl will soon be supplanted by XDBperl, but for the time being it may attract some Informix users to Xthe Perl fold (and I needed a perl/Informix i/f FAST.) X XMany thanks to Winthrop Chan who provided the original sql script, and Xwho did much work on porting version 1.1. Thanks also to Neil S. XBriscoe For help in porting and testing version 1.2, and for his Xgeneral enthusiasm towards isqlperl. X X BUILDING X XTo build, you must have perl already installed, (make runs some perl Xscripts) and the mus program must be in the usub directory of the perl Xdistribution. There will need to be a `usub.o' (built when perl is Xbuilt) in the perl distribution directory. X XYou will also need to have Informix ESQL/C installed on the Xmachine on which you are doing the build. X XEdit the Makefile, appropriate to your site. X XRun `make'. It should only take a minute or so. X X TESTING X XHave a look at the isqlperl script testisql, change the database and Xtable names to something on your site, then run it. Also check out the Xsql script, contributed by W. Chan, for an example of a command driven XSQL interpreter written in isqlperl. X X INSTALLING X XAfter you're happy with the tests, check over the Makefile again. XYou can opt to install the sql script, in which case you will also Xhave to install the finderr.pl library module which it requires. XThen run `make install'. END_OF_FILE if test 2587 -ne `wc -c <'README'`; then echo shar: \"'README'\" unpacked with wrong size! fi # end of 'README' fi if test -f 'sql' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'sql'\" else echo shar: Extracting \"'sql'\" \(5029 characters\) sed "s/^X//" >'sql' <<'END_OF_FILE' X#!/usr/local/bin/isqlperl X X# X# $Id: sql,v 1.7 1993/12/08 19:31:20 bill Exp $ X# X# A cheap cheesy interactive script for isqlperl (Informix Perl) X# - Winthrop Chan - Sep 8, 1993 X# X# Hacked around a bit by bill@tardis.co.uk to show off isqlperl 1.2 X X X($progname = $0) =~ s#.*/##; X X($version) = split(' ', $isql_attrib); Xdie "sorry, must be isqlperl v1.2 or greater\n" unless $version >= 1.2; X X$introtext = <} - displays requested info X XERROR - displays the full error text from the on-line manual X (if available) X X! - runs the specified operating system command. X XEOF X X++$isql_autoclose; X Xif ($database = shift) { X &isql_execute("database $database") || &dowarn(); X} X Xsub setflag { X $pipeflag = 1; X $SIG{PIPE} = 'setflag'; X} X X$SIG{PIPE} = 'setflag'; X Xsub dowarn { X print "$isql_code\n\n"; X print "more info (y/n)? : "; X if ( =~ /y/i) { X require('finderr.pl'); X local($errtxt, $errmsg, $errpat); X $errmsg = "$isql_code"; X $errtxt = &finderr($errmsg); X ($errpat = "$errmsg") =~ s/(\W)/\\$1/g; X $errtxt =~ s/[^\n]*/$errmsg/ unless $errtxt =~ /^$errpat/; X open(MORE, "| more") || die "can't pipe to more: $!"; X print MORE $errtxt; X close(MORE); X $pipeflag = 0; X } X} X X# main loop X Xfor(;;) { X $cmd = ''; X if ($isql_database) { X $prompt = "$progname:$isql_database>"; X if ($prompt ne $oldprompt) { X print "$isql_database: "; X print "", ($isql_transactions ? '' : 'no'), " transactions, "; X print "", ($isql_ansi ? '' : 'not '), "mode ANSII, "; X print "", ($isql_online ? '' : 'not '), "OnLine\n"; X # and set the oldprompt X $oldprompt = $prompt; X } X } else { X $prompt = "$progname>"; X } X do { X print "$prompt "; X do { print "\n"; exit(0); } if (!defined($next = )); X chop($next); X if ($next =~ /^\s*!/) { X system(substr($next, index($next, '!') + 1)); X } else { X $cmd .= " $next"; X } X $prompt = '>' if $cmd =~ /\w/; X } until $cmd =~ /;\s*$/; X X $cmd =~ s/^\s*(\S.*\S)\s*;\s*$/$1/; # normalise X X print "cmd: \"$cmd\"\n" if ($debug); # Print off command X X exit(0) if ($cmd =~ /^quit$/); # If command is "quit" then leave X X if ($cmd =~ s/^info\s+//i) { X X if ($cmd =~ /^databases$/i) { X @databases = &isql_databases(); X if (@databases) { X open(MORE, "|more") || die "can't pipe to more"; X DATABASELOOP: X foreach (@databases) { X print MORE "$_\n"; X if ($pipeflag) { X last DATABASELOOP; X } X } X close(MORE); X $pipeflag = 0; X } X X } elsif ($cmd =~ /^tables$/i) { X $cid = &isql_open(< 99 XEOSQL X if ($cid) { X open(MORE, "|more") || die "can't pipe to more"; X TABLELOOP: X while (($tabname) = &isql_fetch($cid)) { X print MORE "$tabname\n"; X if ($pipeflag) { X &isql_close($cid); X last TABLELOOP; X } X } X close(MORE); X $pipeflag = 0; X &dowarn() if $isql_code && $isql_code != 100; X } else { X &dowarn(); X } X X } elsif ($cmd =~ /^columns\s+for\s+(\w+)$/i) { X $cid = &isql_open("select * from $1"); X if ($cid) { X open(MORE, "|more") || die "can't pipe to more"; X @titles = &isql_titles($cid); X @columns = &isql_columns($cid); X COLUMNLOOP: X for ($i = 0; $i < @titles; ++$i) { X printf MORE "%-19s%s\n", $titles[$i], $columns[$i]; X if ($pipeflag) { X &isql_close($cid); X last COLUMNLOOP; X } X } X close(MORE); X $pipeflag = 0; X } else { X &dowarn(); X } X } else { X $isql_code = -201; # syntax error X &dowarn(); X } X } elsif ($cmd =~ s/^error\s+//i) { X if ($cmd =~ /^(-?\d+)/) { X $isql_code = $1; X &dowarn(); X } else { X $isql_code = -201; X &dowarn(); X } X } elsif ($cmd =~ /^help$/i) { X open(MORE, "|more") || die "can't pipe to more"; X print MORE $helptext; X close(MORE); X $pipeflag = 0; X } elsif ($id = &isql_open($cmd)) { X $sttmnttype = &isql_type($id); X if ($sttmnttype eq 'SELECT') { X open(MORE, "|more") || die "can't pipe to more"; X X @titles = &isql_titles($id); X X PRINTLOOP: X while (@row = &isql_fetch($id)) { X for ($i = 0; $i < @row; ++$i) { X printf MORE "%-19s%s\n", $titles[$i], $row[$i]; X X if ($pipeflag) { X &isql_close($id); X last PRINTLOOP; X } X } X print MORE "\n"; X } X X close(MORE); X $pipeflag = 0; X &dowarn() if $isql_code && $isql_code != 100; X } else { X &isql_execute($id) || &dowarn(); X &isql_close($id); X } X } else { X &dowarn(); X } X} END_OF_FILE if test 5029 -ne `wc -c <'sql'`; then echo shar: \"'sql'\" unpacked with wrong size! fi chmod +x 'sql' # end of 'sql' fi if test -f 'finderr.pl' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'finderr.pl'\" else echo shar: Extracting \"'finderr.pl'\" \(1046 characters\) sed "s/^X//" >'finderr.pl' <<'END_OF_FILE' X# $Id: finderr.pl,v 1.6 1993/12/08 19:52:38 bill Exp $ X# much Much *MUCH* <<>> faster finderr - pilfered from look.pl X Xsub finderr { X local($errmsg) = @_; X local($errno) = (int($errmsg)); X local($errtxt) = (''); X local($INFORMIXDIR); X X $INFORMIXDIR = $ENV{INFORMIXDIR} || '/usr/informix'; X X if (open(ERRMSGTXT, "$INFORMIXDIR/msg/errmsg.txt")) { X local($/) = ("\n\n"); X local($max,$min,$mid,$_); X $max = (stat(ERRMSGTXT))[7]; X SEEK: while ($max - $min > 1) { X $mid = int(($max + $min) / 2); X seek(ERRMSGTXT, $mid, 0); X $_ = if $mid; X while () { X ($num) = split("\t"); X if ($num =~ /^(-?\d+)$/) { X if ($errno < $1) { X $min = $mid; X next SEEK; X } elsif ($errno > $1) { X $max = $mid; X next SEEK; X } else { X $errtxt .= $_; X while () { X last if /^-?\d+\t/; X $errtxt .= $_; X } X last SEEK; X } X } X } X } X X close(ERRMSGTXT); X } X $errtxt = "$errmsg\n\nError number $errno not found\n" unless $errtxt; X $errtxt; X} X X1; END_OF_FILE if test 1046 -ne `wc -c <'finderr.pl'`; then echo shar: \"'finderr.pl'\" unpacked with wrong size! fi # end of 'finderr.pl' fi if test -f 'finderr' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'finderr'\" else echo shar: Extracting \"'finderr'\" \(325 characters\) sed "s/^X//" >'finderr' <<'END_OF_FILE' X#!/usr/local/bin/isqlperl X X# $Id: finderr,v 1.1 1993/12/08 17:14:53 bill Exp $ X X($progname = $0) =~ s#.*/##; X Xsub catch { X 1; X} X X$SIG{PIPE} = 'catch'; X Xrequire('finderr.pl'); X X$err = shift || die "use $progname errorcode\n"; Xopen(MORE, "| more") || die "can't pipe to more: $!"; Xprint MORE &finderr("$err"); Xclose(MORE); END_OF_FILE if test 325 -ne `wc -c <'finderr'`; then echo shar: \"'finderr'\" unpacked with wrong size! fi chmod +x 'finderr' # end of 'finderr' fi if test -f 'isqlmus.mus' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'isqlmus.mus'\" else echo shar: Extracting \"'isqlmus.mus'\" \(11080 characters\) sed "s/^X//" >'isqlmus.mus' <<'END_OF_FILE' X# ifndef lint Xstatic char info[] = "$Id: isqlmus.mus,v 1.13 1993/12/08 16:11:00 bill Exp $"; X# endif X/*--------------------------------------------------- X * X * Module: isqlmus X * X * Purpose: mus i/f to isqlperl X * X * Author: William Hails X * X * Date: Sun Sep 5 13:14:20 BST 1993 X * X * Log: $Log: isqlmus.mus,v $ X * Revision 1.13 1993/12/08 16:11:00 bill X * added $isql_database, $isql_transactions, $isql_ansi, $isql_online X * and &isql_statement(). X * fied minor bug if get_rgetmsg didn't find an error string, and X * made HAS_V410PLUS effective only if !TURBO X * X * Revision 1.12 1993/11/23 18:29:56 bill X * rgetmsg formats isql_code with a "\t" rather than a ": " to comply with X * the format in the errmsgs.txt file X * X * Revision 1.11 1993/11/18 18:42:15 bill X * now allows all the functions, and warns if unimplemented. X * X * Revision 1.10 1993/11/16 20:31:24 bill X * rearranged layout for ease of reading X * X * Revision 1.9 1993/11/16 18:18:24 bill X * delta prior to merge of one-offs with statement-id calls X * X * Revision 1.8 1993/10/28 15:47:32 bill X * passed through lint, cleared up a few minor problems X * X * Revision 1.7 1993/10/28 11:43:37 bill X * 1.2 alpha release X * X * Revision 1.6 1993/10/15 11:02:01 bill X * ready for 1.2 release X * X * Revision 1.5 1993/10/06 18:36:50 bill X * handles rgetmsg for $isql_code and isql_msg X * also tidied up some gcc complaints and has conditions on HAS_V4PLUS X * X * Revision 1.4 1993/09/15 09:48:28 bill X * renamed isql_code fn to isql_ca, and added isql_maxcursors var r/o X * X * Revision 1.3 1993/09/14 18:14:17 bill X * added isql_code function X * X * Revision 1.2 1993/09/05 22:18:50 bill X * added license X * X * Revision 1.1 1993/09/05 19:46:26 bill X * Initial revision X * X * X *---------------------------------------------------*/ X/* X This file is part of the isqlperl system. X X (c) Copyright 1993 by William Hails X All rights reserved. X X This program is free software; you can redistribute it and/or modify X it under the terms of the GNU General Public License as published by X the Free Software Foundation. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X X You should have received a copy of the GNU General Public License X along with this program; if not, write to the Free Software X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X X You can email me as bill@tardis.co.uk or write to William Hails, CLI X Connect Ltd., 19, Quarry Street, Guildford, Surrey, GU1 3UY. England. X*/ X X/* syntax error if more than one defined */ Xstatic char * isql_engine = X#ifdef ONLINE X"ONLINE" X#endif X#ifdef TURBO X"TURBO" X#endif X#ifdef SE X"SE" X#endif X; X Xstatic char attrib[80]; X Xenum uservars { X UV_isql_code, X UV_isql_attrib, X UV_isql_autoclose, X UV_isql_database, X UV_isql_transactions, X UV_isql_ansi, X UV_isql_online, X}; X Xenum usersubs { X US_isql_execute, X US_isql_open, X US_isql_fetch, X US_isql_titles, X US_isql_close, X US_isql_ca, X US_isql_shutdown, X US_isql_msg, X US_isql_databases, X US_isql_type, X US_isql_columns, X US_isql_statement, X}; X Xstatic int usersub(); Xstatic int userval(); Xstatic int userset(); X Xstatic int autoclose; Xstatic char *isql_database; Xstatic int isql_transactions, isql_ansi, isql_online; X X#define MAXDATABASES 256 X#define MAXDBSPACE 3840 /* 256 * (14 + 1) */ X X/*--------------------------------------------------- X * Function: init_sql X * X * Purpose: initialises vars and subroutines X * X * Arguments: nothing X * X * Returns: nothing X * X *---------------------------------------------------*/ X Xinit_isql() X{ X struct ufuncs uf; X char *filename = "isqlperl.c"; X X uf.uf_set = userset; X uf.uf_val = userval; X X#define MAGICNAME(name, ix) uf.uf_index = ix; magicname(name, &uf, sizeof uf) X X MAGICNAME("isql_code", UV_isql_code); X MAGICNAME("isql_attrib", UV_isql_attrib); X MAGICNAME("isql_autoclose", UV_isql_autoclose); X MAGICNAME("isql_database", UV_isql_database); X MAGICNAME("isql_transactions", UV_isql_transactions); X MAGICNAME("isql_ansi", UV_isql_ansi); X MAGICNAME("isql_online", UV_isql_online); X X#define MAGICSUB(name, ix) make_usub(name, ix, usersub, filename) X X MAGICSUB("isql_execute", US_isql_execute); X MAGICSUB("isql_open", US_isql_open); X MAGICSUB("isql_fetch", US_isql_fetch); X MAGICSUB("isql_titles", US_isql_titles); X MAGICSUB("isql_close", US_isql_close); X MAGICSUB("isql_ca", US_isql_ca); X MAGICSUB("isql_msg", US_isql_msg); X MAGICSUB("isql_shutdown", US_isql_shutdown); X MAGICSUB("isql_databases", US_isql_databases); X MAGICSUB("isql_type", US_isql_type); X MAGICSUB("isql_columns", US_isql_columns); X MAGICSUB("isql_statement", US_isql_statement); X X sprintf(attrib, "1.2 %s %d", isql_engine, isql_maxcursors()); X} X X#if !defined(TURBO) && defined(HAS_V410PLUS) X/*--------------------------------------------------- X * Function: get_rgetmsg X * X * Purpose: produces sensible result from rgetmsg X * X * Arguments: error code X * X * Returns: pointer to string X * X *---------------------------------------------------*/ X Xstatic char *get_rgetmsg(sqlcode) Xlong sqlcode; X{ X static char lbuf[512]; X static char rbuf[512]; X int buflen; X char *lbufp; X X lbuf[0] = '\0'; X X if (!sqlcode) X return lbuf; X X sprintf(lbuf, "%d\t", sqlcode); X buflen = strlen(lbuf); X lbufp = lbuf + buflen; X X if (sqlcode == 100) X strcpy(lbufp, "no more rows"); X else if (rgetmsg(sqlcode, lbufp, 512 - buflen)) /* probably no .iem files */ X lbuf[buflen - 1] = '\0'; X else X { X buflen = strlen(lbuf); X lbuf[buflen - 1] = '\0'; /* ditch \n */ X } X X if (sqlca.sqlerrm[0]) X sprintf(rbuf, lbuf, sqlca.sqlerrm); X else X strcpy(rbuf, lbuf); X X return rbuf; X} X#endif X X/*--------------------------------------------------- X * Function: usersub X * X * Purpose: locates and calls sub X * X * Arguments: sub index X * stack pointer X * number of arguments X * X * Returns: stack pointer X * X *---------------------------------------------------*/ X Xstatic int usersub(ix, sp, items) Xint ix; Xregister int sp; Xregister int items; X{ X#if !defined(TURBO) && defined(HAS_V410PLUS) X char *lbuf; X long sqlcode; X#endif X STR **st = stack->ary_array + sp; X X switch (ix) X { X case US_isql_execute: X if (items < 1) X fatal("Usage: &isql_execute($stmnt/$id, @parameters"); X else X { X int retval; X X if (st[1]->str_nok) /* prepared numeric id */ X retval = isql_put(sp, items); X else X retval = isql_execute(sp, items); X str_numset(st[0], (double) retval); X } X return sp; X X case US_isql_open: X if (items < 1) X fatal("Usage: &isql_open($stmnt, @parameters)"); X else X { X int retval; X char *slctstmnt = str_get(st[1]); X retval = isql_open(slctstmnt, sp, items); X str_numset(st[0], (double) retval); X } X return sp; X X case US_isql_columns: X if (items != 1) X fatal("Usage: &isql_columns($id)"); X else X { X int id = (int) str_gnum(st[1]); X sp = isql_columns(sp, id); X } X return sp; X X case US_isql_fetch: X if (items < 1) X fatal("Usage: &isql_fetch($stmnt_or_id, @parameters)"); X else X { X if (st[1]->str_nok) X { X int cursorid = (int) str_gnum(st[1]); X sp = isql_fetch(sp, cursorid); X } X else X { X char *slctstmnt = str_get(st[1]); X sp = isql_select(slctstmnt, sp, items); X } X } X return sp; X X case US_isql_titles: X if (items != 1) X fatal("Usage: &isql_titles($id)"); X else X { X int cursorid = (int) str_gnum(st[1]); X sp = isql_titles(sp, cursorid); X } X return sp; X XCASE int isql_close XI int id XEND X X case US_isql_ca: X if (items) X fatal("Usage: &isql_ca()"); X else X return (isql_ca(sp)); X XCASE int isql_shutdown XEND X X case US_isql_msg: X#if !defined(TURBO) && defined(HAS_V410PLUS) X if (items == 0) X sqlcode = (int) sqlca.sqlcode; X else if (items == 1) X sqlcode = (int) str_gnum(st[1]); X else X fatal("Usage: &isql_msg([$code])"); X X lbuf = get_rgetmsg(sqlcode); X str_set(st[0], lbuf); X#else X WARN("&isql_msg() not fully implemented"); X str_set(st[0], ""); X#endif X break; X X case US_isql_databases: X#ifdef NOGETDBS X WARN("&isql_databases() not fully implemented"); X return sp - 1; /* empty list */ X#else X if (items != 0) X fatal("Usage: &isql_databases()"); X else X { X char *dbnamespace[MAXDATABASES]; X char area[MAXDBSPACE]; X int numbases=0; X int code=sqgetdbs(&numbases, dbnamespace, MAXDATABASES, X area, MAXDBSPACE); X if (code==0 && numbases >0) X { X if (curcsv->wantarray) X { X int i; X astore(stack, sp + numbases, Nullstr); X st = stack->ary_array + sp; X X for (i = 0; i < numbases; ++i) X st[i] = str_2mortal(str_make(dbnamespace[i], X strlen(dbnamespace[i]))); X X return sp + numbases - 1; X } X else X { X str_numset(st[0], (double) numbases); X return sp; X } X } X else X return sp - 1; /* empty list */ X } X#endif X break; X XCASE char* isql_type XI int id XEND X XCASE char* isql_statement XI int id XEND X X default: X fatal("Unimplemented user-defined subroutine"); X } X return (sp); X} X/*--------------------------------------------------- X * Function: userval X * X * Purpose: get uvars X * X * Arguments: index and value to return into X * X * Returns: 0 X * X *---------------------------------------------------*/ X Xstatic int userval(ix, str) Xint ix; XSTR *str; X{ X#if !defined(TURBO) && defined(HAS_V410PLUS) X char *lbuf; X#endif X static int isql_maxcursors(); X X switch (ix) X { X case UV_isql_code: X str_numset(str, (double) sqlca.sqlcode); X#if !defined(TURBO) && defined(HAS_V410PLUS) X lbuf = get_rgetmsg(sqlca.sqlcode); X str_set(str, lbuf); X str->str_nok = 1; /* where have I seen this before? */ X#endif X break; X X case UV_isql_autoclose: X str_numset(str, (double) autoclose); X break; X X case UV_isql_attrib: X str_set(str, attrib); X break; X X case UV_isql_database: X if (isql_database) X str_set(str, isql_database); X else X str_set(str, ""); X break; X X case UV_isql_transactions: X str_numset(str, (double) isql_transactions); X break; X X case UV_isql_ansi: X str_numset(str, (double) isql_ansi); X break; X X case UV_isql_online: X str_numset(str, (double) isql_online); X break; X } X X return(0); X} X/*--------------------------------------------------- X * Function: userset X * X * Purpose: set uvars X * X * Arguments: index and value to set from X * X * Returns: 0 X * X *---------------------------------------------------*/ X Xstatic int userset(ix, str) Xint ix; XSTR *str; X{ X switch (ix) X { X case UV_isql_autoclose: X autoclose = (int) str_gnum(str); X break; X X case UV_isql_code: X sqlca.sqlcode = (short) str_gnum(str); X break; X } X return(0); X} END_OF_FILE if test 11080 -ne `wc -c <'isqlmus.mus'`; then echo shar: \"'isqlmus.mus'\" unpacked with wrong size! fi # end of 'isqlmus.mus' fi if test -f 'isqlperl.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'isqlperl.h'\" else echo shar: Extracting \"'isqlperl.h'\" \(1836 characters\) sed "s/^X//" >'isqlperl.h' <<'END_OF_FILE' X#ident "$Id: isqlperl.h,v 1.5 1993/12/08 16:13:15 bill Exp $" X X/*---------------------------------------------------* X * X * Module: isqlperl.h X * X * Purpose: defines structs for cacheing cursor info X * for embedded sql in perl X * X * Author: William Hails X * X * Date: Sun Sep 5 11:35:49 BST 1993 X * X *---------------------------------------------------*/ X/* X This file is part of the isqlperl system. X X (c) Copyright 1993 by William Hails X All rights reserved. X X This program is free software; you can redistribute it and/or modify X it under the terms of the GNU General Public License as published by X the Free Software Foundation. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X X You should have received a copy of the GNU General Public License X along with this program; if not, write to the Free Software X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X X You can email me as bill@tardis.co.uk or write to William Hails, CLI X Connect Ltd., 19, Quarry Street, Guildford, Surrey, GU1 3UY. England. X*/ X X#define WARN(msg) do { if(dowarn) warn(msg); } while(0) X Xtypedef enum cursorstate { X closed, X prepared, X described, X allocated, X declared, X opened X} cursorstate; X X/* retain type and size info for &isql_types() */ Xstruct sqltype_struct { X short sqltype; X short sqllen; X}; X Xstruct sqlta { X short sqld; X struct sqltype_struct *sqltype; X}; X Xtypedef struct { X struct sqlda *udesc; X struct sqlta *tdesc; X char *buffer; X cursorstate is_open; X int sttmnttype; X char *statement; X} cursor; END_OF_FILE if test 1836 -ne `wc -c <'isqlperl.h'`; then echo shar: \"'isqlperl.h'\" unpacked with wrong size! fi # end of 'isqlperl.h' fi if test -f 'isqlperl.pec' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'isqlperl.pec'\" else echo shar: Extracting \"'isqlperl.pec'\" \(40383 characters\) sed "s/^X//" >'isqlperl.pec' <<'END_OF_FILE' X#ifndef lint Xstatic char sccsinfo[] = "$Id: isqlperl.pec,v 1.23 1993/12/08 18:19:10 bill Exp $"; X#endif X/* X This file is part of the isqlperl system. X X (c) Copyright 1993 by William Hails X All rights reserved. X X This program is free software; you can redistribute it and/or modify X it under the terms of the GNU General Public License as published by X the Free Software Foundation. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X X You should have received a copy of the GNU General Public License X along with this program; if not, write to the Free Software X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X X You can email me as bill@tardis.co.uk or write to William Hails, CLI X Connect Ltd., 19, Quarry Street, Guildford, Surrey, GU1 3UY. England. X*/ X X/*---------------------------------------------------* X * X * Module: isqlperl X * X * Purpose: embedded Informix sql in Perl X * X * Author: William Hails X * X * Date: Sun Sep 5 11:05:39 BST 1993 X * X * $Log: isqlperl.pec,v $ X * Revision 1.23 1993/12/08 18:19:10 bill X * added strdup #ifdef NOSTRDUP X * X * Revision 1.22 1993/12/08 16:15:43 bill X * moved license to top, conditionally added bzero(), wrote X * code to save/forget details on a database statement, and added X * throwaway &isql_statement() because it was so easy to do. X * X * Revision 1.21 1993/11/23 17:20:33 bill X * &isql_type() now gets info from sqlstype.c, generated from X * Informix's sqlstype.h X * X * Revision 1.20 1993/11/18 18:43:17 bill X * isql_shutdown now at least partially implemented, warning if not, X * and WARN macro replaces warn fn call. X * X * Revision 1.19 1993/11/16 20:31:24 bill X * rearranged layout for ease of reading X * X * Revision 1.18 1993/11/16 18:18:24 bill X * delta prior to merge of one-offs with statement-id calls X * X * Revision 1.17 1993/10/28 15:45:50 bill X * passed through lint, cleared up a few minor problems X * X * Revision 1.16 1993/10/28 11:43:37 bill X * 1.2 alpha release X * X * Revision 1.15 1993/10/18 18:16:54 bill X * changed error on running out of cursors from -104 to -276 X * X * Revision 1.14 1993/10/15 11:02:01 bill X * ready for 1.2 release X * X * Revision 1.13 1993/10/14 17:53:41 bill X * support for parameters in isql_execute(), and general X * support for Text and Byte data types X * X * Revision 1.12 1993/10/06 18:38:48 bill X * more robust, added titles fn X * X * Revision 1.11 1993/09/16 18:20:31 bill X * applied wchan's patch X * X * Revision 1.10 1993/09/15 09:46:38 bill X * patched up the $open to always allocate sensible amounts of space, X * and added isql_ca and isql_maxcursors X * X * Revision 1.9 1993/09/13 19:57:14 bill X * sudden attack of paranoia: ++(col->sqllen) X * X * Revision 1.8 1993/09/13 19:48:52 bill X * set MAXDATA to 92, and assign that size to everything except X * SQLCHAR and SQLVCHAR types, where the size info is already X * correct for a CSTRINGTYPE X * X * Revision 1.7 1993/09/13 19:15:00 bill X * converts all data types to strings, with minimum length 48 X * X * Revision 1.6 1993/09/10 02:42:01 bill X * close_cursor() made more solid, and now returns the date X * type correctly. Minor fixes also re. returning undefined X * values and the empty list. X * X * Revision 1.5 1993/09/08 13:05:36 bill X * bug fix du to: wchan@plxsun.plx.com (Winthrop Chan) X * X * Revision 1.4 1993/09/05 22:49:52 bill X * tidied up docn X * X * Revision 1.3 1993/09/05 22:22:21 bill X * added license X * X * Revision 1.2 1993/09/05 19:45:37 bill X * first apparently working version. X * X * Revision 1.1 1993/09/05 15:23:33 bill X * Initial revision X * X * X *---------------------------------------------------*/ X X#include "EXTERN.h" X#include "perl.h" X X#include "sqlhdr.h" X#include "sqlca.h" X#include "sqlda.h" X#include "sqltypes.h" X#ifndef SQ_DATABASE X#include "sqlstype.h" X#endif X#ifndef TURBO X#include "datetime.h" X#endif X X#ifdef NOBZERO X#define bzero(a, b) memset((a), '\0', (b)) Xchar *memset(); X#endif X X#ifdef ONLINE X#include "varchar.h" X#include "locator.h" X#endif X Xstatic int isql_execute(), isql_open(), isql_columns(), isql_fetch(); Xstatic int isql_put(), isql_select(); Xstatic char *isql_type(); Xstatic int isql_titles(), isql_close(), isql_shutdown(), isql_ca(); Xstatic int isql_maxcursors(); Xstatic char *isql_statement(); X#ifndef TURBO Xstatic char *dti_qual(); X#endif Xstatic void save_sqlda_types(); Xstatic char *prepare_input_sqlda(), *prepare_output_sqlda(); Xstatic void perl_to_sqlda(); Xstatic int sqlda_to_perl(); Xstatic short count_parameters(); Xstatic void allocate_sqlvar_for(), eclose_cursor(), free_cursor(); Xstatic int new_cursor(); Xstatic void iqprepare(), iqdscribe(), iqddclcur(), iqcopen(), iqnftch(); Xstatic void iqexecute(), iqclose(), iqfree(); Xstatic void save_dbdetails(), forget_dbdetails(); X X#include "isqlperl.h" X#include "isqlmus.c" X X# define MAXDATA 92 /* max length of non-string sql datatype when X * represented as a string - wasteful but safe X */ X X/* various maiximum lengths for string representations */ X/* In cases of uncertainty, I've erred on the side of caution */ X#define MAXINTLEN 24 X#define MAXSMINTLEN 12 X#define MAXINTERVALLEN 26 X#define MAXDTIMELEN 26 X#define MAXMONEYLEN 34 X#define MAXDATELEN 11 X#define MAXSERIALLEN MAXINTLEN X#define MAXDECIMALLEN 34 X#define MAXSMFLOATLEN MAXDECIMALLEN X#define MAXFLOATLEN MAXDECIMALLEN X#define MAXNULLLEN 1 X X/* maxcursors defined by perl preprocessor run on this file */ Xstatic cursor cursors[MAXCURSORS + 1]; /* + 1 for one off statements */ X X#if !defined(_H_STDLIB) Xextern char *calloc(); X#endif X X#define new_(type) ((type *) calloc(1, sizeof (type))) X#define nnew_(num, type) ((type *) calloc((num), sizeof (type))) X X#define free_(thing) do{if(thing){(void)free(thing);thing=NULL;}}while(0) X X#define min(x,y) ((x) < (y) ? (x) : (y)) X X/* #define DEBUG_SQL */ X X#ifdef DEBUG_SQL X#define debug(x) do { printf x ; fflush(stdout); } while(0) X#else X#define debug(x) X#endif X X#define BADCURSOR -276 /* `Cursor not found' */ X X#ifdef NOSTRDUP Xchar *strdup(str) Xchar *str; X{ X char *res = calloc(strlen(str) + 1, 1); X if (res != NULL) X strcpy(res, str); X return(res); X} X#endif X X/*---------------------------------------------------* X * Function: isql_execute X * X * Purpose: when in doubt, use this one X * X * Arguments: sp and nitems X * X * Returns: logical not of sqlca.sqlcode X * X *---------------------------------------------------*/ X Xstatic int isql_execute(sp, items) Xint sp, items; X{ X $char *cmd; X struct sqlca_s saved_ex_ca; X struct sqlda *parameters; X STR **st = stack->ary_array + sp; X char *buf; X int sttmnttype; X X cmd = str_get(st[1]); X X $ prepare ex from $cmd; X if (sqlca.sqlcode) X return 0; X X $ describe ex into parameters; X X if (sqlca.sqlcode < 0) X { X saved_ex_ca = sqlca; X $free ex; X sqlca = saved_ex_ca; X return 0; X } X X sttmnttype = sqlca.sqlcode; X sqlca.sqlcode = 0; X X if (sttmnttype == 0) X { X $free ex; X sqlca.sqlcode = BADCURSOR; X return 0; X } X else if (sttmnttype == SQ_COMMIT) X { X register int i; X int warned = 0; X X for (i = 0; i < MAXCURSORS; ++i) X if (cursors[i].is_open == opened) X { X free_cursor(i); X if (!warned) X { X WARN("Cursors closed by COMMIT WORK"); X warned = 1; X } X } X } X X if (parameters->sqld == 0 && (parameters->sqld = count_parameters(cmd)) != 0) X /* we were lied to */ X allocate_sqlvar_for(parameters); X X buf = prepare_input_sqlda(parameters); X perl_to_sqlda(sp, items, parameters); X X $ execute ex using descriptor parameters; X X free_(buf); X X if (sttmnttype == SQ_DATABASE || sttmnttype == SQ_CREADB) X { X if (sqlca.sqlcode) X forget_dbdetails(); X else X save_dbdetails(cmd); X } X else if (sttmnttype == SQ_CLSDB) X forget_dbdetails(); X X /* execute *sometimes* frees a $database statement @!$#!!! */ X if (sttmnttype != SQ_DATABASE) X { X saved_ex_ca = sqlca; X $ free ex; X sqlca = saved_ex_ca; X } X X return !sqlca.sqlcode; X} X X/*---------------------------------------------------* X * Function: isql_open X * X * Purpose: opens a cursor, stores the result X * X * Arguments: string select statement X * X * Returns: index of cursor, or 0 on error X * X *---------------------------------------------------*/ X Xstatic int isql_open(selectstmnt, sp, items) Xchar *selectstmnt; Xint sp, items; X{ X int i; X int sqc; X struct sqlvar_struct *col; X struct sqlda *parameters; X X if ((sqc = new_cursor()) == -1) X return 0; X X /* $ prepare usqlobj from $slctstmnt; */ X iqprepare(sqc, selectstmnt); X X if (sqlca.sqlcode) X { X eclose_cursor(sqc); X return 0; X } X X /* $ describe usqlobj into udesc; */ X iqdscribe(sqc); X X if (sqlca.sqlcode < 0) /* statement type >= 0 if success */ X { X eclose_cursor(sqc); X return 0; X } X X cursors[sqc].sttmnttype = sqlca.sqlcode; X sqlca.sqlcode = 0; /* loose the statement type from sqlcode */ X X if (cursors[sqc].sttmnttype == 0) /* select */ X { X save_sqlda_types(sqc); X cursors[sqc].buffer = prepare_output_sqlda(cursors[sqc].udesc); X cursors[sqc].is_open = allocated; X X /* $ declare usqlcurs cursor for usqlobj; */ X iqddclcur(sqc); X X if (sqlca.sqlcode != 0) X { X eclose_cursor(sqc); X return 0; X } X X if ((parameters = new_(struct sqlda)) == NULL) X fatal("out of memory"); X X if ((parameters->sqld = count_parameters(selectstmnt)) != 0) X allocate_sqlvar_for(parameters); X X /* sqlda for the where clause */ X (void) prepare_input_sqlda(parameters); /* won't allocate */ X perl_to_sqlda(sp, items, parameters); X X /* $ open usqlcurs; */ X iqcopen(sqc, parameters); X X free_(parameters->sqlvar); X free_(parameters); X X if (sqlca.sqlcode != 0) X { X eclose_cursor(sqc); X return 0; X } X } X else /* not a select */ X { X if (cursors[sqc].udesc->sqld == 0 && X (cursors[sqc].udesc->sqld = count_parameters(selectstmnt)) != 0) X { X allocate_sqlvar_for(cursors[sqc].udesc); X } X X save_sqlda_types(sqc); X X cursors[sqc].buffer = prepare_input_sqlda(cursors[sqc].udesc); X cursors[sqc].is_open = allocated; X } X X cursors[sqc].statement = strdup(selectstmnt); X X return ++sqc; /* indexed from 1 externally */ X} X X/*--------------------------------------------------- X * Function: isql_columns X * X * Purpose: returns types of vars from cursor or statement X * X * Arguments: perl stack pointer and cursor number X * X * Returns: list of values or () X * X *---------------------------------------------------*/ X Xstatic int isql_columns(sp, sqc) Xint sp, sqc; X{ X struct sqltype_struct *col; X STR **st = stack->ary_array + sp; X int i; X char typebuf[80]; X X --sqc; X X if (sqc < 0 || sqc >= MAXCURSORS || !cursors[sqc].is_open) X { X sqlca.sqlcode = BADCURSOR; X return sp - 1; X } X X if (!curcsv->wantarray) X { X str_numset(st[0], (double) cursors[sqc].tdesc->sqld); X return sp; X } X else X { X astore(stack, sp + cursors[sqc].tdesc->sqld, Nullstr); X st = stack->ary_array + sp; X X for (col = cursors[sqc].tdesc->sqltype, i = 0; X i < cursors[sqc].tdesc->sqld; X ++col, ++i) X { X switch (col->sqltype) X { X case SQLCHAR: X sprintf(typebuf, "CHAR(%d)", col->sqllen); X st[i] = str_2mortal(str_make(typebuf, strlen(typebuf))); X break; X X case SQLSMINT: X strcpy(typebuf, "SMALLINT"); X st[i] = str_2mortal(str_make("SMALLINT", 8)); X break; X X case SQLINT: X st[i] = str_2mortal(str_make("INTEGER", 7)); X break; X X case SQLFLOAT: X st[i] = str_2mortal(str_make("FLOAT", 5)); X break; X X case SQLSMFLOAT: X st[i] = str_2mortal(str_make("SMALLFLOAT", 10)); X break; X X case SQLDECIMAL: X st[i] = str_2mortal(str_make("DECIMAL", 7)); X break; X X case SQLSERIAL: X st[i] = str_2mortal(str_make("SERIAL", 6)); X break; X X case SQLDATE: X st[i] = str_2mortal(str_make("DATE", 4)); X break; X X case SQLMONEY: X st[i] = str_2mortal(str_make("MONEY", 5)); X break; X#ifndef TURBO X case SQLINTERVAL: X strcpy(typebuf, "INTERVAL "); X strcat(typebuf, dti_qual(TU_START(col->sqllen))); X strcat(typebuf, " TO "); X strcat(typebuf, dti_qual(TU_END(col->sqllen))); X st[i] = str_2mortal(str_make(typebuf, strlen(typebuf))); X break; X X case SQLDTIME: X strcpy(typebuf, "DATETIME "); X strcat(typebuf, dti_qual(TU_START(col->sqllen))); X strcat(typebuf, " TO "); X strcat(typebuf, dti_qual(TU_END(col->sqllen))); X st[i] = str_2mortal(str_make(typebuf, strlen(typebuf))); X break; X#endif X#ifdef ONLINE X case SQLVCHAR: X sprintf(typebuf, "VARCHAR(%d, %d)", VCMIN(col->sqllen), X VCMAX(col->sqllen)); X st[i] = str_2mortal(str_make(typebuf, strlen(typebuf))); X break; X X case SQLTEXT: X st[i] = str_2mortal(str_make("TEXT", 4)); X break; X X case SQLBYTES: X st[i] = str_2mortal(str_make("BYTE", 4)); X break; X#endif X default: X st[i] = str_2mortal(str_make("UNRECOGNISED", 12)); X break; X } X } X X return sp + cursors[sqc].udesc->sqld - 1; X } X} X X X/*---------------------------------------------------* X * Function: isql_fetch X * X * Purpose: fetches from open cursor X * X * Arguments: perl stack pointer and cursor number X * X * Returns: list of values, or () X * X *---------------------------------------------------*/ X Xstatic int isql_fetch(sp, sqc) Xint sp; Xint sqc; X{ X STR **st = stack->ary_array + sp; X --sqc; /* zero indexed internally */ X X if (sqc < 0 || sqc >= MAXCURSORS || cursors[sqc].is_open != opened) X { X sqlca.sqlcode = BADCURSOR; X return sp - 1; /* empty array */ X } X X /* $ fetch usqlcurs using descriptor udesc; */ X iqnftch(sqc); X X if (!curcsv->wantarray) X { X if (sqlca.sqlcode == 0) X str_numset(st[0], (double) cursors[sqc].udesc->sqld); X else X { X if (autoclose) X eclose_cursor(sqc); X str_numset(st[0], (double) 0.0); X } X return sp; X } X else X { X if (sqlca.sqlcode == 0) X return (sqlda_to_perl(sp, cursors[sqc].udesc)); X else X { X if (autoclose) X eclose_cursor(sqc); X X return sp - 1; /* empty array ??? */ X } X } X} X X/*--------------------------------------------------- X * Function: isql_put X * X * Purpose: executes prepared statement X * X * Arguments: perl stack pointer number of items X * X * Returns: !sqlca.sqlcode X * X *---------------------------------------------------*/ X Xstatic int isql_put(sp, items) Xint sp, items; X{ X STR **st = stack->ary_array + sp; X int sqc = str_gnum(st[1]); X X --sqc; X X if (sqc < 0 || sqc >= MAXCURSORS || X cursors[sqc].is_open == closed || cursors[sqc].is_open == opened) X { X sqlca.sqlcode = BADCURSOR; X return 0; X } X X perl_to_sqlda(sp, items, cursors[sqc].udesc); X X if (cursors[sqc].sttmnttype == SQ_COMMIT) X { X register int i; X int warned = 0; X X for (i = 0; i < MAXCURSORS; ++i) X if (i != sqc) X { X free_cursor(i); X if (!warned) X { X WARN("Cursors closed by COMMIT WORK"); X warned = 1; X } X } X } X iqexecute(sqc); X X if (cursors[sqc].sttmnttype == SQ_DATABASE || X cursors[sqc].sttmnttype == SQ_CREADB) X { X if (sqlca.sqlcode) X forget_dbdetails(); X else X save_dbdetails(cursors[sqc].statement); X } X else if (cursors[sqc].sttmnttype == SQ_CLSDB) X forget_dbdetails(); X X X return (!sqlca.sqlcode); X} X/*--------------------------------------------------- X * Function: isql_select X * X * Purpose: opens fetches returns and closes X * X * Arguments: string select statement X * perl sp and items X * X * Returns: new sp X * X *---------------------------------------------------*/ X Xstatic int isql_select(selectstmnt, sp, items) X$char *selectstmnt; Xint sp, items; X{ X STR **st = stack->ary_array + sp; X int i; X struct sqlvar_struct *col; X struct sqlda *parameters, *udesc; X char *buffer; X struct sqlca_s save; X X $ prepare usqlobj from $selectstmnt; X X if (sqlca.sqlcode) X { X if (!curcsv->wantarray) X str_numset(st[0], (double) 0.0); X else X --sp; X return(sp); X } X X $ describe usqlobj into udesc; X X if (sqlca.sqlcode < 0) /* statement type >= 0 if success */ X return (sp - 1); X X if (sqlca.sqlcode != 0) /* select */ X { X $free usqlobj; X sqlca.sqlcode = BADCURSOR; X if (!curcsv->wantarray) X str_numset(st[0], (double) 0.0); X else X --sp; X return(sp); X } X else X { X buffer = prepare_output_sqlda(udesc); X X $ declare usqlcurs cursor for usqlobj; X X if (sqlca.sqlcode != 0) X { X save = sqlca; X $free usqlobj; X sqlca = save; X free_(buffer); X if (!curcsv->wantarray) X str_numset(st[0], (double) 0.0); X else X --sp; X return(sp); X } X X if ((parameters = new_(struct sqlda)) == NULL) X fatal("out of memory"); X X if ((parameters->sqld = count_parameters(selectstmnt)) != 0) X { X if ((parameters->sqlvar = X nnew_(parameters->sqld, struct sqlvar_struct)) == NULL) X fatal("out of memory"); X X for (i = 0, col = parameters->sqlvar; X i < parameters->sqld; X ++i, ++col) X col->sqltype = SQLCHAR; X } X X /* sqlda for the where clause */ X (void) prepare_input_sqlda(parameters); /* won't allocate */ X perl_to_sqlda(sp, items, parameters); X X $ open usqlcurs using descriptor parameters; X X free_(parameters->sqlvar); X free_(parameters); X X if (sqlca.sqlcode != 0) X { X save = sqlca; X $free usqlobj; X sqlca = save; X free_(buffer); X if (!curcsv->wantarray) X str_numset(st[0], (double) 0.0); X else X --sp; X return(sp); X } X } X X $ fetch usqlcurs using descriptor udesc; X X if (!curcsv->wantarray) X { X if (sqlca.sqlcode == 0) X str_numset(st[0], (double) udesc->sqld); X else X str_numset(st[0], (double) 0.0); X } X else X { X if (sqlca.sqlcode == 0) X sp = sqlda_to_perl(sp, udesc); X else X --sp; /* empty array ??? */ X } X X save = sqlca; X $close usqlcurs; X $free usqlobj; X sqlca = save; X free_(buffer); X return sp; X} X X/*--------------------------------------------------- X * Function: isql_type X * X * Purpose: returns type of statement id X * X * Arguments: cursor index X * X * Returns: string name X * X *---------------------------------------------------*/ X Xstatic char *isql_type(sqc) Xint sqc; X{ X --sqc; X if (sqc < 0 || sqc >= MAXCURSORS) X return("INVALID"); X X if (cursors[sqc].is_open == closed) X return("CLOSED"); X X switch (cursors[sqc].sttmnttype) X { X case 0: return("SELECT"); X#include "sqlstype.c" X default: return("UNRECOGNISED"); X } X} X X/**************************************************** X * Function: isql_statement X * X * Purpose: returns statement associated with id X * X * Arguments: cursor index X * X * Returns: associated statement X * X *****************************************************/ X Xstatic char *isql_statement(sqc) Xint sqc; X{ X --sqc; X if (sqc < 0 || sqc >= MAXCURSORS || cursors[sqc].is_open == closed) X { X sqlca.sqlcode = BADCURSOR; X return(""); X } X return (cursors[sqc].statement); X} X X/*---------------------------------------------------* X * Function: isql_titles X * X * Purpose: fetches titles from open cursor X * X * Arguments: perl stack pointer and cursor number X * X * Returns: list of names, or () X * X *---------------------------------------------------*/ X Xstatic int isql_titles(sp, sqc) Xint sp; Xint sqc; X{ X struct sqlvar_struct *col; X STR **st = stack->ary_array + sp; X int i; X char *tmps; X static void iqnftch(); X X --sqc; /* zero indexed internally */ X X if (sqc < 0 || sqc >= MAXCURSORS || !cursors[sqc].is_open) X { X sqlca.sqlcode = BADCURSOR; X return (sp -1); X } X X if (!curcsv->wantarray) /* return the number of fields */ X { X str_numset(st[0], (double) cursors[sqc].udesc->sqld); X return sp; X } X else X { X astore(stack, sp + cursors[sqc].udesc->sqld, Nullstr); X st = stack->ary_array + sp; X X for (col = cursors[sqc].udesc->sqlvar, i = 0; X i < cursors[sqc].udesc->sqld; X ++col, ++i) X { X tmps = col->sqlname; X st[i] = str_2mortal(str_make(tmps, strlen(tmps))); X } X X return sp + cursors[sqc].udesc->sqld - 1; X } X} X X/*---------------------------------------------------* X * Function: isql_close X * X * Purpose: just calls free_cursor X * X * Arguments: cursor index X * X * Returns: status X * X *---------------------------------------------------*/ X Xstatic int isql_close(sqc) Xint sqc; X{ X --sqc; X X if (sqc < 0 || sqc >= MAXCURSORS || !cursors[sqc].is_open) X { X sqlca.sqlcode = BADCURSOR; X return 0; X } X X free_cursor(sqc); X return (!sqlca.sqlcode); X} X X/*---------------------------------------------------* X * Function: isql_shutdown X * X * Purpose: calls sqlexit X * X * Arguments: nothing X * X * Returns: status X * X *---------------------------------------------------*/ X Xstatic int isql_shutdown() X{ X int i; X extern int forkflag; /* horrible - this is undocumented libsql variable */ X X for (i = 0; i < MAXCURSORS; ++i) X free_cursor(i); X X if (forkflag == 0) X return 1; X X $ close database; /* ignore any status back from this */ X X#if !defined(TURBO) && defined(HAS_V410PLUS) X sqlexit(); /* kill the sqlexec */ X#else X WARN("&isql_shutdown() not fully implemented"); X#endif X X return(!sqlca.sqlcode); X} X/*--------------------------------------------------- X * Function: isql_ca X * X * Purpose: access to sqlca X * X * Arguments: perl sp X * X * Returns: sqlca in an array context X * X *---------------------------------------------------*/ X X#define SQLCAELEMENTS 17 X Xstatic int isql_ca(sp) Xint sp; X{ X STR **st = stack->ary_array + sp; X int i, j; X X if (curcsv->wantarray) X { X astore(stack, sp + SQLCAELEMENTS, Nullstr); X st = stack->ary_array + sp; X X st[0] = str_mortal(&str_no); X str_numset(st[0], (double) sqlca.sqlcode); X X st[1] = str_2mortal(str_make(sqlca.sqlerrm, strlen(sqlca.sqlerrm))); X X st[2] = str_2mortal(str_make(sqlca.sqlerrp, 8)); X X for (i = 3, j = 0; i < 9; ++i, ++j) X { X st[i] = str_mortal(&str_no); X str_numset(st[i], (double) sqlca.sqlerrd[j]); X } X X st[9] = str_2mortal(str_make(&(sqlca.sqlwarn.sqlwarn0), 1)); X st[10] = str_2mortal(str_make(&(sqlca.sqlwarn.sqlwarn1), 1)); X st[11] = str_2mortal(str_make(&(sqlca.sqlwarn.sqlwarn2), 1)); X st[12] = str_2mortal(str_make(&(sqlca.sqlwarn.sqlwarn3), 1)); X st[13] = str_2mortal(str_make(&(sqlca.sqlwarn.sqlwarn4), 1)); X st[14] = str_2mortal(str_make(&(sqlca.sqlwarn.sqlwarn5), 1)); X st[15] = str_2mortal(str_make(&(sqlca.sqlwarn.sqlwarn6), 1)); X st[16] = str_2mortal(str_make(&(sqlca.sqlwarn.sqlwarn7), 1)); X X return sp + SQLCAELEMENTS - 1; X } X else X { X str_numset(st[0], (double) SQLCAELEMENTS); X return sp; X } X} X/**************************************************** X * Function: save_dbdetails X * X * Purpose: remembers details about just X * created or selected database X * X * Arguments: command containing database name X * X * Returns: void X * X *****************************************************/ X Xstatic void save_dbdetails(cmd) Xchar *cmd; X{ X char *cmdcpy; X X cmdcpy = strdup(cmd); X X if (cmdcpy == NULL) X fatal("out of memory"); X X /* canonicalise */ X for (cmd = cmdcpy; *cmd; ++cmd) X { X if (isupper(*cmd)) X *cmd = tolower(*cmd); X if (isspace(*cmd)) X *cmd = ' '; X } X cmd = strtok(cmdcpy, " "); X while (cmd) X { X if (strcmp(cmd, "database") == 0) { X cmd = strtok(NULL, " "); X free_(isql_database); X if (cmd) X isql_database = strdup(cmd); X break; X } X cmd = strtok(NULL, " "); X } X free(cmdcpy); X X isql_transactions = sqlca.sqlwarn.sqlwarn1 == 'W'; X isql_ansi = sqlca.sqlwarn.sqlwarn2 == 'W'; X isql_online = sqlca.sqlwarn.sqlwarn3 == 'W'; X} X/**************************************************** X * Function: forget_dbdetails X * X * Purpose: forgets details if database is closed X * X * Arguments: none X * X * Returns: void X * X *****************************************************/ X Xstatic void forget_dbdetails() X{ X free_(isql_database); X isql_transactions = isql_ansi = isql_online = 0; X} X X/*--------------------------------------------------- X * Function: dti_qual X * X * Purpose: returns string representation of X * interval or dt q X * (helper for isql_columns()) X * X * Arguments: qualifier X * X * Returns: name X * X *---------------------------------------------------*/ X X#ifndef TURBO Xstatic char *dti_qual(qual) Xint qual; X{ X switch(qual) X { X case TU_YEAR: return ("YEAR"); X case TU_MONTH: return ("MONTH"); X case TU_DAY: return ("DAY"); X case TU_HOUR: return ("HOUR"); X case TU_MINUTE: return ("MINUTE"); X case TU_SECOND: return ("SECOND"); X case TU_F1: return ("FRACTION(1)"); X case TU_F2: return ("FRACTION(2)"); X case TU_F3: return ("FRACTION(3)"); X case TU_F4: return ("FRACTION(4)"); X case TU_F5: return ("FRACTION(5)"); X default: return ("?"); X } X} X#endif X/*--------------------------------------------------- X * Function: save_sqlda_types X * X * Purpose: retains relevant info from struct sqlda X * X * Arguments: cursor index X * X * Returns: void X * X *---------------------------------------------------*/ Xstatic void save_sqlda_types(sqc) Xint sqc; X{ X register int i; X register struct sqlvar_struct *var; X register struct sqltype_struct *type; X struct sqlta *new; X struct sqlda *old; X X if ((cursors[sqc].tdesc = new_(struct sqlta)) == NULL) X fatal("out of memory"); X X new = cursors[sqc].tdesc; X old = cursors[sqc].udesc; X X debug(("statement has %d parameters\n", old->sqld)); X if ((new->sqld = old->sqld) != 0) X { X if ((new->sqltype = nnew_(new->sqld, struct sqltype_struct)) == NULL) X fatal("out of memory"); X X for (i = 0, type = new->sqltype, var = old->sqlvar; X i < new->sqld; X ++i, ++type, ++var) X { X debug(("param %d is type %d\n", i, var->sqltype)); X type->sqltype = var->sqltype; X type->sqllen = var->sqllen; X } X } X} X X/*--------------------------------------------------- X * Function: prepare_input_sqlda X * X * Purpose: allocates buffers and sets data types X * for an input sqlda called by open and X * execute of a non-select statement X * also called to prepare the sqlda for X * the where clause of a select statement X * X * Arguments: newly described sqlda X * X * Returns: char * buffer allocated for X * on line Blob locators X * X *---------------------------------------------------*/ X Xstatic char *prepare_input_sqlda(parameters) Xstruct sqlda *parameters; X{ X register struct sqlvar_struct *par; X register int i; X#ifdef ONLINE X loc_t *locp; X loc_t *blobbuf; X int nblobs = 0; X#endif X X for (i = 0, par = parameters->sqlvar; i < parameters->sqld; ++i, ++par) X { X switch(par->sqltype) X { X#ifdef ONLINE X case SQLBYTES: X case SQLTEXT: X ++nblobs; X /* indicators are in the BLOB */ X par->sqltype = CLOCATORTYPE; X par->sqlind = NULL; X par->sqlidata = NULL; X break; X#endif X default: X par->sqltype = CSTRINGTYPE; X break; X } X#ifndef TURBO X par->sqlitype = CSHORTTYPE; X par->sqlilen = sizeof(short); X#endif X } X X#ifdef ONLINE X if (nblobs) X { X if ((blobbuf = nnew_(nblobs, loc_t)) == NULL) X fatal("out of memory"); X X for (i = 0, par = parameters->sqlvar; nblobs; ++i, ++par, --nblobs) X { X if (par->sqltype == CLOCATORTYPE) X { X par->sqldata = (char *) &blobbuf[nblobs - 1]; X locp = (loc_t *) par->sqldata; X locp->loc_loctype = LOCMEMORY; X } X } X return ((char *) blobbuf); X } X else X#endif X return NULL; X} X/*--------------------------------------------------- X * Function: prepare_output_sqlda X * X * Purpose: allocates sqlda and buffer for output X * from a select X * X * Arguments: cursor index X * X * Returns: allocated buffer X * X *---------------------------------------------------*/ X Xstatic char * prepare_output_sqlda(udesc) Xstruct sqlda *udesc; X{ X int pos = 0; X register struct sqlvar_struct *col; X register int i; X char *cp, *rtypalign(), *buffer; X X for (col = udesc->sqlvar, i = 0; i < udesc->sqld; col++, i++) X { X switch (col->sqltype & SQLTYPE) /* necessary ??? */ X { X case SQLCHAR: X col->sqltype = CSTRINGTYPE; X ++(col->sqllen); X break; X#ifdef ONLINE X case SQLBYTES: X case SQLTEXT: X col->sqltype = CLOCATORTYPE; X col->sqllen = sizeof(loc_t); X break; X X case SQLVCHAR: X col->sqltype = CSTRINGTYPE; X col->sqllen = VCMAX(col->sqllen) + 1; X break; X#endif X case SQLSMINT: X col->sqltype = CSTRINGTYPE; X col->sqllen = MAXSMINTLEN; X break; X X case SQLINT: X col->sqltype = CSTRINGTYPE; X col->sqllen = MAXINTLEN; X break; X X case SQLFLOAT: X col->sqltype = CSTRINGTYPE; X col->sqllen = MAXFLOATLEN; X break; X X case SQLSMFLOAT: X col->sqltype = CSTRINGTYPE; X col->sqllen = MAXSMFLOATLEN; X break; X X case SQLDECIMAL: X col->sqltype = CSTRINGTYPE; X col->sqllen = MAXDECIMALLEN; X break; X X case SQLSERIAL: X col->sqltype = CSTRINGTYPE; X col->sqllen = MAXSERIALLEN; X break; X X case SQLDATE: X col->sqltype = CSTRINGTYPE; X col->sqllen = MAXDATELEN; X break; X X case SQLMONEY: X col->sqltype = CSTRINGTYPE; X col->sqllen = MAXMONEYLEN; X break; X#ifndef TURBO X case SQLDTIME: X col->sqltype = CSTRINGTYPE; X col->sqllen = MAXDTIMELEN; X break; X X case SQLINTERVAL: X col->sqltype = CSTRINGTYPE; X col->sqllen = MAXINTERVALLEN; X break; X#endif X case SQLNULL: X col->sqltype = CSTRINGTYPE; X col->sqllen = MAXNULLLEN; X break; X X default: X col->sqllen = MAXDATA; /* O.T.T. */ X break; X } X X /* work out how big a buffer we'll need */ X pos = (int) rtypalign(pos, CLONGTYPE); /* round up data ptr */ X pos += col->sqllen; /* add length */ X pos = (int) rtypalign(pos, CSHORTTYPE); /* round up indicator */ X pos += sizeof(short); /* add the length */ X } X X buffer = calloc(1, pos); /* couple of K, tops */ X X if (buffer == NULL) X fatal("prepare_output_sqlda - out of memory"); X X X /* point each column into the buffer */ X for (col = udesc->sqlvar, i = 0, cp = buffer; i < udesc->sqld; ++col, ++i) X { X cp = rtypalign(cp, CLONGTYPE); /* round up data ptr */ X col->sqldata = cp; /* and assign */ X cp += col->sqllen; /* add the length */ X cp = rtypalign(cp, CSHORTTYPE); /* round up indicator */ X col->sqlind = (short *) cp; /* and assign */ X#ifndef TURBO X col->sqlidata = (char *) col->sqlind; /* other indicator */ X col->sqlitype = CSHORTTYPE; X col->sqlilen = sizeof(short); X#endif X cp += sizeof(short); /* add the length of the indicator */ X X#ifdef ONLINE X /* initialise any locator struct */ X if (col->sqltype == CLOCATORTYPE) X { X loc_t *locp = (loc_t *) col->sqldata; X locp->loc_loctype = LOCMEMORY; X locp->loc_type = col->sqltype; X locp->loc_buffer = NULL; X locp->loc_indicator = 0; X locp->loc_size = locp->loc_bufsize = -1; X } X#endif X } X X return(buffer); X} X/*--------------------------------------------------- X * Function: perl_to_sqlda X * X * Purpose: fills in the values for an input sqlda X * X * Arguments: sp, items, and partially allocated sqlda X * X * Returns: void X * X *---------------------------------------------------*/ X Xstatic void perl_to_sqlda(sp, items, parameters) Xint sp, items; Xstruct sqlda *parameters; X{ X STR **st = stack->ary_array + sp; X register struct sqlvar_struct *par; X static short myind = -1; X register int i, p; X#ifdef ONLINE X loc_t *locp; X#endif X X for (i = 0, p = 2, par = parameters->sqlvar; X i < parameters->sqld; X ++i, ++p, ++par) X { X#ifdef ONLINE X if (par->sqltype == CLOCATORTYPE) X { X locp = (loc_t *) par->sqldata; X X if (p <= items && X st[p] != &str_undef && X (st[p]->str_nok || st[p]->str_pok)) X { X locp->loc_indicator = 0; X locp->loc_buffer = str_get(st[p]); X locp->loc_size = locp->loc_bufsize = st[p]->str_len - 1; X } X else X { X locp->loc_indicator = -1; X locp->loc_buffer = NULL; X } X } X else X#endif X if (p <= items && X st[p] != &str_undef && X (st[p]->str_nok || st[p]->str_pok)) X { X par->sqlind = NULL; X par->sqldata = str_get(st[p]); X par->sqllen = strlen(par->sqldata) + 1; X } X else X { X par->sqlind = &myind; X#ifndef TURBO X par->sqlidata = (char *) par->sqlind; X#endif X } X } X} X/*--------------------------------------------------- X * Function: sqlda_to_perl X * X * Purpose: fills perl array from sqlda X * X * Arguments: perl sp and sqlda X * X * Returns: sp X * X *---------------------------------------------------*/ X Xstatic int sqlda_to_perl(sp, udesc) Xint sp; Xstruct sqlda *udesc; X{ X STR **st = stack->ary_array + sp; X struct sqlvar_struct *col; X int i; X X astore(stack, sp + udesc->sqld, Nullstr); X X for (col = udesc->sqlvar, i = 0; i < udesc->sqld; ++col, ++i) X { X#ifdef ONLINE X if (col->sqltype == CLOCATORTYPE) X { X if (*(col->sqlind) >= 0) X { X loc_t *locp = (loc_t *) col->sqldata; X X if (locp->loc_indicator >= 0) X st[i] = str_2mortal(str_make(locp->loc_buffer, X locp->loc_size)); X else X st[i] = str_mortal(&str_undef); X } X else X st[i] = str_mortal(&str_undef); X } X else X { X#endif X if (*(col->sqlind) >= 0) X st[i] = str_2mortal(str_make(col->sqldata, strlen(col->sqldata))); X else X st[i] = str_mortal(&str_undef); X#ifdef ONLINE X } X#endif X } X X return sp + udesc->sqld - 1; X} X/*--------------------------------------------------- X * Function: count_parameters X * X * Purpose: counts the number of placeholders X * in an sql statement X * X * Arguments: string to parse X * X * Returns: count of parameters X * X *---------------------------------------------------*/ X Xstatic short count_parameters(sttmnt) Xregister char *sttmnt; X{ X register short strmask = -1; X register short count = 0; X X for(;;) X { X switch (*sttmnt++) X { X case '"': X strmask = ~strmask; X break; X case '?': X count += strmask & 1; X break; X case '\0': X return count; X } X } X} X/**************************************************** X * Function: allocate_sqlvar_for X * X * Purpose: allocates sqlvar for arg sqlda X * *assumes* sqld > 0 X * this should only get called if the X * $describe reports 0 parameters X * when in fact there are some. X * i.e. for other than a select or X * an insert. X * X * Arguments: sqlda X * X * Returns: nothing X * X *****************************************************/ X Xstatic void allocate_sqlvar_for(parameters) Xstruct sqlda *parameters; X{ X int i; X struct sqlvar_struct *col; X X if ((parameters->sqlvar = nnew_(parameters->sqld, struct sqlvar_struct)) == NULL) X fatal("out of memory"); X X for (i = 0, col = parameters->sqlvar; i < parameters->sqld; ++i, ++col) X { X col->sqltype = SQLCHAR; X /* best I can do without parsing the statement and X * querying systables: X */ X col->sqlname = strdup("UNKNOWN"); X } X} X/*--------------------------------------------------- X * Function: isql_maxcursors X * X * Purpose: just returns MAXCURSORS, which is X * only visible in the .pec file X * X * Arguments: none X * X * Returns: MAXCURSORS X * X *---------------------------------------------------*/ X Xstatic int isql_maxcursors() { return MAXCURSORS; } X X/*--------------------------------------------------- X * Function: eclose_cursor X * X * Purpose: saves sqlca around call to free_cursor X * X * Arguments: cursor index X * X * Returns: void X * X *---------------------------------------------------*/ X Xstatic void eclose_cursor(sqc) Xint sqc; X{ X struct sqlca_s save; X save = sqlca; X free_cursor(sqc); X sqlca = save; X} X X/*---------------------------------------------------* X * Function: free_cursor X * X * Purpose: frees/closes/deallocates/removes/obliterates ... X * X * Arguments: cursor index X * X * Returns: status X * X *---------------------------------------------------*/ X Xstatic void free_cursor(sqc) Xint sqc; X{ X switch (cursors[sqc].is_open) /* fallthrough case statement */ X { X case opened: X iqclose(sqc); /* $ close usqlcurs; */ X case declared: X case allocated: X free_(cursors[sqc].buffer); X free_(cursors[sqc].statement); X case described: X free_(cursors[sqc].tdesc->sqltype); X free_(cursors[sqc].tdesc); X case prepared: X iqfree(sqc); /* $ free usqlobj; */ X case closed: X break; X } X X cursors[sqc].is_open = closed; X} X X/*---------------------------------------------------* X * Function: new_cursor X * X * Purpose: locates a free cursor from the array X * X * Arguments: none X * X * Returns: cursor id or -1 if not found X * X *---------------------------------------------------*/ X Xstatic int new_cursor() X{ X int i; X X for (i = 0; i < MAXCURSORS; ++i) X { X if (!cursors[i].is_open) X { X bzero(&cursors[i], sizeof (cursor)); X return i; X } X } X X sqlca.sqlcode = -276; /* fake: `Cursor not found' */ X return -1; X} X X/*--------------------------------------------------- X * Function: iqprepare X * X * Purpose: prepares nominated cursor from select statement X * X * Arguments: cursor index and statement X * X * Returns: void X * X *---------------------------------------------------*/ X Xstatic void iqprepare(sqc, slctstmnt) Xint sqc; X$char *slctstmnt; X{ X switch (sqc) X { X/* pec2ec script expands this */ XINTERVAL X case THISNUMBER: X $ prepare usqlobjTHISNUMBER from $slctstmnt; X break; XEND X } X X if (sqlca.sqlcode == 0) X cursors[sqc].is_open = prepared; X} X X/*--------------------------------------------------- X * Function: iqdscribe X * X * Purpose: describes cursor into relevant descriptor X * X * Arguments: cursor index X * X * Returns: void X * X *---------------------------------------------------*/ X Xstatic void iqdscribe(sqc) Xint sqc; X{ X struct sqlda *udesc = 0; X X switch (sqc) X { XINTERVAL X case THISNUMBER: X $ describe usqlobjTHISNUMBER into udesc; X break; XEND X } X X cursors[sqc].udesc = udesc; X X if (sqlca.sqlcode >= 0) X { X debug(("described statement is type %d\n", sqlca.sqlcode)); X cursors[sqc].is_open = described; X } X} X X/*--------------------------------------------------- X * Function: iqddclcur X * X * Purpose: declares relevant cursor X * X * Arguments: cursor index X * X * Returns: void X * X *---------------------------------------------------*/ X Xstatic void iqddclcur(sqc) Xint sqc; X{ X switch(sqc) X { XINTERVAL X case THISNUMBER: X $ declare usqlcursTHISNUMBER cursor for usqlobjTHISNUMBER; X break; XEND X } X X if (sqlca.sqlcode == 0) X cursors[sqc].is_open = declared; X} X X/*--------------------------------------------------- X * Function: iqcopen X * X * Purpose: opens relevant cursor X * X * Arguments: cursor index and parameters X * X * Returns: void X * X *---------------------------------------------------*/ X Xstatic void iqcopen(sqc, parameters) Xint sqc; Xstruct sqlda *parameters; X{ X switch (sqc) X { XINTERVAL X case THISNUMBER: X $ open usqlcursTHISNUMBER using descriptor parameters; X break; XEND X } X X if (sqlca.sqlcode == 0) X cursors[sqc].is_open = opened; X} X X/*--------------------------------------------------- X * Function: iqnftch X * X * Purpose: fetches from open cursor X * X * Arguments: cursor index X * X * Returns: void X * X *---------------------------------------------------*/ X Xstatic void iqnftch(sqc) Xint sqc; X{ X struct sqlda *udesc; X X udesc = cursors[sqc].udesc; X X switch (sqc) X { XINTERVAL X case THISNUMBER: X $ fetch usqlcursTHISNUMBER using descriptor udesc; X break; XEND X } X} X/*--------------------------------------------------- X * Function: iqexecute X * X * Purpose: executes statement X * X * Arguments: cursor index X * X * Returns: void X * X *---------------------------------------------------*/ X Xstatic void iqexecute(sqc) Xint sqc; X{ X struct sqlda *udesc; X X udesc = cursors[sqc].udesc; X X switch (sqc) X { XINTERVAL X case THISNUMBER: X $ execute usqlobjTHISNUMBER using descriptor udesc; X break; XEND X } X} X/*--------------------------------------------------- X * Function: iqclose X * X * Purpose: closes cursor X * X * Arguments: cursor index X * X * Returns: void X * X *---------------------------------------------------*/ X Xstatic void iqclose(sqc) Xint sqc; X{ X switch (sqc) X { XINTERVAL X case THISNUMBER: X $ close usqlcursTHISNUMBER; X break; XEND X } X} X/*--------------------------------------------------- X * Function: iqfree X * X * Purpose: frees closed cursor X * X * Arguments: cursor index X * X * Returns: void X * X *---------------------------------------------------*/ X Xstatic void iqfree(sqc) Xint sqc; X{ X switch (sqc) X { XINTERVAL X case THISNUMBER: X $ free usqlobjTHISNUMBER; X break; XEND X } X bzero(&cursors[sqc], sizeof(cursor)); X} END_OF_FILE if test 40383 -ne `wc -c <'isqlperl.pec'`; then echo shar: \"'isqlperl.pec'\" unpacked with wrong size! fi # end of 'isqlperl.pec' fi if test -f 'pec2ec' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'pec2ec'\" else echo shar: Extracting \"'pec2ec'\" \(2064 characters\) sed "s/^X//" >'pec2ec' <<'END_OF_FILE' X#!/usr/local/bin/perl X# X# change the above as appropriate X# X# $Id: pec2ec,v 1.5 1993/11/23 17:23:08 bill Exp $ X# X# This file is part of the isqlperl system. X# X# (c) Copyright 1993 by William Hails X# All rights reserved. X# X# This program is free software; you can redistribute it and/or modify X# it under the terms of the GNU General Public License as published by X# the Free Software Foundation. X# X# This program is distributed in the hope that it will be useful, X# but WITHOUT ANY WARRANTY; without even the implied warranty of X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X# GNU General Public License for more details. X# X# You should have received a copy of the GNU General Public License X# along with this program; if not, write to the Free Software X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X# X# You can email me as bill@tardis.co.uk or write to William Hails, CLI X# Connect Ltd., 19, Quarry Street, Guildford, Surrey, GU1 3UY. England. X# X# X# Quick hack to allow configuring of MAXCURSORS from the Makefile X# (expands case statements etc.) X X($progname = $0) =~ s#.*/##; X Xsub usage { X die "use: $progname \n"; X} X X$maxcursors = shift || &usage(); X$maxcursors =~ /^\d+$/ || &usage(); X$file = shift || &usage(); X Xopen(PEC, $file) || die "$file: $!"; X Xprint <) { X s/MAXCURSORS/$maxcursors/g; X X if (/^INTERVAL/ .. /^END/) { X if (/^INTERVAL/) { X $line = $. + 1; X $accum = ''; X } elsif (/^END/) { X for ($i = 0; $i < $maxcursors; ++$i) { X ($copy = $accum) =~ s/THISNUMBER/$i/g; X print qq!#line $line "$file"\n!; X print $copy; X } X printf qq!#line %d "$file"\n!, $. + 1; X } else { X $accum .= $_; X $accum .= sprintf(qq!#line %d "$file"\n!, $. + 1) if /^\s*\$/; X } X } else { X print; X do { printf qq!#line %d "$file"\n!, $. + 1; } if /^\s*\$/; X } X} END_OF_FILE if test 2064 -ne `wc -c <'pec2ec'`; then echo shar: \"'pec2ec'\" unpacked with wrong size! fi chmod +x 'pec2ec' # end of 'pec2ec' fi if test -f 'mkstype' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'mkstype'\" else echo shar: Extracting \"'mkstype'\" \(1323 characters\) sed "s/^X//" >'mkstype' <<'END_OF_FILE' X#!/usr/local/bin/perl X# X# $Id: mkstype,v 1.3 1993/11/23 16:59:01 bill Exp $ X# X# This file is part of the isqlperl system. X# X# (c) Copyright 1993 by William Hails X# All rights reserved. X# X# This program is free software; you can redistribute it and/or modify X# it under the terms of the GNU General Public License as published by X# the Free Software Foundation. X# X# This program is distributed in the hope that it will be useful, X# but WITHOUT ANY WARRANTY; without even the implied warranty of X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X# GNU General Public License for more details. X# X# You should have received a copy of the GNU General Public License X# along with this program; if not, write to the Free Software X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X# X# You can email me as bill@tardis.co.uk or write to William Hails, CLI X# Connect Ltd., 19, Quarry Street, Guildford, Surrey, GU1 3UY. England. X# X# X# make a case statement from a header file ($INFORMIXDIR/incl/sqlstype.h X# hopefully) to avoid version incompatibilities. X X($progname = $0) =~ s#.*/##; X Xprint <) { X /^#\s*define\s+SQ_(\w+)/ && print qq#case SQ_$1: return("$1");\n#; X} END_OF_FILE if test 1323 -ne `wc -c <'mkstype'`; then echo shar: \"'mkstype'\" unpacked with wrong size! fi chmod +x 'mkstype' # end of 'mkstype' fi if test -f 'testisql' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'testisql'\" else echo shar: Extracting \"'testisql'\" \(7611 characters\) sed "s/^X//" >'testisql' <<'END_OF_FILE' X#!./isqlperl -w X# X# $Id: testisql,v 1.10 1993/12/08 16:30:02 bill Exp $ X# X# demo script for isqlperl X X# insert your favourite database here X$database = 'tagdb'; X X# and your favourite table here X$table = 'calls'; X X# demonstrate $isql_autoclose X++$isql_autoclose; X X# demonstrate $isql_attrib Xprint "This is isqlperl $isql_attrib\n\n"; X($version, $engine, $macursors) = split(' ', $isql_attrib); Xprint <&1") || die "$!"; X select(DATABASES); X $~ = DATABASES; X write; X print "\n"; X select(STDOUT); X close(DATABASES); X} X X X$no_isql_databases = <; X} X Xsub ask { X print "@_ ?"; X chop($ans = ); X $ans; X} END_OF_FILE if test 7611 -ne `wc -c <'testisql'`; then echo shar: \"'testisql'\" unpacked with wrong size! fi chmod +x 'testisql' # end of 'testisql' fi if test -f 'usersub.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'usersub.c'\" else echo shar: Extracting \"'usersub.c'\" \(1410 characters\) sed "s/^X//" >'usersub.c' <<'END_OF_FILE' X/* $Header: /vol/tag/isqlperl/RCS/usersub.c,v 1.2 1993/09/05 22:26:53 bill Exp $ X * X * $Log: usersub.c,v $ X * Revision 1.2 1993/09/05 22:26:53 bill X * added license X * X * Revision 1.1 1993/09/05 22:25:12 bill X * Initial revision X * X * Revision 4.0 91/03/20 01:56:34 lwall X * 4.0 baseline. X * X * Revision 3.0.1.1 90/08/09 04:06:10 lwall X * patch19: Initial revision X * X */ X/* X This file is part of the isql system. X X (c) Copyright 1993 by William Hails X All rights reserved. X X This program is free software; you can redistribute it and/or modify X it under the terms of the GNU General Public License as published by X the Free Software Foundation. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X X You should have received a copy of the GNU General Public License X along with this program; if not, write to the Free Software X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X X You can email me as bill@tardis.co.uk or write to William Hails, CLI X Connect Ltd., 19, Quarry Street, Guildford, Surrey, GU1 3UY. England. X*/ X X#include "EXTERN.h" X#include "perl.h" X Xint Xuserinit() X{ X init_isql(); X} X END_OF_FILE if test 1410 -ne `wc -c <'usersub.c'`; then echo shar: \"'usersub.c'\" unpacked with wrong size! fi # end of 'usersub.c' fi if test -f 'isqlperl.man' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'isqlperl.man'\" else echo shar: Extracting \"'isqlperl.man'\" \(17924 characters\) sed "s/^X//" >'isqlperl.man' <<'END_OF_FILE' X.\" $Id: isqlperl.man,v 1.11 1993/12/06 16:00:29 bill Exp $ X.\" X.\" This file is part of the isqlperl system. X.\" X.\" (c) Copyright 1993 by William Hails X.\" All rights reserved. X.\" X.\" This program is free software; you can redistribute it and/or modify X.\" it under the terms of the GNU General Public License as published by X.\" the Free Software Foundation. X.\" X.\" This program is distributed in the hope that it will be useful, X.\" but WITHOUT ANY WARRANTY; without even the implied warranty of X.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X.\" GNU General Public License for more details. X.\" X.\" You should have received a copy of the GNU General Public License X.\" along with this program; if not, write to the Free Software X.\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X.\" X.\" You can email me as bill@tardis.co.uk or write to William Hails, CLI X.\" Connect Ltd., 19, Quarry Street, Guildford, Surrey, GU1 3UY. England. X.TH ISQLPERL 1 "$Date: 1993/12/06 16:00:29 $" "Version 1.2" X X.SH NAME X.B isqlperl X\- Perl interface to Informix Databases X X.SH SYNOPSIS X.nf X\fI$status\fB = &isql_execute(\fI$sttmnt_or_id\fB, \fI@params\fB); X\fI$id\fB = &isql_open(\fI$statement\fB, \fI@params\fB); X\fI@titles\fB = &isql_titles(\fI$id\^\fB); X\fI$sttmnt\fB = &isql_statement(\fI$id\^\fB); X\fI$type\fB = &isql_type(\fI$id\^\fB); X\fI@types\fB = &isql_columns(\fI$id\^\fB); X\fI@row\fB = &isql_fetch(\fI$sttmnt_or_id\fR, \fI@params\fB); X\fI$status\fB = &isql_close(\fI$id\^\fB); X\fI$status\fB = &isql_shutdown(\|); X\fI@databases\fB = &isql_databases(\|); X\fI$errmsg\fB = &isql_msg(\fR[\fI$code\fR]\fB); X\fI@sqlca\fB = &isql_ca(\|); X\fB$isql_code; X\fB$isql_autoclose; X\fB$isql_attrib; X\fB$isql_database; X\fB$isql_transactions; X\fB$isql_ansi; X\fB$isql_online; X\fR X.fi X X.de EG \" example X.IP X.RS X.RS X.nf X.. X X.de EE \" end example X.fi X.RE X.RE X.. X X.SH DESCRIPTION X.B Isqlperl Xis a collection of usub extensions to perl, allowing direct access to X.I Informix Xdatabases from within a perl script. Here's how it works. X X.TP X\fI$status\fB = &isql_execute(\fI$sttmnt_or_id\fB, \fI@params\fB);\fR Xperforms the sql command X.IR $sttmnt_or_id , Xwhich can be either an \s-2SQL\s+2 statement, or a numeric statement id Xreturned from a call to X.BR &isql_open(\|) . XIt returns the logical not of the resulting sqlca.sqlcode, so you can Xsay: X.EG X\fB&isql_execute(\fI$cmd\^\fB) |\|\|| die "$isql_code"\fR; X.EE X.IP XIt can be used to run any \s-2SQL\s+2 command which is not a naked Xselect statement. X.IP XIf the statement, or the string from which the id was prepared, Xcontains variable place holders (question marks) the values should be Xsupplied by the optional parameters. For example: X.EG X\fB&isql_execute(<'isqlperl.doc' <<'END_OF_FILE' X X X XISQLPERL(1) USER COMMANDS ISQLPERL(1) X X X XNAME X isqlperl - Perl interface to Informix Databases X X XSYNOPSIS X $status = &isql_execute($sttmnt_or_id, @params); X $id = &isql_open($statement, @params); X @titles = &isql_titles($id); X $sttmnt = &isql_statement($id); X $type = &isql_type($id); X @types = &isql_columns($id); X @row = &isql_fetch($sttmnt_or_id, @params); X $status = &isql_close($id); X $status = &isql_shutdown(); X @databases = &isql_databases(); X $errmsg = &isql_msg([$code]); X @sqlca = &isql_ca(); X $isql_code; X $isql_autoclose; X $isql_attrib; X $isql_database; X $isql_transactions; X $isql_ansi; X $isql_online; X X X X X XDESCRIPTION X Isqlperl is a collection of usub extensions to perl, allow- X ing direct access to Informix databases from within a perl X script. Here's how it works. X X X $status = &isql_execute($sttmnt_or_id, @params); X performs the sql command $sttmnt_or_id, which can be X either an SQL statement, or a numeric statement id X returned from a call to &isql_open(). It returns the X logical not of the resulting sqlca.sqlcode, so you can X say: X X X &isql_execute($cmd) || die "$isql_code"; X X It can be used to run any SQL command which is not a X naked select statement. X X If the statement, or the string from which the id was X prepared, contains variable place holders (question X marks) the values should be supplied by the optional X parameters. For example: X X X XVersion 1.2 Last change: $Date: 1993/12/06 16:00:29 $ 1 X X X X X X XISQLPERL(1) USER COMMANDS ISQLPERL(1) X X X X X &isql_execute(<