diff --git a/scsh/odbc/README b/scsh/odbc/README index cdba85d..943ecc2 100644 --- a/scsh/odbc/README +++ b/scsh/odbc/README @@ -22,17 +22,18 @@ RCS file: /cvsroot/scsh/scsh-0.6/autogen.sh,v retrieving revision 1.7 diff -u -r1.7 autogen.sh --- autogen.sh 12 Feb 2002 16:26:05 -0000 1.7 -+++ autogen.sh 20 Mar 2003 16:01:57 -0000 -@@ -2,7 +2,7 @@ ++++ autogen.sh 23 Apr 2003 15:23:43 -0000 +@@ -2,7 +2,8 @@ autoheader && autoconf && -./configure && -+./configure --with-iODBC=/usr/lib && ++./configure --with-iODBC=/afs/wsi/i386_fbsd46 && ++##./configure --with-iODBC=/usr/lib && touch scsh/*.c && touch build/filenames.scm && rm -f scheme48.image cig/cig.image scsh/scsh.image && -@@ -12,5 +12,4 @@ +@@ -12,5 +13,4 @@ make i-know-what-i-am-doing && make c/scheme48.h&& make linker && @@ -42,11 +43,11 @@ diff -u -r1.7 autogen.sh Index: configure.in =================================================================== RCS file: /cvsroot/scsh/scsh-0.6/configure.in,v -retrieving revision 1.27 -diff -u -r1.27 configure.in ---- configure.in 13 Dec 2002 15:22:13 -0000 1.27 -+++ configure.in 20 Mar 2003 16:01:57 -0000 -@@ -394,7 +394,30 @@ +retrieving revision 1.28 +diff -u -r1.28 configure.in +--- configure.in 16 Apr 2003 12:41:36 -0000 1.28 ++++ configure.in 23 Apr 2003 15:23:43 -0000 +@@ -373,7 +373,30 @@ AC_SUBST(LIBS) AC_SUBST(TMPDIR) @@ -65,12 +66,12 @@ diff -u -r1.27 configure.in + +AC_ARG_WITH(iODBC, + [ --with-iODBC=DIR Support for iODBC ], -+ [ with_iodbc=$with_iodbc ], ++ [ with_iodbc=$withval ], + [ with_iodbc=no ] + ) +if test "$with_iodbc" != no; then -+ odbc_includes="-I$with_iodbc/include" -+ odbc_libs="-liodbc -L$with_iodbc/lib" ++ odbc_includes="-I$withval/include" ++ odbc_libs="-liodbc -L$withval/lib" + AC_SUBST(odbc_includes) + AC_SUBST(odbc_libs) +fi @@ -81,10 +82,10 @@ diff -u -r1.27 configure.in Index: Makefile.in =================================================================== RCS file: /cvsroot/scsh/scsh-0.6/Makefile.in,v -retrieving revision 1.59 -diff -u -r1.59 Makefile.in ---- Makefile.in 13 Jan 2003 06:17:49 -0000 1.59 -+++ Makefile.in 20 Mar 2003 16:01:57 -0000 +retrieving revision 1.61 +diff -u -r1.61 Makefile.in +--- Makefile.in 10 Mar 2003 12:13:02 -0000 1.61 ++++ Makefile.in 23 Apr 2003 15:23:43 -0000 @@ -8,8 +8,8 @@ VPATH = @srcdir@ CC = @CC@ @@ -101,8 +102,8 @@ diff -u -r1.59 Makefile.in # out of the CVS repository. # We cannot use Scsh here since -i is not understood. -BUILD_RUNNABLE = /afs/wsi/i386_fbsd32/bin/scheme48 -+BUILD_RUNNABLE = /afs/wsi/ppc_macx55/scheme48-0.53/bin/scheme48 +#BUILD_RUNNABLE = /afs/wsi/ppc_macx55/scheme48-0.53/bin/scheme48 ++BUILD_RUNNABLE = /afs/wsi/i386_fbsd32/scheme48-0.53/bin/scheme48 RUNNABLE = scsh MANPAGE = $(RUNNABLE).$(manext) LIB = $(libdir)/$(RUNNABLE) @@ -141,175 +142,34 @@ diff -u -r1.59 Makefile.in # Socket rules c/unix/socket.o: c/scheme48.h c/fd-io.h c/event.h -@@ -835,7 +843,8 @@ +@@ -837,7 +845,10 @@ scsh/rx/re-high.scm \ scsh/rx/regexp.scm \ scsh/rx/re-low.scm \ - scsh/rx/regress.scm + scsh/rx/regress.scm \ ++ scsh/odbc/odbc-interfaces.scm \ ++ scsh/odbc/odbc-packages.scm \ + scsh/odbc/odbc.scm # scsh/dbm.scm db.scm ndbm.scm # jcontrol +@@ -861,7 +872,9 @@ + $(srcdir)/scsh/rx/packages.scm \ + $(srcdir)/scsh/scsh-package.scm \ + $(srcdir)/scsh/lib/ccp-pack.scm \ +- $(srcdir)/scsh/lib/char-package.scm ++ $(srcdir)/scsh/lib/char-package.scm \ ++ $(srcdir)/scsh/odbc/odbc-interfaces.scm \ ++ $(srcdir)/scsh/odbc/odbc-packages.scm + + opens = floatnums scsh ccp-lib scsh-top-package scsh-here-string-hax \ + srfi-1 srfi-13 srfi-14 # srfi-14 is also exported by scsh + This will add some rules to Makefile and add two options to configure: --with-iODBC=PATH and --with-unixODBC=PATH. -This patch will add a module odbc to the package configuration. With -this patch, it's possible to type ,open odbc at the scsh prompt to -load all the beautiful ODBC functions into scsh: - -Index: scsh-package.scm -=================================================================== -RCS file: /cvsroot/scsh/scsh-0.6/scsh/scsh-package.scm,v -retrieving revision 1.59 -diff -u -r1.59 scsh-package.scm ---- scsh-package.scm 25 Feb 2003 12:58:37 -0000 1.59 -+++ scsh-package.scm 20 Mar 2003 16:03:38 -0000 -@@ -597,3 +597,21 @@ - signals - srfi-9) - (files srfi-19)) -+ -+;;; ODBC stuff -+ -+(define-structure odbc-data-types odbc-data-types-interface -+ (open -+ scheme define-structure -+ external-calls) -+ (files (odbc odbc-types))) -+ -+(define-structure odbc odbc-interface -+ (open -+ scheme define-record-types -+ external-calls -+ scsh-utilities -+ conditions signals) -+ (files (odbc odbc) -+ (odbc odbc-bindcol))) -+ -Index: scsh-interfaces.scm -=================================================================== -RCS file: /cvsroot/scsh/scsh-0.6/scsh/scsh-interfaces.scm,v -retrieving revision 1.53 -diff -u -r1.53 scsh-interfaces.scm ---- scsh-interfaces.scm 25 Feb 2003 12:58:37 -0000 1.53 -+++ scsh-interfaces.scm 20 Mar 2003 16:03:39 -0000 -@@ -1166,13 +1166,13 @@ - (export crypt)) - - (define-interface uname-interface -- (export uname -- uname:os-name -- uname:node-name -- uname:release -- uname:version -- uname:machine -- type/uname)) -+ (export uname -+ uname:os-name -+ uname:node-name -+ uname:release -+ uname:version -+ uname:machine -+ type/uname)) - - (define-interface md5-interface - (export make-md5-context -@@ -1275,3 +1275,92 @@ - ;; Date to string/string to date converters. - date->string - string->date)) -+ -+;;; ODBC stuff -+(define-interface odbc-data-types-interface -+ (export -+ -+ make-sql-date -+ sql-date? -+ sql-date-year -+ sql-date-month -+ sql-date-day -+ -+ make-sql-time -+ sql-time? -+ sql-time-hour -+ sql-time-minute -+ sql-time-second -+ -+ make-sql-timestamp -+ sql-timestamp? -+ sql-timestamp-year -+ sql-timestamp-month -+ sql-timestamp-day -+ sql-timestamp-hour -+ sql-timestamp-minute -+ sql-timestamp-second -+ sql-timestamp-fraction -+ -+ make-sql-numeric -+ sql-numeric? -+ sql-numeric-precision -+ sql-numeric-scale -+ sql-numeric-sign -+ sql-numeric-value)) -+ -+(define-interface odbc-interface -+ (export -+ odbc-handle? -+ environment-handle? -+ connection-handle? -+ statement-handle? -+ descriptor-handle? -+ -+ odbc-alloc-environment-handle -+ odbc-alloc-connection-handle -+ odbc-alloc-statement-handle -+ odbc-sql-connect -+ -+ odbc-sql-data-sources -+ odbc-sql-drivers -+ odbc-sql-get-info-int -+ odbc-sql-get-info-string -+ odbc-sql-get-func -+ odbc-sql-get-type-info -+ -+ odbc-sql-set-connect-attr-int -+ odbc-sql-set-connect-attr-string -+ odbc-sql-get-connect-attr-string -+ odbc-sql-get-connect-attr-int -+ odbc-sql-set-env-attr-int -+ odbc-sql-get-env-attr-int -+ odbc-sql-set-stmt-attr-int -+ odbc-sql-get-stmt-attr-int -+ -+ odbc-sql-prepare -+ odbc-sql-bind-parameter-exec-out -+ odbc-sql-get-cursor-name -+ odbc-sql-set-cursor-name -+ -+ odbc-sql-execute -+ odbc-sql-execute-direct -+ -+ odbc-sql-row-count -+ odbc-sql-get-data -+ odbc-sql-fetch -+ -+ odbc-sql-free-statement -+ odbc-sql-close-cursor -+ odbc-sql-cancel -+ odbc-sql-num-result-cols -+ odbc-sql-describe-col -+ -+ odbc-sql-disconnect -+ odbc-sql-free-handle -+ -+ odbc-buffer-exceeded? -+ signal-buffer-exceeded -+ odbc-unbound-column? -+ signal-unbound-column -+ odbc-sql-bindcol)) - Now it's time to build scsh. Edit the call to configure in autgen.sh to your needs, e.g.: diff --git a/scsh/odbc/generate-constants.scm b/scsh/odbc/generate-constants.scm index cbde6ef..e74d25b 100644 --- a/scsh/odbc/generate-constants.scm +++ b/scsh/odbc/generate-constants.scm @@ -1,3 +1,5 @@ +; ,open srfi-13 + (define (pretty-print-constant str) (string-map (lambda (c) (if (char=? c #\_) #\- c)) @@ -23,20 +25,30 @@ (else (error "don't know this type " type))))) +(define (generate-constant-list c-name scheme-name type) + (let ((real-scheme-name (or scheme-name (pretty-print-constant c-name)))) + (format (current-output-port) "\t ~A\\n" real-scheme-name))) + (define (generate-comment str) (format (current-output-port) "printf(\"\\n\\n~A\\n\");~%" str)) -(define (generate-constants const-list) +(define (do-with-constants const-list print-func) (map (lambda (thing) (cond ((string? thing) (generate-comment thing)) ((list? thing) - (generate-print-func (car thing) (cadr thing) (caddr thing))) + (print-func (car thing) (cadr thing) (caddr thing))) (else (error "Don't know what to do with this " thing)))) const-list)) +(define (generate-constants const-list) + (do-with-constants const-list generate-constants)) + +(define (generate-list-of-constants const-list) + (do-with-constants const-list generate-constant-list)) + (define odbc-constants-from-sql-h '(";;; some return values" ("SQL_NULL_DATA" #f dec) @@ -1685,3 +1697,9 @@ (generate-constants odbc-constants-from-sqlext-h) (close-output-port (current-output-port)))) +(with-output-to-file "constants.txt" + (lambda () + (for-each (lambda (name) + (format (current-output-port) "\t~A~%" name)) + clist) + (close-output-port (current-output-port)))) diff --git a/scsh/odbc/odbc-constants.scm b/scsh/odbc/odbc-constants.scm index 04f8a86..1908f6b 100644 --- a/scsh/odbc/odbc-constants.scm +++ b/scsh/odbc/odbc-constants.scm @@ -1691,12 +1691,6 @@ (define sql-table-stat 0) -;;; Defines for SQLTables -(define sql-all-catalogs %) -(define sql-all-schemas %) -(define sql-all-table-types %) - - ;;; Options for SQLDriverConnect (define sql-driver-noprompt 0) (define sql-driver-complete 1) @@ -1757,7 +1751,3 @@ (define sql-pt-unknown 0) (define sql-pt-procedure 1) (define sql-pt-function 2) - - -;;; This define is too large for RC (very funny!!!) -(define sql-odbc-keywords ABSOLUTE,ACTION,ADA,ADD,ALL,ALLOCATE,ALTER,AND,ANY,ARE,AS,ASC,ASSERTION,AT,AUTHORIZATION,AVG,BEGIN,BETWEEN,BIT,BIT_LENGTH,BOTH,BY,CASCADE,CASCADED,CASE,CAST,CATALOG,CHAR,CHAR_LENGTH,CHARACTER,CHARACTER_LENGTH,CHECK,CLOSE,COALESCE,COLLATE,COLLATION,COLUMN,COMMIT,CONNECT,CONNECTION,CONSTRAINT,CONSTRAINTS,CONTINUE,CONVERT,CORRESPONDING,COUNT,CREATE,CROSS,CURRENT,CURRENT_DATE,CURRENT_TIME,CURRENT_TIMESTAMP,CURRENT_USER,CURSOR,DATE,DAY,DEALLOCATE,DEC,DECIMAL,DECLARE,DEFAULT,DEFERRABLE,DEFERRED,DELETE,DESC,DESCRIBE,DESCRIPTOR,DIAGNOSTICS,DISCONNECT,DISTINCT,DOMAIN,DOUBLE,DROP,ELSE,END,END-EXEC,ESCAPE,EXCEPT,EXCEPTION,EXEC,EXECUTE,EXISTS,EXTERNAL,EXTRACT,FALSE,FETCH,FIRST,FLOAT,FOR,FOREIGN,FORTRAN,FOUND,FROM,FULL,GET,GLOBAL,GO,GOTO,GRANT,GROUP,HAVING,HOUR,IDENTITY,IMMEDIATE,IN,INCLUDE,INDEX,INDICATOR,INITIALLY,INNER,INPUT,INSENSITIVE,INSERT,INT,INTEGER,INTERSECT,INTERVAL,INTO,IS,ISOLATION,JOIN,KEY,LANGUAGE,LAST,LEADING,LEFT,LEVEL,LIKE,LOCAL,LOWER,MATCH,MAX,MIN,MINUTE,MODULE,MONTH,NAMES,NATIONAL,NATURAL,NCHAR,NEXT,NO,NONE,NOT,NULL,NULLIF,NUMERIC,OCTET_LENGTH,OF,ON,ONLY,OPEN,OPTION,OR,ORDER,OUTER,OUTPUT,OVERLAPS,PAD,PARTIAL,PASCAL,PLI,POSITION,PRECISION,PREPARE,PRESERVE,PRIMARY,PRIOR,PRIVILEGES,PROCEDURE,PUBLIC,READ,REAL,REFERENCES,RELATIVE,RESTRICT,REVOKE,RIGHT,ROLLBACK,ROWSSCHEMA,SCROLL,SECOND,SECTION,SELECT,SESSION,SESSION_USER,SET,SIZE,SMALLINT,SOME,SPACE,SQL,SQLCA,SQLCODE,SQLERROR,SQLSTATE,SQLWARNING,SUBSTRING,SUM,SYSTEM_USER,TABLE,TEMPORARY,THEN,TIME,TIMESTAMP,TIMEZONE_HOUR,TIMEZONE_MINUTE,TO,TRAILING,TRANSACTION,TRANSLATE,TRANSLATION,TRIM,TRUE,UNION,UNIQUE,UNKNOWN,UPDATE,UPPER,USAGE,USER,USING,VALUE,VALUES,VARCHAR,VARYING,VIEW,WHEN,WHENEVER,WHERE,WITH,WORK,WRITE,YEAR,ZONE) diff --git a/scsh/odbc/odbc-interfaces.scm b/scsh/odbc/odbc-interfaces.scm new file mode 100644 index 0000000..873c591 --- /dev/null +++ b/scsh/odbc/odbc-interfaces.scm @@ -0,0 +1,1433 @@ +(define-interface low-odbc-interface + (export + + ;;; data types + environment-handle? + environment-handle-handle + + connection-handle? + connection-handle-handle + connection-handle-environment + connection-handle-connected? + + statement-handle? + statement-handle-handle + statement-handle-connection + + odbc-handle? + odbc-handle + handle-record-type->c-handle-identifier + + odbc-column? + odbc-column-name + odbc-column-type + odbc-column-size + odbc-column-digits + odbc-column-nullable? + + odbc-parameter? + odbc-parameter-type + odbc-parameter-size + odbc-parameter-digits + odbc-parameter-nullable + + ;;; errors, conditions + odbc-error? + odbc-api-version-mismatch? + odbc-unknown-integer-type? + odbc-buffer-alloc-error? + odbc-unknown-c-type-identifier-error? + odbc-bindcol-unbound-column-error? + odbc-bindcol-rebinding-error? + + ;; functions + odbc-alloc-environment-handle + odbc-alloc-connection-handle + odbc-alloc-statement-handle + odbc-sql-connect + odbc-sql-browse-connect + + odbc-sql-data-sources + odbc-sql-drivers + odbc-sql-get-info-int + odbc-sql-get-info-string + odbc-sql-get-func + odbc-sql-get-type-info + + odbc-sql-set-connect-attr-string + odbc-sql-set-connect-attr-int + odbc-sql-get-connect-attr-string + odbc-sql-get-connect-attr-int + odbc-sql-set-env-attr-int + odbc-sql-get-env-attr-int + odbc-sql-set-stmt-attr-string + odbc-sql-set-stmt-attr-int + odbc-sql-get-stmt-attr-int + odbc-sql-get-stmt-attr-string + + odbc-sql-get-desc-field-int + odbc-sql-get-desc-field-string + + odbc-sql-prepare + odbc-sql-get-cursor-name + odbc-sql-set-cursor-name + + odbc-sql-execute + odbc-sql-execute-direct + odbc-sql-native-sql + odbc-sql-describe-param + odbc-sql-num-params + + odbc-sql-row-count + odbc-sql-get-data + odbc-sql-set-pos + odbc-sql-bulk-operations + odbc-sql-more-results + odbc-sql-fetch + + odbc-sql-column-privileges + odbc-sql-columns + odbc-sql-foreign-keys + odbc-sql-primary-keys + odbc-sql-procedure-columns + odbc-sql-procedures + odbc-sql-special-columns + odbc-sql-statistics + odbc-sql-table-privileges + odbc-sql-tables + + odbc-sql-free-statement + odbc-sql-close-cursor + odbc-sql-cancel + odbc-sql-num-result-cols + odbc-sql-describe-col + odbc-sql-col-attribute + + odbc-sql-disconnect + odbc-sql-free-handle + odbc-sql-get-diag-recs + + odbc-call-successful? + raise-odbc-api-version-mismatch-error + raise-odbc-unknown-integer-type-error + raise-odbc-buffer-alloc-error + raise-odbc-unknown-c-type-identifier-error + raise-odbc-bindcol-unbound-column-error + raise-odbc-bindcol-rebinding-error + + odbc-set-initial-retval-buffer-size + odbc-get-initial-retval-buffer-size)) + +;;; + +(define-interface low-odbc-constants-interface + (export + sql-null-data + sql-data-at-exec + sql-success + sql-success-with-info + sql-no-data + sql-error + sql-invalid-handle + sql-still-executing + sql-need-data + sql-nts + sql-ntsl + sql-max-message-length + sql-date-len + sql-time-len + sql-timestamp-len + sql-handle-env + sql-handle-dbc + sql-handle-stmt + sql-handle-desc + sql-attr-output-nts + sql-attr-auto-ipd + sql-attr-metadata-id + sql-attr-app-row-desc + sql-attr-app-param-desc + sql-attr-imp-row-desc + sql-attr-imp-param-desc + sql-attr-cursor-scrollable + sql-attr-cursor-sensitivity + sql-nonscrollable + sql-scrollable + sql-desc-count + sql-desc-type + sql-desc-length + sql-desc-octet-length-ptr + sql-desc-precision + sql-desc-scale + sql-desc-datetime-interval-code + sql-desc-nullable + sql-desc-indicator-ptr + sql-desc-data-ptr + sql-desc-name + sql-desc-unnamed + sql-desc-octet-length + sql-desc-alloc-type + sql-diag-returncode + sql-diag-number + sql-diag-row-count + sql-diag-sqlstate + sql-diag-native + sql-diag-message-text + sql-diag-dynamic-function + sql-diag-class-origin + sql-diag-subclass-origin + sql-diag-connection-name + sql-diag-server-name + sql-diag-dynamic-function-code + sql-diag-alter-domain + sql-diag-alter-table + sql-diag-call + sql-diag-create-assertion + sql-diag-create-character-set + sql-diag-create-collation + sql-diag-create-domain + sql-diag-create-index + sql-diag-create-schema + sql-diag-create-table + sql-diag-create-translation + sql-diag-create-view + sql-diag-delete-where + sql-diag-drop-assertion + sql-diag-drop-character-set + sql-diag-drop-collation + sql-diag-drop-domain + sql-diag-drop-index + sql-diag-drop-schema + sql-diag-drop-table + sql-diag-drop-translation + sql-diag-drop-view + sql-diag-dynamic-delete-cursor + sql-diag-dynamic-update-cursor + sql-diag-grant + sql-diag-insert + sql-diag-revoke + sql-diag-select-cursor + sql-diag-unknown-statement + sql-diag-update-where + sql-unknown-type + sql-char + sql-numeric + sql-decimal + sql-integer + sql-smallint + sql-float + sql-real + sql-double + sql-datetime + sql-varchar + sql-type-date + sql-type-time + sql-type-timestamp + sql-unspecified + sql-insensitive + sql-sensitive + sql-all-types + sql-default + sql-ard-type + sql-code-date + sql-code-time + sql-code-timestamp + sql-false + sql-true + sql-no-nulls + sql-nullable + sql-nullable-unknown + sql-pred-none + sql-pred-char + sql-pred-basic + sql-named + sql-unnamed + sql-desc-alloc-auto + sql-desc-alloc-user + sql-close + sql-drop + sql-unbind + sql-reset-params + sql-fetch-next + sql-fetch-first + sql-fetch-last + sql-fetch-prior + sql-fetch-absolute + sql-fetch-relative + sql-commit + sql-rollback + sql-null-henv + sql-null-hdbc + sql-null-hstmt + sql-null-hdesc + sql-null-handle + sql-scope-currow + sql-scope-transaction + sql-scope-session + sql-pc-unknown + sql-pc-non-pseudo + sql-pc-pseudo + sql-row-identifier + sql-index-unique + sql-index-all + sql-index-clustered + sql-index-hashed + sql-index-other + sql-api-sqlallocconnect + sql-api-sqlallocenv + sql-api-sqlallochandle + sql-api-sqlallocstmt + sql-api-sqlbindcol + sql-api-sqlbindparam + sql-api-sqlcancel + sql-api-sqlclosecursor + sql-api-sqlcolattribute + sql-api-sqlcolumns + sql-api-sqlconnect + sql-api-sqlcopydesc + sql-api-sqldatasources + sql-api-sqldescribecol + sql-api-sqldisconnect + sql-api-sqlendtran + sql-api-sqlerror + sql-api-sqlexecdirect + sql-api-sqlexecute + sql-api-sqlfetch + sql-api-sqlfetchscroll + sql-api-sqlfreeconnect + sql-api-sqlfreeenv + sql-api-sqlfreehandle + sql-api-sqlfreestmt + sql-api-sqlgetconnectattr + sql-api-sqlgetcursorname + sql-api-sqlgetdata + sql-api-sqlgetdescfield + sql-api-sqlgetdescrec + sql-api-sqlgetdiagfield + sql-api-sqlgetdiagrec + sql-api-sqlgetenvattr + sql-api-sqlgetfunctions + sql-api-sqlgetinfo + sql-api-sqlgetstmtattr + sql-api-sqlgetstmtoption + sql-api-sqlgettypeinfo + sql-api-sqlnumresultcols + sql-api-sqlparamdata + sql-api-sqlprepare + sql-api-sqlputdata + sql-api-sqlrowcount + sql-api-sqlsetconnectattr + sql-api-sqlsetconnectoption + sql-api-sqlsetcursorname + sql-api-sqlsetdescfield + sql-api-sqlsetdescrec + sql-api-sqlsetenvattr + sql-api-sqlsetparam + sql-api-sqlsetstmtattr + sql-api-sqlsetstmtoption + sql-api-sqlspecialcolumns + sql-api-sqlstatistics + sql-api-sqltables + sql-api-sqltransact + sql-max-driver-connections + sql-maximum-driver-connections + sql-max-concurrent-activities + sql-maximum-driver-connections + sql-data-source-name + sql-fetch-direction + sql-server-name + sql-search-pattern-escape + sql-dbms-name + sql-dbms-ver + sql-accessible-tables + sql-accessible-procedures + sql-cursor-commit-behavior + sql-data-source-read-only + sql-default-txn-isolation + sql-identifier-case + sql-identifier-quote-char + sql-max-column-name-len + sql-maximum-column-name-length + sql-max-cursor-name-len + sql-maximum-cursor-name-length + sql-max-schema-name-len + sql-maximum-schema-name-length + sql-max-catalog-name-len + sql-maximum-catalog-name-length + sql-max-table-name-len + sql-scroll-concurrency + sql-txn-capable + sql-transaction-capable + sql-user-name + sql-txn-isolation-option + sql-transaction-isolation-option + sql-integrity + sql-getdata-extensions + sql-null-collation + sql-alter-table + sql-order-by-columns-in-select + sql-special-characters + sql-max-columns-in-group-by + sql-maximum-columns-in-group-by + sql-max-columns-in-index + sql-maximum-columns-in-index + sql-max-columns-in-order-by + sql-maximum-columns-in-order-by + sql-max-columns-in-select + sql-maximum-columns-in-select + sql-max-columns-in-table + sql-max-index-size + sql-maximum-index-size + sql-max-row-size + sql-maximum-row-size + sql-max-statement-len + sql-maximum-statement-length + sql-max-tables-in-select + sql-maximum-tables-in-select + sql-max-user-name-len + sql-maximum-user-name-length + sql-oj-capabilities + sql-outer-join-capabilities + sql-xopen-cli-year + sql-cursor-sensitivity + sql-describe-parameter + sql-catalog-name + sql-collation-seq + sql-max-identifier-len + sql-maximum-identifier-length + sql-at-add-column + sql-at-drop-column + sql-at-add-constraint + sql-am-none + sql-am-connection + sql-am-statement + sql-cb-delete + sql-cb-close + sql-cb-preserve + sql-fd-fetch-next + sql-fd-fetch-first + sql-fd-fetch-last + sql-fd-fetch-prior + sql-fd-fetch-absolute + sql-fd-fetch-relative + sql-gd-any-column + sql-gd-any-order + sql-ic-upper + sql-ic-lower + sql-ic-sensitive + sql-ic-mixed + sql-oj-left + sql-oj-right + sql-oj-full + sql-oj-nested + sql-oj-not-ordered + sql-oj-inner + sql-oj-all-comparison-ops + sql-scco-read-only + sql-scco-lock + sql-scco-opt-rowver + sql-scco-opt-values + sql-tc-none + sql-tc-dml + sql-tc-all + sql-tc-ddl-commit + sql-tc-ddl-ignore + sql-txn-read-uncommitted + sql-transaction-read-uncommitted + sql-txn-read-uncommitted + sql-transaction-read-committed + sql-txn-repeatable-read + sql-transaction-repeatable-read + sql-txn-serializable + sql-transaction-serializable + sql-nc-high + sql-nc-low + sql-spec-major + sql-spec-minor + sql-spec-string + sql-sqlstate-size + sql-max-dsn-length + sql-max-option-string-length + sql-handle-senv + sql-attr-odbc-version + sql-attr-connection-pooling + sql-attr-cp-match + sql-cp-one-per-driver + sql-cp-one-per-henv + sql-cp-default + sql-cp-strict-match + sql-cp-relaxed-match + sql-cp-match-default + sql-ov-odbc2 + sql-ov-odbc3 + sql-access-mode + sql-autocommit + sql-login-timeout + sql-opt-trace + sql-opt-tracefile + sql-translate-dll + sql-translate-option + sql-txn-isolation + sql-current-qualifier + sql-odbc-cursors + sql-quiet-mode + sql-packet-size + sql-attr-access-mode + sql-attr-autocommit + sql-attr-connection-timeout + sql-attr-current-catalog + sql-attr-disconnect-behavior + sql-attr-enlist-in-dtc + sql-attr-enlist-in-xa + sql-attr-login-timeout + sql-attr-odbc-cursors + sql-attr-packet-size + sql-attr-quiet-mode + sql-attr-trace + sql-attr-tracefile + sql-attr-translate-lib + sql-attr-translate-option + sql-attr-txn-isolation + sql-attr-connection-dead + sql-db-return-to-pool + sql-db-disconnect + sql-db-default + sql-dtc-done + sql-cd-true + sql-cd-false + sql-query-timeout + sql-max-rows + sql-noscan + sql-max-length + sql-async-enable + sql-bind-type + sql-cursor-type + sql-concurrency + sql-keyset-size + sql-rowset-size + sql-simulate-cursor + sql-retrieve-data + sql-use-bookmarks + sql-get-bookmark + sql-row-number + sql-attr-async-enable + sql-attr-concurrency + sql-attr-cursor-type + sql-attr-enable-auto-ipd + sql-attr-fetch-bookmark-ptr + sql-attr-keyset-size + sql-attr-max-length + sql-attr-max-rows + sql-attr-noscan + sql-attr-param-bind-offset-ptr + sql-attr-param-bind-type + sql-attr-param-operation-ptr + sql-attr-param-status-ptr + sql-attr-params-processed-ptr + sql-attr-paramset-size + sql-attr-query-timeout + sql-attr-retrieve-data + sql-attr-row-bind-offset-ptr + sql-attr-row-bind-type + sql-attr-row-number + sql-attr-row-operation-ptr + sql-attr-row-status-ptr + sql-attr-rows-fetched-ptr + sql-attr-row-array-size + sql-attr-simulate-cursor + sql-attr-use-bookmarks + sql-col-pred-char + sql-col-pred-basic + sql-is-pointer + sql-is-uinteger + sql-is-integer + sql-is-usmallint + sql-is-smallint + sql-param-bind-by-column + sql-param-bind-type-default + sql-query-timeout-default + sql-max-rows-default + sql-noscan-off + sql-noscan-on + sql-noscan-default + sql-max-length-default + sql-async-enable-off + sql-async-enable-on + sql-async-enable-default + sql-bind-by-column + sql-bind-type-default + sql-concur-read-only + sql-concur-lock + sql-concur-rowver + sql-concur-values + sql-concur-default + sql-cursor-forward-only + sql-cursor-keyset-driven + sql-cursor-dynamic + sql-cursor-static + sql-cursor-type-default + sql-rowset-size-default + sql-keyset-size-default + sql-sc-non-unique + sql-sc-try-unique + sql-sc-unique + sql-rd-off + sql-rd-on + sql-rd-default + sql-ub-off + sql-ub-on + sql-ub-default + sql-ub-fixed + sql-ub-variable + sql-desc-array-size + sql-desc-array-status-ptr + sql-desc-auto-unique-value + sql-desc-base-column-name + sql-desc-base-table-name + sql-desc-bind-offset-ptr + sql-desc-bind-type + sql-desc-case-sensitive + sql-desc-catalog-name + sql-desc-concise-type + sql-desc-datetime-interval-precision + sql-desc-display-size + sql-desc-fixed-prec-scale + sql-desc-label + sql-desc-literal-prefix + sql-desc-literal-suffix + sql-desc-local-type-name + sql-desc-maximum-scale + sql-desc-minimum-scale + sql-desc-num-prec-radix + sql-desc-parameter-type + sql-desc-rows-processed-ptr + sql-desc-schema-name + sql-desc-searchable + sql-desc-type-name + sql-desc-table-name + sql-desc-unsigned + sql-desc-updatable + sql-diag-cursor-row-count + sql-diag-row-number + sql-diag-column-number + sql-date + sql-interval + sql-time + sql-timestamp + sql-longvarchar + sql-binary + sql-varbinary + sql-longvarbinary + sql-bigint + sql-tinyint + sql-bit + sql-code-year + sql-code-month + sql-code-day + sql-code-hour + sql-code-minute + sql-code-second + sql-code-year-to-month + sql-code-day-to-hour + sql-code-day-to-minute + sql-code-day-to-second + sql-code-hour-to-minute + sql-code-hour-to-second + sql-code-minute-to-second + sql-interval-year + sql-interval-month + sql-interval-day + sql-interval-hour + sql-interval-minute + sql-interval-second + sql-interval-year-to-month + sql-interval-day-to-hour + sql-interval-day-to-minute + sql-interval-day-to-second + sql-interval-hour-to-minute + sql-interval-hour-to-second + sql-interval-minute-to-second + sql-c-char + sql-c-long + sql-c-short + sql-c-float + sql-c-double + sql-c-numeric + sql-signed-offset + sql-unsigned-offset + sql-c-date + sql-c-time + sql-c-timestamp + sql-c-type-date + sql-c-type-time + sql-c-type-timestamp + sql-c-interval-year + sql-c-interval-month + sql-c-interval-day + sql-c-interval-hour + sql-c-interval-minute + sql-c-interval-second + sql-c-interval-year-to-month + sql-c-interval-day-to-hour + sql-c-interval-day-to-minute + sql-c-interval-day-to-second + sql-c-interval-hour-to-minute + sql-c-interval-hour-to-second + sql-c-interval-minute-to-second + sql-c-binary + sql-c-bit + sql-c-sbigint + sql-c-ubigint + sql-c-tinyint + sql-c-slong + sql-c-sshort + sql-c-stinyint + sql-c-ulong + sql-c-ushort + sql-c-utinyint + sql-c-bookmark + sql-c-varbookmark + sql-no-row-number + sql-no-column-number + sql-row-number-unknown + sql-column-number-unknown + sql-default-param + sql-ignore + sql-column-ignore + sql-len-data-at-exec-offset + sql-param-type-default + sql-setparam-value-max + sql-column-count + sql-column-name + sql-column-type + sql-column-length + sql-column-precision + sql-column-scale + sql-column-display-size + sql-column-nullable + sql-column-unsigned + sql-column-money + sql-column-updatable + sql-column-auto-increment + sql-column-case-sensitive + sql-column-searchable + sql-column-type-name + sql-column-table-name + sql-column-owner-name + sql-column-qualifier-name + sql-column-label + sql-colatt-opt-max + sql-colatt-opt-min + sql-attr-readonly + sql-attr-write + sql-attr-readwrite-unknown + sql-unsearchable + sql-like-only + sql-all-except-like + sql-searchable + sql-pred-searchable + sql-no-total + sql-api-sqlallochandlestd + sql-api-sqlbulkoperations + sql-api-sqlbindparameter + sql-api-sqlbrowseconnect + sql-api-sqlcolattributes + sql-api-sqlcolumnprivileges + sql-api-sqldescribeparam + sql-api-sqldriverconnect + sql-api-sqldrivers + sql-api-sqlextendedfetch + sql-api-sqlforeignkeys + sql-api-sqlmoreresults + sql-api-sqlnativesql + sql-api-sqlnumparams + sql-api-sqlparamoptions + sql-api-sqlprimarykeys + sql-api-sqlprocedurecolumns + sql-api-sqlprocedures + sql-api-sqlsetpos + sql-api-sqlsetscrolloptions + sql-api-sqltableprivileges + sql-api-all-functions + sql-api-loadbyordinal + sql-api-odbc3-all-functions + sql-api-odbc3-all-functions-size + sql-info-first + sql-active-connections + sql-active-statements + sql-driver-hdbc + sql-driver-henv + sql-driver-hstmt + sql-driver-name + sql-driver-ver + sql-odbc-api-conformance + sql-odbc-ver + sql-row-updates + sql-odbc-sag-cli-conformance + sql-odbc-sql-conformance + sql-procedures + sql-concat-null-behavior + sql-cursor-rollback-behavior + sql-expressions-in-orderby + sql-max-owner-name-len + sql-max-procedure-name-len + sql-max-qualifier-name-len + sql-mult-result-sets + sql-multiple-active-txn + sql-outer-joins + sql-owner-term + sql-procedure-term + sql-qualifier-name-separator + sql-qualifier-term + sql-scroll-options + sql-table-term + sql-convert-functions + sql-numeric-functions + sql-string-functions + sql-system-functions + sql-timedate-functions + sql-convert-bigint + sql-convert-binary + sql-convert-bit + sql-convert-char + sql-convert-date + sql-convert-decimal + sql-convert-double + sql-convert-float + sql-convert-integer + sql-convert-longvarchar + sql-convert-numeric + sql-convert-real + sql-convert-smallint + sql-convert-time + sql-convert-timestamp + sql-convert-tinyint + sql-convert-varbinary + sql-convert-varchar + sql-convert-longvarbinary + sql-odbc-sql-opt-ief + sql-correlation-name + sql-non-nullable-columns + sql-driver-hlib + sql-driver-odbc-ver + sql-lock-types + sql-pos-operations + sql-positioned-statements + sql-bookmark-persistence + sql-static-sensitivity + sql-file-usage + sql-column-alias + sql-group-by + sql-keywords + sql-owner-usage + sql-qualifier-usage + sql-quoted-identifier-case + sql-subqueries + sql-union + sql-max-row-size-includes-long + sql-max-char-literal-len + sql-timedate-add-intervals + sql-timedate-diff-intervals + sql-need-long-data-len + sql-max-binary-literal-len + sql-like-escape-clause + sql-qualifier-location + sql-active-environments + sql-alter-domain + sql-sql-conformance + sql-datetime-literals + sql-async-mode + sql-batch-row-count + sql-batch-support + sql-catalog-location + sql-catalog-name-separator + sql-catalog-term + sql-catalog-usage + sql-convert-wchar + sql-convert-interval-day-time + sql-convert-interval-year-month + sql-convert-wlongvarchar + sql-convert-wvarchar + sql-create-assertion + sql-create-character-set + sql-create-collation + sql-create-domain + sql-create-schema + sql-create-table + sql-create-translation + sql-create-view + sql-driver-hdesc + sql-drop-assertion + sql-drop-character-set + sql-drop-collation + sql-drop-domain + sql-drop-schema + sql-drop-table + sql-drop-translation + sql-drop-view + sql-dynamic-cursor-attributes1 + sql-dynamic-cursor-attributes2 + sql-forward-only-cursor-attributes1 + sql-forward-only-cursor-attributes2 + sql-index-keywords + sql-info-schema-views + sql-keyset-cursor-attributes1 + sql-keyset-cursor-attributes2 + sql-max-async-concurrent-statements + sql-odbc-interface-conformance + sql-param-array-row-counts + sql-param-array-selects + sql-schema-term + sql-schema-usage + sql-sql92-datetime-functions + sql-sql92-foreign-key-delete-rule + sql-sql92-foreign-key-update-rule + sql-sql92-grant + sql-sql92-numeric-value-functions + sql-sql92-predicates + sql-sql92-relational-join-operators + sql-sql92-revoke + sql-sql92-row-value-constructor + sql-sql92-string-functions + sql-sql92-value-expressions + sql-standard-cli-conformance + sql-static-cursor-attributes1 + sql-static-cursor-attributes2 + sql-aggregate-functions + sql-ddl-index + sql-dm-ver + sql-insert-statement + sql-union-statement + sql-at-add-column-single + sql-at-add-column-default + sql-at-add-column-collation + sql-at-set-column-default + sql-at-drop-column-default + sql-at-drop-column-cascade + sql-at-drop-column-restrict + sql-at-add-table-constraint + sql-at-drop-table-constraint-cascade + sql-at-drop-table-constraint-restrict + sql-at-constraint-name-definition + sql-at-constraint-initially-deferred + sql-at-constraint-initially-immediate + sql-at-constraint-deferrable + sql-at-constraint-non-deferrable + sql-cvt-char + sql-cvt-numeric + sql-cvt-decimal + sql-cvt-integer + sql-cvt-smallint + sql-cvt-float + sql-cvt-real + sql-cvt-double + sql-cvt-varchar + sql-cvt-longvarchar + sql-cvt-binary + sql-cvt-varbinary + sql-cvt-bit + sql-cvt-tinyint + sql-cvt-bigint + sql-cvt-date + sql-cvt-time + sql-cvt-timestamp + sql-cvt-longvarbinary + sql-cvt-interval-year-month + sql-cvt-interval-day-time + sql-cvt-wchar + sql-cvt-wlongvarchar + sql-cvt-wvarchar + sql-fn-str-concat + sql-fn-str-insert + sql-fn-str-left + sql-fn-str-ltrim + sql-fn-str-length + sql-fn-str-locate + sql-fn-str-lcase + sql-fn-str-repeat + sql-fn-str-replace + sql-fn-str-right + sql-fn-str-rtrim + sql-fn-str-substring + sql-fn-str-ucase + sql-fn-str-ascii + sql-fn-str-char + sql-fn-str-difference + sql-fn-str-locate-2 + sql-fn-str-soundex + sql-fn-str-space + sql-fn-str-bit-length + sql-fn-str-char-length + sql-fn-str-character-length + sql-fn-str-octet-length + sql-fn-str-position + sql-ssf-convert + sql-ssf-lower + sql-ssf-upper + sql-ssf-substring + sql-ssf-translate + sql-ssf-trim-both + sql-ssf-trim-leading + sql-ssf-trim-trailing + sql-fn-num-abs + sql-fn-num-acos + sql-fn-num-asin + sql-fn-num-atan + sql-fn-num-atan2 + sql-fn-num-ceiling + sql-fn-num-cos + sql-fn-num-cot + sql-fn-num-exp + sql-fn-num-floor + sql-fn-num-log + sql-fn-num-mod + sql-fn-num-sign + sql-fn-num-sin + sql-fn-num-sqrt + sql-fn-num-tan + sql-fn-num-pi + sql-fn-num-rand + sql-fn-num-degrees + sql-fn-num-log10 + sql-fn-num-power + sql-fn-num-radians + sql-fn-num-round + sql-fn-num-truncate + sql-snvf-bit-length + sql-snvf-char-length + sql-snvf-character-length + sql-snvf-extract + sql-snvf-octet-length + sql-snvf-position + sql-fn-td-now + sql-fn-td-curdate + sql-fn-td-dayofmonth + sql-fn-td-dayofweek + sql-fn-td-dayofyear + sql-fn-td-month + sql-fn-td-quarter + sql-fn-td-week + sql-fn-td-year + sql-fn-td-curtime + sql-fn-td-hour + sql-fn-td-minute + sql-fn-td-second + sql-fn-td-timestampadd + sql-fn-td-timestampdiff + sql-fn-td-dayname + sql-fn-td-monthname + sql-fn-td-current-date + sql-fn-td-current-time + sql-fn-td-current-timestamp + sql-fn-td-extract + sql-sdf-current-date + sql-sdf-current-time + sql-sdf-current-timestamp + sql-fn-sys-username + sql-fn-sys-dbname + sql-fn-sys-ifnull + sql-fn-tsi-frac-second + sql-fn-tsi-second + sql-fn-tsi-minute + sql-fn-tsi-hour + sql-fn-tsi-day + sql-fn-tsi-week + sql-fn-tsi-month + sql-fn-tsi-quarter + sql-fn-tsi-year + sql-ca1-next + sql-ca1-absolute + sql-ca1-relative + sql-ca1-bookmark + sql-ca1-lock-no-change + sql-ca1-lock-exclusive + sql-ca1-lock-unlock + sql-ca1-pos-position + sql-ca1-pos-update + sql-ca1-pos-delete + sql-ca1-pos-refresh + sql-ca1-positioned-update + sql-ca1-positioned-delete + sql-ca1-select-for-update + sql-ca1-bulk-add + sql-ca1-bulk-update-by-bookmark + sql-ca1-bulk-delete-by-bookmark + sql-ca1-bulk-fetch-by-bookmark + sql-ca2-read-only-concurrency + sql-ca2-lock-concurrency + sql-ca2-opt-rowver-concurrency + sql-ca2-opt-values-concurrency + sql-ca2-sensitivity-additions + sql-ca2-sensitivity-deletions + sql-ca2-sensitivity-updates + sql-ca2-max-rows-select + sql-ca2-max-rows-insert + sql-ca2-max-rows-delete + sql-ca2-max-rows-update + sql-ca2-max-rows-catalog + sql-ca2-max-rows-affects-all + sql-ca2-crc-exact + sql-ca2-crc-approximate + sql-ca2-simulate-non-unique + sql-ca2-simulate-try-unique + sql-ca2-simulate-unique + sql-oac-none + sql-oac-level1 + sql-oac-level2 + sql-oscc-not-compliant + sql-oscc-compliant + sql-osc-minimum + sql-osc-core + sql-osc-extended + sql-cb-null + sql-cb-non-null + sql-so-forward-only + sql-so-keyset-driven + sql-so-dynamic + sql-so-mixed + sql-so-static + sql-fd-fetch-bookmark + sql-cn-none + sql-cn-different + sql-cn-any + sql-nnc-null + sql-nnc-non-null + sql-nc-start + sql-nc-end + sql-file-not-supported + sql-file-table + sql-file-qualifier + sql-file-catalog + sql-gd-block + sql-gd-bound + sql-ps-positioned-delete + sql-ps-positioned-update + sql-ps-select-for-update + sql-gb-not-supported + sql-gb-group-by-equals-select + sql-gb-group-by-contains-select + sql-gb-no-relation + sql-gb-collate + sql-ou-dml-statements + sql-ou-procedure-invocation + sql-ou-table-definition + sql-ou-index-definition + sql-ou-privilege-definition + sql-su-dml-statements + sql-su-procedure-invocation + sql-su-table-definition + sql-su-index-definition + sql-su-privilege-definition + sql-qu-dml-statements + sql-qu-procedure-invocation + sql-qu-table-definition + sql-qu-index-definition + sql-qu-privilege-definition + sql-cu-dml-statements + sql-cu-procedure-invocation + sql-cu-table-definition + sql-cu-index-definition + sql-cu-privilege-definition + sql-sq-comparison + sql-sq-exists + sql-sq-in + sql-sq-quantified + sql-sq-correlated-subqueries + sql-u-union + sql-u-union-all + sql-bp-close + sql-bp-delete + sql-bp-drop + sql-bp-transaction + sql-bp-update + sql-bp-other-hstmt + sql-bp-scroll + sql-ss-additions + sql-ss-deletions + sql-ss-updates + sql-cv-create-view + sql-cv-check-option + sql-cv-cascaded + sql-cv-local + sql-lck-no-change + sql-lck-exclusive + sql-lck-unlock + sql-pos-position + sql-pos-refresh + sql-pos-update + sql-pos-delete + sql-pos-add + sql-ql-start + sql-ql-end + sql-af-avg + sql-af-count + sql-af-max + sql-af-min + sql-af-sum + sql-af-distinct + sql-af-all + sql-sc-fips127-2-transitional + sql-sc-sql92-intermediate + sql-sc-sql92-full + sql-dl-sql92-date + sql-dl-sql92-time + sql-dl-sql92-timestamp + sql-dl-sql92-interval-year + sql-dl-sql92-interval-month + sql-dl-sql92-interval-day + sql-dl-sql92-interval-hour + sql-dl-sql92-interval-minute + sql-dl-sql92-interval-second + sql-dl-sql92-interval-year-to-month + sql-dl-sql92-interval-day-to-hour + sql-dl-sql92-interval-day-to-minute + sql-dl-sql92-interval-day-to-second + sql-dl-sql92-interval-hour-to-minute + sql-dl-sql92-interval-hour-to-second + sql-dl-sql92-interval-minute-to-second + sql-cl-start + sql-cl-end + sql-brc-procedures + sql-brc-explicit + sql-brc-rolled-up + sql-bs-select-explicit + sql-bs-row-count-explicit + sql-bs-select-proc + sql-bs-row-count-proc + sql-parc-batch + sql-parc-no-batch + sql-pas-batch + sql-pas-no-batch + sql-pas-no-select + sql-ik-none + sql-ik-asc + sql-ik-desc + sql-ik-all + sql-isv-assertions + sql-isv-character-sets + sql-isv-check-constraints + sql-isv-collations + sql-isv-column-domain-usage + sql-isv-column-privileges + sql-isv-columns + sql-isv-constraint-column-usage + sql-isv-constraint-table-usage + sql-isv-domain-constraints + sql-isv-domains + sql-isv-key-column-usage + sql-isv-referential-constraints + sql-isv-schemata + sql-isv-sql-languages + sql-isv-table-constraints + sql-isv-table-privileges + sql-isv-tables + sql-isv-translations + sql-isv-usage-privileges + sql-isv-view-column-usage + sql-isv-view-table-usage + sql-isv-views + sql-am-none + sql-am-connection + sql-am-statement + sql-ad-constraint-name-definition + sql-ad-add-domain-constraint + sql-ad-drop-domain-constraint + sql-ad-add-domain-default + sql-ad-drop-domain-default + sql-ad-add-constraint-initially-deferred + sql-ad-add-constraint-initially-immediate + sql-ad-add-constraint-deferrable + sql-ad-add-constraint-non-deferrable + sql-cs-create-schema + sql-cs-authorization + sql-cs-default-character-set + sql-ctr-create-translation + sql-ca-create-assertion + sql-ca-constraint-initially-deferred + sql-ca-constraint-initially-immediate + sql-ca-constraint-deferrable + sql-ca-constraint-non-deferrable + sql-ccs-create-character-set + sql-ccs-collate-clause + sql-ccs-limited-collation + sql-ccol-create-collation + sql-cdo-create-domain + sql-cdo-default + sql-cdo-constraint + sql-cdo-collation + sql-cdo-constraint-name-definition + sql-cdo-constraint-initially-deferred + sql-cdo-constraint-initially-immediate + sql-cdo-constraint-deferrable + sql-cdo-constraint-non-deferrable + sql-ct-create-table + sql-ct-commit-preserve + sql-ct-commit-delete + sql-ct-global-temporary + sql-ct-local-temporary + sql-ct-constraint-initially-deferred + sql-ct-constraint-initially-immediate + sql-ct-constraint-deferrable + sql-ct-constraint-non-deferrable + sql-ct-column-constraint + sql-ct-column-default + sql-ct-column-collation + sql-ct-table-constraint + sql-ct-constraint-name-definition + sql-di-create-index + sql-di-drop-index + sql-dc-drop-collation + sql-dd-drop-domain + sql-dd-restrict + sql-dd-cascade + sql-ds-drop-schema + sql-ds-restrict + sql-ds-cascade + sql-dcs-drop-character-set + sql-da-drop-assertion + sql-dt-drop-table + sql-dt-restrict + sql-dt-cascade + sql-dtr-drop-translation + sql-dv-drop-view + sql-dv-restrict + sql-dv-cascade + sql-is-insert-literals + sql-is-insert-searched + sql-is-select-into + sql-oic-core + sql-oic-level1 + sql-oic-level2 + sql-sfkd-cascade + sql-sfkd-no-action + sql-sfkd-set-default + sql-sfkd-set-null + sql-sfku-cascade + sql-sfku-no-action + sql-sfku-set-default + sql-sfku-set-null + sql-sg-usage-on-domain + sql-sg-usage-on-character-set + sql-sg-usage-on-collation + sql-sg-usage-on-translation + sql-sg-with-grant-option + sql-sg-delete-table + sql-sg-insert-table + sql-sg-insert-column + sql-sg-references-table + sql-sg-references-column + sql-sg-select-table + sql-sg-update-table + sql-sg-update-column + sql-sp-exists + sql-sp-isnotnull + sql-sp-isnull + sql-sp-match-full + sql-sp-match-partial + sql-sp-match-unique-full + sql-sp-match-unique-partial + sql-sp-overlaps + sql-sp-unique + sql-sp-like + sql-sp-in + sql-sp-between + sql-sp-comparison + sql-sp-quantified-comparison + sql-srjo-corresponding-clause + sql-srjo-cross-join + sql-srjo-except-join + sql-srjo-full-outer-join + sql-srjo-inner-join + sql-srjo-intersect-join + sql-srjo-left-outer-join + sql-srjo-natural-join + sql-srjo-right-outer-join + sql-srjo-union-join + sql-sr-usage-on-domain + sql-sr-usage-on-character-set + sql-sr-usage-on-collation + sql-sr-usage-on-translation + sql-sr-grant-option-for + sql-sr-cascade + sql-sr-restrict + sql-sr-delete-table + sql-sr-insert-table + sql-sr-insert-column + sql-sr-references-table + sql-sr-references-column + sql-sr-select-table + sql-sr-update-table + sql-sr-update-column + sql-srvc-value-expression + sql-srvc-null + sql-srvc-default + sql-srvc-row-subquery + sql-sve-case + sql-sve-cast + sql-sve-coalesce + sql-sve-nullif + sql-scc-xopen-cli-version1 + sql-scc-iso92-cli + sql-us-union + sql-us-union-all + sql-dtc-enlist-expensive + sql-dtc-unenlist-expensive + sql-fetch-first-user + sql-fetch-first-system + sql-entire-rowset + sql-position + sql-refresh + sql-update + sql-delete + sql-add + sql-setpos-max-option-value + sql-update-by-bookmark + sql-delete-by-bookmark + sql-fetch-by-bookmark + sql-lock-no-change + sql-lock-exclusive + sql-lock-unlock + sql-setpos-max-lock-value + sql-best-rowid + sql-rowver + sql-pc-not-pseudo + sql-quick + sql-ensure + sql-table-stat + sql-driver-noprompt + sql-driver-complete + sql-driver-prompt + sql-driver-complete-required + sql-fetch-bookmark + sql-row-success + sql-row-deleted + sql-row-updated + sql-row-norow + sql-row-added + sql-row-error + sql-row-success-with-info + sql-row-proceed + sql-row-ignore + sql-param-success + sql-param-success-with-info + sql-param-error + sql-param-unused + sql-param-diag-unavailable + sql-param-proceed + sql-param-ignore + sql-cascade + sql-restrict + sql-set-null + sql-no-action + sql-set-default + sql-initially-deferred + sql-initially-immediate + sql-not-deferrable + sql-param-type-unknown + sql-param-input + sql-param-input-output + sql-result-col + sql-param-output + sql-return-value + sql-pt-unknown + sql-pt-procedure + sql-pt-function)) diff --git a/scsh/odbc/odbc-packages.scm b/scsh/odbc/odbc-packages.scm new file mode 100644 index 0000000..91707a7 --- /dev/null +++ b/scsh/odbc/odbc-packages.scm @@ -0,0 +1,12 @@ +(define-structure low-odbc low-odbc-interface + (open + scheme external-calls scsh-utilities + define-record-types + conditions signals) + (files + odbc)) + +(define-structure low-odbc-constants low-odbc-constants-interface + (open scheme) + (files + odbc-constants)) diff --git a/scsh/odbc/odbc.c b/scsh/odbc/odbc.c index 308e6da..5a15a32 100644 --- a/scsh/odbc/odbc.c +++ b/scsh/odbc/odbc.c @@ -23,64 +23,28 @@ s48_value odbc_alloc_environment_handle() ODBC_DEBUG_PRINTF_2("SQLAllocEnv(...): %x\n", henv); #endif /* (ODBCVER >= 0x300) */ - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - return s48_enter_integer((long)henv); - case SQL_ERROR: -#if (ODBCVER >= 0x300) - ODBC_RAISE_EXCEPTION("SQLAllocHandle returned SQL_ERROR"); -#else - ODBC_RAISE_EXCEPTION("SQLAllocEnv returned SQL_ERROR"); -#endif /* (ODBCVER >= 0x300) */ - default: -#if (ODBCVER >= 0x300) - ODBC_RAISE_EXCEPTION("SQLAllocHandle unknown return value"); -#else - ODBC_RAISE_EXCEPTION("SQLAllocEnv unknown return value"); -#endif /* (ODBCVER >= 0x300) */ - } + return s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_integer((long)henv) : + S48_UNSPECIFIC); } /* given a valid environment handle (type SQLHENV) this function * sets the environment attributes. This needs to be done before * allocating a connection handle */ -void odbc_sql_set_env_attr(SQLHENV env_handle) +s48_value odbc_sql_set_env_attr(SQLHENV env_handle) { - SQLRETURN retval; retval = SQLSetEnvAttr(env_handle, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3, 0); ODBC_DEBUG_PRINTF_2("odbc_set_environment() %x\n", env_handle); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLSetEnvAttr returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLSetEnvAttr got invalid handle. Is your ODBC broken?"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLSetEnvAttr returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Given a valid environment handle get a connection handle */ -s48_value odbc_alloc_connection_handle(s48_value env_handle) { - +s48_value odbc_alloc_connection_handle(s48_value env_handle) +{ SQLHDBC hdbc; SQLRETURN retval; SQLHENV envh; @@ -95,45 +59,14 @@ s48_value odbc_alloc_connection_handle(s48_value env_handle) { ODBC_DEBUG_PRINTF_3("SQLAllocConnect(%x, ...): %x\n", envh, hdbc); #endif /* ODBCVER >= 0x300 */ - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer((long)hdbc); - } - case SQL_ERROR: - { -#if (ODBCVER >= 0x300) - ODBC_RAISE_EXCEPTION("SQLAllocHandle returned SQL_ERROR"); -#else - ODBC_RAISE_EXCEPTION("SQLAllocConnect returned SQL_ERROR"); -#endif /* ODBCVER >= 0x300 */ - break; - } - case SQL_INVALID_HANDLE: - { -#if (ODBCVER >= 0x300) - ODBC_RAISE_EXCEPTION("SQLAllocHandle got invalid handle"); -#else - ODBC_RAISE_EXCEPTION("SQLAllocConnect got invalid handle"); -#endif /* ODBCVER >= 0x300 */ - break; - } - default: - { -#if (ODBCVER >= 0x300) - ODBC_RAISE_EXCEPTION("SQLAllocHandle returned unknown error code"); -#else - ODBC_RAISE_EXCEPTION("SQLAllocConnect returned unknown error code"); -#endif /* ODBCVER >= 0x300 */ - break; - } - } + return s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_integer((long)hdbc) : + S48_UNSPECIFIC); } /* Given a valid connection handle get a statement handle */ -s48_value odbc_alloc_statement_handle(s48_value conn_handle) { - +s48_value odbc_alloc_statement_handle(s48_value conn_handle) +{ SQLHSTMT hstmt; SQLRETURN retval; SQLHANDLE ch; @@ -148,40 +81,9 @@ s48_value odbc_alloc_statement_handle(s48_value conn_handle) { ODBC_DEBUG_PRINTF_3("SQLAllocStmt() %x %x\n", ch, hstmt); #endif /* ODBCVER >= 0x300 */ - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer((long)hstmt); - } - case SQL_ERROR: - { -#if (ODBCVER >= 0x300) - ODBC_RAISE_EXCEPTION("SQLAllocHandle returned SQL_ERROR"); -#else - ODBC_RAISE_EXCEPTION("SQLAllocStmt returned SQL_ERROR"); -#endif /* ODBCVER >= 0x300 */ - break; - } - case SQL_INVALID_HANDLE: - { -#if (ODBCVER >= 0x300) - ODBC_RAISE_EXCEPTION("SQLAllocHandle got invalid handle"); -#else - ODBC_RAISE_EXCEPTION("SQLAllocStmt returned SQL_ERROR"); -#endif /* ODBCVER >= 0x300 */ - break; - } - default: - { -#if (ODBCVER >= 0x300) - ODBC_RAISE_EXCEPTION("SQLAllocHandle returned unknown error code"); -#else - ODBC_RAISE_EXCEPTION("SQLAllocStmt returned unknown error code"); -#endif /* ODBCVER >= 0x300 */ - break; - } - } + return s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_integer((long)hstmt) : + S48_UNSPECIFIC); } /* Connect to a server */ @@ -190,7 +92,6 @@ s48_value odbc_sql_connect(s48_value connection_handle, s48_value user_name, s48_value authentication) { - SQLHDBC ch; SQLCHAR *dsn, *user, *auth; SQLRETURN retval; @@ -203,30 +104,11 @@ s48_value odbc_sql_connect(s48_value connection_handle, ODBC_DEBUG_PRINTF_5("odbc_sql_connect() %x '%s' '%s' '%s'\n", ch, dsn, user,auth); retval = SQLConnect(ch, - dsn, SQL_NTS, - user, SQL_NTS, - auth, SQL_NTS); + dsn, S48_STRING_LENGTH(ds_name), + user, S48_STRING_LENGTH(user_name), + auth, S48_STRING_LENGTH(authentication)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLConnect returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLConnect got invalid handle"); - break; - } - default: - ODBC_RAISE_EXCEPTION("SQLConnect returned an unknown error code"); - break; - } + return s48_enter_integer(retval); } s48_value odbc_sql_browse_connect(s48_value conn_handle, s48_value conn_string) @@ -235,10 +117,14 @@ s48_value odbc_sql_browse_connect(s48_value conn_handle, s48_value conn_string) SQLCHAR *buffer = NULL; SQLRETURN retval; SQLSMALLINT buffer_needed, buffer_len; + s48_value res = S48_UNSPECIFIC; + S48_DECLARE_GC_PROTECT(1); + S48_GC_PROTECT_1(res); ch = (SQLHDBC) s48_extract_integer(conn_handle); - ODBC_DEBUG_PRINTF_3("odbc_sql_browse_connect() %x '%s'\n", ch, s48_extract_string(conn_string)); - buffer_len = ODBC_RETVAL_BUFFER_INITIAL_SIZE; + ODBC_DEBUG_PRINTF_3("odbc_sql_browse_connect() %x '%s'\n", + ch, s48_extract_string(conn_string)); + buffer_len = odbc_initial_retval_buffer_size; for (;;) { @@ -248,40 +134,18 @@ s48_value odbc_sql_browse_connect(s48_value conn_handle, s48_value conn_string) (SQLSMALLINT) S48_STRING_LENGTH(conn_string), buffer, buffer_len, &buffer_needed); - if (ODBC_SUCCESS(retval) && (buffer_needed > buffer_len)) + if (SQL_SUCCEEDED(retval) && (buffer_needed > buffer_len)) buffer_len = buffer_needed+1; else break; } - - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - s48_value res = s48_enter_string(buffer); - free(buffer); - return res; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLBrowseConnect returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLBrowseConnect got invalid handle"); - break; - } - case SQL_NEED_DATA: - { - return s48_enter_integer(SQL_NEED_DATA); - } - default: - { - ODBC_RAISE_EXCEPTION("SQLBrowseConnect returned unknown error code"); - break; - } - } + + res = s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_string(buffer) : + S48_UNSPECIFIC); + free(buffer); + S48_GC_UNPROTECT(); + return res; } /* @@ -295,112 +159,71 @@ s48_value odbc_sql_browse_connect(s48_value conn_handle, s48_value conn_string) /* Returns a list of available data sources. */ s48_value odbc_sql_data_sources(s48_value env_handle) { - SQLHENV eh; SQLUSMALLINT dir; SQLRETURN retval; - SQLCHAR *server_name, *driver_descr; + int first; SQLSMALLINT server_name_len, driver_descr_len; SQLSMALLINT server_name_needed, driver_descr_needed; - s48_value result = S48_UNSPECIFIC; - int first, more_items; + SQLCHAR *server_name = NULL; + SQLCHAR *driver_descr = NULL; + s48_value res_list = S48_NULL; + s48_value res = S48_UNSPECIFIC; - S48_DECLARE_GC_PROTECT(1); - S48_GC_PROTECT_1(result); - + S48_DECLARE_GC_PROTECT(2); + S48_GC_PROTECT_2(res_list, res); eh = (SQLHENV) s48_extract_integer(env_handle); - ODBC_DEBUG_PRINTF_1("odbc_sql_data_sources\n"); + server_name_len = driver_descr_len = odbc_initial_retval_buffer_size; - server_name_len = driver_descr_len = ODBC_RETVAL_BUFFER_INITIAL_SIZE; - server_name = (SQLCHAR *) calloc(server_name_len, sizeof(SQLCHAR)); - driver_descr = (SQLCHAR *) calloc(driver_descr_len, sizeof(SQLCHAR)); - - if ((server_name == NULL) || (driver_descr == NULL)) + first = 1; + for (;;) { - ODBC_RAISE_EXCEPTION("Could not allocate memory for return values"); - return S48_UNSPECIFIC; - } + for (;;) + { + odbc_sql_alloc((void **) &server_name, server_name_len, sizeof(SQLCHAR)); + odbc_sql_alloc((void **) &driver_descr, driver_descr_len, sizeof(SQLCHAR)); + + retval = SQLDataSources(eh, + (first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT), + server_name, sizeof(SQLCHAR)*server_name_len, + &server_name_needed, + driver_descr, sizeof(SQLCHAR)*driver_descr_len, + &driver_descr_needed); + + if (SQL_SUCCEEDED(retval) && ((server_name_needed > server_name_len) || + (driver_descr_needed > driver_descr_len))) + { + if (server_name_needed > server_name_len) + server_name_len = server_name_needed + 1; + if (driver_descr_needed > driver_descr_len) + driver_descr_len = driver_descr_needed + 1; + } + else + break; + } - redo_loop: - ODBC_DEBUG_PRINTF_1("redo_loop\n"); - result = S48_NULL; - first = more_items = 1; + if (SQL_SUCCEEDED(retval)) + res_list = s48_cons(s48_cons(s48_enter_string(server_name), + s48_enter_string(driver_descr)), + res_list); + else + res_list = S48_UNSPECIFIC; + + if (retval == SQL_NO_DATA) + { + res = s48_list_2(s48_enter_integer(retval), res_list); + free(server_name); + free(driver_descr); + S48_GC_UNPROTECT(); + return res; + } + first = 0; + } - while (more_items) { - - retval = SQLDataSources(eh, - (first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT), - server_name, sizeof(SQLCHAR)*server_name_len, &server_name_needed, - driver_descr, sizeof(SQLCHAR)*driver_descr_len, &driver_descr_needed); - - if (ODBC_SUCCESS(retval)) - { - int redo_call = 0; - - if (server_name_needed > server_name_len) - { - ODBC_DEBUG_PRINTF_2("realloc() server_name %d\n", server_name_needed); - server_name_len = server_name_needed+1; - server_name = (SQLCHAR *) realloc(server_name, (size_t) server_name_len); - redo_call = 1; - } - if (driver_descr_needed > driver_descr_len) - { - ODBC_DEBUG_PRINTF_2("realloc() driver_descr %d\n", driver_descr_needed+1); - driver_descr_len = driver_descr_needed+1; - driver_descr = (SQLCHAR *) realloc(driver_descr, (size_t) driver_descr_len); - redo_call = 1; - } - - if ((server_name == NULL) || (driver_descr == NULL)) - { - ODBC_RAISE_EXCEPTION("Could not allocate memory for return values"); - return S48_UNSPECIFIC; - } - - if (redo_call) goto redo_loop; - } - - first = 0; - - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - result = s48_cons(s48_cons(s48_enter_string(server_name), - s48_enter_string(driver_descr)), - result); - break; - } - case SQL_NO_DATA: - { - more_items = 0; - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLDataSources returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLDataSources got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLDataSources returned unknown error code"); - break; - } - } - } - - free(server_name); - free(driver_descr); - + /* never reached */ S48_GC_UNPROTECT(); - return result; + return s48_list_2(s48_enter_integer(retval), S48_UNSPECIFIC); } /* Returns the list of installed drivers and their attributes. */ @@ -409,66 +232,67 @@ s48_value odbc_sql_drivers(s48_value env_handle) #if (ODBCVER >= 0x0200) SQLHENV eh; SQLRETURN retval; - SQLCHAR driver_descr[ODBC_MAX_DRIVER_NAME_LEN]; - SQLSMALLINT driver_descr_len; - SQLCHAR driver_attr[ODBC_MAX_DRIVER_NAME_LEN]; - SQLSMALLINT driver_attr_len; - s48_value result = S48_UNSPECIFIC; - int first, more_items; - - S48_DECLARE_GC_PROTECT(1); - S48_GC_PROTECT_1(result); + int first; + SQLSMALLINT driver_descr_len, driver_attr_len; + SQLSMALLINT driver_descr_needed, driver_attr_needed; + SQLCHAR *driver_attr = NULL; + SQLCHAR *driver_descr = NULL; + s48_value res_list = S48_NULL; + s48_value res = S48_UNSPECIFIC; + S48_DECLARE_GC_PROTECT(2); + S48_GC_PROTECT_2(res, res_list); eh = (SQLHENV) s48_extract_integer(env_handle); - ODBC_DEBUG_PRINTF_1("odbc_sql_drivers\n"); - result = S48_NULL; - first = more_items = 0; - - while (more_items) { - - retval = SQLDrivers(eh, - (SQLUSMALLINT) (first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT), - driver_descr, ODBC_MAX_DRIVER_NAME_LEN, &driver_descr_len, - driver_attr, ODBC_MAX_DRIVER_NAME_LEN, &driver_attr_len); - first = 1; - - switch (retval) + driver_descr_len = driver_attr_len = odbc_initial_retval_buffer_size; + first = 0; + + for (;;) { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - result = s48_cons(s48_cons(s48_enter_string(driver_descr), - s48_enter_string(driver_attr)), - result); - break; + for (;;) + { + odbc_sql_alloc((void **) &driver_descr, driver_descr_len, sizeof(SQLCHAR)); + odbc_sql_alloc((void **) &driver_attr, driver_attr_len, sizeof(SQLCHAR)); + + retval = SQLDrivers(eh, + (SQLUSMALLINT) (first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT), + driver_descr, driver_descr_len, &driver_descr_needed, + driver_attr, driver_attr_len, &driver_attr_needed); + + if (SQL_SUCCEEDED(retval) && ((driver_descr_needed > driver_descr_len) || + (driver_attr_needed > driver_attr_len))) + { + if (driver_descr_needed > driver_descr_len) + driver_descr_len = driver_descr_needed + 1; + if (driver_attr_needed > driver_attr_len) + driver_attr_len = driver_attr_needed + 1; + } + else + break; + } + + if (SQL_SUCCEEDED(retval)) + res_list = s48_cons(s48_cons(s48_enter_string(driver_descr), + s48_enter_string(driver_attr)), + res_list); + + if (retval == SQL_NO_DATA) + { + res = s48_list_2(s48_enter_integer(retval), res_list); + free(driver_descr); + free(driver_attr); + S48_GC_UNPROTECT(); + return res; + } + + first = 1; } - case SQL_NO_DATA: - { - more_items = 0; - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLDrivers returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLDrivers got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLDrivers returned unknown error code"); - break; - } - } - } - + + /* not reached */ S48_GC_UNPROTECT(); - return result; + return res; #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x200"); + RAISE_API_VERSION_MISMATCH("SQLDrivers", ODBCVER, 0x200); #endif /* ODBCVER >= 0x200 */ } @@ -476,7 +300,6 @@ s48_value odbc_sql_drivers(s48_value env_handle) * (use if the information is an integer) */ s48_value odbc_sql_get_info_int(s48_value conn_handle, s48_value info_key) { - SQLHDBC ch; SQLUSMALLINT ik; SQLRETURN retval; @@ -484,170 +307,87 @@ s48_value odbc_sql_get_info_int(s48_value conn_handle, s48_value info_key) SQLSMALLINT buffer_size; ODBC_DEBUG_PRINTF_1("odbc_sql_get_info_int\n"); - ch = (SQLHDBC) s48_extract_integer(conn_handle); ik = (SQLUSMALLINT) s48_extract_integer(info_key); - retval = SQLGetInfo(ch, ik, &info, sizeof(SQLUINTEGER), &buffer_size); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(info); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetInfo returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetInfo got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLGetInfo returned unknown error code"); - break; - } - } + return s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_integer(info) : + S48_UNSPECIFIC); } /* Returns information about a specific driver and data source. * (use if the information is a string) */ s48_value odbc_sql_get_info_string(s48_value conn_handle, s48_value info_key) { - SQLHDBC ch; SQLUSMALLINT ik; SQLRETURN retval; SQLCHAR *buffer = NULL; SQLSMALLINT buffer_needed, buffer_len; + s48_value res = S48_UNSPECIFIC; + S48_DECLARE_GC_PROTECT(1); + S48_GC_PROTECT_1(res); ODBC_DEBUG_PRINTF_1("odbc_sql_get_info_string\n"); - ch = (SQLHDBC) s48_extract_integer(conn_handle); ik = (SQLUSMALLINT) s48_extract_integer(info_key); - buffer_len = ODBC_RETVAL_BUFFER_INITIAL_SIZE; + buffer_len = odbc_initial_retval_buffer_size; for (;;) { odbc_sql_alloc((void **) &buffer, buffer_len, sizeof(SQLCHAR)); - retval = SQLGetInfo(ch, ik, buffer, buffer_len, &buffer_needed); - if (ODBC_SUCCESS(retval) && (buffer_needed > buffer_len)) + if (SQL_SUCCEEDED(retval) && (buffer_needed > buffer_len)) buffer_len = buffer_needed+1; else break; } - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - s48_value res = s48_enter_string(buffer); - free(buffer); - return res; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetInfo returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetInfo got invalid exception"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLGetInfo returned unknown error code"); - break; - } - } + res = s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_string(buffer) : + S48_UNSPECIFIC); + free(buffer); + S48_GC_UNPROTECT(); + return res; } /* Returns supported driver functions. (for a multiple functions) */ s48_value odbc_sql_get_func_exists(s48_value conn_handle, s48_value fun_id) { - SQLHDBC ch; SQLUSMALLINT fi, supported[SQL_API_ODBC3_ALL_FUNCTIONS_SIZE]; SQLRETURN retval; - s48_value vec; int i; ODBC_DEBUG_PRINTF_1("odbc_sql_func_exists\n"); - ch = (SQLHDBC) s48_extract_integer(conn_handle); fi = (SQLUSMALLINT) s48_extract_integer(fun_id); - retval = SQLGetFunctions(ch, fi, supported); - - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return SQL_FUNC_EXISTS(supported, fi) == SQL_TRUE ? S48_TRUE : S48_FALSE; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetFunctions returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetFunctions got invalid exception"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLGetFunctions returned unknown error code"); - break; - } - } + + if (SQL_SUCCEEDED(retval)) + return + s48_list_2(s48_enter_integer(retval), + SQL_FUNC_EXISTS(supported, fi) == SQL_TRUE ? S48_TRUE : + S48_FALSE); + else + return s48_list_2(s48_enter_integer(retval), S48_UNSPECIFIC); } /* Returns information about supported data types. */ s48_value odbc_sql_get_type_info(s48_value stmt_handle, s48_value data_type) { - SQLHSTMT sh; SQLSMALLINT dt; SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_get_type_info\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); dt = (SQLSMALLINT) s48_extract_integer(data_type); - retval = SQLGetTypeInfo(sh, dt); - - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetTypeInfo returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetTypeInfo got invalid handle"); - break; - } - /* TODO: handle SQL_STILL_EXECUTING */ - default: - { - ODBC_RAISE_EXCEPTION("SQLGetTypeInfo returned unknown error code"); - break; - } - } + + return s48_enter_integer(retval); } /* @@ -669,37 +409,14 @@ s48_value odbc_sql_set_connect_attr_int(s48_value conn_handle, SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_set_connect_attr_int\n"); - ch = (SQLHDBC) s48_extract_integer(conn_handle); attr = (SQLINTEGER) s48_extract_integer(attribute); val = (SQLUINTEGER) s48_extract_integer(value); - retval = SQLSetConnectAttr(ch, attr, &val, 0); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLSetConnectAttr returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLSetConnectAttr got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLSetConnectAttr got unknown error code"); - break; - } - } + return s48_enter_integer(retval); #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLSetConnectAttr", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -714,37 +431,14 @@ s48_value odbc_sql_set_connect_attr_string(s48_value conn_handle, SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_set_connect_attr_string\n"); - ch = (SQLHDBC) s48_extract_integer(conn_handle); attr = (SQLINTEGER) s48_extract_integer(attribute); val = (SQLCHAR *) s48_extract_string(value); - retval = SQLSetConnectAttr(ch, attr, val, S48_STRING_LENGTH(value)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLSetConnectAttr returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLSetConnectAttr got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLSetConnectAttr got unknown error code"); - break; - } - } + return s48_enter_integer(retval); #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLSetConnectAttr", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -757,48 +451,31 @@ s48_value odbc_sql_get_connect_attr_string(s48_value conn_handle, SQLCHAR *buffer = NULL; SQLINTEGER buffer_needed, buffer_len; SQLRETURN retval; + s48_value res = S48_UNSPECIFIC; + S48_DECLARE_GC_PROTECT(1); + S48_GC_PROTECT_1(res); ODBC_DEBUG_PRINTF_1("odbc_sql_get_connect_attr_string\n"); - - buffer_len = ODBC_RETVAL_BUFFER_INITIAL_SIZE; + buffer_len = odbc_initial_retval_buffer_size; for (;;) { odbc_sql_alloc((void **) &buffer, buffer_len, sizeof(SQLCHAR)); - retval = SQLGetConnectAttr(ch, attr, buffer, buffer_len, &buffer_needed); - if (ODBC_SUCCESS(retval) && (buffer_needed > buffer_len)) + if (SQL_SUCCEEDED(retval) && (buffer_needed > buffer_len)) buffer_needed = buffer_len; else break; } - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - s48_value res = s48_enter_string(buffer); - free(buffer); - return res; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetConnectAttr returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetConnectAttr got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLGetConnectAttr returned unknown error code"); - break; - } - } + res = s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_string(buffer) : + S48_UNSPECIFIC); + free(buffer); + S48_GC_UNPROTECT(); + return res; #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLGetConnectAttr", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -813,34 +490,14 @@ s48_value odbc_sql_get_connect_attr_int(s48_value conn_handle, SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_get_connect_attr_int\n"); - retval = SQLGetConnectAttr(ch, attr, &buffer, sizeof(SQLUINTEGER), &buffer_size); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(buffer); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetConnectAttr returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetConnectAttr got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLGetConnectAttr returned unknown error code"); - break; - } - } + return s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_integer(buffer) : + S48_UNSPECIFIC); #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLGetConnectAttr", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -856,35 +513,13 @@ s48_value odbc_sql_set_env_attr_int(s48_value env_handle, eh = (SQLHENV) s48_extract_integer(env_handle); attr = (SQLINTEGER) s48_extract_integer(attribute); - val = (SQLUINTEGER) s48_extract_integer(value); - - ODBC_DEBUG_PRINTF_4("odbc_sql_get_env_attr_int eh %x attr %d value %d\n", eh, attr, val); - retval = SQLSetEnvAttr(eh, attr, &val, sizeof(SQLUINTEGER)); + val = s48_extract_integer(value); + ODBC_DEBUG_PRINTF_4("odbc_sql_set_env_attr_int eh %x attr %d value %d\n", eh, attr, val); + retval = SQLSetEnvAttr(eh, attr, (SQLPOINTER) &val, sizeof(SQLUINTEGER)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLSetEnvAttr returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLSetEnvAttr got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLSetEnvAttr returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLSetConnectAttr", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -901,34 +536,14 @@ s48_value odbc_sql_get_env_attr_int(s48_value env_handle, eh = (SQLHENV) s48_extract_integer(env_handle); attr = (SQLINTEGER) s48_extract_integer(attribute); val = (SQLUINTEGER) s48_extract_integer(value); - ODBC_DEBUG_PRINTF_4("odbc_sql_get_env_attr_int eh %x attr %d value %d\n", eh, attr, val); retval = SQLGetEnvAttr(eh, attr, &val, sizeof(SQLUINTEGER), &str_len); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(val); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetEnvAttr returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetEnvAttr got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLGetEnvAttr returned unknown error code"); - break; - } - } + return s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_integer(val) : + S48_UNSPECIFIC); #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLGetEnvAttr", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -944,37 +559,14 @@ s48_value odbc_sql_set_stmt_attr_int(s48_value stmt_handle, SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_get_stmt_attr_int\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); attr = (SQLINTEGER) s48_extract_integer(attribute); val = (SQLUINTEGER) s48_extract_integer(value); - retval = SQLSetStmtAttr(sh, attr, &val, 0); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLSetStmtAttr returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLSetStmtAttr got invalid handel"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLSetStmtAttr returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLSetStmtAttr", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -989,37 +581,14 @@ s48_value odbc_sql_set_stmt_attr_string(s48_value stmt_handle, SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_set_stmt_attr_string\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); attr = (SQLINTEGER) s48_extract_integer(attribute); val = (SQLCHAR *) s48_extract_string(value); - retval = SQLSetStmtAttr(sh, attr, val, S48_STRING_LENGTH(value)); - - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLSetStmtAttr returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLSetStmtAttr got invalid handel"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLSetStmtAttr returned unknown error code"); - break; - } - } + + return s48_enter_integer(retval); #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLSetStmtAttr", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -1031,36 +600,15 @@ s48_value odbc_sql_get_stmt_attr_int(s48_value stmt_handle, s48_value attribute) SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_get_stmt_attr_int\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); attr = (SQLINTEGER) s48_extract_integer(attribute); - retval = SQLGetStmtAttr(sh, attr, &val, sizeof(SQLINTEGER), &buf_size); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(val); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetStmtAttr returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetStmtAttr got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLGetStmtAttr returned unknown error code"); - break; - } - } + return s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_integer(val) : + S48_UNSPECIFIC); #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLGetStmtAttr", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -1072,48 +620,32 @@ s48_value odbc_sql_get_stmt_attr_string(s48_value stmt_handle, SQLINTEGER attr, buffer_len, buffer_needed; SQLCHAR *buffer = NULL; SQLRETURN retval; + s48_value res = S48_UNSPECIFIC; + S48_DECLARE_GC_PROTECT(1); + S48_GC_PROTECT_1(res); ODBC_DEBUG_PRINTF_1("odbc_sql_get_stmt_attr_string\n"); - - buffer_len = ODBC_RETVAL_BUFFER_INITIAL_SIZE; + buffer_len = odbc_initial_retval_buffer_size; for (;;) { odbc_sql_alloc((void **) &buffer, buffer_len, sizeof(SQLCHAR)); retval = SQLGetStmtAttr(sh, attr, &buffer, buffer_len, &buffer_needed); - if (ODBC_SUCCESS(retval) && (buffer_needed > buffer_len)) + if (SQL_SUCCEEDED(retval) && (buffer_needed > buffer_len)) buffer_len = buffer_needed+1; else break; } - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - s48_value res = s48_enter_string(buffer); - free(buffer); - return res; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetStmtAttr returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetStmtAttr got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLGetStmtAttr returned unknown error code"); - break; - } - } + res = s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_string(buffer) : + S48_UNSPECIFIC); + free(buffer); + S48_GC_UNPROTECT(); + return res; #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLGetStmtAttr", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -1134,9 +666,12 @@ s48_value odbc_sql_get_desc_field_int(s48_value desc_handle, s48_value rec_numbe SQLSMALLINT rn, fi; SQLINTEGER value, buffer_len; SQLRETURN retval; + s48_value res = S48_UNSPECIFIC; + s48_value scheme_int = S48_UNSPECIFIC; - ODBC_DEBUG_PRINTF_1("odbc_sql_get_desc_field_int\n"); - + S48_DECLARE_GC_PROTECT(2); + S48_GC_PROTECT_2(res, scheme_int); + ODBC_DEBUG_PRINTF_1("odbc_sql_get_desc_field_int\n"); dh = (SQLHDESC) s48_extract_integer(desc_handle); rn = (SQLSMALLINT) s48_extract_integer(rec_number); fi = (SQLSMALLINT) s48_extract_integer(field_id); @@ -1144,49 +679,30 @@ s48_value odbc_sql_get_desc_field_int(s48_value desc_handle, s48_value rec_numbe retval = SQLGetDescField(dh, rn, fi, (SQLPOINTER) &value, sizeof(SQLINTEGER), &buffer_len); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: + if (SQL_SUCCEEDED(retval)) + switch (buffer_len) { - switch (buffer_len) - { - case SQL_IS_INTEGER: - return s48_enter_integer((SQLINTEGER) value); - case SQL_IS_UINTEGER: - return s48_enter_integer((SQLUINTEGER) value); - case SQL_IS_SMALLINT: - return s48_enter_integer((SQLSMALLINT) value); - case SQL_IS_USMALLINT: - return s48_enter_integer((SQLUSMALLINT) value); - default: - { - ODBC_RAISE_EXCEPTION("SQLGetDescField returned unknown integer type"); - break; - } - } - } - case SQL_NO_DATA: - { - return S48_FALSE; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetDescField returned SQL_ERROR"); + case SQL_IS_INTEGER: + scheme_int = s48_enter_integer((SQLINTEGER) value); break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetDescField got invalid handle"); + case SQL_IS_UINTEGER: + scheme_int = s48_enter_integer((SQLUINTEGER) value); break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLGetDescField returned unknown error code"); + case SQL_IS_SMALLINT: + scheme_int = s48_enter_integer((SQLSMALLINT) value); + break; + case SQL_IS_USMALLINT: + scheme_int = s48_enter_integer((SQLUSMALLINT) value); break; + default: + RAISE_UNKNOWN_INTEGER_TYPE_ERROR("SQLGetDescField", buffer_len); } - } + + res = s48_list_2(s48_enter_integer(retval), scheme_int); + S48_GC_UNPROTECT(); + return res; #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLGetDescField", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -1200,56 +716,38 @@ s48_value odbc_sql_get_desc_field_string(s48_value desc_handle, s48_value rec_nu SQLCHAR *buffer = NULL; SQLINTEGER buffer_len, buffer_needed; SQLRETURN retval; + s48_value res = S48_UNSPECIFIC; + s48_value scheme_str = S48_UNSPECIFIC; + S48_DECLARE_GC_PROTECT(2); + S48_GC_PROTECT_2(res, scheme_str); ODBC_DEBUG_PRINTF_1("odbc_sql_get_desc_field_string\n"); - dh = (SQLHDESC) s48_extract_integer(desc_handle); rn = (SQLSMALLINT) s48_extract_integer(rec_number); fi = (SQLSMALLINT) s48_extract_integer(field_id); - buffer_len = ODBC_RETVAL_BUFFER_INITIAL_SIZE; + buffer_len = odbc_initial_retval_buffer_size; for (;;) { odbc_sql_alloc((void **) &buffer, buffer_len, sizeof(SQLCHAR)); retval = SQLGetDescField(dh, rn, fi, (SQLPOINTER) buffer, buffer_len, &buffer_needed); - if (ODBC_SUCCESS(retval) && (buffer_needed > buffer_len)) + if (SQL_SUCCEEDED(retval) && (buffer_needed > buffer_len)) buffer_len = buffer_needed+1; else break; } - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - s48_value res = s48_enter_string(buffer); - free(buffer); - return res; - } - case SQL_NO_DATA: - { - return S48_FALSE; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetDescField returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetDescField got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLGetDescField returned unknown error code"); - break; - } - } + if (SQL_SUCCEEDED(retval)) + scheme_str = s48_enter_string(buffer); + + free(buffer); + res = s48_list_2(s48_enter_integer(retval), scheme_str); + S48_GC_UNPROTECT(); + return res; #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLGetDescField", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -1271,280 +769,12 @@ s48_value odbc_sql_prepare(s48_value stmt_handle, s48_value stmt_txt) ODBC_DEBUG_PRINTF_1("odbc_sql_prepare\n"); sh = (SQLHSTMT) s48_extract_integer(stmt_handle); query = (SQLCHAR *) s48_extract_string(stmt_txt); - retval = SQLPrepare(sh, query, S48_STRING_LENGTH(stmt_txt)); - switch (retval) { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLPrepare got invalid handle"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLPrepare returned SQL_ERROR"); - break; - } - case SQL_STILL_EXECUTING: - { - /* Not yet implemented, raise an error meanwhile */ - ODBC_RAISE_EXCEPTION("SQLPrepare returned SQL_STILL_EXECUTING"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLPrepare returned an unknown error code"); - break; - } - } + return s48_enter_integer(retval); } -s48_value odbc_sql_bind_parameter_exec_out(s48_value stmt_handle, - s48_value param_vals) -{ -#if (ODBCVER >= 0x200) - SQLHSTMT sh; - SQLSMALLINT value_type, param_type; - SQLRETURN retval; - unsigned int i; - - ODBC_DEBUG_PRINTF_1("odbc_sql_bind_parameter_exec_out\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); - - /* bind parameters */ - for (i = 0; i < S48_VECTOR_LENGTH(param_vals); i++) { - - ODBC_DEBUG_PRINTF_2("Binding parameter %d", i); - - value_type = (SQLSMALLINT) - s48_extract_integer(S48_CAR(S48_CDR(S48_VECTOR_REF(param_vals, i)))); - param_type = (SQLSMALLINT) - s48_extract_integer(S48_CDR(S48_CDR(S48_VECTOR_REF(param_vals, i)))); - - switch (value_type) - { - case SQL_C_CHAR: - case SQL_C_BINARY: - { - SQLCHAR *value; - SQLUINTEGER val_len; - - ODBC_DEBUG_PRINTF_1("value_type is string\n"); - value = (SQLCHAR *) - s48_extract_string(S48_CAR(S48_VECTOR_REF(param_vals, i))); - val_len = - (SQLUINTEGER) S48_STRING_LENGTH(S48_CAR(S48_VECTOR_REF(param_vals, i))); - - retval = SQLBindParameter(sh, (SQLUSMALLINT) (i+1), - SQL_PARAM_OUTPUT, - value_type, param_type, - val_len, 0, - value, 0, (void *)SQL_NTS); - break; - } - case SQL_C_SHORT: - case SQL_C_LONG: - { - SQLINTEGER value; - SQLINTEGER cb_val; - - ODBC_DEBUG_PRINTF_1("value_type integer\n"); - cb_val = 0; - value = (SQLINTEGER) - s48_extract_integer(S48_CAR(S48_VECTOR_REF(param_vals, i))); - - retval = SQLBindParameter(sh, (SQLUSMALLINT) (i+1), - SQL_PARAM_OUTPUT, - value_type, param_type, - 0, 0, - &value, 0, &cb_val); - break; - } - case SQL_C_BIT: - case SQL_C_STINYINT: - case SQL_C_UTINYINT: - { - SQLCHAR value; - SQLINTEGER cb_val; - - cb_val = 0; - value = (SQLCHAR) - s48_extract_char(S48_CAR(S48_VECTOR_REF(param_vals, i))); - - retval = SQLBindParameter(sh, (SQLUSMALLINT) (i+1), - SQL_PARAM_OUTPUT, - value_type, param_type, - 0, 0, - &value, 0, &cb_val); - break; - } - case SQL_C_FLOAT: - { - SQLREAL value; - SQLINTEGER cb_val; - - ODBC_DEBUG_PRINTF_1("value_type is float\n"); - cb_val = 0; - value = (SQLREAL) - S48_UNSAFE_EXTRACT_DOUBLE(S48_CAR(S48_VECTOR_REF(param_vals, i))); - - retval = SQLBindParameter(sh, (SQLUSMALLINT) (i+1), - SQL_PARAM_OUTPUT, - value_type, param_type, - 0, 0, - &value, 0, &cb_val); - break; - } - case SQL_C_DOUBLE: - { - SQLDOUBLE value; - SQLINTEGER cb_val; - - ODBC_DEBUG_PRINTF_1("value_type is double\n"); - cb_val = 0; - value = (SQLDOUBLE) - S48_UNSAFE_EXTRACT_DOUBLE(S48_CAR(S48_VECTOR_REF(param_vals, i))); - - retval = SQLBindParameter(sh, (SQLUSMALLINT) (i+1), - SQL_PARAM_OUTPUT, - value_type, param_type, - 0, 0, - &value, 0, &cb_val); - break; - } - case SQL_C_TYPE_DATE: - { - SQL_DATE_STRUCT value; - SQLINTEGER cb_val; - - ODBC_DEBUG_PRINTF_1("value_type is date\n"); - cb_val = 0; - sql_date_record_to_struct(param_vals, &value); - - retval = SQLBindParameter(sh, (SQLUSMALLINT) (i+1), - SQL_PARAM_OUTPUT, - value_type, param_type, - 0, 0, - &value, 0, &cb_val); - break; - } - case SQL_C_TYPE_TIME: - { - SQL_TIME_STRUCT value; - SQLINTEGER cb_val; - - ODBC_DEBUG_PRINTF_1("value_type is time\n"); - cb_val = 0; - sql_time_record_to_struct(param_vals, &value); - - retval = SQLBindParameter(sh, (SQLUSMALLINT) (i+1), - SQL_PARAM_OUTPUT, - value_type, param_type, - 0, 0, - &value, 0, &cb_val); - break; - } - case SQL_C_TYPE_TIMESTAMP: - { - SQL_TIMESTAMP_STRUCT value; - SQLINTEGER cb_val; - - ODBC_DEBUG_PRINTF_1("value_type is timestamp\n"); - cb_val = 0; - sql_timestamp_record_to_struct(param_vals, &value); - - retval = SQLBindParameter(sh, (SQLUSMALLINT) (i+1), - SQL_PARAM_OUTPUT, - value_type, param_type, - 0, 0, - &value, 0, &cb_val); - break; - } - /* case SQL_C_NUMERIC: */ - /* { */ - /* SQL_NUMERIC_STRUCT value; */ - /* SQLINTEGER cb_val; */ - - /* cb_val = 0; */ - /* value.precision = (SQLCHAR) */ - /* s48_extract_char(S48_RECORD_REF(S48_CAR(S48_VECTOR_REF(param_vals, i)), */ - /* SR_SQL_NUMERIC_PRECISION)); */ - - /* value.scale = (SQLSCHAR) */ - /* s48_extract_char(S48_RECORD_REF(S48_CAR(S48_VECTOR_REF(param_vals, i)), */ - /* SR_SQL_NUMERIC_SCALE)); */ - - /* value.sign = (SQLCHAR) */ - /* s48_extract_char(S48_RECORD_REF(S48_CAR(S48_VECTOR_REF(param_vals, i)), */ - /* SR_SQL_NUMERIC_SIGN)); */ - - - - /* } */ - - default: - { - ODBC_RAISE_EXCEPTION("SQLBindParameter: unknown/unsupported value type"); - break; - } - } - - ODBC_DEBUG_PRINTF_1("All parameters bound\n"); - - /* check the return value of SQLBindParameter */ - if ((retval != SQL_SUCCESS) || (retval != SQL_SUCCESS_WITH_INFO)) { - switch (retval) - { - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLBindParameter returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLBindParameter got invalid handle"); - break; - } - } - } - } /* for */ - - ODBC_DEBUG_PRINTF_1("Executing statement\n"); - - /* execute statement */ - - retval = SQLExecute(sh); - - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLExcute returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLExcute got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLExcute returned unknown error code"); - break; - } - } -#else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x200"); -#endif /* ODBCVER >= 0x200 */ -} +/* FIXME: implement SQLBindParameter */ s48_value odbc_sql_get_cursor_name(s48_value stmt_handle) { @@ -1552,84 +782,46 @@ s48_value odbc_sql_get_cursor_name(s48_value stmt_handle) SQLRETURN retval; SQLCHAR *buffer = NULL; SQLSMALLINT buffer_len, buffer_needed; + s48_value res = S48_UNSPECIFIC; + s48_value scheme_str = S48_UNSPECIFIC; + S48_DECLARE_GC_PROTECT(2); + S48_GC_PROTECT_2(res, scheme_str); ODBC_DEBUG_PRINTF_1("odbc_sql_get_cursor_name\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); - - buffer_len = ODBC_RETVAL_BUFFER_INITIAL_SIZE; + buffer_len = odbc_initial_retval_buffer_size; for (;;) { odbc_sql_alloc((void **) &buffer, buffer_len, sizeof(SQLCHAR)); retval = SQLGetCursorName(sh, buffer, buffer_len, &buffer_needed); - if (ODBC_SUCCESS(retval) && (buffer_needed > buffer_len)) + if (SQL_SUCCEEDED(retval) && (buffer_needed > buffer_len)) buffer_len = buffer_needed+1; else break; } - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - s48_value res = s48_enter_string(buffer); - free(buffer); - return s48_enter_string(buffer); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetCursorName returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetCursorName got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLGetCursorName returned unknown error code"); - break; - } - } + if (SQL_SUCCEEDED(retval)) + scheme_str = s48_enter_string(buffer); + + free(buffer); + res = s48_list_2(s48_enter_integer(retval), scheme_str); + S48_GC_UNPROTECT(); + return res; } -void odbc_sql_set_cursor_name(s48_value stmt_handle, s48_value cursorname) +s48_value odbc_sql_set_cursor_name(s48_value stmt_handle, s48_value cursorname) { SQLHSTMT sh; SQLCHAR *cn; SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_set_cursor_name\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); cn = (SQLCHAR *) s48_extract_string(cursorname); - retval = SQLSetCursorName(sh, cn, S48_STRING_LENGTH(cursorname)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLSetCursorName returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLSetCursorName got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLSetCursorName returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* @@ -1642,83 +834,29 @@ void odbc_sql_set_cursor_name(s48_value stmt_handle, s48_value cursorname) s48_value odbc_sql_execute(s48_value stmt_handle) { - SQLHSTMT sh; SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_execute\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); - retval = SQLExecute(sh); - - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLExecute returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLExecute got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLExecute returned unknown error code"); - break; - } - } + + return s48_enter_integer(retval); } s48_value odbc_sql_execute_direct(s48_value stmt_handle, s48_value stmt) { - SQLHSTMT sh; SQLCHAR *query; SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_execute_direct\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); query = (SQLCHAR *) s48_extract_string(stmt); - retval = SQLExecDirect(sh, query, S48_STRING_LENGTH(stmt)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - case SQL_NEED_DATA: case SQL_NO_DATA: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLExecDirect returned SQL_ERROR"); - break; - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLExecDirect returned SQL_STILL_EXECUTING, not implemented yet"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLExecDirect got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLExecDirect returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Returns the text of an SQL statement as translated by the driver. */ @@ -1728,49 +866,35 @@ s48_value odbc_sql_native_sql(s48_value conn_handle, s48_value stmt_txt) SQLCHAR *stmt_in, *stmt_out = NULL; SQLINTEGER buffer_len, buffer_needed; SQLRETURN retval; - + s48_value res = S48_UNSPECIFIC; + s48_value scheme_str = S48_UNSPECIFIC; + + S48_DECLARE_GC_PROTECT(2); + S48_GC_PROTECT_2(res, scheme_str); ch = (SQLHDBC) s48_extract_integer(conn_handle); stmt_in = (SQLCHAR *) s48_extract_string(stmt_txt); - ODBC_DEBUG_PRINTF_1("odbc_sql_native_sql\n"); - buffer_len = ODBC_RETVAL_BUFFER_INITIAL_SIZE; + buffer_len = odbc_initial_retval_buffer_size; for (;;) { odbc_sql_alloc((void **) &stmt_out, buffer_len, sizeof(SQLCHAR)); retval = SQLNativeSql(ch, stmt_in, S48_STRING_LENGTH(stmt_txt), stmt_out, buffer_len, &buffer_needed); - if (ODBC_SUCCESS(retval) && buffer_needed > buffer_len) + if (SQL_SUCCEEDED(retval) && buffer_needed > buffer_len) buffer_len = buffer_needed+1; else break; } - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - s48_value res = s48_enter_string(stmt_out); - free(stmt_out); - return res; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLNativeSql returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLNativeSql got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLNativeSql returned unknoen error code"); - break; - } - } + if (SQL_SUCCEEDED(retval)) + scheme_str = s48_enter_string(stmt_out); + + free(stmt_out); + res = s48_list_2(s48_enter_integer(retval), scheme_str); + S48_GC_UNPROTECT(); + return res; } /* Returns the description for a specific parameter in a statement */ @@ -1781,50 +905,28 @@ s48_value odbc_sql_describe_param(s48_value stmt_handle, s48_value parameter_no) SQLUINTEGER ps; SQLSMALLINT dt, dd, n; SQLRETURN retval; - s48_value result = S48_UNSPECIFIC; - - S48_DECLARE_GC_PROTECT(1); - S48_GC_PROTECT_1(result); + s48_value res = S48_UNSPECIFIC; + s48_value scheme_rec = S48_UNSPECIFIC; + S48_DECLARE_GC_PROTECT(2); + S48_GC_PROTECT_2(res, scheme_rec); ODBC_DEBUG_PRINTF_1("odbc_sql_describe_param\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); pn = (SQLUSMALLINT) s48_extract_integer(parameter_no); - retval = SQLDescribeParam(sh, pn, &dt, &ps, &dd, &n); - switch (retval) + if (SQL_SUCCEEDED(retval)) { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - result = s48_make_record(odbc_parameter_record_type); - S48_RECORD_SET(result, SR_ODBC_PARAMETER_TYPE, s48_enter_integer(dt)); - S48_RECORD_SET(result, SR_ODBC_PARAMETER_SIZE, s48_enter_integer(ps)); - S48_RECORD_SET(result, SR_ODBC_PARAMETER_DIGITS, s48_enter_integer(dd)); - S48_RECORD_SET(result, SR_ODBC_PARAMETER_NULLABLE, s48_enter_integer(n)); - return result; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLDescribeParam returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLDescribeParam got invalid handle"); - break; - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLDescribeParam returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLDescribeParam returned unknown error code"); - break; - } + scheme_rec = s48_make_record(odbc_parameter_record_type); + S48_RECORD_SET(scheme_rec, SR_ODBC_PARAMETER_TYPE, s48_enter_integer(dt)); + S48_RECORD_SET(scheme_rec, SR_ODBC_PARAMETER_SIZE, s48_enter_integer(ps)); + S48_RECORD_SET(scheme_rec, SR_ODBC_PARAMETER_DIGITS, s48_enter_integer(dd)); + S48_RECORD_SET(scheme_rec, SR_ODBC_PARAMETER_NULLABLE, s48_enter_integer(n)); } + + res = s48_list_2(s48_enter_integer(retval), scheme_rec); + S48_GC_UNPROTECT(); + return res; } /* Returns the number of parameters in a statement */ @@ -1835,37 +937,12 @@ s48_value odbc_sql_num_params(s48_value stmt_handle) SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_num_params\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); retval = SQLNumParams(sh, ¶ms); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(params); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLNumParams returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLNumParams returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLNumParams got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLNumParams returned unknown error code"); - break; - } - } + return s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_integer(params) : + S48_UNSPECIFIC); } /* @@ -1883,78 +960,54 @@ s48_value odbc_sql_row_count(s48_value stmt_handle) SQLINTEGER rowcount; sh = (SQLHSTMT) s48_extract_integer(stmt_handle); - ODBC_DEBUG_PRINTF_1("odbc_sql_row_count\n"); - retval = SQLRowCount(sh, &rowcount); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(rowcount); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLRowCount returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLRowCount got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLRowCount returned unknown error code"); - break; - } - } + return s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_integer(rowcount) : + S48_UNSPECIFIC); } -s48_value odbc_sql_get_data(s48_value stmt_handle, s48_value column_number, - s48_value target_type, s48_value buffer_size) - +s48_value odbc_sql_get_data(s48_value stmt_handle, s48_value column_number, + s48_value target_type) { SQLHSTMT sh; - SQLUSMALLINT cn, bl; - SQLSMALLINT tt; - SQLRETURN retval; + SQLUSMALLINT cn; + SQLSMALLINT tt, buffer_len; SQLINTEGER buffer_needed; + SQLRETURN retval; void *buffer = NULL; s48_value result = S48_UNSPECIFIC; S48_DECLARE_GC_PROTECT(1); + S48_GC_PROTECT_1(result); sh = (SQLHSTMT) s48_extract_integer(stmt_handle); cn = (SQLUSMALLINT) s48_extract_integer(column_number); tt = (SQLSMALLINT) s48_extract_integer(target_type); - bl = (SQLUSMALLINT) s48_extract_integer(buffer_size); + ODBC_DEBUG_PRINTF_4("odbc_sql_get_data() sh:%x cn:%d tt:%d\n", sh, cn, tt); - ODBC_DEBUG_PRINTF_5("odbc_sql_get_data() sh:%x cn:%d tt:%d bl:%d\n", sh, cn, tt, bl); - - odbc_sql_alloc((void **) &buffer, buffer_size, sizeof_sql_c_type_identifier(tt)); - retval = SQLGetData(sh, cn, tt, buffer, buffer_size, &buffer_needed); - - switch (retval) + buffer_len = odbc_initial_retval_buffer_size; + for (;;) { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - S48_GC_PROTECT_1(result); - result = s48_cons(buffer_to_s48_value(buffer, tt), - s48_enter_integer(buffer_needed)); - free(buffer); - S48_GC_UNPROTECT(); - return result; - } - case SQL_NO_DATA: - ODBC_RAISE_EXCEPTION("SQLGetData returned SQL_NO_DATA"); - case SQL_STILL_EXECUTING: - ODBC_RAISE_EXCEPTION("SQLGetData returned SQL_STILL_EXECUTING, not yet implemented"); - case SQL_ERROR: - ODBC_RAISE_EXCEPTION("SQLGetData returned SQL_ERROR"); - default: - ODBC_RAISE_EXCEPTION("SQLGetData returned unknown error code"); + odbc_sql_alloc((void **) &buffer, buffer_len, sizeof_sql_c_type_identifier(tt)); + retval = SQLGetData(sh, cn, tt, buffer, buffer_len, &buffer_needed); + + if (SQL_SUCCEEDED(retval) && (buffer_needed > buffer_len)) + buffer_len = buffer_needed+1; + else + break; } + + if (SQL_SUCCEEDED(retval)) + { + result = s48_list_2(s48_enter_integer(retval), buffer_to_s48_value(buffer, tt)); + free(buffer); + } + else + result = s48_list_2(s48_enter_integer(retval), S48_UNSPECIFIC); + + S48_GC_UNPROTECT(); + return result; } /* Positions a cursor within a fetched block of data and allows an application @@ -1971,39 +1024,10 @@ s48_value odbc_sql_set_pos(s48_value stmt_handle, s48_value row_number, rn = (SQLUSMALLINT) s48_extract_integer(row_number); op = (SQLUSMALLINT) s48_extract_integer(operation); lt = (SQLUSMALLINT) s48_extract_integer(lock_type); - ODBC_DEBUG_PRINTF_5("odbc_sql_set_pos() sh:%x rn:%d op:%d lt:%d\n", sh, rn, op, lt); - retval = SQLSetPos(sh, rn, op, lt); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - case SQL_NEED_DATA: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLSetPos returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLSetPos returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLSetPos got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLSetPos returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Performs bulk insertions and bulk bookmark operations, including @@ -2016,42 +1040,13 @@ s48_value odbc_sql_bulk_operations(s48_value stmt_handle, s48_value operation) SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_bulk_operations\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); op = (SQLUSMALLINT) s48_extract_integer(operation); - retval = SQLBulkOperations(sh, op); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - case SQL_NEED_DATA: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLBulkOperations returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLBulkOperations returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLBulkOperations got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLBulkOperations returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLBulkOperations", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -2063,39 +1058,10 @@ s48_value odbc_sql_more_results(s48_value stmt_handle) SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_more_results\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); - retval = SQLMoreResults(sh); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - case SQL_NO_DATA: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLMoreResults returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLMoreResults returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLMoreResults got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLMoreResults returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } s48_value odbc_sql_fetch(s48_value stmt_handle) @@ -2105,101 +1071,44 @@ s48_value odbc_sql_fetch(s48_value stmt_handle) sh = (SQLHSTMT) s48_extract_integer(stmt_handle); ODBC_DEBUG_PRINTF_2("odbc_sql_fetch() %x\n", sh); - retval = SQLFetch(sh); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - case SQL_NO_DATA: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLFetch returned SQL_STILL_EXECUTING, not yet implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLFetch returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLFetch got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLFetch returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } s48_value odbc_sql_num_result_cols(s48_value stmt_handle) { - SQLHSTMT sh; SQLSMALLINT numcols; SQLRETURN retval; sh = (SQLHSTMT) s48_extract_integer(stmt_handle); - ODBC_DEBUG_PRINTF_1("odbc_sql_num_result_cols\n"); - retval = SQLNumResultCols(sh, &numcols); - - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(numcols); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLNumResultCols returned SQL_STILL_EXECUTING, not yet implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLNumResultCols returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLNumResultCols got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLNumResultCols returned unknown error code"); - break; - } - } + + return s48_list_2(s48_enter_integer(retval), + SQL_SUCCEEDED(retval) ? s48_enter_integer(numcols) : + S48_UNSPECIFIC); } s48_value odbc_sql_describe_col(s48_value stmt_handle, s48_value column_number) { - SQLHSTMT sh; SQLSMALLINT cn; SQLCHAR *buffer = NULL; SQLSMALLINT buffer_len, buffer_needed, data_type, digits, nullable; SQLUINTEGER col_size; SQLRETURN retval; + s48_value res = S48_UNSPECIFIC; s48_value col_rec = S48_UNSPECIFIC; - S48_DECLARE_GC_PROTECT(1); - S48_GC_PROTECT_1(col_rec); - + S48_DECLARE_GC_PROTECT(2); + S48_GC_PROTECT_2(res, col_rec); ODBC_DEBUG_PRINTF_1("odbc_sql_describe_col\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); cn = (SQLSMALLINT) s48_extract_integer(column_number); - buffer_len = ODBC_RETVAL_BUFFER_INITIAL_SIZE; + buffer_len = odbc_initial_retval_buffer_size; for (;;) { odbc_sql_alloc((void **) &buffer, buffer_len, sizeof(SQLCHAR)); @@ -2208,53 +1117,31 @@ s48_value odbc_sql_describe_col(s48_value stmt_handle, s48_value column_number) &data_type, &col_size, &digits, &nullable); - if (ODBC_SUCCESS(retval) && (buffer_needed > buffer_len)) + if (SQL_SUCCEEDED(retval) && (buffer_needed > buffer_len)) buffer_len = buffer_needed+1; else break; } - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - col_rec = s48_make_record(odbc_column_record_type); - S48_RECORD_SET(col_rec, SR_ODBC_COLUMN_NAME, - s48_enter_string(buffer)); - S48_RECORD_SET(col_rec, SR_ODBC_COLUMN_TYPE, - s48_enter_integer(data_type)); - S48_RECORD_SET(col_rec, SR_ODBC_COLUMN_SIZE, - s48_enter_integer(col_size)); - S48_RECORD_SET(col_rec, SR_ODBC_COLUMN_DIGITS, - s48_enter_integer(digits)); - S48_RECORD_SET(col_rec, SR_ODBC_COLUMN_NULLABLE, - s48_enter_integer(nullable)); + if (SQL_SUCCEEDED(retval)) + { + col_rec = s48_make_record(odbc_column_record_type); + S48_RECORD_SET(col_rec, SR_ODBC_COLUMN_NAME, + s48_enter_string(buffer)); + S48_RECORD_SET(col_rec, SR_ODBC_COLUMN_TYPE, + s48_enter_integer(data_type)); + S48_RECORD_SET(col_rec, SR_ODBC_COLUMN_SIZE, + s48_enter_integer(col_size)); + S48_RECORD_SET(col_rec, SR_ODBC_COLUMN_DIGITS, + s48_enter_integer(digits)); + S48_RECORD_SET(col_rec, SR_ODBC_COLUMN_NULLABLE, + s48_enter_integer(nullable)); + } - S48_GC_UNPROTECT(); - free(buffer); - return col_rec; - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLDescribeCol returned SQL_STILL_EXECUTING, not yet implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLDescribeCol returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLDescribeCol got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLDescribeCol returned unknown error code"); - break; - } - } + res = s48_list_2(s48_enter_integer(retval), col_rec); + free(buffer); + S48_GC_UNPROTECT(); + return res; } /* Describes attributes of a column in the result set */ @@ -2268,18 +1155,18 @@ s48_value odbc_sql_col_attribute(s48_value stmt_handle, s48_value column_number, SQLSMALLINT buffer_len, buffer_needed; SQLINTEGER intbuffer; SQLRETURN retval; - s48_value res_string, res; + s48_value res_string = S48_UNSPECIFIC; + s48_value res_pair = S48_UNSPECIFIC; + s48_value res = S48_UNSPECIFIC; - S48_DECLARE_GC_PROTECT(1); - S48_GC_PROTECT_1(res); - + S48_DECLARE_GC_PROTECT(3); + S48_GC_PROTECT_3(res, res_pair, res_string); ODBC_DEBUG_PRINTF_1("odbc_sql_col_attribute\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); cn = (SQLUSMALLINT) s48_extract_integer(column_number); fi = (SQLUSMALLINT) s48_extract_integer(field_id); - buffer_len = ODBC_RETVAL_BUFFER_INITIAL_SIZE; + buffer_len = odbc_initial_retval_buffer_size; for (;;) { odbc_sql_alloc((void **) &buffer, buffer_len, sizeof(SQLCHAR)); @@ -2288,48 +1175,27 @@ s48_value odbc_sql_col_attribute(s48_value stmt_handle, s48_value column_number, buffer, buffer_len, &buffer_needed, &intbuffer); - if (ODBC_SUCCESS(retval) && (buffer_needed > buffer_len)) + if (SQL_SUCCEEDED(retval) && (buffer_needed > buffer_len)) buffer_len = buffer_needed+1; else break; } - - switch (retval) + + if (SQL_SUCCEEDED(retval)) { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - res = s48_cons(s48_enter_string(buffer), s48_enter_integer(intbuffer)); - free(buffer); - S48_GC_UNPROTECT(); - return res; - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLColAttribute returned SQL_STILL_EXECUTING. Not implemented yet."); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLColAttribute returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLColAttribute got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLColAttribute returned unknown error code"); - break; - } + res_string = s48_enter_string(buffer); + res_pair = s48_cons(res_string, s48_enter_integer(intbuffer)); } + + free(buffer); + res = s48_list_2(s48_enter_integer(retval), res_pair); + S48_GC_UNPROTECT(); + return res; #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLColAttribute", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } - ColumnRecPtr bindcol_lookup_binding(SQLHSTMT stmt_handle, SQLUSMALLINT column_no) { StmtRecPtr stmt; @@ -2365,8 +1231,7 @@ s48_value bindcol_lookup_binding_scheme(s48_value stmt_handle, s48_value column_ col = bindcol_lookup_binding(sh, cn); if (col == NULL) - s48_call_scheme(S48_SHARED_BINDING_REF(signal_unbound_column), 2, - stmt_handle, column_no); + RAISE_ODBC_BINDCOL_UNBOUND_COLUMN_ERROR((long)sh, cn) else { ODBC_DEBUG_PRINTF_2("bindcol_lookup_binding_scheme(): col_buf:%x\n", col->col_buffer); @@ -2404,7 +1269,7 @@ s48_value odbc_sql_bindcol(s48_value stmt_handle, s48_value column_no, ODBC_DEBUG_PRINTF_1("odbc_sql_bindcol(): new binding\n"); col = (ColumnRec *) malloc(sizeof(ColumnRec)); if (col == NULL) - ODBC_RAISE_EXCEPTION("odbc_sql_bindcol(): Could not allocate buffer"); + RAISE_ODBC_BUFFER_ALLOC_ERROR(sizeof(ColumnRec)); /* initialize it */ col->col_no = cn; @@ -2417,7 +1282,7 @@ s48_value odbc_sql_bindcol(s48_value stmt_handle, s48_value column_no, ODBC_DEBUG_PRINTF_3("odbc_sql_bindcol() malloc %x %d\n", col->col_buffer, sizeof_sql_c_type_identifier(tt)*bl); if (col->col_buffer == NULL) - ODBC_RAISE_EXCEPTION("odbc_sql_bindcol(): Could not allocate buffer"); + RAISE_ODBC_BUFFER_ALLOC_ERROR(sizeof_sql_c_type_identifier(tt)*bl); /* store col in global_bindcol_list */ bindcol_bind_column(sh, cn, col); @@ -2428,7 +1293,7 @@ s48_value odbc_sql_bindcol(s48_value stmt_handle, s48_value column_no, ODBC_DEBUG_PRINTF_1("odbc_sql_bindcol(): rebinding existing binding\n"); if (tt != col->target_type) - ODBC_RAISE_EXCEPTION("odbc_sql_bindcol(): While rebinding buffers: old/new target type do not match"); + RAISE_ODBC_BINDCOL_REBINDING_ERROR("While rebinding buffers: old/new target type do not match") /* free the old buffer, allocate a new one */ free(col->col_buffer); @@ -2437,35 +1302,14 @@ s48_value odbc_sql_bindcol(s48_value stmt_handle, s48_value column_no, ODBC_DEBUG_PRINTF_3("odbc_sql_bindcol() reallocate %x %d\n", col->col_buffer, sizeof_sql_c_type_identifier(tt)*bl); if (col->col_buffer == NULL) - ODBC_RAISE_EXCEPTION("odbc_sql_bindcol(): Could not allocate buffer"); + RAISE_ODBC_BUFFER_ALLOC_ERROR(sizeof_sql_c_type_identifier(tt)*bl); } /* at this point ColumRecPtr col has been created or updated, call SQLBindCol() */ retval = SQLBindCol(sh, cn, tt, col->col_buffer, col->buffer_len, &col->buffer_needed); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return S48_UNSPECIFIC; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLBindCol returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLBindCol got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLBindCol returned unknown error code"); - break; - } - } -} + return s48_enter_integer(retval); +} void bindcol_bind_column(SQLHSTMT stmt_handle, SQLUSMALLINT column_no, ColumnRecPtr new_col) { @@ -2498,7 +1342,7 @@ void bindcol_bind_column(SQLHSTMT stmt_handle, SQLUSMALLINT column_no, ColumnRec ODBC_DEBUG_PRINTF_1("bindcol_bind_column() global_bindcol_list is empty\n"); new_stmt = (StmtRecPtr) malloc(sizeof(StmtRec)); if (new_stmt == NULL) - ODBC_RAISE_EXCEPTION("bindcol_bind_column(): Error allocating memory"); + RAISE_ODBC_BUFFER_ALLOC_ERROR(sizeof(StmtRec)); new_stmt->next = NULL; new_stmt->stmt_handle = stmt_handle; new_stmt->col_recs = new_col; @@ -2528,7 +1372,7 @@ void bindcol_unbind_colum(SQLHSTMT stmt_handle, SQLUSMALLINT column_no) col = col->next; } if (col == NULL) - s48_call_scheme(S48_SHARED_BINDING_REF(signal_unbound_column), 2, stmt_handle, column_no); + RAISE_ODBC_BINDCOL_UNBOUND_COLUMN_ERROR((long)stmt_handle, column_no) ODBC_DEBUG_PRINTF_2("bindcol_unbind_colum() free %x\n", col->col_buffer); free(col->col_buffer); prev_col->next = col->next; @@ -2543,8 +1387,7 @@ void bindcol_unbind_colum(SQLHSTMT stmt_handle, SQLUSMALLINT column_no) prev_stmt = stmt; stmt = stmt->next; } - s48_call_scheme(S48_SHARED_BINDING_REF(signal_unbound_column), 2, - s48_enter_integer((long) stmt_handle), s48_enter_integer(column_no)); + RAISE_ODBC_BINDCOL_UNBOUND_COLUMN_ERROR((long)stmt_handle, column_no) } s48_value bindcol_finalize_bindcols(s48_value stmt_handle) @@ -2609,46 +1452,18 @@ s48_value odbc_sql_column_privileges(s48_value stmt_handle, s48_value catalog_na SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_column_privileges\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); catalog = (SQLCHAR *) s48_extract_string(catalog_name); schema = (SQLCHAR *) s48_extract_string(schema_name); table = (SQLCHAR *) s48_extract_string(table_name); column = (SQLCHAR *) s48_extract_string(column_name); - retval = SQLColumnPrivileges(sh, catalog, S48_STRING_LENGTH(catalog_name), schema, S48_STRING_LENGTH(schema_name), table, S48_STRING_LENGTH(table_name), column, S48_STRING_LENGTH(column_name)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLColumnPrivileges returned SQL_STILL_EXECUTING. Not implemented yet"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLColumnPrivileges returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLColumnPrivileges got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLColumnPrivileges returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Returns the list of column names in a specified table */ @@ -2661,46 +1476,18 @@ s48_value odbc_sql_columns(s48_value stmt_handle, s48_value catalog_name, SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_columns\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); catalog = (SQLCHAR *) s48_extract_string(catalog_name); schema = (SQLCHAR *) s48_extract_string(schema_name); table = (SQLCHAR *) s48_extract_string(table_name); column = (SQLCHAR *) s48_extract_string(column_name); - retval = SQLColumns(sh, catalog, S48_STRING_LENGTH(catalog_name), schema, S48_STRING_LENGTH(schema_name), table, S48_STRING_LENGTH(table_name), column, S48_STRING_LENGTH(column_name)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLColumns returned SQL_STILL_EXECUTING. Not implemented yet"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLColumns returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLColumns got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLColumns returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Returns a list of columns names that make up foreign keys, @@ -2716,7 +1503,6 @@ s48_value odbc_sql_foreign_keys(s48_value stmt_handle, s48_value pk_catalog_name SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_foreign_keys\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); pk_catalog = (SQLCHAR *) s48_extract_string(pk_catalog_name); pk_schema = (SQLCHAR *) s48_extract_string(pk_schema_name); @@ -2724,7 +1510,6 @@ s48_value odbc_sql_foreign_keys(s48_value stmt_handle, s48_value pk_catalog_name fk_catalog = (SQLCHAR *) s48_extract_string(fk_catalog_name); fk_schema = (SQLCHAR *) s48_extract_string(fk_schema_name); fk_table = (SQLCHAR *) s48_extract_string(fk_table_name); - retval = SQLForeignKeys(sh, pk_catalog, S48_STRING_LENGTH(pk_catalog_name), pk_schema, S48_STRING_LENGTH(pk_schema_name), @@ -2733,33 +1518,7 @@ s48_value odbc_sql_foreign_keys(s48_value stmt_handle, s48_value pk_catalog_name fk_schema, S48_STRING_LENGTH(fk_schema_name), fk_table, S48_STRING_LENGTH(fk_table_name)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLForeignKeys returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLForeignKeys returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLForeignKeys got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLForeignKeys returned unknwon error code"); - break; - } - } + return s48_enter_integer(retval); } /* Returns the list of column names that make up the primary key for a table */ @@ -2771,44 +1530,16 @@ s48_value odbc_sql_primary_keys(s48_value stmt_handle, s48_value catalog_name, SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_primary_keys\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); catalog = (SQLCHAR *) s48_extract_string(catalog_name); schema = (SQLCHAR *) s48_extract_string(schema_name); table = (SQLCHAR *) s48_extract_string(table_name); - retval = SQLPrimaryKeys(sh, catalog, S48_STRING_LENGTH(catalog_name), schema, S48_STRING_LENGTH(schema_name), table, S48_STRING_LENGTH(table_name)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLPrimaryKeys returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLPrimaryKeys returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLPrimaryKeys got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLPrimaryKeys returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Returns the list of input and output parameters, as well as the columns @@ -2822,46 +1553,18 @@ s48_value odbc_sql_procedure_columns(s48_value stmt_handle, s48_value catalog_na SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_procedure_columns\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); catalog = (SQLCHAR *) s48_extract_string(catalog_name); schema = (SQLCHAR *) s48_extract_string(schema_name); proc = (SQLCHAR *) s48_extract_string(proc_name); column = (SQLCHAR *) s48_extract_string(column_name); - retval = SQLProcedureColumns(sh, catalog, S48_STRING_LENGTH(catalog_name), schema, S48_STRING_LENGTH(schema_name), proc, S48_STRING_LENGTH(proc_name), column, S48_STRING_LENGTH(column_name)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLProcedureColumns returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLProcedureColumns returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLProcedureColumns got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLProcedureColumns return unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Returns the list of procedure names stored in a specific data source. */ @@ -2873,44 +1576,16 @@ s48_value odbc_sql_procedures(s48_value stmt_handle, s48_value catalog_name, SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_procedures\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); catalog = (SQLCHAR *) s48_extract_string(catalog_name); schema = (SQLCHAR *) s48_extract_string(schema_name); proc = (SQLCHAR *) s48_extract_string(proc_name); - retval = SQLProcedures(sh, catalog, S48_STRING_LENGTH(catalog_name), schema, S48_STRING_LENGTH(schema_name), proc, S48_STRING_LENGTH(proc_name)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLProcedures returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLProcedures returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLProcedures got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLProcedures returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Returns information about the optimal set of columns that uniquely identifies @@ -2927,7 +1602,6 @@ s48_value odbc_sql_special_columns(s48_value stmt_handle, s48_value identifier_t SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_special_columns\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); it = (SQLSMALLINT) s48_extract_integer(identifier_type); catalog = (SQLCHAR *) s48_extract_string(catalog_name); @@ -2935,40 +1609,13 @@ s48_value odbc_sql_special_columns(s48_value stmt_handle, s48_value identifier_t table = (SQLCHAR *) s48_extract_string(table_name); s = (SQLSMALLINT) s48_extract_integer(scope); n = (SQLSMALLINT) s48_extract_integer(nullable); - retval = SQLSpecialColumns(sh, it, catalog, S48_STRING_LENGTH(catalog_name), schema, S48_STRING_LENGTH(schema_name), table, S48_STRING_LENGTH(table_name), s, n); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLSpecialColumns returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLSpecialColumns returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLSpecialColumns got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLSpecialColumns returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Returns statistics about a single table and the list of indexes associated @@ -2983,47 +1630,19 @@ s48_value odbc_sql_statistics(s48_value stmt_handle, s48_value catalog_name, SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_statistics\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); catalog = (SQLCHAR *) s48_extract_string(catalog_name); schema = (SQLCHAR *) s48_extract_string(schema_name); table = (SQLCHAR *) s48_extract_string(table_name); u = (SQLSMALLINT) s48_extract_integer(unique); r = (SQLSMALLINT) s48_extract_integer(reserved); - retval = SQLStatistics(sh, catalog, S48_STRING_LENGTH(catalog_name), schema, S48_STRING_LENGTH(schema_name), table, S48_STRING_LENGTH(table_name), u, r); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLStatistics returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLStatistics returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLStatistics got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLStatistics returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Returns a list of tables and the privileges associated with each table */ @@ -3035,44 +1654,16 @@ s48_value odbc_sql_table_privileges(s48_value stmt_handle, s48_value catalog_nam SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_table_privileges\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); catalog = (SQLCHAR *) s48_extract_string(catalog_name); schema = (SQLCHAR *) s48_extract_string(schema_name); table = (SQLCHAR *) s48_extract_string(table_name); - retval = SQLTablePrivileges(sh, catalog, S48_STRING_LENGTH(catalog_name), schema, S48_STRING_LENGTH(schema_name), table, S48_STRING_LENGTH(table_name)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLTablePrivileges returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLTablePrivileges returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLTablePrivileges got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLTablePrivileges returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Returns the list of table names stored in a specific data source */ @@ -3085,43 +1676,15 @@ s48_value odbc_sql_tables(s48_value stmt_handle, s48_value catalog_name, SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_tables\n"); - retval = SQLTables(sh, catalog, S48_STRING_LENGTH(catalog_name), schema, S48_STRING_LENGTH(schema_name), tablen, S48_STRING_LENGTH(table_name), tablet, S48_STRING_LENGTH(table_type)); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_STILL_EXECUTING: - { - ODBC_RAISE_EXCEPTION("SQLTables returned SQL_STILL_EXECUTING. Not implemented"); - break; - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLTables returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLTables got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLTables returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } - /* * * PART 9 @@ -3140,34 +1703,11 @@ s48_value odbc_sql_free_statement(s48_value stmt_handle, s48_value option) SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_free_statement\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); opt = (SQLUSMALLINT) s48_extract_integer(option); - retval = SQLFreeStmt(sh, opt); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLFreeStmt returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLFreeStmt got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLFreeStmt returned unknown error"); - break; - } - } + return s48_enter_integer(retval); } /* Closes a cursor that has been opened on a statement handle */ @@ -3178,68 +1718,25 @@ s48_value odbc_sql_close_cursor(s48_value stmt_handle) SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_close_cursor\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); retval = SQLCloseCursor(sh); - switch (retval) { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLCloseCursor returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLCloseCursor got an invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLCloseCursor returned an unknown error code"); - break; - } - } + return s48_enter_integer(retval); #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLCloseCursor", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } /* Cancels an SQL statement */ s48_value odbc_sql_cancel(s48_value stmt_handle) { - SQLHSTMT sh; SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_cancel\n"); - retval = SQLCancel(sh); - switch (retval) { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLCancel returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLCancel got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLCancel returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Commits or rolls back a transaction */ @@ -3252,37 +1749,14 @@ s48_value odbc_sql_endtran(s48_value handle_type, s48_value handle, SQLRETURN retval; ODBC_DEBUG_PRINTF_1("odbc_sql_endtran\n"); - ht = (SQLSMALLINT) s48_extract_integer(handle_type); h = (SQLHANDLE) s48_extract_integer(handle); ct = (SQLSMALLINT) s48_extract_integer(completion_type); retval = SQLEndTran(ht, h, ct); - - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLEndTran returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLEndTran got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLEndTran returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLEndTran", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -3297,37 +1771,14 @@ s48_value odbc_sql_endtran(s48_value handle_type, s48_value handle, /* Closes the connection */ s48_value odbc_sql_disconnect(s48_value conn_handle) { - SQLHDBC ch; SQLRETURN retval; ch = (SQLHDBC) s48_extract_integer(conn_handle); ODBC_DEBUG_PRINTF_2("odbc_sql_disconnect() %x\n", ch); - retval = SQLDisconnect(ch); - switch (retval) - { - case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLDisconnect returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLDisconnect got invalid hande"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLDisconnect returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); } /* Free a handle */ @@ -3340,34 +1791,12 @@ s48_value odbc_sql_free_handle(s48_value handle_type, s48_value handle) ht = (SQLSMALLINT) s48_extract_integer(handle_type); h = (SQLHANDLE) s48_extract_integer(handle); - ODBC_DEBUG_PRINTF_3("odbc_sql_free_handle() %x %d\n", h, ht); retval = SQLFreeHandle(ht, h); - switch (retval) - { - case SQL_SUCCESS: - { - return s48_enter_integer(retval); - } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLFreeHandle returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLFreeHandle got invalid handle"); - break; - } - default: - { - ODBC_RAISE_EXCEPTION("SQLFreeHandle returned unknown error code"); - break; - } - } + return s48_enter_integer(retval); #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLFreeHandle", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -3390,19 +1819,17 @@ s48_value odbc_sql_get_diag_recs(s48_value handle_type, s48_value handle) SQLSMALLINT i, more_recs, buffer_len, buffer_needed; SQLRETURN retval; s48_value res = S48_UNSPECIFIC; + s48_value rec_list = S48_NULL; s48_value diag_rec = S48_UNSPECIFIC; - S48_DECLARE_GC_PROTECT(2); - S48_GC_PROTECT_2(res, diag_rec); - + S48_DECLARE_GC_PROTECT(3); + S48_GC_PROTECT_3(res, rec_list, diag_rec); ht = (SQLSMALLINT) s48_extract_integer(handle_type); h = (SQLHANDLE) s48_extract_integer(handle); - res = S48_NULL; - ODBC_DEBUG_PRINTF_1("odbc_sql_get_diag_recs\n"); i = more_recs = 1; - buffer_len = ODBC_RETVAL_BUFFER_INITIAL_SIZE; + buffer_len = odbc_initial_retval_buffer_size; while (more_recs) { diag_rec = s48_make_record(odbc_diag_record_type); @@ -3414,8 +1841,11 @@ s48_value odbc_sql_get_diag_recs(s48_value handle_type, s48_value handle) sql_state, &native_error, buffer, buffer_len, &buffer_needed); - if (ODBC_SUCCESS(retval) && (buffer_needed > buffer_len)) + if (SQL_SUCCEEDED(retval) && (buffer_needed > buffer_len)) + { + ODBC_DEBUG_PRINTF_3("buffer_needed %d buffer_len %d\n", buffer_needed, buffer_len); buffer_len = buffer_needed+1; + } else break; } @@ -3427,7 +1857,9 @@ s48_value odbc_sql_get_diag_recs(s48_value handle_type, s48_value handle) S48_RECORD_SET(diag_rec, SR_ODBC_DIAG_SQL_STATE, s48_enter_string(sql_state)); S48_RECORD_SET(diag_rec, SR_ODBC_DIAG_NATIVE_ERROR, s48_enter_integer(native_error)); S48_RECORD_SET(diag_rec, SR_ODBC_DIAG_MESSAGE, s48_enter_string(buffer)); - res = s48_cons(diag_rec, res); + rec_list = s48_cons(diag_rec, rec_list); + free(buffer); + buffer = NULL; break; } case SQL_NO_DATA: @@ -3435,30 +1867,23 @@ s48_value odbc_sql_get_diag_recs(s48_value handle_type, s48_value handle) more_recs = 0; break; } - case SQL_ERROR: - { - ODBC_RAISE_EXCEPTION("SQLGetDiagRec returned SQL_ERROR"); - break; - } - case SQL_INVALID_HANDLE: - { - ODBC_RAISE_EXCEPTION("SQLGetDiagRec got invalid handle"); - break; - } default: - { - ODBC_RAISE_EXCEPTION("SQLGetDiagRec returned unknown error code"); - break; + { + free(buffer); + res = s48_list_2(s48_enter_integer(retval), S48_UNSPECIFIC); + S48_GC_UNPROTECT(); + return res; } } i++; } - S48_GC_UNPROTECT(); /* res */ + res = s48_list_2(s48_enter_integer(retval), rec_list); free(buffer); + S48_GC_UNPROTECT(); return res; #else - ODBC_RAISE_EXCEPTION("ODBC driver manager API version not >= 0x300"); + RAISE_API_VERSION_MISMATCH("SQLGetDiagRec", ODBCVER, 0x300); #endif /* ODBCVER >= 0x300 */ } @@ -3674,7 +2099,7 @@ size_t sizeof_sql_c_type_identifier(SQLSMALLINT ctypeid) case SQL_C_NUMERIC: return sizeof(SQL_NUMERIC_STRUCT); /* case SQL_C_GUID: return sizeof(SQLGUID); */ default: - ODBC_RAISE_EXCEPTION("Unknown c data type identifier"); + RAISE_ODBC_UNKNOWN_C_TYPE_IDENTIFIER_ERROR(0, ctypeid); break; } } @@ -3691,14 +2116,11 @@ void odbc_sql_alloc(void **buffer, size_t buffer_len, size_t type_len) else { ODBC_DEBUG_PRINTF_2("realloc bl:%d\n", buffer_len*type_len); - *buffer = (void *) realloc(*buffer, buffer_len*type_len); + *buffer = (void *) realloc(*buffer, (buffer_len+1)*type_len); } if (*buffer == NULL) - { - ODBC_RAISE_EXCEPTION("Could not allocate return value buffer"); - return; - } + RAISE_ODBC_BUFFER_ALLOC_ERROR((buffer_len+1)*type_len); } s48_value buffer_to_s48_value(void *buffer, SQLSMALLINT ctypeid) @@ -3733,11 +2155,23 @@ s48_value buffer_to_s48_value(void *buffer, SQLSMALLINT ctypeid) return struct_to_sql_timestamp_record((SQL_TIMESTAMP_STRUCT *) buffer); /* case SQL_C_NUMERIC: */ default: - ODBC_RAISE_EXCEPTION("Unknown c data type identifier"); + RAISE_ODBC_UNKNOWN_C_TYPE_IDENTIFIER_ERROR((long)buffer, ctypeid); break; } } +/* set initial return value buffer size */ +s48_value odbc_set_initial_retval_buffer_size(s48_value nobytes) +{ + odbc_initial_retval_buffer_size = (SQLUSMALLINT) s48_extract_integer(nobytes); +} + +/* get initial return value buffer size */ +s48_value odbc_get_intial_retval_buffer_size() +{ + return s48_enter_integer((int) odbc_initial_retval_buffer_size); +} + void s48_init_odbc(void) { /* bindings for record types */ @@ -3750,15 +2184,29 @@ void s48_init_odbc(void) S48_GC_PROTECT_GLOBAL(odbc_parameter_record_type); odbc_column_record_type = s48_get_imported_binding("odbc-parameter"); - S48_GC_PROTECT_GLOBAL(signal_unbound_column); - signal_unbound_column = s48_get_imported_binding("signal-unbound-column"); - - S48_GC_PROTECT_GLOBAL(signal_buffer_exceeded); - signal_buffer_exceeded = s48_get_imported_binding("signal-buffer-exceeded"); - S48_GC_PROTECT_GLOBAL(bindcol_buffer_record_type); bindcol_buffer_record_type = s48_get_imported_binding("bindcol-buffer"); + /* import conditions */ + S48_GC_PROTECT_GLOBAL(raise_odbc_api_version_mismatch_error); + raise_odbc_api_version_mismatch_error + = s48_get_imported_binding("raise-odbc-api-version-mismatch-error"); + S48_GC_PROTECT_GLOBAL(raise_odbc_unknown_integer_type_error); + raise_odbc_unknown_integer_type_error + = s48_get_imported_binding("raise-odbc-unknown-integer-type-error"); + S48_GC_PROTECT_GLOBAL(raise_odbc_buffer_alloc_error); + raise_odbc_buffer_alloc_error + = s48_get_imported_binding("raise-odbc-buffer-alloc-error"); + S48_GC_PROTECT_GLOBAL(raise_odbc_unknown_c_type_identifier_error); + raise_odbc_unknown_c_type_identifier_error + = s48_get_imported_binding("raise-odbc-unknown-c-type-identifier-error"); + S48_GC_PROTECT_GLOBAL(raise_odbc_bindcol_unbound_column_error); + raise_odbc_bindcol_unbound_column_error + = s48_get_imported_binding("raise-odbc-bindcol-unbound-column-error"); + S48_GC_PROTECT_GLOBAL(raise_odbc_bindcol_rebinding_error); + raise_odbc_bindcol_rebinding_error + = s48_get_imported_binding("raise-odbc-bindcol-rebinding-error"); + /* init global variables */ global_bindcol_list = NULL; @@ -3800,7 +2248,6 @@ void s48_init_odbc(void) /* PART 5 */ S48_EXPORT_FUNCTION(odbc_sql_prepare); - S48_EXPORT_FUNCTION(odbc_sql_bind_parameter_exec_out); S48_EXPORT_FUNCTION(odbc_sql_get_cursor_name); S48_EXPORT_FUNCTION(odbc_sql_set_cursor_name); @@ -3849,4 +2296,7 @@ void s48_init_odbc(void) /* misc functions */ S48_EXPORT_FUNCTION(bindcol_finalize_bindcols); + S48_EXPORT_FUNCTION(odbc_set_initial_retval_buffer_size); + S48_EXPORT_FUNCTION(odbc_get_intial_retval_buffer_size); + } diff --git a/scsh/odbc/odbc.h b/scsh/odbc/odbc.h index 196228b..5251377 100644 --- a/scsh/odbc/odbc.h +++ b/scsh/odbc/odbc.h @@ -2,7 +2,6 @@ #include /* ODBC header files */ - #include #include #include @@ -14,24 +13,9 @@ #define ERROR_MSG_BUFFER_LEN 255 -#define ODBC_MAX_STR_LEN 255 -#define ODBC_MAX_DRIVER_NAME_LEN ODBC_MAX_STR_LEN -#define ODBC_GET_INFO_MAX_LEN ODBC_MAX_STR_LEN -#define ODBC_GET_CONNECT_ATTR_MAX_LEN ODBC_MAX_STR_LEN -#define ODBC_GET_STMT_ATTR_MAX_LEN ODBC_MAX_STR_LEN -#define ODBC_GET_DATA_MAX_STR_LEN ODBC_MAX_STR_LEN -#define ODBC_DESCRIBE_COL_MAX_STR_LEN ODBC_MAX_STR_LEN -#define ODBC_MAX_CURSOR_NAME_STR_LEN ODBC_MAX_STR_LEN -#define ODBC_MAX_NATIVE_SQL_STR_LEN ODBC_MAX_STR_LEN -#define ODBC_MAX_GET_DESC_FIELD_STR_LEN ODBC_MAX_STR_LEN - -#define ODBC_RETVAL_BUFFER_INITIAL_SIZE 3 - /* turn debug messages on/off. */ #define ODBC_DEBUG_MSGS 1 -#define ODBC_RAISE_EXCEPTION(MSG) s48_raise_string_os_error(MSG) - #ifdef ODBC_DEBUG_MSGS #define ODBC_DEBUG_DIAGREC(ht, h) odbc_debug_msgs(ht, h); #else @@ -52,10 +36,43 @@ #define ODBC_DEBUG_PRINTF_5(str, arg1, arg2, arg3, arg4) ; #endif -/* offsets for scheme records */ +/* import conditions */ +static s48_value raise_odbc_api_version_mismatch_error = S48_FALSE; -/* some useful macros */ -#define ODBC_SUCCESS(retval) ((retval == SQL_SUCCESS) || (retval == SQL_SUCCESS_WITH_INFO)) +#define RAISE_API_VERSION_MISMATCH(FUNNAME, APIVER, APIVERNEEDED) \ + s48_call_scheme(S48_SHARED_BINDING_REF(raise_odbc_api_version_mismatch_error), \ + 3, s48_enter_string(FUNNAME), \ + s48_enter_integer(APIVER), s48_enter_integer(APIVERNEEDED)); + +static s48_value raise_odbc_unknown_integer_type_error = S48_FALSE; + +#define RAISE_UNKNOWN_INTEGER_TYPE_ERROR(FUNNAME, TYPEID) \ + s48_call_scheme(S48_SHARED_BINDING_REF(raise_odbc_unknown_integer_type_error), \ + 2, s48_enter_string(FUNNAME), s48_enter_integer(TYPEID)); + +static s48_value raise_odbc_buffer_alloc_error = S48_FALSE; + +#define RAISE_ODBC_BUFFER_ALLOC_ERROR(BUFFERLEN) \ + s48_call_scheme(S48_SHARED_BINDING_REF(raise_odbc_buffer_alloc_error), \ + 1, s48_enter_integer(BUFFERLEN)); + +static s48_value raise_odbc_unknown_c_type_identifier_error = S48_FALSE; + +#define RAISE_ODBC_UNKNOWN_C_TYPE_IDENTIFIER_ERROR(BUFFER, TYPEID) \ + s48_call_scheme(S48_SHARED_BINDING_REF(raise_odbc_unknown_c_type_identifier_error), \ + 2, s48_enter_integer(BUFFER), s48_enter_integer(TYPEID)); + +static s48_value raise_odbc_bindcol_unbound_column_error = S48_FALSE; + +#define RAISE_ODBC_BINDCOL_UNBOUND_COLUMN_ERROR(STMTHANDLE, COLUMNNO) \ + s48_call_scheme(S48_SHARED_BINDING_REF(raise_odbc_bindcol_unbound_column_error), \ + 2, s48_enter_integer(STMTHANDLE), s48_enter_integer(COLUMNNO)); + +static s48_value raise_odbc_bindcol_rebinding_error = S48_FALSE; + +#define RAISE_ODBC_BINDCOL_REBINDING_ERROR(TEXTMSG) \ + s48_call_scheme(S48_SHARED_BINDING_REF(raise_odbc_bindcol_rebinding_error), \ + 1, s48_enter_string(TEXTMSG)); /* corresponds to sql-date */ static s48_value sql_date_record_type = S48_FALSE; @@ -121,9 +138,6 @@ static s48_value bindcol_buffer_record_type = S48_FALSE; #define SR_BINDCOL_BUFFER_LENGTH 1 #define SR_BINDCOL_BUFFER_TARGET_TYPE 2 -static s48_value signal_unbound_column = S48_FALSE; -static s48_value signal_buffer_exceeded = S48_FALSE; - typedef struct bindcol_col_rec *ColumnRecPtr; typedef struct bindcol_col_rec { @@ -171,7 +185,7 @@ s48_value odbc_alloc_environment_handle(); /* given a valid environment handle (type SQLHENV) this function * sets the environment attributes. This needs to be done before * allocating a connection handle */ -void odbc_sql_set_env_attr(SQLHENV env_handle); +s48_value odbc_sql_set_env_attr(SQLHENV env_handle); /* Given a valid environment handle get a connection handle */ s48_value odbc_alloc_connection_handle(s48_value env_handle); @@ -286,12 +300,9 @@ s48_value odbc_sql_get_desc_field_string(s48_value desc_handle, s48_value rec_nu /* Prepare a SQL statement for execution */ s48_value odbc_sql_prepare(s48_value stmt_handle, s48_value stmt_txt); -s48_value odbc_sql_bind_parameter_exec_out(s48_value stmt_handle, - s48_value param_vals); - s48_value odbc_sql_get_cursor_name(s48_value stmt_handle); -void odbc_sql_set_cursor_name(s48_value stmt_handle, s48_value cursorname); +s48_value odbc_sql_set_cursor_name(s48_value stmt_handle, s48_value cursorname); /* * @@ -324,8 +335,8 @@ s48_value odbc_sql_num_params(s48_value stmt_handle); s48_value odbc_sql_row_count(s48_value stmt_handle); -s48_value odbc_sql_get_data(s48_value stmt_handle, s48_value column_number, - s48_value target_type, s48_value buffer_size); +s48_value odbc_sql_get_data(s48_value stmt_handle, s48_value column_number, + s48_value target_type); /* Positions a cursor within a fetched block of data and allows an application to refresh data in the rowset or to update or delete data in the result @@ -486,6 +497,16 @@ s48_value struct_to_sql_time_record(SQL_TIME_STRUCT *ts); void sql_timestamp_record_to_struct(s48_value sql_timestamp, SQL_TIMESTAMP_STRUCT *ts); +/* initial return value buffer size */ +#define ODBC_RETVAL_BUFFER_DEFAULT_SIZE 255 +static SQLUSMALLINT odbc_initial_retval_buffer_size = ODBC_RETVAL_BUFFER_DEFAULT_SIZE; + +/* set initial return value buffer size */ +s48_value odbc_set_initial_retval_buffer_size(s48_value nobytes); + +/* get initial return value buffer size */ +s48_value odbc_get_intial_retval_buffer_size(); + void odbc_sql_alloc(void **buffer, size_t buffer_len, size_t type_len); size_t sizeof_sql_c_type_identifier(SQLSMALLINT ctypeid); diff --git a/scsh/odbc/odbc.scm b/scsh/odbc/odbc.scm index 1ab018a..8ee5df2 100644 --- a/scsh/odbc/odbc.scm +++ b/scsh/odbc/odbc.scm @@ -63,6 +63,94 @@ (else (error "Unknown handle type: " record)))) +;;; conditions +(define-condition-type 'odbc-error '(error)) + +(define odbc-error? + (condition-predicate 'odbc-error)) + +(define-condition-type 'odbc-api-version-mismatch '(odbc-error)) + +(define odbc-api-version-mismatch? + (condition-predicate 'odbc-api-version-mismatch)) + +(define (raise-odbc-api-version-mismatch-error function-name + api-version + api-version-needed) + (apply signal 'odbc-api-version-mismatch + 'function-name function-name + 'odbc-driver-manager-api-version api-version + 'min-api-version-required api-version-needed)) + +(define-exported-binding + "raise-odbc-api-version-mismatch-error" + raise-odbc-api-version-mismatch-error) + +;;; +(define-condition-type 'odbc-unknown-integer-type '(odbc-error)) + +(define odbc-unknown-integer-type? + (condition-predicate 'odbc-unknown-integer-type)) + +(define (raise-odbc-unknown-integer-type-error function-name type-id) + (apply signal 'odbc-unknown-integer-type + 'function-name function-name 'type-id type-id)) + +(define-exported-binding + "raise-odbc-unknown-integer-type-error" raise-odbc-unknown-integer-type-error) + +;;; +(define-condition-type 'odbc-buffer-alloc-error '(odbc-error)) + +(define odbc-buffer-alloc-error? + (condition-predicate 'odbc-buffer-alloc-error)) + +(define (raise-odbc-buffer-alloc-error buffer-length) + (apply signal 'odbc-buffer-alloc-error 'buffer-length buffer-length)) + +(define-exported-binding + "raise-odbc-buffer-alloc-error" raise-odbc-buffer-alloc-error) + +;;; +(define-condition-type 'odbc-unknown-c-type-identifier-error '(odbc-error)) + +(define odbc-unknown-c-type-identifier-error? + (condition-predicate 'odbc-unknown-c-type-identifier-error)) + +(define (raise-odbc-unknown-c-type-identifier-error buffer ctypeid) + (apply signal 'odbc-unknown-c-type-identifier-error + 'buffer buffer 'ctypeid ctypeid)) + +(define-exported-binding + "raise-odbc-unknown-c-type-identifier-error" + raise-odbc-unknown-c-type-identifier-error) + +;;; +(define-condition-type 'odbc-bindcol-unbound-column '(odbc-error)) + +(define odbc-bindcol-unbound-column-error? + (condition-predicate 'odbc-bindcol-unbound-column)) + +(define (raise-odbc-bindcol-unbound-column-error stmt-handle column-no) + (apply signal 'odbc-bindcol-unbound-column + 'statement-handle stmt-handle 'column-no column-no)) + +(define-exported-binding "raise-odbc-bindcol-unbound-column-error" + raise-odbc-bindcol-unbound-column-error) + +;;; +(define-condition-type 'odbc-bindcol-rebinding-error '(odbc-error)) + +(define odbc-bindcol-rebinding-error? + (condition-predicate 'odbc-bindcol-rebinding-error)) + +(define (raise-odbc-bindcol-rebinding-error text-msg) + (apply signal 'odbc-bindcol-rebinding-error text-msg)) + +(define-exported-binding "raise-odbc-bindcol-rebinding-error" + raise-odbc-bindcol-rebinding-error) + +;;; (define-record-type odbc-column :odbc-column (really-make-odbc-column name type size digits nullable?) odbc-column? @@ -456,34 +544,32 @@ (define sql-invalid-handle -2) (define sql-need-data 99) -(define-record-type odbc-column :odbc-column - (really-make-odbc-column name type size digits nullable) - odbc-column? - (name odbc-column-name) - (type odbc-column-type) - (size odbc-column-size) - (digits odbc-column-digits) - (nullable odbc-column-nullable)) - ;;; PART 1 (define (odbc-alloc-environment-handle) - (let ((env-handle (really-make-environment-handle - (odbc-alloc-environment-handle-internal)))) - (add-finalizer! env-handle odbc-sql-free-handle) - env-handle)) + (let* ((status.value (odbc-alloc-environment-handle-internal)) + (status (car status.value)) + (value (cadr status.value))) + (if (odbc-call-successful? status) + (let ((env-handle (really-make-environment-handle value))) + (add-finalizer! env-handle odbc-sql-free-handle) + (values status env-handle)) + (values status value)))) (import-lambda-definition odbc-alloc-environment-handle-internal () "odbc_alloc_environment_handle") (define (odbc-alloc-connection-handle env-handle) - (check-arg environment-handle? env-handle odbc-alloc-connection-handle) - (let ((conn-handle (really-make-connection-handle - (odbc-alloc-connection-handle-internal - (environment-handle-handle env-handle)) env-handle #f))) - (add-finalizer! conn-handle free-connection-handle) - conn-handle)) + (let* ((status.value (odbc-alloc-connection-handle-internal + (environment-handle-handle env-handle))) + (status (car status.value)) + (value (cadr status.value))) + (if (odbc-call-successful? status) + (let ((conn-handle (really-make-environment-handle value))) + (add-finalizer! conn-handle free-connection-handle) + (values status conn-handle)) + (values status value)))) (import-lambda-definition odbc-alloc-connection-handle-internal (env-handle) @@ -496,19 +582,20 @@ (odbc-sql-free-handle conn-handle)) (define (odbc-alloc-statement-handle conn-handle) - (check-arg connection-handle? conn-handle odbc-alloc-statement-handle) - (let ((stmt-handle (really-make-statement-handle - (odbc-alloc-statement-handle-internal - (connection-handle-handle conn-handle)) - conn-handle))) - (add-finalizer! stmt-handle free-statement-handle) - stmt-handle)) + (let* ((status.value (odbc-alloc-statement-handle-internal + (connection-handle-handle conn-handle))) + (status (car status.value)) + (value (cadr status.value))) + (if (odbc-call-successful? status) + (let ((stmt-handle (really-make-statement-handle value))) + (add-finalizer! stmt-handle free-statement-handle) + (values status stmt-handle)) + (values status value)))) (define (free-statement-handle stmt-handle) (bindcol-finalize-bindcols (statement-handle-handle stmt-handle)) (odbc-sql-free-handle stmt-handle)) - (import-lambda-definition odbc-alloc-statement-handle-internal (db-handle) "odbc_alloc_statement_handle") @@ -519,7 +606,6 @@ ;;; returns odbc-return-value (define (odbc-sql-connect conn-handle server-name user-name auth) - (check-arg connection-handle? conn-handle odbc-sql-connect) (let ((return-value (odbc-sql-connect-internal (connection-handle-handle conn-handle) server-name user-name auth))) @@ -532,10 +618,10 @@ "odbc_sql_connect") (define (odbc-sql-browse-connect conn-handle connection-string) - (check-arg connection-handle? conn-handle odbc-sql-browse-connect) - (odbc-sql-browse-connect-internal (connection-handle-handle conn-handle) - connection-string)) - + (apply values + (odbc-sql-browse-connect-internal + (connection-handle-handle conn-handle) connection-string))) + (import-lambda-definition odbc-sql-browse-connect-internal (conn-handle connection-string) "odbc_sql_browse_connect") @@ -543,48 +629,53 @@ ;;; PART 2 (define (odbc-sql-data-sources env-handle) - (check-arg environment-handle? env-handle odbc-sql-data-sources) - (reverse (odbc-sql-data-sources-internal (environment-handle-handle env-handle)))) + (apply values + (odbc-sql-data-sources-internal + (environment-handle-handle env-handle)))) (import-lambda-definition odbc-sql-data-sources-internal (env-handle) "odbc_sql_data_sources") (define (odbc-sql-drivers env-handle) - (check-arg environment-handle? env-handle odbc-sql-drivers) - (odbc-sql-drivers-internal (environment-handle-handle env-handle))) + (apply values + (odbc-sql-drivers-internal + (environment-handle-handle env-handle)))) (import-lambda-definition odbc-sql-drivers-internal (env-handle) "odbc_sql_drivers") (define (odbc-sql-get-info-int conn-handle info-key) - (check-arg connection-handle? conn-handle odbc-sql-get-info-int) - (odbc-sql-get-info-int-internal (connection-handle-handle conn-handle) info-key)) + (apply values + (odbc-sql-get-info-int-internal + (connection-handle-handle conn-handle) info-key))) (import-lambda-definition odbc-sql-get-info-int-internal (conn-handle info-key) "odbc_sql_get_info_int") (define (odbc-sql-get-info-string conn-handle info-key) - (check-arg connection-handle-handle conn-handle odbc-sql-get-info-string) - (odbc-sql-get-info-string-internal (connection-handle-handle conn-handle) info-key)) + (apply values + (odbc-sql-get-info-string-internal + (connection-handle-handle conn-handle) info-key))) (import-lambda-definition odbc-sql-get-info-string-internal (conn-handle info-key) "odbc_sql_get_info_string") (define (odbc-sql-get-func conn-handle fun-id) - (check-arg connection-handle? conn-handle odbc-sql-get-func) - (odbc-sql-get-func-exists-internal (connection-handle-handle conn-handle) fun-id)) + (apply values + (odbc-sql-get-func-exists-internal + (connection-handle-handle conn-handle) fun-id))) (import-lambda-definition odbc-sql-get-func-exists-internal (conn-handle fun-id) "odbc_sql_get_func_exists") (define (odbc-sql-get-type-info stmt-handle data-type) - (check-arg statement-handle? stmt-handle data-type) - (odbc-sql-get-type-info-internal (statement-handle-handle stmt-handle) data-type)) + (odbc-sql-get-type-info-internal + (statement-handle-handle stmt-handle) data-type)) (import-lambda-definition odbc-sql-get-type-info-internal (stmt-handle data-type) @@ -593,90 +684,85 @@ ;;; PART 3 (define (odbc-sql-set-connect-attr-int conn-handle attribute value) - (check-arg connection-handle? conn-handle odbc-sql-set-connect-attr-int) - (odbc-sql-set-connect-attr-int-internal (connection-handle-handle conn-handle) - attribute value)) + (odbc-sql-set-connect-attr-int-internal + (connection-handle-handle conn-handle) attribute value)) (import-lambda-definition odbc-sql-set-connect-attr-int-internal (conn-handle attribute value) "odbc_sql_set_connect_attr_int") (define (odbc-sql-set-connect-attr-string conn-handle attribute value) - (check-arg connection-handle? conn-handle odbc-sql-set-connect-attr-string) - (odbc-sql-set-connect-attr-string-internal (connection-handle-handle conn-handle) - attribute value)) + (odbc-sql-set-connect-attr-string-internal + (connection-handle-handle conn-handle) attribute value)) (import-lambda-definition odbc-sql-set-connect-attr-string-internal (conn-handle attribute value) "odbc_sql_set_connect_attr_string") (define (odbc-sql-get-connect-attr-string conn-handle attribute) - (check-arg connection-handle? conn-handle odbc-sql-get-connect-attr-string) - (odbc-sql-get-connect-attr-string-internal (connection-handle-handle conn-handle) - attribute)) - + (apply values + (odbc-sql-get-connect-attr-string-internal + (connection-handle-handle conn-handle) attribute))) + (import-lambda-definition odbc-sql-get-connect-attr-string-internal (conn-handle attribute) "odbc_sql_get_connect_attr_string") (define (odbc-sql-get-connect-attr-int conn-handle attribute) - (check-arg connection-handle? conn-handle odbc-sql-get-connect-attr-int) - (odbc-sql-get-connect-attr-int-internal (connection-handle-handle conn-handle) - attribute)) + (apply values + (odbc-sql-get-connect-attr-int-internal + (connection-handle-handle conn-handle) attribute))) (import-lambda-definition odbc-sql-get-connect-attr-int-internal (conn-handle attribute) "odbc_sql_get_connect_attr_int") (define (odbc-sql-set-env-attr-int env-handle attribute value) - (check-arg environment-handle? env-handle odbc-sql-set-env-attr-int) - (odbc-sql-set-env-attr-int-internal (environment-handle-handle env-handle) - attribute value)) + (odbc-sql-set-env-attr-int-internal + (environment-handle-handle env-handle) attribute value)) (import-lambda-definition odbc-sql-set-env-attr-int-internal (env-handle attribute value) "odbc_sql_set_env_attr_int") (define (odbc-sql-get-env-attr-int env-handle attribute value) - (check-arg environment-handle? env-handle odbc-sql-get-connect-attr-int) - (odbc-sql-get-env-attr-int-internal (environment-handle-handle env-handle) - attribute value)) + (apply values + (odbc-sql-get-env-attr-int-internal + (environment-handle-handle env-handle) attribute value))) (import-lambda-definition odbc-sql-get-env-attr-int-internal (env-handle attribute value) "odbc_sql_get_env_attr_int") (define (odbc-sql-set-stmt-attr-int stmt-handle attribute value) - (check-arg statement-handle? stmt-handle odbc-sql-set-stmt-attr-int) - (odbc-sql-set-stmt-attr-int-internal (statement-handle-handle stmt-handle) - attribute value)) + (odbc-sql-set-stmt-attr-int-internal + (statement-handle-handle stmt-handle) attribute value)) (import-lambda-definition odbc-sql-set-stmt-attr-int-internal (stmt-handle attribute value) "odbc_sql_set_stmt_attr_int") (define (odbc-sql-set-stmt-attr-string stmt-handle attribute value) - (check-arg statement-handle? stmt-handle odbc-sql-set-stmt-attr-string) - (odbc-sql-set-stmt-attr-string-internal (statement-handle-handle stmt-handle) - attribute value)) + (odbc-sql-set-stmt-attr-string-internal + (statement-handle-handle stmt-handle) attribute value)) (import-lambda-definition odbc-sql-set-stmt-attr-string-internal (stmt-handle attribute value) "odbc_sql_set_stmt_attr_string") (define (odbc-sql-get-stmt-attr-int stmt-handle attribute) - (check-arg statement-handle? stmt-handle odbc-sql-get-stmt-attr-int) - (odbc-sql-get-stmt-attr-int-internal (statement-handle-handle stmt-handle) - attribute)) + (apply values + (odbc-sql-get-stmt-attr-int-internal + (statement-handle-handle stmt-handle) attribute))) (import-lambda-definition odbc-sql-get-stmt-attr-int-internal (stmt-handle attribute) "odbc_sql_get_stmt_attr_int") (define (odbc-sql-get-stmt-attr-string stmt-handle attribute) - (check-arg statement-handle? stmt-handle odbc-sql-get-stmt-attr-string) - (odbc-sql-get-stmt-attr-string-internal (statement-handle-handle stmt-handle) - attribute)) + (apply values + (odbc-sql-get-stmt-attr-string-internal + (statement-handle-handle stmt-handle) attribute))) (import-lambda-definition odbc-sql-get-stmt-attr-string-internal (stmt-handle attribute) @@ -685,18 +771,18 @@ ;;; PART 4 (define (odbc-sql-get-desc-field-int desc-handle record-number field-id) - (check-arg descriptor-handle? desc-handle odbc-sql-get-desc-field-int) - (odbc-sql-get-desc-field-int-internal (descriptor-handle-handle desc-handle) - record-number field-id)) + (apply values + (odbc-sql-get-desc-field-int-internal + (descriptor-handle-handle desc-handle) record-number field-id))) (import-lambda-definition odbc-sql-get-desc-field-int-internal (desc-handle record-number field-id) "odbc_sql_get_desc_field_int") (define (odbc-sql-get-desc-field-string desc-handle record-number field-id) - (check-arg descriptor-handle? desc-handle odbc-sql-get-desc-field-string) - (odbc-sql-get-desc-field-string-internal (descriptor-handle-handle desc-handle) - record-number field-id)) + (apply values + (odbc-sql-get-desc-field-string-internal + (descriptor-handle-handle desc-handle) record-number field-id))) (import-lambda-definition odbc-sql-get-desc-field-string-internal (desc-handle record-number field-id) @@ -705,34 +791,25 @@ ;;; PART 5 (define (odbc-sql-prepare stmt-handle stmt-txt) - (check-arg statement-handle? stmt-handle odbc-sql-prepare) - (odbc-sql-prepare-internal (statement-handle-handle stmt-handle) - stmt-txt)) + (odbc-sql-prepare-internal + (statement-handle-handle stmt-handle) stmt-txt)) (import-lambda-definition odbc-sql-prepare-internal (stmt-handle stmt-txt) "odbc_sql_prepare") -(define (odbc-sql-bind-parameter-exec-out stmt-handle param-vals) - (check-arg statement-handle? stmt-handle odbc-sql-bind-parameter-exec-out) - (odbc-sql-bind-parameter-exec-out-internal (statement-handle-handle stmt-handle) - param-vals)) - -(import-lambda-definition odbc-sql-bind-parameter-exec-out-internal - (stmt-handle param-vals) - "odbc_sql_bind_parameter_exec_out") - (define (odbc-sql-get-cursor-name stmt-handle) - (check-arg statement-handle? stmt-handle odbc-sql-get-cursor-name) - (odbc-sql-get-cursor-name-internal (statement-handle-handle stmt-handle))) + (apply values + (odbc-sql-get-cursor-name-internal + (statement-handle-handle stmt-handle)))) (import-lambda-definition odbc-sql-get-cursor-name-internal (stmt-handle) "odbc_sql_get_cursor_name") (define (odbc-sql-set-cursor-name stmt-handle cursor-name) - (check-arg statement-handle? stmt-handle odbc-sql-set-cursor-name) - (odbc-sql-set-cursor-name-internal (statement-handle-handle stmt-handle) cursor-name)) + (odbc-sql-set-cursor-name-internal + (statement-handle-handle stmt-handle) cursor-name)) (import-lambda-definition odbc-sql-set-cursor-name-internal (stmt-handle cursor-name) @@ -741,7 +818,6 @@ ;;; PART 6 (define (odbc-sql-execute stmt-handle) - (check-arg statement-handle? stmt-handle odbc-sql-execute) (odbc-sql-execute-internal (statement-handle-handle stmt-handle))) (import-lambda-definition odbc-sql-execute-internal @@ -749,35 +825,35 @@ "odbc_sql_execute") (define (odbc-sql-execute-direct stmt-handle stmt-txt) - (check-arg statement-handle? stmt-handle odbc-sql-execute-direct) - (odbc-sql-execute-direct-internal (statement-handle-handle stmt-handle) - stmt-txt)) + (odbc-sql-execute-direct-internal + (statement-handle-handle stmt-handle) stmt-txt)) (import-lambda-definition odbc-sql-execute-direct-internal (stmt-handle stmt-txt) "odbc_sql_execute_direct") (define (odbc-sql-native-sql conn-handle stmt-txt) - (check-arg connection-handle? conn-handle odbc-sql-native-sql) - (odbc-sql-native-sql-internal (connection-handle-handle conn-handle) - stmt-txt)) + (apply values + (odbc-sql-native-sql-internal + (connection-handle-handle conn-handle) stmt-txt))) (import-lambda-definition odbc-sql-native-sql-internal (conn-handle stmt-txt) "odbc_sql_native_sql") (define (odbc-sql-describe-param stmt-handle parameter-no) - (check-arg statement-handle? stmt-handle odbc-sql-describe-param) - (odbc-sql-describe-param-internal (statement-handle-handle stmt-handle) - parameter-no)) + (apply values + (odbc-sql-describe-param-internal + (statement-handle-handle stmt-handle) parameter-no))) (import-lambda-definition odbc-sql-describe-param-internal (stmt-handle parameter-no) "odbc_sql_describe_param") (define (odbc-sql-num-params stmt-handle) - (check-arg statement-handle? stmt-handle odbc-sql-num-params) - (odbc-sql-num-params-internal (statement-handle-handle stmt-handle))) + (apply values + (odbc-sql-num-params-internal + (statement-handle-handle stmt-handle)))) (import-lambda-definition odbc-sql-num-params-internal (stmt-handle) @@ -786,51 +862,49 @@ ;;; PART 7 (define (odbc-sql-row-count stmt-handle) - (check-arg statement-handle? stmt-handle odbc-sql-row-count) - (odbc-sql-row-count-internal (statement-handle-handle stmt-handle))) + (apply values + (odbc-sql-row-count-internal + (statement-handle-handle stmt-handle)))) (import-lambda-definition odbc-sql-row-count-internal (stmt-handle) "odbc_sql_row_count") -(define (odbc-sql-get-data stmt-handle column-number target-type buffer-size) - (check-arg statement-handle? stmt-handle odbc-sql-get-data) +(define (odbc-sql-get-data stmt-handle column-number target-type) (odbc-sql-get-data-internal (statement-handle-handle stmt-handle) column-number target-type)) (import-lambda-definition odbc-sql-get-data-internal - (stmt-handle column-number target-type buffer-size) + (stmt-handle column-number target-type) "odbc_sql_get_data") (define (odbc-sql-set-pos stmt-handle row-number operation lock-type) - (check-arg statement-handle? stmt-handle odbc-sql-set-pos) - (odbc-sql-set-pos-internal (statement-handle-handle stmt-handle) - row-number operation lock-type)) + (odbc-sql-set-pos-internal + (statement-handle-handle stmt-handle) row-number operation lock-type)) (import-lambda-definition odbc-sql-set-pos-internal (stmt-handle row-number operation lock-type) "odbc_sql_set_pos") (define (odbc-sql-bulk-operations stmt-handle operation) - (check-arg statement-handle? stmt-handle odbc-sql-bulk-operations) - (odbc-sql-bulk-operations-internal (statement-handle-handle stmt-handle) - operation)) + (odbc-sql-bulk-operations-internal + (statement-handle-handle stmt-handle) operation)) (import-lambda-definition odbc-sql-bulk-operations-internal (stmt-handle operation) "odbc_sql_bulk_operations") (define (odbc-sql-more-results stmt-handle) - (check-arg statement-handle? stmt-handle odbc-sql-more-results) - (odbc-sql-more-results-internal (statement-handle-handle stmt-handle))) + (odbc-sql-more-results-internal + (statement-handle-handle stmt-handle))) (import-lambda-definition odbc-sql-more-results-internal (stmt-handle) "odbc_sql_more_results") (define (odbc-sql-fetch stmt-handle) - (check-arg statement-handle-handle stmt-handle odbc-sql-fetch) - (odbc-sql-fetch-internal (statement-handle-handle stmt-handle))) + (odbc-sql-fetch-internal + (statement-handle-handle stmt-handle))) (import-lambda-definition odbc-sql-fetch-internal (stmt-handle) @@ -942,7 +1016,7 @@ (stmt-handle catalog-name schema-name table-type table-type) "odbc_sql_tables") -;;; part 9 +;;; PART 9 (define (odbc-sql-free-statement stmt-handle option) (check-arg statement-handle? stmt-handle odbc-sql-free-statement) @@ -1029,6 +1103,14 @@ (handle-type handle) "odbc_sql_get_diag_recs") +(import-lambda-definition odbc-set-initial-retval-buffer-size + (no-bytes) + "odbc_set_initial_retval_buffer_size") + +(import-lambda-definition odbc-get-initial-retval-buffer-size + () + "odbc_get_intial_retval_buffer_size") + ;;; misc stuff (define (odbc-call-successful? odbc-return-value) (or (equal? odbc-return-value sql-success) diff --git a/scsh/odbc/odbc.tex b/scsh/odbc/odbc.tex index 3733640..df21eb9 100644 --- a/scsh/odbc/odbc.tex +++ b/scsh/odbc/odbc.tex @@ -26,8 +26,8 @@ their own drivers. The \textit{Data Source Name}, DSN for short, associates credentials needed to logon a certain database with a the apropriate driver to access that database. If an application wishes to connect to a DSN -the driver manager loads the ##angegeben## driver and routes all -functions call by the application via this driver to the database. +the driver manager loads the specified driver and routes all functions +call by the application via this driver to the database. The are at least two implementation of ODBC driver managers for UNIX systems: unixODBC~\cite{BlaBla} and iODBC~\cite{BlaBla}. The Scheme @@ -37,8 +37,8 @@ during compilation of scsh which one to use. Support for ODBC at this time is quite low-level---for alsmost each function or data structure in the ODBC API there is a function call in Scheme. This chapter describes how to call the API functions from -Scheme, but does not cover the ##funktionsweise## of the underlying -ODBC function call in detail. Microsoft's ODBC API reference +Scheme, but does not cover the functionality of the underlying ODBC +function call in detail. Microsoft's ODBC API reference manual~\cite{BlaBla} explains all API functions in great detail. \section{ODBC Data Types}