diff --git a/src/odbc/Makefile b/src/odbc/Makefile new file mode 100644 index 0000000..b664804 --- /dev/null +++ b/src/odbc/Makefile @@ -0,0 +1,387 @@ +# Generated automatically from Makefile.in by configure. +# Makefile.in generated automatically by automake 1.4 from Makefile.am + +# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + +SHELL = /bin/sh + +srcdir = . +top_srcdir = ../.. +prefix = /usr/local +exec_prefix = ${prefix} + +bindir = ${exec_prefix}/bin +sbindir = ${exec_prefix}/sbin +libexecdir = ${exec_prefix}/libexec +datadir = ${prefix}/share +sysconfdir = ${prefix}/etc +sharedstatedir = ${prefix}/com +localstatedir = ${prefix}/var +libdir = ${exec_prefix}/lib +infodir = ${prefix}/info +mandir = ${prefix}/man +includedir = ${prefix}/include +oldincludedir = /usr/include + +DESTDIR = + +pkgdatadir = $(datadir)/mdbtools +pkglibdir = $(libdir)/mdbtools +pkgincludedir = $(includedir)/mdbtools + +top_builddir = ../.. + +ACLOCAL = aclocal +AUTOCONF = autoconf +AUTOMAKE = automake +AUTOHEADER = autoheader + +INSTALL = /usr/bin/install -c +INSTALL_PROGRAM = ${INSTALL} $(AM_INSTALL_PROGRAM_FLAGS) +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_SCRIPT = ${INSTALL_PROGRAM} +transform = s,x,x, + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = i686-pc-linux-gnu +host_triplet = i686-pc-linux-gnu +AS = @AS@ +CC = gcc +DLLTOOL = @DLLTOOL@ +LD = /usr/bin/ld +LEX = flex +LIBTOOL = $(SHELL) $(top_builddir)/libtool +LN_S = ln -s +MAKEINFO = makeinfo +NM = /usr/bin/nm -B +OBJDUMP = @OBJDUMP@ +PACKAGE = mdbtools +RANLIB = ranlib +READLINE_LIBS = -lncurses -lreadline +VERSION = 0.3 +YACC = bison -y + +bin_PROGRAMS = unittest +lib_LTLIBRARIES = libmdbodbc.la +libmdbodbc_la_SOURCES = odbc.c connectparams.c +#libmdbodbc_la_LIBADD= ../libmdb/libmdb.la ../sql/libmdbsql.la +INCLUDES = -I ../../include `glib-config --cflags` +LIBS = -lfl +unittest_LDADD = libmdbodbc.la ../libmdb/libmdb.la ../sql/libmdbsql.la +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(lib_LTLIBRARIES) + + +DEFS = -DPACKAGE=\"mdbtools\" -DVERSION=\"0.3\" -DYYTEXT_POINTER=1 -DHAVE_FCNTL_H=1 -DHAVE_LIMITS_H=1 -DHAVE_UNISTD_H=1 -DHAVE_WORDEXP_H=1 -DHAVE_READLINE=1 -I. -I$(srcdir) +CPPFLAGS = +LDFLAGS = +libmdbodbc_la_LDFLAGS = +libmdbodbc_la_LIBADD = +libmdbodbc_la_OBJECTS = odbc.lo connectparams.lo +PROGRAMS = $(bin_PROGRAMS) + +unittest_SOURCES = unittest.c +unittest_OBJECTS = unittest.o +unittest_DEPENDENCIES = libmdbodbc.la ../libmdb/libmdb.la \ +../sql/libmdbsql.la +unittest_LDFLAGS = +CFLAGS = -g -O2 +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ +DIST_COMMON = Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = gtar +GZIP_ENV = --best +DEP_FILES = .deps/connectparams.P .deps/odbc.P .deps/unittest.P +SOURCES = $(libmdbodbc_la_SOURCES) unittest.c +OBJECTS = $(libmdbodbc_la_OBJECTS) unittest.o + +all: all-redirect +.SUFFIXES: +.SUFFIXES: .S .c .lo .o .s +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu src/odbc/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-libLTLIBRARIES: + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + +distclean-libLTLIBRARIES: + +maintainer-clean-libLTLIBRARIES: + +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(libdir) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + echo "$(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p"; \ + $(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \ + done + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +.s.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +.S.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + +maintainer-clean-libtool: + +libmdbodbc.la: $(libmdbodbc_la_OBJECTS) $(libmdbodbc_la_DEPENDENCIES) + $(LINK) -rpath $(libdir) $(libmdbodbc_la_LDFLAGS) $(libmdbodbc_la_OBJECTS) $(libmdbodbc_la_LIBADD) $(LIBS) + +mostlyclean-binPROGRAMS: + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) + +distclean-binPROGRAMS: + +maintainer-clean-binPROGRAMS: + +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(bindir) + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + if test -f $$p; then \ + echo " $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \ + $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ + else :; fi; \ + done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + list='$(bin_PROGRAMS)'; for p in $$list; do \ + rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ + done + +unittest: $(unittest_OBJECTS) $(unittest_DEPENDENCIES) + @rm -f unittest + $(LINK) $(unittest_LDFLAGS) $(unittest_OBJECTS) $(unittest_LDADD) $(LIBS) + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $$unique $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = src/odbc + +distdir: $(DISTFILES) + here=`cd $(top_builddir) && pwd`; \ + top_distdir=`cd $(top_distdir) && pwd`; \ + distdir=`cd $(distdir) && pwd`; \ + cd $(top_srcdir) \ + && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu src/odbc/Makefile + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + if test -d $$d/$$file; then \ + cp -pr $$d/$$file $(distdir)/$$file; \ + else \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ + fi; \ + done + +DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) + +-include $(DEP_FILES) + +mostlyclean-depend: + +clean-depend: + +distclean-depend: + -rm -rf .deps + +maintainer-clean-depend: + +%.o: %.c + @echo '$(COMPILE) -c $<'; \ + $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-cp .deps/$(*F).pp .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm .deps/$(*F).pp + +%.lo: %.c + @echo '$(LTCOMPILE) -c $<'; \ + $(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \ + < .deps/$(*F).pp > .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm -f .deps/$(*F).pp +info-am: +info: info-am +dvi-am: +dvi: dvi-am +check-am: all-am +check: check-am +installcheck-am: +installcheck: installcheck-am +install-exec-am: install-libLTLIBRARIES install-binPROGRAMS +install-exec: install-exec-am + +install-data-am: +install-data: install-data-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am +install: install-am +uninstall-am: uninstall-libLTLIBRARIES uninstall-binPROGRAMS +uninstall: uninstall-am +all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) +all-redirect: all-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install +installdirs: + $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(bindir) + + +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + +maintainer-clean-generic: +mostlyclean-am: mostlyclean-libLTLIBRARIES mostlyclean-compile \ + mostlyclean-libtool mostlyclean-binPROGRAMS \ + mostlyclean-tags mostlyclean-depend mostlyclean-generic + +mostlyclean: mostlyclean-am + +clean-am: clean-libLTLIBRARIES clean-compile clean-libtool \ + clean-binPROGRAMS clean-tags clean-depend clean-generic \ + mostlyclean-am + +clean: clean-am + +distclean-am: distclean-libLTLIBRARIES distclean-compile \ + distclean-libtool distclean-binPROGRAMS distclean-tags \ + distclean-depend distclean-generic clean-am + -rm -f libtool + +distclean: distclean-am + +maintainer-clean-am: maintainer-clean-libLTLIBRARIES \ + maintainer-clean-compile maintainer-clean-libtool \ + maintainer-clean-binPROGRAMS maintainer-clean-tags \ + maintainer-clean-depend maintainer-clean-generic \ + distclean-am + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +maintainer-clean: maintainer-clean-am + +.PHONY: mostlyclean-libLTLIBRARIES distclean-libLTLIBRARIES \ +clean-libLTLIBRARIES maintainer-clean-libLTLIBRARIES \ +uninstall-libLTLIBRARIES install-libLTLIBRARIES mostlyclean-compile \ +distclean-compile clean-compile maintainer-clean-compile \ +mostlyclean-libtool distclean-libtool clean-libtool \ +maintainer-clean-libtool mostlyclean-binPROGRAMS distclean-binPROGRAMS \ +clean-binPROGRAMS maintainer-clean-binPROGRAMS uninstall-binPROGRAMS \ +install-binPROGRAMS tags mostlyclean-tags distclean-tags clean-tags \ +maintainer-clean-tags distdir mostlyclean-depend distclean-depend \ +clean-depend maintainer-clean-depend info-am info dvi-am dvi check \ +check-am installcheck-am installcheck install-exec-am install-exec \ +install-data-am install-data install-am install uninstall-am uninstall \ +all-redirect all-am all installdirs mostlyclean-generic \ +distclean-generic clean-generic maintainer-clean-generic clean \ +mostlyclean distclean maintainer-clean + + +odbc: $(EXTRA_LTLIBRARIES) + @echo '' + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/odbc/Makefile.am b/src/odbc/Makefile.am new file mode 100644 index 0000000..9bc7743 --- /dev/null +++ b/src/odbc/Makefile.am @@ -0,0 +1,12 @@ +bin_PROGRAMS = unittest +lib_LTLIBRARIES = libmdbodbc.la +libmdbodbc_la_SOURCES= odbc.c connectparams.c +#libmdbodbc_la_LIBADD= ../libmdb/libmdb.la ../sql/libmdbsql.la +INCLUDES = -I ../../include `glib-config --cflags` +LIBS = @LEXLIB@ +unittest_LDADD = libmdbodbc.la ../libmdb/libmdb.la ../sql/libmdbsql.la + +## Need blank statement to avoid compiling odbc.c +odbc: $(EXTRA_LTLIBRARIES) + @echo '' + diff --git a/src/odbc/Makefile.in b/src/odbc/Makefile.in new file mode 100644 index 0000000..3ac0224 --- /dev/null +++ b/src/odbc/Makefile.in @@ -0,0 +1,387 @@ +# Makefile.in generated automatically by automake 1.4 from Makefile.am + +# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DESTDIR = + +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ + +top_builddir = ../.. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ +AS = @AS@ +CC = @CC@ +DLLTOOL = @DLLTOOL@ +LD = @LD@ +LEX = @LEX@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +MAKEINFO = @MAKEINFO@ +NM = @NM@ +OBJDUMP = @OBJDUMP@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +READLINE_LIBS = @READLINE_LIBS@ +VERSION = @VERSION@ +YACC = @YACC@ + +bin_PROGRAMS = unittest +lib_LTLIBRARIES = libmdbodbc.la +libmdbodbc_la_SOURCES = odbc.c connectparams.c +#libmdbodbc_la_LIBADD= ../libmdb/libmdb.la ../sql/libmdbsql.la +INCLUDES = -I ../../include `glib-config --cflags` +LIBS = @LEXLIB@ +unittest_LDADD = libmdbodbc.la ../libmdb/libmdb.la ../sql/libmdbsql.la +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(lib_LTLIBRARIES) + + +DEFS = @DEFS@ -I. -I$(srcdir) +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ +libmdbodbc_la_LDFLAGS = +libmdbodbc_la_LIBADD = +libmdbodbc_la_OBJECTS = odbc.lo connectparams.lo +PROGRAMS = $(bin_PROGRAMS) + +unittest_SOURCES = unittest.c +unittest_OBJECTS = unittest.o +unittest_DEPENDENCIES = libmdbodbc.la ../libmdb/libmdb.la \ +../sql/libmdbsql.la +unittest_LDFLAGS = +CFLAGS = @CFLAGS@ +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ +DIST_COMMON = Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = gtar +GZIP_ENV = --best +DEP_FILES = .deps/connectparams.P .deps/odbc.P .deps/unittest.P +SOURCES = $(libmdbodbc_la_SOURCES) unittest.c +OBJECTS = $(libmdbodbc_la_OBJECTS) unittest.o + +all: all-redirect +.SUFFIXES: +.SUFFIXES: .S .c .lo .o .s +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu src/odbc/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-libLTLIBRARIES: + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + +distclean-libLTLIBRARIES: + +maintainer-clean-libLTLIBRARIES: + +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(libdir) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + echo "$(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p"; \ + $(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \ + done + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +.s.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +.S.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + +maintainer-clean-libtool: + +libmdbodbc.la: $(libmdbodbc_la_OBJECTS) $(libmdbodbc_la_DEPENDENCIES) + $(LINK) -rpath $(libdir) $(libmdbodbc_la_LDFLAGS) $(libmdbodbc_la_OBJECTS) $(libmdbodbc_la_LIBADD) $(LIBS) + +mostlyclean-binPROGRAMS: + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) + +distclean-binPROGRAMS: + +maintainer-clean-binPROGRAMS: + +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(bindir) + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + if test -f $$p; then \ + echo " $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \ + $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ + else :; fi; \ + done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + list='$(bin_PROGRAMS)'; for p in $$list; do \ + rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ + done + +unittest: $(unittest_OBJECTS) $(unittest_DEPENDENCIES) + @rm -f unittest + $(LINK) $(unittest_LDFLAGS) $(unittest_OBJECTS) $(unittest_LDADD) $(LIBS) + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $$unique $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = src/odbc + +distdir: $(DISTFILES) + here=`cd $(top_builddir) && pwd`; \ + top_distdir=`cd $(top_distdir) && pwd`; \ + distdir=`cd $(distdir) && pwd`; \ + cd $(top_srcdir) \ + && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu src/odbc/Makefile + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + if test -d $$d/$$file; then \ + cp -pr $$d/$$file $(distdir)/$$file; \ + else \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ + fi; \ + done + +DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) + +-include $(DEP_FILES) + +mostlyclean-depend: + +clean-depend: + +distclean-depend: + -rm -rf .deps + +maintainer-clean-depend: + +%.o: %.c + @echo '$(COMPILE) -c $<'; \ + $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-cp .deps/$(*F).pp .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm .deps/$(*F).pp + +%.lo: %.c + @echo '$(LTCOMPILE) -c $<'; \ + $(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \ + < .deps/$(*F).pp > .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm -f .deps/$(*F).pp +info-am: +info: info-am +dvi-am: +dvi: dvi-am +check-am: all-am +check: check-am +installcheck-am: +installcheck: installcheck-am +install-exec-am: install-libLTLIBRARIES install-binPROGRAMS +install-exec: install-exec-am + +install-data-am: +install-data: install-data-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am +install: install-am +uninstall-am: uninstall-libLTLIBRARIES uninstall-binPROGRAMS +uninstall: uninstall-am +all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) +all-redirect: all-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install +installdirs: + $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(bindir) + + +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + +maintainer-clean-generic: +mostlyclean-am: mostlyclean-libLTLIBRARIES mostlyclean-compile \ + mostlyclean-libtool mostlyclean-binPROGRAMS \ + mostlyclean-tags mostlyclean-depend mostlyclean-generic + +mostlyclean: mostlyclean-am + +clean-am: clean-libLTLIBRARIES clean-compile clean-libtool \ + clean-binPROGRAMS clean-tags clean-depend clean-generic \ + mostlyclean-am + +clean: clean-am + +distclean-am: distclean-libLTLIBRARIES distclean-compile \ + distclean-libtool distclean-binPROGRAMS distclean-tags \ + distclean-depend distclean-generic clean-am + -rm -f libtool + +distclean: distclean-am + +maintainer-clean-am: maintainer-clean-libLTLIBRARIES \ + maintainer-clean-compile maintainer-clean-libtool \ + maintainer-clean-binPROGRAMS maintainer-clean-tags \ + maintainer-clean-depend maintainer-clean-generic \ + distclean-am + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +maintainer-clean: maintainer-clean-am + +.PHONY: mostlyclean-libLTLIBRARIES distclean-libLTLIBRARIES \ +clean-libLTLIBRARIES maintainer-clean-libLTLIBRARIES \ +uninstall-libLTLIBRARIES install-libLTLIBRARIES mostlyclean-compile \ +distclean-compile clean-compile maintainer-clean-compile \ +mostlyclean-libtool distclean-libtool clean-libtool \ +maintainer-clean-libtool mostlyclean-binPROGRAMS distclean-binPROGRAMS \ +clean-binPROGRAMS maintainer-clean-binPROGRAMS uninstall-binPROGRAMS \ +install-binPROGRAMS tags mostlyclean-tags distclean-tags clean-tags \ +maintainer-clean-tags distdir mostlyclean-depend distclean-depend \ +clean-depend maintainer-clean-depend info-am info dvi-am dvi check \ +check-am installcheck-am installcheck install-exec-am install-exec \ +install-data-am install-data install-am install uninstall-am uninstall \ +all-redirect all-am all installdirs mostlyclean-generic \ +distclean-generic clean-generic maintainer-clean-generic clean \ +mostlyclean distclean maintainer-clean + + +odbc: $(EXTRA_LTLIBRARIES) + @echo '' + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/odbc/connectparams.c b/src/odbc/connectparams.c new file mode 100644 index 0000000..db8cb8a --- /dev/null +++ b/src/odbc/connectparams.c @@ -0,0 +1,447 @@ +/* MDB Tools - A library for reading MS Access database file + * Copyright (C) 2000 Brian Bruns + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include + +#include "connectparams.h" + +#ifndef SYS_ODBC_INI +#define SYS_ODBC_INI "/etc/odbc.ini" +#endif + +#define max_line 256 +static char line[max_line]; + +static guint HashFunction (gconstpointer key); +static GString* GetIniFileName (); +static int FileExists (const gchar* name); +static int FindSection (FILE* stream, const char* section); +static int GetNextItem (FILE* stream, char** name, char** value); + +static void visit (gpointer key, gpointer value, gpointer user_data); +static gboolean cleanup (gpointer key, gpointer value, gpointer user_data); + +/* + * Allocate create a ConnectParams object + */ + +ConnectParams* NewConnectParams () +{ + ConnectParams* params = malloc (sizeof (ConnectParams)); + if (!params) + return params; + + params->dsnName = g_string_new (""); + params->iniFileName = NULL; + params->table = g_hash_table_new (HashFunction, g_str_equal); + + return params; +} + +/* + * Destroy a ConnectParams object + */ + +void FreeConnectParams (ConnectParams* params) +{ + if (params) + { + if (params->dsnName) + g_string_free (params->dsnName, TRUE); + if (params->iniFileName) + g_string_free (params->iniFileName, TRUE); + if (params->table) + { + g_hash_table_foreach_remove (params->table, cleanup, NULL); + g_hash_table_destroy (params->table); + } + } +} + +/* + * Find the settings for the specified ODBC DSN + */ + +gboolean LookupDSN (ConnectParams* params, const gchar* dsnName) +{ + if (!params) { + fprintf(stderr,"LookupDSN: no parameters, returning FALSE"); + return FALSE; + } + /* + * Set the DSN name property + */ + /* params->dsnName = g_string_assign (params->dsnName, dsnName); */ + /* + * Search for the ODBC ini file + */ + if (!(params->iniFileName = GetIniFileName ())) { + fprintf(stderr,"LookupDSN: GetIniFileName returned FALSE"); + return FALSE; + } + + if (!LoadDSN (params->iniFileName->str, dsnName, params->table)) { + fprintf(stderr,"LookupDSN: LoadDSN returned FALSE"); + return FALSE; + } + + return TRUE; +} + +/* + * Get the value of a given ODBC Connection Parameter + */ + +gchar* GetConnectParam (ConnectParams* params, const gchar* paramName) +{ + if (!params || !params->table) + return NULL; + + return g_hash_table_lookup (params->table, paramName); +} + +/* + * Apply a connection string to the ODBC Parameter Settings + */ + +void SetConnectString (ConnectParams* params, const gchar* connectString) +{ + int end; + char *cs, *s, *p, *name, *value; + gpointer key; + gpointer oldvalue; + + if (!params) + return; + /* + * Make a copy of the connection string so we can modify it + */ + cs = strdup (connectString); + s = cs; + /* + * Loop over ';' seperated name=value pairs + */ + p = strchr (s, '='); + while (p) + { + if (p) *p = '\0'; + /* + * Extract name + */ + name = s; + if (p) s = p + 1; + /* + * Extract value + */ + p = strchr (s, ';'); + if (p) *p = '\0'; + value = s; + if (p) s = p + 1; + /* + * remove trailing spaces from name + */ + end = strlen (name) - 1; + while (end > 0 && name[end] == ' ') + name[end--] = '\0'; + /* + * remove leading spaces from value + */ + while (*value == ' ') + value++; + + if (g_hash_table_lookup_extended (params->table, name, &key, &oldvalue)) + { + /* + * remove previous value + */ + g_hash_table_remove (params->table, key); + /* + * cleanup strings + */ + free (key); + free (oldvalue); + } + /* + * Insert the name/value pair into the hash table. + * + * Note that these strdup allocations are freed in cleanup, + * which is called by FreeConnectParams. + */ + g_hash_table_insert (params->table, strdup (name), strdup (value)); + + p = strchr (s, '='); + } + + free (cs); +} + +/* + * Dump all the ODBC Connection Paramters to a file (e.g. stdout) + */ + +void DumpParams (ConnectParams* params, FILE* output) +{ + if (!params) + { + g_printerr ("NULL ConnectionParams pointer\n"); + return; + } + + if (params->dsnName) + g_printerr ("Parameter values for DSN: %s\n", params->dsnName->str); + + if (params->iniFileName) + g_printerr ("Ini File is %s\n", params->iniFileName->str); + + g_hash_table_foreach (params->table, visit, output); +} + +/* + * Return the value of the DSN from the conneciton string + */ + +gchar* ExtractDSN (ConnectParams* params, const gchar* connectString) +{ + char *p, *q, *s; + + if (!params) + return NULL; + /* + * Position ourselves to the beginning of "DSN" + */ + p = strstr (connectString, "DSN"); + if (!p) return NULL; + /* + * Position ourselves to the "=" + */ + q = strchr (p, '='); + if (!q) return NULL; + /* + * Skip over any leading spaces + */ + q++; + while (*q == ' ') + q++; + /* + * Copy the DSN value to a buffer + */ + s = line; + while (*q && *q != ';') + *s++ = *q++; + *s = '\0'; + /* + * Save it as a string in the params object + */ + params->dsnName = g_string_assign (params->dsnName, line); + + return params->dsnName->str; +} + +/* + * Begin local function definitions + */ + +static GString* GetIniFileName () +{ + char* setting; + GString* iniFileName = g_string_new (""); + /* + * First, try the ODBCINI environment variable + */ + if ((setting = getenv ("ODBCINI")) != NULL) + { + g_string_assign (iniFileName, getenv ("ODBCINI")); + + if (FileExists (iniFileName->str)) + return iniFileName; + + g_string_assign (iniFileName, ""); + } + /* + * Second, try the HOME environment variable + */ + if ((setting = getenv ("HOME")) != NULL) + { + g_string_assign (iniFileName, setting); + iniFileName = g_string_append (iniFileName, "/.odbc.ini"); + + if (FileExists (iniFileName->str)) + return iniFileName; + + g_string_assign (iniFileName, ""); + } + /* + * As a last resort, try SYS_ODBC_INI + */ + g_string_assign (iniFileName, SYS_ODBC_INI); + if (FileExists (iniFileName->str)) + return iniFileName; + + g_string_assign (iniFileName, ""); + + return iniFileName; +} + +static int FileExists (const gchar* name) +{ + struct stat fileStat; + + return (stat (name, &fileStat) == 0); +} + +static int FindSection (FILE* stream, const char* section) +{ + char* s; + char sectionPattern[max_line]; + int len; + + strcpy (sectionPattern, "["); + strcat (sectionPattern, section); + strcat (sectionPattern, "]"); + + s = fgets (line, max_line, stream); + while (s != NULL) + { + /* + * Get rid of the newline character + */ + len = strlen (line); + if (len > 0) line[strlen (line) - 1] = '\0'; + /* + * look for the section header + */ + if (strcmp (line, sectionPattern) == 0) + return 1; + + s = fgets (line, max_line, stream); + } + + return 0; +} + +int LoadDSN ( + const gchar* iniFileName, const gchar* dsnName, GHashTable* table) +{ + FILE* stream; + gchar* name; + gchar* value; + + if ((stream = fopen (iniFileName, "r" )) != NULL ) + { + if (!FindSection (stream, dsnName)) + { + g_printerr ("Couldn't find DSN %s in %s\n", iniFileName, dsnName); + fclose (stream); + return 0; + } + else + { + while (GetNextItem (stream, &name, &value)) + { + g_hash_table_insert (table, strdup (name), strdup (value)); + } + } + + fclose( stream ); + } + + return 1; +} + +/* + * Make a hash from all the characters + */ +static guint HashFunction (gconstpointer key) +{ + guint value = 0; + const char* s = key; + + while (*s) value += *s++; + + return value; +} + +static int GetNextItem (FILE* stream, char** name, char** value) +{ + char* s; + int len; + char equals[] = "="; /* used for seperator for strtok */ + char* token; + + if (name == NULL || value == NULL) + { + g_printerr ("GetNextItem, invalid parameters"); + return 0; + } + + s = fgets (line, max_line, stream); + if (s == NULL) + { + perror ("fgets"); + return 0; + } + /* + * Get rid of the newline character + */ + len = strlen (line); + if (len > 0) line[strlen (line) - 1] = '\0'; + /* + * Extract name from name = value + */ + if ((token = strtok (line, equals)) == NULL) return 0; + + len = strlen (token); + while (len > 0 && token[len-1] == ' ') + { + len--; + token[len] = '\0'; + } + *name = token; + /* + * extract value from name = value + */ + token = strtok (NULL, equals); + if (token == NULL) return 0; + while (*token && token[0] == ' ') + token++; + + *value = token; + + return 1; +} + +static void visit (gpointer key, gpointer value, gpointer user_data) +{ + FILE* output = (FILE*) user_data; + + g_printerr ("Parameter: %s, Value: %s\n", key, value); +} + +static gboolean cleanup (gpointer key, gpointer value, gpointer user_data) +{ + free (key); + free (value); + + return TRUE; +} + + diff --git a/src/odbc/connectparams.h b/src/odbc/connectparams.h new file mode 100644 index 0000000..9100d97 --- /dev/null +++ b/src/odbc/connectparams.h @@ -0,0 +1,42 @@ +/* MDB Tools - A library for reading MS Access database file + * Copyright (C) 2000 Brian Bruns + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _ODBC_INI_LOAD_ +#define _ODBC_INI_LOAD_ + +#include + +typedef struct +{ + GString* dsnName; + GString* iniFileName; + GHashTable* table; +} ConnectParams; + +ConnectParams* NewConnectParams (); +void FreeConnectParams (ConnectParams* params); + +gboolean LookupDSN (ConnectParams* params, const gchar* dsnName); +gchar* GetConnectParam (ConnectParams* params, const gchar* paramName); +void SetConnectString (ConnectParams* params, const gchar* connectString); +void DumpParams (ConnectParams* params, FILE* output); + +gchar* ExtractDSN (ConnectParams* params, const gchar* connectString); + +#endif diff --git a/src/odbc/odbc.c b/src/odbc/odbc.c new file mode 100644 index 0000000..9cf0958 --- /dev/null +++ b/src/odbc/odbc.c @@ -0,0 +1,1042 @@ +/* MDB Tools - A library for reading MS Access database file + * Copyright (C) 2000 Brian Bruns + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef UNIXODBC +#include +#include +#else +#include "isql.h" +#include "isqlext.h" +#endif + +#include + +#include +#include + +#include "connectparams.h" + +static char software_version[] = "$Id: odbc.c,v 1.1 2001/07/10 22:36:20 brianb Exp $"; +static void *no_unused_var_warn[] = {software_version, + no_unused_var_warn}; + +static SQLSMALLINT _odbc_get_client_type(int srv_type); +static int _odbc_fix_literals(struct _hstmt *stmt); +static int _odbc_get_server_type(int clt_type); +static int _odbc_get_string_size(int size, char *str); +static SQLRETURN SQL_API _SQLAllocConnect(SQLHENV henv, SQLHDBC FAR *phdbc); +static SQLRETURN SQL_API _SQLAllocEnv(SQLHENV FAR *phenv); +static SQLRETURN SQL_API _SQLAllocStmt(SQLHDBC hdbc, SQLHSTMT FAR *phstmt); +static SQLRETURN SQL_API _SQLFreeConnect(SQLHDBC hdbc); +static SQLRETURN SQL_API _SQLFreeEnv(SQLHENV henv); +static SQLRETURN SQL_API _SQLFreeStmt(SQLHSTMT hstmt, SQLUSMALLINT fOption); + +#define _MAX_ERROR_LEN 255 +static char lastError[_MAX_ERROR_LEN+1]; + +static void LogError (const char* error) +{ + /* + * Someday, I might make this store more than one error. + */ + strncpy (lastError, error, _MAX_ERROR_LEN); + lastError[_MAX_ERROR_LEN] = '\0'; /* in case we had a long message */ +} + +/* + * Driver specific connectionn information + */ + +typedef struct +{ + struct _hdbc hdbc; + ConnectParams* params; +} ODBCConnection; + +static SQLRETURN do_connect ( + SQLHDBC hdbc, + SQLCHAR FAR *database +) +{ + struct _hdbc *dbc = (struct _hdbc *) hdbc; + struct _henv *env = (struct _henv *) dbc->henv; + + if (mdb_sql_open(env->sql,database)) { + return SQL_SUCCESS; + } else { + return SQL_ERROR; + } +} + +SQLRETURN SQL_API SQLDriverConnect( + SQLHDBC hdbc, + SQLHWND hwnd, + SQLCHAR FAR *szConnStrIn, + SQLSMALLINT cbConnStrIn, + SQLCHAR FAR *szConnStrOut, + SQLSMALLINT cbConnStrOutMax, + SQLSMALLINT FAR *pcbConnStrOut, + SQLUSMALLINT fDriverCompletion) +{ + SQLCHAR FAR* dsn = NULL; + SQLCHAR FAR* database = NULL; + ConnectParams* params; + SQLRETURN ret; + + strcpy (lastError, ""); + + params = ((ODBCConnection*) hdbc)->params; + + if (!(dsn = ExtractDSN (params, szConnStrIn))) + { + LogError ("Could not find DSN in connect string"); + return SQL_ERROR; + } + else if (!LookupDSN (params, dsn)) + { + LogError ("Could not find DSN in odbc.ini"); + return SQL_ERROR; + } + else + { + SetConnectString (params, szConnStrIn); + + if (!(database = GetConnectParam (params, "Database"))) + { + LogError ("Could not find Database parameter"); + return SQL_ERROR; + } + } + ret = do_connect (hdbc, database); + return ret; +} + +SQLRETURN SQL_API SQLBrowseConnect( + SQLHDBC hdbc, + SQLCHAR FAR *szConnStrIn, + SQLSMALLINT cbConnStrIn, + SQLCHAR FAR *szConnStrOut, + SQLSMALLINT cbConnStrOutMax, + SQLSMALLINT FAR *pcbConnStrOut) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLColumnPrivileges( + SQLHSTMT hstmt, + SQLCHAR FAR *szCatalogName, + SQLSMALLINT cbCatalogName, + SQLCHAR FAR *szSchemaName, + SQLSMALLINT cbSchemaName, + SQLCHAR FAR *szTableName, + SQLSMALLINT cbTableName, + SQLCHAR FAR *szColumnName, + SQLSMALLINT cbColumnName) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLDescribeParam( + SQLHSTMT hstmt, + SQLUSMALLINT ipar, + SQLSMALLINT FAR *pfSqlType, + SQLUINTEGER FAR *pcbParamDef, + SQLSMALLINT FAR *pibScale, + SQLSMALLINT FAR *pfNullable) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLExtendedFetch( + SQLHSTMT hstmt, + SQLUSMALLINT fFetchType, + SQLINTEGER irow, + SQLUINTEGER FAR *pcrow, + SQLUSMALLINT FAR *rgfRowStatus) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLForeignKeys( + SQLHSTMT hstmt, + SQLCHAR FAR *szPkCatalogName, + SQLSMALLINT cbPkCatalogName, + SQLCHAR FAR *szPkSchemaName, + SQLSMALLINT cbPkSchemaName, + SQLCHAR FAR *szPkTableName, + SQLSMALLINT cbPkTableName, + SQLCHAR FAR *szFkCatalogName, + SQLSMALLINT cbFkCatalogName, + SQLCHAR FAR *szFkSchemaName, + SQLSMALLINT cbFkSchemaName, + SQLCHAR FAR *szFkTableName, + SQLSMALLINT cbFkTableName) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLMoreResults( + SQLHSTMT hstmt) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLNativeSql( + SQLHDBC hdbc, + SQLCHAR FAR *szSqlStrIn, + SQLINTEGER cbSqlStrIn, + SQLCHAR FAR *szSqlStr, + SQLINTEGER cbSqlStrMax, + SQLINTEGER FAR *pcbSqlStr) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLNumParams( + SQLHSTMT hstmt, + SQLSMALLINT FAR *pcpar) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLParamOptions( + SQLHSTMT hstmt, + SQLUINTEGER crow, + SQLUINTEGER FAR *pirow) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLPrimaryKeys( + SQLHSTMT hstmt, + SQLCHAR FAR *szCatalogName, + SQLSMALLINT cbCatalogName, + SQLCHAR FAR *szSchemaName, + SQLSMALLINT cbSchemaName, + SQLCHAR FAR *szTableName, + SQLSMALLINT cbTableName) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLProcedureColumns( + SQLHSTMT hstmt, + SQLCHAR FAR *szCatalogName, + SQLSMALLINT cbCatalogName, + SQLCHAR FAR *szSchemaName, + SQLSMALLINT cbSchemaName, + SQLCHAR FAR *szProcName, + SQLSMALLINT cbProcName, + SQLCHAR FAR *szColumnName, + SQLSMALLINT cbColumnName) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLProcedures( + SQLHSTMT hstmt, + SQLCHAR FAR *szCatalogName, + SQLSMALLINT cbCatalogName, + SQLCHAR FAR *szSchemaName, + SQLSMALLINT cbSchemaName, + SQLCHAR FAR *szProcName, + SQLSMALLINT cbProcName) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLSetPos( + SQLHSTMT hstmt, + SQLUSMALLINT irow, + SQLUSMALLINT fOption, + SQLUSMALLINT fLock) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLTablePrivileges( + SQLHSTMT hstmt, + SQLCHAR FAR *szCatalogName, + SQLSMALLINT cbCatalogName, + SQLCHAR FAR *szSchemaName, + SQLSMALLINT cbSchemaName, + SQLCHAR FAR *szTableName, + SQLSMALLINT cbTableName) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLDrivers( + SQLHENV henv, + SQLUSMALLINT fDirection, + SQLCHAR FAR *szDriverDesc, + SQLSMALLINT cbDriverDescMax, + SQLSMALLINT FAR *pcbDriverDesc, + SQLCHAR FAR *szDriverAttributes, + SQLSMALLINT cbDrvrAttrMax, + SQLSMALLINT FAR *pcbDrvrAttr) +{ + return SQL_SUCCESS; +} +SQLRETURN SQL_API SQLSetEnvAttr ( + SQLHENV EnvironmentHandle, + SQLINTEGER Attribute, + SQLPOINTER Value, + SQLINTEGER StringLength) +{ + return SQL_SUCCESS; +} + + +SQLRETURN SQL_API SQLBindParameter( + SQLHSTMT hstmt, + SQLUSMALLINT ipar, + SQLSMALLINT fParamType, + SQLSMALLINT fCType, + SQLSMALLINT fSqlType, + SQLUINTEGER cbColDef, + SQLSMALLINT ibScale, + SQLPOINTER rgbValue, + SQLINTEGER cbValueMax, + SQLINTEGER FAR *pcbValue) +{ +struct _hstmt *stmt; + + stmt = (struct _hstmt *) hstmt; + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLAllocHandle( + SQLSMALLINT HandleType, + SQLHANDLE InputHandle, + SQLHANDLE * OutputHandle) +{ + switch(HandleType) { + case SQL_HANDLE_STMT: + return _SQLAllocStmt(InputHandle,OutputHandle); + break; + case SQL_HANDLE_DBC: + return _SQLAllocConnect(InputHandle,OutputHandle); + break; + case SQL_HANDLE_ENV: + return _SQLAllocEnv(OutputHandle); + break; + } +} +static SQLRETURN SQL_API _SQLAllocConnect( + SQLHENV henv, + SQLHDBC FAR *phdbc) +{ +struct _henv *env; +ODBCConnection* dbc; + + env = (struct _henv *) henv; + dbc = (SQLHDBC) malloc (sizeof (ODBCConnection)); + memset(dbc,'\0',sizeof (ODBCConnection)); + dbc->hdbc.henv=env; + + dbc->params = NewConnectParams (); + *phdbc=dbc; + + return SQL_SUCCESS; +} +SQLRETURN SQL_API SQLAllocConnect( + SQLHENV henv, + SQLHDBC FAR *phdbc) +{ + return _SQLAllocConnect(henv, phdbc); +} + +static SQLRETURN SQL_API _SQLAllocEnv( + SQLHENV FAR *phenv) +{ +struct _henv *env; + + env = (SQLHENV) malloc(sizeof(struct _henv)); + memset(env,'\0',sizeof(struct _henv)); + *phenv=env; + env->sql = mdb_sql_init(); + return SQL_SUCCESS; +} +SQLRETURN SQL_API SQLAllocEnv( + SQLHENV FAR *phenv) +{ + return _SQLAllocEnv(phenv); +} + +static SQLRETURN SQL_API _SQLAllocStmt( + SQLHDBC hdbc, + SQLHSTMT FAR *phstmt) +{ +struct _hdbc *dbc; +struct _hstmt *stmt; + + dbc = (struct _hdbc *) hdbc; + + stmt = (SQLHSTMT) malloc(sizeof(struct _hstmt)); + memset(stmt,'\0',sizeof(struct _hstmt)); + stmt->hdbc=hdbc; + *phstmt = stmt; + + return SQL_SUCCESS; +} +SQLRETURN SQL_API SQLAllocStmt( + SQLHDBC hdbc, + SQLHSTMT FAR *phstmt) +{ + return _SQLAllocStmt(hdbc,phstmt); +} + +SQLRETURN SQL_API SQLBindCol( + SQLHSTMT hstmt, + SQLUSMALLINT icol, + SQLSMALLINT fCType, + SQLPOINTER rgbValue, + SQLINTEGER cbValueMax, + SQLINTEGER FAR *pcbValue) +{ + struct _hstmt *stmt; + + stmt = (struct _hstmt *) hstmt; + + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLCancel( + SQLHSTMT hstmt) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLConnect( + SQLHDBC hdbc, + SQLCHAR FAR *szDSN, + SQLSMALLINT cbDSN, + SQLCHAR FAR *szUID, + SQLSMALLINT cbUID, + SQLCHAR FAR *szAuthStr, + SQLSMALLINT cbAuthStr) +{ + SQLCHAR FAR* database = NULL; + ConnectParams* params; + SQLRETURN ret; + + strcpy (lastError, ""); + + params = ((ODBCConnection*) hdbc)->params; + + if (!LookupDSN (params, szDSN)) + { + LogError ("Could not find DSN in odbc.ini"); + return SQL_ERROR; + } + else if (!(database = GetConnectParam (params, "Database"))) + { + LogError ("Could not find Database parameter"); + return SQL_ERROR; + } + + ret = do_connect (hdbc, database); + return ret; +} + +SQLRETURN SQL_API SQLDescribeCol( + SQLHSTMT hstmt, + SQLUSMALLINT icol, + SQLCHAR FAR *szColName, + SQLSMALLINT cbColNameMax, + SQLSMALLINT FAR *pcbColName, + SQLSMALLINT FAR *pfSqlType, + SQLUINTEGER FAR *pcbColDef, + SQLSMALLINT FAR *pibScale, + SQLSMALLINT FAR *pfNullable) +{ +int cplen, namelen, i; +struct _hstmt *stmt = (struct _hstmt *) hstmt; + + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLColAttributes( + SQLHSTMT hstmt, + SQLUSMALLINT icol, + SQLUSMALLINT fDescType, + SQLPOINTER rgbDesc, + SQLSMALLINT cbDescMax, + SQLSMALLINT FAR *pcbDesc, + SQLINTEGER FAR *pfDesc) +{ +int cplen, len = 0; +struct _hstmt *stmt; +struct _hdbc *dbc; + + stmt = (struct _hstmt *) hstmt; + dbc = (struct _hdbc *) stmt->hdbc; + + + /* dont check column index for these */ + switch(fDescType) { + case SQL_COLUMN_COUNT: + return SQL_SUCCESS; + break; + } + + switch(fDescType) { + case SQL_COLUMN_NAME: + break; + case SQL_COLUMN_TYPE: + break; + case SQL_COLUMN_LENGTH: + break; + case SQL_COLUMN_DISPLAY_SIZE: + switch(_odbc_get_client_type(1)) { + case SQL_CHAR: + case SQL_VARCHAR: + break; + case SQL_INTEGER: + *pfDesc = 8; + break; + case SQL_SMALLINT: + *pfDesc = 6; + break; + case SQL_TINYINT: + *pfDesc = 4; + break; + } + break; + } + return SQL_SUCCESS; +} + + +SQLRETURN SQL_API SQLDisconnect( + SQLHDBC hdbc) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLError( + SQLHENV henv, + SQLHDBC hdbc, + SQLHSTMT hstmt, + SQLCHAR FAR *szSqlState, + SQLINTEGER FAR *pfNativeError, + SQLCHAR FAR *szErrorMsg, + SQLSMALLINT cbErrorMsgMax, + SQLSMALLINT FAR *pcbErrorMsg) +{ + SQLRETURN result = SQL_NO_DATA_FOUND; + + if (strlen (lastError) > 0) + { + strcpy (szSqlState, "08001"); + strcpy (szErrorMsg, lastError); + if (pcbErrorMsg) + *pcbErrorMsg = strlen (lastError); + if (pfNativeError) + *pfNativeError = 1; + + result = SQL_SUCCESS; + strcpy (lastError, ""); + } + + return result; +} + +static SQLRETURN SQL_API _SQLExecute( SQLHSTMT hstmt) +{ +struct _hstmt *stmt = (struct _hstmt *) hstmt; +int ret; + + fprintf(stderr,"query = %s\n",stmt->query); + _odbc_fix_literals(stmt); + + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLExecDirect( + SQLHSTMT hstmt, + SQLCHAR FAR *szSqlStr, + SQLINTEGER cbSqlStr) +{ +struct _hstmt *stmt = (struct _hstmt *) hstmt; +int ret; + + strcpy(stmt->query, szSqlStr); + + return _SQLExecute(hstmt); +} + +SQLRETURN SQL_API SQLExecute( + SQLHSTMT hstmt) +{ + return _SQLExecute(hstmt); +} + +SQLRETURN SQL_API SQLFetch( + SQLHSTMT hstmt) +{ +int ret; +int i; +struct _hstmt *stmt; +SQLINTEGER len=0; +unsigned char *src; +int srclen; + + stmt=(struct _hstmt *)hstmt; + +} + +SQLRETURN SQL_API SQLFreeHandle( + SQLSMALLINT HandleType, + SQLHANDLE Handle) +{ + switch(HandleType) { + case SQL_HANDLE_STMT: + _SQLFreeStmt(Handle,SQL_DROP); + break; + case SQL_HANDLE_DBC: + _SQLFreeConnect(Handle); + break; + case SQL_HANDLE_ENV: + _SQLFreeEnv(Handle); + break; + } + return SQL_SUCCESS; +} + +static SQLRETURN SQL_API _SQLFreeConnect( + SQLHDBC hdbc) +{ + ODBCConnection* dbc = (ODBCConnection*) hdbc; + + + FreeConnectParams (dbc->params); + free (dbc); + + return SQL_SUCCESS; +} +SQLRETURN SQL_API SQLFreeConnect( + SQLHDBC hdbc) +{ + return _SQLFreeConnect(hdbc); +} + +static SQLRETURN SQL_API _SQLFreeEnv( + SQLHENV henv) +{ + return SQL_SUCCESS; +} +SQLRETURN SQL_API SQLFreeEnv( + SQLHENV henv) +{ + return _SQLFreeEnv(henv); +} + +static SQLRETURN SQL_API _SQLFreeStmt( + SQLHSTMT hstmt, + SQLUSMALLINT fOption) +{ +struct _hstmt *stmt=(struct _hstmt *)hstmt; + + if (fOption==SQL_DROP) { + free (hstmt); + } else if (fOption==SQL_CLOSE) { + } else { + } + return SQL_SUCCESS; +} +SQLRETURN SQL_API SQLFreeStmt( + SQLHSTMT hstmt, + SQLUSMALLINT fOption) +{ + return _SQLFreeStmt(hstmt, fOption); +} + +SQLRETURN SQL_API SQLGetStmtAttr ( + SQLHSTMT StatementHandle, + SQLINTEGER Attribute, + SQLPOINTER Value, + SQLINTEGER BufferLength, + SQLINTEGER * StringLength) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLGetCursorName( + SQLHSTMT hstmt, + SQLCHAR FAR *szCursor, + SQLSMALLINT cbCursorMax, + SQLSMALLINT FAR *pcbCursor) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLNumResultCols( + SQLHSTMT hstmt, + SQLSMALLINT FAR *pccol) +{ +struct _hstmt *stmt; + + stmt=(struct _hstmt *)hstmt; + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLPrepare( + SQLHSTMT hstmt, + SQLCHAR FAR *szSqlStr, + SQLINTEGER cbSqlStr) +{ + struct _hstmt *stmt=(struct _hstmt *)hstmt; + + if (cbSqlStr!=SQL_NTS) { + strncpy(stmt->query, szSqlStr, cbSqlStr); + stmt->query[cbSqlStr]='\0'; + } else { + strcpy(stmt->query, szSqlStr); + } + + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLRowCount( + SQLHSTMT hstmt, + SQLINTEGER FAR *pcrow) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLSetCursorName( + SQLHSTMT hstmt, + SQLCHAR FAR *szCursor, + SQLSMALLINT cbCursor) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLTransact( + SQLHENV henv, + SQLHDBC hdbc, + SQLUSMALLINT fType) +{ + return SQL_SUCCESS; +} + + +SQLRETURN SQL_API SQLSetParam( /* Use SQLBindParameter */ + SQLHSTMT hstmt, + SQLUSMALLINT ipar, + SQLSMALLINT fCType, + SQLSMALLINT fSqlType, + SQLUINTEGER cbParamDef, + SQLSMALLINT ibScale, + SQLPOINTER rgbValue, + SQLINTEGER FAR *pcbValue) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLColumns( + SQLHSTMT hstmt, + SQLCHAR FAR *szCatalogName, + SQLSMALLINT cbCatalogName, + SQLCHAR FAR *szSchemaName, + SQLSMALLINT cbSchemaName, + SQLCHAR FAR *szTableName, + SQLSMALLINT cbTableName, + SQLCHAR FAR *szColumnName, + SQLSMALLINT cbColumnName) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLGetConnectOption( + SQLHDBC hdbc, + SQLUSMALLINT fOption, + SQLPOINTER pvParam) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLGetData( + SQLHSTMT hstmt, + SQLUSMALLINT icol, + SQLSMALLINT fCType, + SQLPOINTER rgbValue, + SQLINTEGER cbValueMax, + SQLINTEGER FAR *pcbValue) +{ +struct _hstmt *stmt; +unsigned char *src; +int srclen; + + stmt = (struct _hstmt *) hstmt; + return 0; +} + +SQLRETURN SQL_API SQLGetFunctions( + SQLHDBC hdbc, + SQLUSMALLINT fFunction, + SQLUSMALLINT FAR *pfExists) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLGetInfo( + SQLHDBC hdbc, + SQLUSMALLINT fInfoType, + SQLPOINTER rgbInfoValue, + SQLSMALLINT cbInfoValueMax, + SQLSMALLINT FAR *pcbInfoValue) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLGetStmtOption( + SQLHSTMT hstmt, + SQLUSMALLINT fOption, + SQLPOINTER pvParam) +{ + return SQL_SUCCESS; +} + +SQLRETURN SQL_API SQLGetTypeInfo( + SQLHSTMT hstmt, + SQLSMALLINT fSqlType) +{ +struct _hstmt *stmt; + + stmt = (struct _hstmt *) hstmt; + if (!fSqlType) { + strcpy(stmt->query, "SELECT * FROM tds_typeinfo"); + } else { + sprintf(stmt->query, "SELECT * FROM tds_typeinfo WHERE SQL_DATA_TYPE = %d", fSqlType); + } + + return _SQLExecute(hstmt); + } + + SQLRETURN SQL_API SQLParamData( + SQLHSTMT hstmt, + SQLPOINTER FAR *prgbValue) + { + return SQL_SUCCESS; + } + + SQLRETURN SQL_API SQLPutData( + SQLHSTMT hstmt, + SQLPOINTER rgbValue, + SQLINTEGER cbValue) + { + return SQL_SUCCESS; + } + + SQLRETURN SQL_API SQLSetConnectOption( + SQLHDBC hdbc, + SQLUSMALLINT fOption, + SQLUINTEGER vParam) + { + return SQL_SUCCESS; + } + + SQLRETURN SQL_API SQLSetStmtOption( + SQLHSTMT hstmt, + SQLUSMALLINT fOption, + SQLUINTEGER vParam) + { + return SQL_SUCCESS; + } + + SQLRETURN SQL_API SQLSpecialColumns( + SQLHSTMT hstmt, + SQLUSMALLINT fColType, + SQLCHAR FAR *szCatalogName, + SQLSMALLINT cbCatalogName, + SQLCHAR FAR *szSchemaName, + SQLSMALLINT cbSchemaName, + SQLCHAR FAR *szTableName, + SQLSMALLINT cbTableName, + SQLUSMALLINT fScope, + SQLUSMALLINT fNullable) + { + return SQL_SUCCESS; + } + + SQLRETURN SQL_API SQLStatistics( + SQLHSTMT hstmt, + SQLCHAR FAR *szCatalogName, + SQLSMALLINT cbCatalogName, + SQLCHAR FAR *szSchemaName, + SQLSMALLINT cbSchemaName, + SQLCHAR FAR *szTableName, + SQLSMALLINT cbTableName, + SQLUSMALLINT fUnique, + SQLUSMALLINT fAccuracy) + { + return SQL_SUCCESS; + } + + SQLRETURN SQL_API SQLTables( + SQLHSTMT hstmt, + SQLCHAR FAR *szCatalogName, + SQLSMALLINT cbCatalogName, + SQLCHAR FAR *szSchemaName, + SQLSMALLINT cbSchemaName, + SQLCHAR FAR *szTableName, + SQLSMALLINT cbTableName, + SQLCHAR FAR *szTableType, + SQLSMALLINT cbTableType) + { + char *query, *p; + char *sptables = "exec sp_tables "; + int querylen, clen, slen, tlen, ttlen; + int first = 1; + struct _hstmt *stmt; + + stmt = (struct _hstmt *) hstmt; + + clen = _odbc_get_string_size(cbCatalogName, szCatalogName); + slen = _odbc_get_string_size(cbSchemaName, szSchemaName); + tlen = _odbc_get_string_size(cbTableName, szTableName); + ttlen = _odbc_get_string_size(cbTableType, szTableType); + + querylen = strlen(sptables) + clen + slen + tlen + ttlen + 40; /* a little padding for quotes and commas */ + query = (char *) malloc(querylen); + p = query; + + strcpy(p, sptables); + p += strlen(sptables); + + if (tlen) { + *p++ = '"'; + strncpy(p, szTableName, tlen); *p+=tlen; + *p++ = '"'; + first = 0; + } + if (slen) { + if (!first) *p++ = ','; + *p++ = '"'; + strncpy(p, szSchemaName, slen); *p+=slen; + *p++ = '"'; + first = 0; + } + if (clen) { + if (!first) *p++ = ','; + *p++ = '"'; + strncpy(p, szCatalogName, clen); *p+=clen; + *p++ = '"'; + first = 0; + } + if (ttlen) { + if (!first) *p++ = ','; + *p++ = '"'; + strncpy(p, szTableType, ttlen); *p+=ttlen; + *p++ = '"'; + first = 0; + } + *p++ = '\0'; + // fprintf(stderr,"\nquery = %s\n",query); + + strcpy(stmt->query, query); + return _SQLExecute(hstmt); +} + + +SQLRETURN SQL_API SQLDataSources( + SQLHENV henv, + SQLUSMALLINT fDirection, + SQLCHAR FAR *szDSN, + SQLSMALLINT cbDSNMax, + SQLSMALLINT FAR *pcbDSN, + SQLCHAR FAR *szDescription, + SQLSMALLINT cbDescriptionMax, + SQLSMALLINT FAR *pcbDescription) +{ + return SQL_SUCCESS; +} + +static int _odbc_fix_literals(struct _hstmt *stmt) +{ +char tmp[4096],begin_tag[11]; +char *s, *d, *p; +int i, quoted = 0, find_end = 0; +char quote_char; + + s=stmt->query; + d=tmp; + while (*s) { + if (!quoted && (*s=='"' || *s=='\'')) { + quoted = 1; + quote_char = *s; + } else if (quoted && *s==quote_char) { + quoted = 0; + } + if (!quoted && find_end && *s=='}') { + s++; /* ignore the end of tag */ + } else if (!quoted && *s=='{') { + for (p=s,i=0;*p && *p!=' ';p++) i++; + if (i>10) { + /* garbage */ + *d++=*s++; + } else { + strncpy(begin_tag, s, i); + begin_tag[i] = '\0'; + /* printf("begin tag %s\n", begin_tag); */ + s += i; + find_end = 1; + } + } else { + *d++=*s++; + } + } + *d='\0'; + strcpy(stmt->query,tmp); +} + +static int _odbc_get_string_size(int size, char *str) +{ + if (!str) { + return 0; + } + if (size==SQL_NTS) { + return strlen(str); + } else { + return size; + } +} +static int _odbc_get_server_type(int clt_type) +{ + switch (clt_type) { + case SQL_CHAR: + case SQL_VARCHAR: + case SQL_BIT: + case SQL_TINYINT: + case SQL_SMALLINT: + case SQL_INTEGER: + case SQL_DOUBLE: + case SQL_DECIMAL: + case SQL_NUMERIC: + case SQL_FLOAT: + } +} +static SQLSMALLINT _odbc_get_client_type(int srv_type) +{ + switch (srv_type) { + } +} diff --git a/src/odbc/unittest.c b/src/odbc/unittest.c new file mode 100644 index 0000000..99544df --- /dev/null +++ b/src/odbc/unittest.c @@ -0,0 +1,243 @@ +/* FreeTDS - Library of routines accessing Sybase and Microsoft databases + * Copyright (C) 1998-1999 Brian Bruns + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* #include */ +#include +#include + +#include + +static char software_version[] = "$Id: unittest.c,v 1.1 2001/07/10 22:36:20 brianb Exp $"; +static void *no_unused_var_warn[] = {software_version, + no_unused_var_warn}; + + + +#define SALES_PERSON_LEN 2 +#define STATUS_LEN 6 + +SQLSMALLINT sOrderID; +SQLSMALLINT sCustID; +DATE_STRUCT dsOpenDate; +SQLCHAR szSalesPerson[SALES_PERSON_LEN] = "D"; +SQLCHAR szStatus[STATUS_LEN]; +SQLINTEGER cbOrderID = 0, cbCustID = 0, cbOpenDate = 0, cbSalesPerson = SQL_NTS, + cbStatus = SQL_NTS; +SQLRETURN retcode; +HENV henv; +HDBC hdbc; +SQLHSTMT hstmt; + + +static void printStatementError(HSTMT hstmt, char *msg) +{ + UCHAR szSqlState[6]; + UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH]; + SDWORD dwNativeError; + SWORD wErrorMsg; + + SQLError(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, + szSqlState, &dwNativeError, szErrorMsg, + SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg); + + fprintf(stderr,"%s\n%s\n%s\n",msg, + szSqlState, szErrorMsg); +} + + +int main() +{ + retcode = SQLAllocEnv(&henv); + + if (SQLAllocConnect(henv, &hdbc) != SQL_SUCCESS) + { + UCHAR szSqlState[6]; + UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH]; + SDWORD dwNativeError; + SWORD wErrorMsg; + + SQLError(henv, SQL_NULL_HDBC, SQL_NULL_HSTMT, + szSqlState, &dwNativeError, szErrorMsg, + SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg); + + fprintf(stderr,"problem with SQLAllocConnect\n%s\n%s\n", + szSqlState, szErrorMsg); + exit(1); + } + + + retcode = SQLSetConnectOption(hdbc, SQL_ACCESS_MODE, SQL_MODE_READ_ONLY); + if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) + { + UCHAR szSqlState[6]; + UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH]; + SDWORD dwNativeError; + SWORD wErrorMsg; + + SQLError(SQL_NULL_HENV, hdbc, SQL_NULL_HSTMT, + szSqlState, &dwNativeError, szErrorMsg, + SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg); + + fprintf(stderr,"problem with SQLSetConnectOption\n%s\n%s\n", + szSqlState, szErrorMsg); + exit(1); + } + + retcode = SQLSetConnectOption(hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_ON); + if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) + { + UCHAR szSqlState[6]; + UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH]; + SDWORD dwNativeError; + SWORD wErrorMsg; + + SQLError(SQL_NULL_HENV, hdbc, SQL_NULL_HSTMT, + szSqlState, &dwNativeError, szErrorMsg, + SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg); + + fprintf(stderr,"problem with SQLSetConnectOption\n%s\n%s\n", + szSqlState, szErrorMsg); + exit(1); + } + + + retcode = SQLConnect(hdbc, + /* + (UCHAR *)"SYBASE", SQL_NTS, + (UCHAR *)"ken", SQL_NTS, + (UCHAR *)"asdfasdf", SQL_NTS); + */ + (UCHAR *)"Northwind", SQL_NTS, + (UCHAR *)"", SQL_NTS, + (UCHAR *)"", SQL_NTS); + /* sleep(600); */ + if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) + { + UCHAR szSqlState[6]; + UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH]; + SDWORD dwNativeError; + SWORD wErrorMsg; + + SQLError(SQL_NULL_HENV, hdbc, SQL_NULL_HSTMT, + szSqlState, &dwNativeError, szErrorMsg, + SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg); + + fprintf(stderr,"problem with SQLConnect\n%s\n%s\n", + szSqlState, szErrorMsg); + exit(1); + } + + + if (SQLAllocStmt(hdbc, &hstmt)!= SQL_SUCCESS) + { + UCHAR szSqlState[6]; + UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH]; + SDWORD dwNativeError; + SWORD wErrorMsg; + + SQLError(SQL_NULL_HENV, hdbc, SQL_NULL_HSTMT, + szSqlState, &dwNativeError, szErrorMsg, + SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg); + + fprintf(stderr,"problem with SQLAllocStmt\n%s\n%s\n", + szSqlState, szErrorMsg); + exit(1); + } + + +#if 0 + retcode = SQLTables(hstmt, + (unsigned char *) NULL, 0, + (unsigned char *) "%", 1, + (unsigned char *) "%", 1, + (unsigned char *) "VIEW,TABLE", 10); + if (! (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)) + { + printf("got table stuff\n"); + } + else + { + printStatementError(hstmt, "SQLTable"); + } +#else + /* Prepare the SQL statement with parameter markers. */ + + retcode = SQLPrepare(hstmt, + (unsigned char *)"select ShipName from Orders where OrderID > 11000", + SQL_NTS); + + if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) + { + long p1; + // char p2[256]; + long p1Len = sizeof(p1); + // long p2Len; + long sAge = 1023; + long cbAge = sizeof(long); + UCHAR szCol1[60]; + + SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, + 0, 0, szCol1, 0, &p1Len); + +// p1Len = SQL_NULL_DATA; + /* Execute statement with first row. */ + + p1 = 8192; +// p1[0] = '%'; +// p1Len = 1; +// p2[0] = '%'; +// p2Len = 1; + printf("excecuting first statement\n"); + retcode = SQLExecute(hstmt); + if (retcode != SQL_SUCCESS) + { + UCHAR szSqlState[6]; + UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH]; + SDWORD dwNativeError; + SWORD wErrorMsg; + + SQLError(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, + szSqlState, &dwNativeError, szErrorMsg, + SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg); + + fprintf(stderr,"problem with SQLExecute\n%s\n%s\n", + szSqlState, szErrorMsg); + exit(1); + } + while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS) + { + // nop + printf("szCol1 = %s\n",szCol1); + } + if (retcode != SQL_NO_DATA_FOUND) + { + printStatementError(hstmt, "problem with SQLFetch"); + exit(1); + } + + + /* + SQLCloseCursor(hstmt); + */ + } +#endif + printf("Done\n"); + + return 1; +}