diff --git a/scheme/odbc-interfaces.scm b/scheme/odbc-interfaces.scm new file mode 100644 index 0000000..a577c5a --- /dev/null +++ b/scheme/odbc-interfaces.scm @@ -0,0 +1,1438 @@ +(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 + + odbc-diag-sql-state + odbc-diag-native-error + odbc-diag-message + + ;;; 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-bindcol + + 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/scheme/odbc-packages.scm b/scheme/odbc-packages.scm new file mode 100644 index 0000000..6fc9cda --- /dev/null +++ b/scheme/odbc-packages.scm @@ -0,0 +1,12 @@ +(define-structure low-odbc low-odbc-interface + (open + scheme external-calls scsh-utilities + srfi-1 define-record-types + conditions signals + low-odbc-constants) + (files odbc)) + +(define-structure low-odbc-constants low-odbc-constants-interface + (open scheme) + (files + odbc-constants)) diff --git a/scheme/odbc-types.scm b/scheme/odbc-types.scm new file mode 100644 index 0000000..18c62f2 --- /dev/null +++ b/scheme/odbc-types.scm @@ -0,0 +1,70 @@ +(define-record-type sql-date :sql-date + (make-sql-date year month day) + sql-date? + (year sql-date-year) + (month sql-date-month) + (day sql-date-day)) + +(define-record-discloser :sql-date + (lambda (rec) + `(sql-date year ,(sql-date-year rec) + month ,(sql-date-month rec) + day ,(sql-date-day rec)))) + +(define-exported-binding "sql-date-record-type" :sql-date) + +(define-record-type sql-time :sql-time + (make-sql-time hour minute second) + sql-time? + (hour sql-time-hour) + (minute sql-time-minute) + (second sql-time-second)) + +(define-record-discloser :sql-time + (lambda (rec) + `(sql-time hour ,(sql-time-hour rec) + minute ,(sql-time-minute rec) + second ,(sql-time-second rec)))) + +(define-exported-binding "sql-time-record-type" :sql-time) + +(define-record-type sql-timestamp :sql-timestamp + (make-sql-timestamp year month day hour minute second fraction) + sql-timestamp? + (year sql-timestamp-year) + (month sql-timestamp-month) + (day sql-timestamp-day) + (hour sql-timestamp-hour) + (minute sql-timestamp-minute) + (second sql-timestamp-second) + (fraction sql-timestamp-fraction)) + +(define-record-discloser :sql-timestamp + (lambda (rec) + `(sql-timestamp year ,(sql-timestamp-year rec) + month ,(sql-timestamp-month rec) + day ,(sql-timestamp-day rec) + hour ,(sql-timestamp-hour rec) + minute ,(sql-timestamp-minute rec) + second ,(sql-timestamp-second rec) + fraction ,(sql-timestamp-fraction rec)))) + +(define-exported-binding "sql-timestamp-record-type" :sql-timestamp) + +(define-record-type sql-numeric :sql-numeric + (make-sql-numeric precision scale sign value) + sql-numeric? + (precision sql-numeric-precision) + (scale sql-numeric-scale) + (sign sql-numeric-sign) + (value sql-numeric-value)) + +(define-record-discloser :sql-numeric + (lambda (rec) + `(sql-numeric precision ,(sql-numeric-precision rec) + scale ,(sql-numeric-scale rec) + sign ,(sql-numeric-sign rec) + value ,(sql-numeric-value rec)))) + +(define-exported-binding "sql-numeric" :sql-numeric) + diff --git a/scheme/odbc.scm b/scheme/odbc.scm new file mode 100644 index 0000000..9afe854 --- /dev/null +++ b/scheme/odbc.scm @@ -0,0 +1,1286 @@ + +;;; ODBC handle types +(define-record-type environment-handle :environment-handle + (really-make-environment-handle handle) + environment-handle? + (handle environment-handle-handle)) + +(define-exported-binding "environment-handle" :environment-handle) + +(define-record-type connection-handle :connection-handle + (really-make-connection-handle handle environment connected?) + connection-handle? + (handle connection-handle-handle) + (environment connection-handle-environment) + (connected? connection-handle-connected? set-connection-handle-connected?!)) + +(define-exported-binding "connection-handle" :connection-handle) + +(define-record-type statement-handle :statement-handle + (really-make-statement-handle handle connection parameter-bindings) + statement-handle? + (handle statement-handle-handle) + (connection statement-handle-connection) + (parameter-bindings statement-handle-parameter-bindings + set-statement-handle-parameter-bindings!)) + +(define-exported-binding "statement-handle" :statement-handle) + +(define-record-type descriptor-handle :descriptor-handle + (really-make-descriptor-handle handle) + descriptor-handle? + (handle descriptor-handle-handle)) + +(define-exported-binding "descriptor-handle" :descriptor-handle) + +; record type to store infos from SQLGetDiagRec() +(define-record-type odbc-diag :odbc-diag + (really-make-odbc-diag-rec sql-state native-error message) + odbc-diag? + (sql-state odbc-diag-sql-state) + (native-error odbc-diag-native-error) + (message odbc-diag-message)) + +(define-exported-binding "odbc-diag" :odbc-diag) + +(define (odbc-handle? thing) + (or (environment-handle? thing) + (connection-handle? thing) + (statement-handle? thing) + (descriptor-handle? thing))) + +(define (odbc-handle handle) + (cond + ((environment-handle? handle) (environment-handle-handle handle)) + ((connection-handle? handle) (connection-handle-handle handle)) + ((statement-handle? handle) (statement-handle-handle handle)) + ((descriptor-handle? handle) (descriptor-handle-handle handle)) + (else + (error "Expected odbc-handle, got " handle odbc-handle)))) + +;;; map a record to a handle type identifier (see sql.h) +(define (handle-record-type->c-handle-identifier record) + (cond ((environment-handle? record) 1) ; SQL_HANDLE_ENV + ((connection-handle? record) 2) ; SQL_HANDLE_DBC + ((statement-handle? record) 3) ; SQL_HANDLE_STMT + (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-condition-type 'odbc-bind-parameter-rebinding-error '(odbc-error)) + +(define odbc-bind-parameter-rebinding-error? + (condition-predicate 'odbc-bind-parameter-rebinding-error)) + +(define (raise-odbc-bind-parameter-rebinding-error + stmt-handle parameter-no this-rebind-order-no current-rebind-order-no) + (apply signal 'odbc-bind-parameter-rebinding-error + 'stmt-handle stmt-handle 'parameter-no parameter-no + 'this-rebind-order-no this-rebind-order-no + 'current-rebind-order-no current-rebind-order-no)) + +;;; +(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?)) + +(define-exported-binding "odbc-column" :odbc-column) + +;;; parameter descriptions (returned by SQLDescribeParams()) +(define-record-type odbc-parameter :odbc-parameter + (really-make-odbc-parameter type size digits nullable) + odbc-parameter? + (type odbc-parameter-type) + (size odbc-parameter-size) + (digits odbc-parameter-digits) + (nullable odbc-parameter-nullable)) + +(define-exported-binding "odbc-parameter" :odbc-parameter) + +;;; parameter bind (for usage with SQLBindParameter()) +(define-record-type odbc-bind-parameter :odbc-bind-parameter + (really-make-odbc-bind-parameter + statement-handle parameter-no input-output-type value-type parameter-type + column-size decimal-digits parameter-value-input-ptr parameter-value-output-ptr + buffer-length rebind-order-no) + odbc-bind-parameter? + (statement-handle odbc-bind-parameter-statement-handle) + (parameter-no odbc-bind-parameter-parameter-no) + (input-output-type odbc-bind-parameter-input-output-type) + (value-type odbc-bind-parameter-value-type) + (parameter-type odbc-bind-parameter-parameter-type) + (column-size odbc-bind-parameter-column-size) + (decimal-digits odbc-bind-parameter-decimal-digits) + (parameter-value-input-ptr odbc-bind-parameter-parameter-value-input-ptr) + (parameter-value-output-ptr odbc-bind-parameter-parameter-value-output-ptr) + (buffer-length odbc-bind-parameter-buffer-length) + (rebind-order-no odbc-bind-parameter-rebind-order-no + set-odbc-bind-parameter-rebind-order-no!)) + +;;; options for SQLFreeStmt from sql.h +(define sql-disconnect-opt-close 0) +(define sql-disconnect-opt-drop 1) +(define sql-disconnect-opt-unbind 2) +(define sql-disconnect-opt-reset-params 3) + +;;; options for SQLDataSource from sql.h +(define sql-datasources-fetch-next 1) +(define sql-datasources-fetch-first 2) + +;;; C type identifier +(define sql-type-c-char 1) ; SQL_C_CHAR +(define sql-type-c-long 4) ; SQL_C_LONG +(define sql-type-c-short 5) ; SQL_C_SHORT +(define sql-type-c-float 7) ; SQL_C_FLOAT +(define sql-type-c-double 8) ; SQL_C_DOUBLE +(define sql-type-c-numeric 2) ; SQL_C_NUMERIC +(define sql-type-c-default 99) ; SQL_C_DEFAULT (not mentioned in Appendix D?!?!?) +(define sql-type-c-date 9) ; SQL_C_DATE +(define sql-type-c-time 10) ; SQL_C_TIME +(define sql-type-c-timestamp 11) ; SQL_C_TIMESTAMP +(define sql-type-c-binary -2) ; SQL_C_BINARY +(define sql-type-c-bit -7) ; SQL_C_BIT +; missing: all the SQL_C_INTERVAL* stuff + +;;; ODBC type identifier +(define sql-type-unknown 0) ; SQL_UNKNOWN_TYPE +(define sql-type-char 1) ; SQL_CHAR +(define sql-type-numeric 2) ; SQL_NUMERIC +(define sql-type-decimal 3) ; SQL_DECIMAL +(define sql-type-integer 4) ; SQL_INTEGER +(define sql-type-smallint 5) ; SQL_SMALLINT +(define sql-type-float 6) ; SQL_FLOAT +(define sql-type-real 7) ; SQL_REAL +(define sql-type-double 8) ; SQL_DOUBLE +(define sql-type-datetime 9) ; SQL_DATETIME +(define sql-type-varchar 12) ; SQL_VARCHAR +(define sql-type-date 91) ; SQL_TYPE_DATE +(define sql-type-time 92) ; SQL_TYPE_TIME +(define sql-type-timestamp 93) ; SQL_TYPE_TIMESTAMP + +(define (c-type-identifier->odbc-type-identifier c-type) + (error "Not yet implemented")) + +(define (odbc-type-identifier->c-type-identifier odbc-type) + (cond ((member odbc-type '(sql-type-char sql-type-varchar)) + sql-type-c-char) + ((member odbc-type '(sql-type-real sql-type-float sql-type-double)) + sql-type-c-double) + ((equal? odbc-type sql-type-numeric) + sql-type-c-numeric) + ((equal? odbc-type sql-type-decimal) + (error "Can't handle type SQL_DECIMAL yet")) + ((equal? odbc-type sql-type-integer) + sql-type-c-long) +; ((equal? odbc-type sql-type-smallint) +; sql-type-c-smallint) + ((equal? odbc-type sql-type-datetime) + (error "Can't handle type SQL_DATETIME yet")) + ((equal? odbc-type sql-type-date) + (error "Can't handle type SQL_TYPE_DATE yet")) + ((equal? odbc-type sql-type-time) + (error "Can't handle type SQL_TYPE_TIME yet")) + ((equal? odbc-type sql-type-timestamp) + (error "Can't handle type SQL_TYPE_TIMESTAMP yet")) + ((equal? odbc-type sql-type-unknown) + (error "Can't handle type SQL_UNKNOWN_TYPE")) + (else + (error "unknown SQL type")))) + +;;; ODBC function ids for SQLGetFunctions +(define sql-api-sqlallocconnect 1) +(define sql-api-sqlallocenv 2) +(define sql-api-sqlallochandle 1001) +(define sql-api-sqlallocstmt 3) +(define sql-api-sqlbindcol 4) +(define sql-api-sqlbinparam 1002) +(define sql-api-sqlcancel 5) +(define sql-api-sqlclosecursor 1003) +(define sql-api-sqlcolattribute 6) +(define sql-api-sqlcolumns 40) +(define sql-api-sqlconnect 7) +(define sql-api-sqlcopydesc 1004) +(define sql-api-sqldatasources 57) +(define sql-api-sqldescribecol 8) +(define sql-api-sqldisconnect 9) +(define sql-api-sqlendtran 1005) +(define sql-api-sqlerror 10) +(define sql-api-sqlexecdirect 11) +(define sql-api-sqlexecute 12) +(define sql-api-sqlfetch 13) +(define sql-api-sqlfetchscroll 1021) +(define sql-api-sqlfreeconnect 14) +(define sql-api-sqlfreeenv 15) +(define sql-api-sqlfreehandle 1006) +(define sql-api-sqlfreestmt 16) +(define sql-api-sqlgetconnectattr 1007) +(define sql-api-sqlgetconenctoption 42) +(define sql-api-sqlgetcursorname 17) +(define sql-api-sqlgetdata 43) +(define sql-api-sqlgetdescfield 1008) +(define sql-api-sqlgetdescrec 1009) +(define sql-api-sqlgetdiagfield 1010) +(define sql-api-sqlgetdiagrec 1011) +(define sql-api-sqlgetenvattr 1012) +(define sql-api-sqlgetfunctions 44) +(define sql-api-sqlgetinfo 45) +(define sql-api-sqlgetstmtattr 1014) +(define sql-api-sqlgetstmtoption 46) +(define sql-api-sqlgettypeinfo 47) +(define sql-api-sqlnumresultcols 18) +(define sql-api-sqlparamdata 48) +(define sql-api-sqlprepare 19) +(define sql-api-sqlputdata 49) +(define sql-api-sqlrowcount 20) +(define sql-api-sqlsetconnectattr 1016) +(define sql-api-sqlsetconnectoption 50) +(define sql-api-sqlsetcursorname 21) +(define sql-api-sqlsetdescfield 1017) +(define sql-api-sqlsetdescrec 1018) +(define sql-api-sqlsetenvattr 1019) +(define sql-api-sqlsetparam 22) +(define sql-api-sqlsetstmtattr 1020) +(define sql-api-sqlsetstmtoption 51) +(define sql-api-sqlspecialcolumns 52) +(define sql-api-sqlstatistics 53) +(define sql-api-sqltables 54) +(define sql-api-transact 23) + +;;; additional function identifiers +(define sql-api-sqlallochandlestd 73) +(define sql-api-sqlbulkoperations 24) +(define sql-api-sqlbindparameter 72) +(define sql-api-sqlbrowseconnect 55) +(define sql-api-sqlcolattributes 6) +(define sql-api-sqlcolumnprivileges 56) +(define sql-api-sqldescribeparam 58) +(define sql-api-sqldriverconnect 41) +(define sql-api-sqldrivers 71) +(define sql-api-sqlextendedfetch 59) +(define sql-api-sqlforeignkeys 60) +(define sql-api-sqlmoreresults 61) +(define sql-api-sqlnativesql 62) +(define sql-api-sqlnumparams 63) +(define sql-api-sqlparamoptions 64) +(define sql-api-sqlprimarykeys 65) +(define sql-api-sqlprocedurecolumns 66) +(define sql-api-sqlprcoedures 67) +(define sql-api-sqlsetpos 68) +(define sql-api-sqlsetscrolloptions 69) +(define sql-api-sqltableprivileges 70) + +;;; info keys for odbc-sql-get-info-arg-int/string +; ODBC 1.0, returns integer +(define sql-get-info-arg-maxdriverconnections 0) +; ODBC 1.0, returns integer +(define sql-get-info-arg-maxconcurrentactivities 1) +; ODBC 1.0, returns string +(define sql-get-info-arg-datasourcename 2) +; deprecated in ODBC 3.x returns ? +(define sql-get-info-arg-fetchdirection 8) +; ODBC 1.0, returns string +(define sql-get-info-arg-servername 13) +; ODBC 1.0, returns string +(define sql-get-info-arg-searchpatternescape 14) +; ODBC 1.0, returns string +(define sql-get-info-arg-dbmsname 17) +; ODBC 1.0, returns string +(define sql-get-info-arg-dbmsver 18) +; ODBC 1.0, returns string +(define sql-get-info-arg-accessibletables 19) +; ODBC 1.0, returns string +(define sql-get-info-arg-accessibaleprocedures 20) +; ODBC 1.0, returns integer +(define sql-get-info-arg-cursor-commit-behaviour 23) +; ODBC 1.0, returns string +(define sql-get-info-arg-datasourcereadonly 25) +; ODBC 1.0, returns integer +(define sql-get-info-arg-defaulttxnisolation 26) +; ODBC 1.0, returns integer +(define sql-get-info-arg-identifiercase 28) +; ODBC 1.0, returns string +(define sql-get-info-arg-identifierquotechar 29) +; ODBC 1.0 returns integer +(define sql-get-info-arg-maxcolumnnamelen 30) +(define sql-get-info-arg-maximumcolumnnamelen 30) +; ODBC 1.0 returns integer +(define sql-get-info-arg-maxcursornamelen 31) +(define sql-get-info-arg-maximumcursornamelen 31) +; ODBC 1.0 returns integer +(define sql-get-info-arg-maxschemanamelen 32) +(define sql-get-info-arg-maximumschemenamelen 32) +; ODBC 1.0 returns integer +(define sql-get-info-arg-maxcatalognamelen 34) +(define sql-get-info-arg-maximumcatalognamelen 34) +; ODBC 1.0 returns integer +(define sql-get-info-arg-maxtablenamelen 35) +; defined in sql.h, but no reference in ODBC manual +; (define sql-get-info-arg--scrollconcurrency 43) +; ODBC 1.0 returns integer +(define sql-get-info-arg-txncapable 46) +(define sql-get-info-arg-transaction-capable 46) +; ODBC 1.0 returns string +(define sql-get-info-arg-username 47) +; ODBC 1.0 returns integer +(define sql-get-info-arg-txnisolationoption 72) +(define sql-get-info-arg-transcationisolationoption 72) +; ODBC 1.0 returns string +(define sql-get-info-arg-integrity 73) +; ODBC 2.0 returns integer +(define sql-get-info-arg-getdataextensions 81) +; ODBC 2.0 returns integer +(define sql-get-info-arg-nullcollation 85) +; ODBC 2.0 returns integer +(define sql-get-info-arg-altertable 86) +; ODBC 2.0 returns string +(define sql-get-info-arg-specialcharacters 94) +; ODBC 2.0 returns integer +(define sql-get-info-arg-maxcolumnsingroupby 97) +(define sql-get-info-arg-maximumcolumnsingroupby 97) +; ODBC 2.0 returns integer +(define sql-get-info-arg-maxcolumnsinindex 98) +(define sql-get-info-arg-maximumcolumnsinindex 98) +; ODBC 2.0 returns integer +(define sql-get-info-arg-maxcolumnsinorderby 99) +(define sql-get-info-arg-maximumcolumnsinorderby 99) +; ODBC 2.0 returns integer +(define sql-get-info-arg-maxcolumnsinselect 100) +(define sql-get-info-arg-maximumcolumnsinselect 100) +; ODBC 2.0 returns integer +(define sql-get-info-arg-maxcolumnsintable 101) +; ODBC 2.0 returns integer +(define sql-get-info-arg-maxindexsize 102) +(define sql-get-info-arg-maximumindexsize 102) +; ODBC 2.0 returns integer +(define sql-get-info-arg-maxrowsize 104) +(define sql-get-info-arg-maximumrowsize 104) +; ODBC 2.0 returns integer +(define sql-get-info-arg-maxstatementlen 105) +(define sql-get-info-arg-maximumstatemenlen 105) +; ODBC 2.0 returns integer +(define sql-get-info-arg-maxtablesinselect 106) +(define sql-get-info-arg-maximumtablesinselect 106) +; ODBC 2.0 returns integer +(define sql-get-info-arg-maxusernamelen 107) +(define sql-get-info-arg-maximumusernamelen 107) +; ODBC 2.01 returns integer +(define sql-get-info-arg-ojcapabilities 115) +(define sql-get-info-arg-outerjoincapabilities 115) + +; ODBC return values for SQLGetInfo sql-get-info-arg-identifiercase (SQL_IDENTIFIER_CASE) +(define sql-ic-upper 1) +(define sql-ic-lower 2) +(define sql-ic-sensitive 3) +(define sql-ic-mixed 4) + +; ODBC return values for SQLGetInfo sql-get-info-arg-defaulttxnisolation (SQL_DEFAULT_TXN_ISOLATION) +(define sql-txn-read-uncommited #x00000001) +(define sql-txn-read-committed #x00000002) +(define sql-txn-repeatable-read #x00000004) +(define sql-txn-serializable #x00000008) + +; ODBC return values for SQLGetInfo sql-get-info-arg-txncapable (SQL_TXN_CAPABLE) +(define sql-tc-none 0) +(define sql-tc-dml 1) +(define sql-tc-all 2) +(define sql-tc-ddl-commit 3) +(define sql-tc-ddl-ignore 4) + +; ODBC return values for SQLGetInfo sql-get-info-arg-getdataextensions (SQL_GETDATA_EXTENSIONS) +(define sql-gd-any-column #x00000001) +(define sql-gd-any-order #x00000002) +(define sql-gd-block #x00000004) +(define sql-gd-bound #x00000008) + +; ODBC return values for SQLGetInfo sql-get-info-arg-nullcollation (SQL_NULL_COLLATION) +(define sql-nc-end #x0004) +(define sql-nc-start #x0002) +; missing sql-nc-high sql-nc-low + +; ODBC return values for SQLGetInfo sql-get-info-arg-altertable (SQL_ALTER_TABLE) +(define sql-at-add-colum #x00000001) +(define sql-at-drop-column #x00000002) +(define sql-at-add-constraint #x00000008) +(define sql-at-add-column-single #x00000020) +(define sql-at-add-column-default #x00000040) +(define sql-at-add-column-collation #x00000080) +(define sql-at-set-column-default #x00000100) +(define sql-at-drop-column-default #x00000200) +(define sql-at-drop-column-cascade #x00000400) +(define sql-at-drop-column-restrict #x00000800) +(define sql-at-drop-table-constraint #x00001000) +(define sql-at-drop-table-constraint-cascade #x00002000) +(define sql-at-drop-table-constraint-restrict #x00004000) +(define sql-at-constraint-name-definition #x00008000) +(define sql-at-constraint-initially-deferred #x00010000) +(define sql-at-constraint-initially-immediate #x00020000) +(define sql-at-constraint-deferrable #x00040000) +(define sql-at-constraint-non-deferrable #x00080000) + +; ODBC return values for SQLGetInfo sql-get-info-arg-ojcapabilities (SQL_OJ_CAPABILITIES) +(define sql-oj-left #x00000001) +(define sql-oj-right #x00000002) +(define sql-oj-full #x00000004) +(define sql-oj-nested #x00000008) +(define sql-oj-not-ordered #x00000010) +(define sql-oj-inner #x00000020) +(define sql-oj-all-comparison-ops #x00000040) + +; ODBC data types for use with odbc_sql_get_type_info +(define sql-datatype-unknown 0) +(define sql-datatype-char 1) +(define sql-datatype-numeric 2) +(define sql-datatype-decimal 3) +(define sql-datatype-integer 4) +(define sql-datatype-smallint 5) +(define sql-datatype-float 6) +(define sql-datatype-real 7) +(define sql-datatype-double 8) +(define sql-datatype-datetime 9) +(define sql-datatype-interval 10) +(define sql-datatype-varchar 12) +(define sql-datatype-date 91) +(define sql-datatype-time 92) +(define sql-datatype-timestamp 93) + +; possible identifier-type arguments for SQLSpecialColumns() (odbc-sql-special-columns) +(define sql-best-rowid 1) +(define sql-rowver 2) + +; possible scope arguments for SQLSpecialColumns() (odbc-sql-special-columns) +(define sql-scope-currow 0) +(define sql-scope-transaction 1) +(define sql-scope-session 2) + +; possible nullable arguments for SQLSpecialColumns() (odbc-sql-special-columns) +(define sql-no-nulls 0) +(define sql-nullable 1) + +; possible unique arguments for SQLStatistics() (odbc-sql-statistics) +(define sql-index-unique 0) +(define sql-index-all 1) + +; possible reserved arguments for SQLStatistics() (odbc-sql-statistics) +(define sql-ensure 1) +(define sql-quick 0) + +; possible operation arguments for SQLSetPos() (odbc-sql-set-pos) +(define sql-position 0) +(define sql-refresh 1) +(define sql-update 2) +(define sql-delete 3) + +; possible lock-type arguments for SQLSetPos() (odbc-sql-set-pos) +(define sql-lock-no-change 0) +(define sql-lock-exclusive 1) +(define sql-lock-unlock 2) + +; possible operation arguments for SQLBulkOperations() (odbc-sql-bulk-operations) +(define sql-add 4) +(define sql-update-by-bookmark 5) +(define sql-delete-by-bookmark 6) +(define sql-fetch-by-bookmark 7) + +;;; ODBC return values +(define sql-error -1) +(define sql-success 0) +(define sql-success-with-info 1) +(define sql-no-data 100) +(define sql-invalid-handle -2) +(define sql-need-data 99) + +;;; PART 1 + +(define (odbc-alloc-environment-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) + (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-connection-handle value env-handle #f))) + (add-finalizer! conn-handle free-connection-handle) + (values status conn-handle)) + (values status value)))) + +(import-lambda-definition odbc-alloc-connection-handle-internal + (env-handle) + "odbc_alloc_connection_handle") + +;;; maybe we should raise a warning like "implicit connect" here? +(define (free-connection-handle conn-handle) + (if (connection-handle-connected? conn-handle) + (odbc-sql-disconnect conn-handle)) + (odbc-sql-free-handle conn-handle)) + +(define (odbc-alloc-statement-handle conn-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 conn-handle '()))) + (add-finalizer! stmt-handle free-statement-handle) + (values status stmt-handle)) + (values status value)))) + +;;; FIXME: free parameter-bindings, dealloc buffers +(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") + +(import-lambda-definition bindcol-finalize-bindcols + (stmt-handle) + "bindcol_finalize_bindcols") + +;;; returns odbc-return-value +(define (odbc-sql-connect conn-handle server-name user-name auth) + (let ((return-value (odbc-sql-connect-internal + (connection-handle-handle conn-handle) + server-name user-name auth))) + (if (odbc-call-successful? return-value) + (set-connection-handle-connected?! conn-handle #t)) + return-value)) + +(import-lambda-definition odbc-sql-connect-internal + (conn-handle server-name user-name auth) + "odbc_sql_connect") + +(define (odbc-sql-browse-connect 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") + +;;; PART 2 + +(define (odbc-sql-data-sources 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) + (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) + (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) + (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) + (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) + (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) + "odbc_sql_get_type_info") + +;;; PART 3 + +(define (odbc-sql-set-connect-attr-int conn-handle attribute value pass-by-reference?) + (odbc-sql-set-connect-attr-int-internal + (connection-handle-handle conn-handle) attribute value pass-by-reference?)) + +(import-lambda-definition odbc-sql-set-connect-attr-int-internal + (conn-handle attribute value pass-by-reference?) + "odbc_sql_set_connect_attr_int") + +(define (odbc-sql-set-connect-attr-string 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) + (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) + (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 pass-by-reference?) + (odbc-sql-set-env-attr-int-internal + (environment-handle-handle env-handle) attribute value pass-by-reference?)) + +(import-lambda-definition odbc-sql-set-env-attr-int-internal + (env-handle attribute value pass-by-reference?) + "odbc_sql_set_env_attr_int") + +(define (odbc-sql-get-env-attr-int 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 pass-by-reference?) + (odbc-sql-set-stmt-attr-int-internal + (statement-handle-handle stmt-handle) attribute value pass-by-reference?)) + +(import-lambda-definition odbc-sql-set-stmt-attr-int-internal + (stmt-handle attribute value pass-by-reference?) + "odbc_sql_set_stmt_attr_int") + +(define (odbc-sql-set-stmt-attr-string 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) + (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) + (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) + "odbc_sql_get_stmt_attr_string") + +;;; PART 4 + +(define (odbc-sql-get-desc-field-int 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) + (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) + "odbc_sql_get_desc_field_string") + +;;; PART 5 + +(define (odbc-sql-prepare 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 (find-bind-parameter stmt-handle parameter-no) + (fold-right + (lambda (bind-parameter res) + (if (= (odbc-bind-parameter-parameter-no bind-parameter) parameter-no) + bind-parameter + res)) + #f (statement-handle-parameter-bindings stmt-handle))) + +(define (odbc-sql-bind-parameter-set-procedure-maker bind-parameter) + (let ((rebind-order-no (odbc-bind-parameter-rebind-order-no bind-parameter))) + (lambda (value) + (if (= (odbc-bind-parameter-rebind-order-no bind-parameter) rebind-order-no) + (bind-parameter-set-buffer bind-parameter value) + (raise-odbc-bind-parameter-rebinding-error + (odbc-bind-parameter-statement-handle bind-parameter) + (odbc-bind-parameter-parameter-no bind-parameter) + rebind-order-no + (odbc-bind-parameter-rebind-order-no bind-parameter)))))) + +(define (odbc-sql-bind-parameter-get-thunk-maker bind-parameter) + (let ((rebind-order-no (odbc-bind-parameter-rebind-order-no bind-parameter))) + (lambda (value) + (if (= (odbc-bind-parameter-rebind-order-no bind-parameter) rebind-order-no) + (bind-parameter-get-buffer bind-parameter) + (raise-odbc-bind-parameter-rebinding-error + (odbc-bind-parameter-statement-handle bind-parameter) + (odbc-bind-parameter-parameter-no bind-parameter) + rebind-order-no + (odbc-bind-parameter-rebind-order-no bind-parameter)))))) + +(define (odbc-sql-bind-parameter-for-input + stmt-handle parameter-no value-type parameter-type + column-size decimal-digits) + (cond + ((find-bind-parameter stmt-handle parameter-no) + => (lambda (bind-parameter) + ;; rebind this parameter + (set-odbc-bind-parameter-rebind-order-no! + bind-parameter (+ 1 (odbc-bind-parameter-rebind-order-no bind-parameter))) + ;; do something useful here + (odbc-sql-bind-parameter-set-procedure-maker bind-parameter))) + (else + (let ((bind-parameter + (really-make-odbc-bind-parameter + (statement-handle-handle stmt-handle) + parameter-no sql-param-input value-type + parameter-type column-size decimal-digits + #f #f #f 0))) + (set-statement-handle-parameter-bindings! + stmt-handle + (cons bind-parameter (statement-handle-parameter-bindings stmt-handle))) + ;; do something useful here + (odbc-sql-bind-parameter-set-procedure-maker bind-parameter))))) + +(define (odbc-sql-bind-parameter-for-input-and-output + stmt-handle parameter-no value-type parameter-type + column-size decimal-digits buffer-length) + (cond + ((find-bind-parameter stmt-handle parameter-no) + => (lambda (bind-parameter) + (set-odbc-bind-parameter-rebind-order-no! + bind-parameter (+ 1 (odbc-bind-parameter-rebind-order-no bind-parameter))) + ;; do something useful here + (values + (odbc-sql-bind-parameter-get-thunk-maker bind-parameter) + (odbc-sql-bind-parameter-set-procedure-maker bind-parameter)))) + (else + (let ((bind-parameter + (really-make-odbc-bind-parameter + (statement-handle-handle stmt-handle) + parameter-no sql-param-input-output value-type + parameter-type column-size decimal-digits + #f #f #f 0))) + (set-statement-handle-parameter-bindings! + stmt-handle + (cons bind-parameter (statement-handle-parameter-bindings stmt-handle))) + ;; do something useful here + (values + (odbc-sql-bind-parameter-get-thunk-maker bind-parameter) + (odbc-sql-bind-parameter-set-procedure-maker bind-parameter)))))) + +(define (odbc-sql-bind-parameter-for-output + stmt-handle parameter-no value-type parameter-type + column-size decimal-digits buffer-length) + (cond + ((find-bind-parameter stmt-handle parameter-no) + => (lambda (bind-parameter) + (set-odbc-bind-parameter-rebind-order-no! + bind-parameter (+ 1 (odbc-bind-parameter-rebind-order-no bind-parameter))) + ;; do something useful here + (odbc-sql-bind-parameter-get-thunk-maker bind-parameter))) + (else + (let ((bind-parameter + (really-make-odbc-bind-parameter + (statement-handle-handle stmt-handle) + parameter-no sql-param-output value-type + parameter-type column-size decimal-digits + #f #f #f 0))) + (set-statement-handle-parameter-bindings! + stmt-handle + (cons bind-parameter (statement-handle-parameter-bindings stmt-handle))) + ;; do something useful here + (odbc-sql-bind-parameter-get-thunk-maker bind-parameter))))) + +(import-lambda-definition odbc-sql-bind-parameter-internal + (bind-parameter-rec) + "odbc_sql_bind_parameter") + +(import-lambda-definition bind-parameter-set-buffer + (bind-parameter-rec value) + "bind_parameter_set_buffer") + +(import-lambda-definition bind-parameter-get-buffer + (bind-parameter-rec) + "bind_parameter_get_buffer") + +(define (odbc-sql-get-cursor-name 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) + (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) + "odbc_sql_set_cursor_name") + +;;; PART 6 + +(define (odbc-sql-execute stmt-handle) + (odbc-sql-execute-internal (statement-handle-handle stmt-handle))) + +(import-lambda-definition odbc-sql-execute-internal + (stmt-handle) + "odbc_sql_execute") + +(define (odbc-sql-execute-direct 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) + (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) + (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) + (apply values + (odbc-sql-num-params-internal + (statement-handle-handle stmt-handle)))) + +(import-lambda-definition odbc-sql-num-params-internal + (stmt-handle) + "odbc_sql_num_params") + +;;; PART 7 + +(define (odbc-sql-row-count 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) + (apply values + (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) + "odbc_sql_get_data") + +(define (odbc-sql-set-pos 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) + (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) + (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) + (odbc-sql-fetch-internal + (statement-handle-handle stmt-handle))) + +(import-lambda-definition odbc-sql-fetch-internal + (stmt-handle) + "odbc_sql_fetch") + +(define (odbc-sql-bindcol stmt-handle column-no target-type buffer-len) + (let ((handle (statement-handle-handle stmt-handle))) + (odbc-sql-bindcol-internal handle column-no target-type buffer-len) + (lambda () + (bindcol-lookup-binding-scheme handle column-no)))) + +(import-lambda-definition odbc-sql-bindcol-internal + (stmt-handle column-no target-type buffer-len) + "odbc_sql_bindcol") + +(import-lambda-definition bindcol-lookup-binding-scheme + (stmt-handle column-no) + "bindcol_lookup_binding_scheme") + +;;; PART 8 + +(define (odbc-sql-column-privileges stmt-handle catalog-name schema-name + table-name column-name) + (check-arg statement-handle? stmt-handle odbc-sql-column-privileges) + (odbc-sql-column-privileges-internal (statement-handle-handle stmt-handle) + catalog-name schema-name + table-name column-name)) + +(import-lambda-definition odbc-sql-column-privileges-internal + (stmt-handle catalog-name schema-name table-name column-name) + "odbc_sql_column_privileges") + +(define (odbc-sql-columns stmt-handle catalog-name schema-name + table-name column-name) + (check-arg statement-handle? stmt-handle odbc-sql-columns) + (odbc-sql-columns-internal (statement-handle-handle stmt-handle) + catalog-name schema-name table-name column-name)) + +(import-lambda-definition odbc-sql-columns-internal + (stmt-handle catalog-name schema-name table-name column-name) + "odbc_sql_columns") + +(define (odbc-sql-foreign-keys stmt-handle + pk-catalog-name pk-schema-name pk-table-name + fk-catalog-name fk-schema-name fk-table-name) + (check-arg statement-handle? stmt-handle odbc-sql-foreign-keys) + (odbc-sql-foreign-keys-internal (statement-handle-handle stmt-handle) + pk-catalog-name pk-schema-name pk-table-name + fk-catalog-name fk-schema-name fk-table-name)) + +(import-lambda-definition odbc-sql-foreign-keys-internal + (stmt-handle + pk-catalog-name pk-schema-name pk-table-name + fk-catalog-name fk-schema-name fk-table-name) + "odbc_sql_foreign_keys") + +(define (odbc-sql-primary-keys stmt-handle catalog-name schema-name table-name) + (check-arg statement-handle? stmt-handle odbc-sql-primary-keys) + (odbc-sql-primary-keys-internal (statement-handle-handle stmt-handle) + catalog-name schema-name table-name)) + +(import-lambda-definition odbc-sql-primary-keys-internal + (stmt-handle catalog-name schema-name table-name) + "odbc_sql_primary_keys") + +(define (odbc-sql-procedure-columns stmt-handle catalog-name schema-name + proc-name column-name) + (check-arg statement-handle? stmt-handle odbc-sql-procedure-columns) + (odbc-sql-procedure-columns-internal (statement-handle-handle stmt-handle) + catalog-name schema-name proc-name column-name)) + +(import-lambda-definition odbc-sql-procedure-columns-internal + (stmt-handle catalog-name schema-name proc-name column-name) + "odbc_sql_procedure_columns") + +(define (odbc-sql-procedures stmt-handle catalog-name schema-name proc-name) + (check-arg statement-handle? stmt-handle odbc-sql-procedures) + (odbc-sql-procedures-internal (statement-handle-handle stmt-handle) + catalog-name schema-name proc-name)) + +(import-lambda-definition odbc-sql-procedures-internal + (stmt-handle catalog-name schema-name proc-name) + "odbc_sql_procedures") + +(define (odbc-sql-special-columns stmt-handle identifier-type catalog-name + schema-name table-name scope nullable) + (check-arg statement-handle? stmt-handle odbc-sql-special-columns) + (odbc-sql-special-columns-internal (statement-handle-handle stmt-handle) + identifier-type catalog-name + schema-name table-name schema-name nullable)) + +(import-lambda-definition odbc-sql-special-columns-internal + (stmt-handle identifier-type catalog-name + schema-name table-name scope nullable?) + "odbc_sql_special_columns") + +(define (odbc-sql-statistics stmt-handle catalog-name schema-name table-name + unique reserved) + (check-arg statement-handle? stmt-handle odbc-sql-statistics) + (odbc-sql-statistics-internal (statement-handle-handle stmt-handle) + catalog-name schema-name table-name unique reserved)) + +(import-lambda-definition odbc-sql-statistics-internal + (stmt-handle catalog-name schema-name table-name + unique reserved) + "odbc_sql_statistics") + +(define (odbc-sql-table-privileges stmt-handle catalog-name schema-name table-name) + (check-arg statement-handle? stmt-handle odbc-sql-table-privileges) + (odbc-sql-table-privileges-internal (statement-handle-handle stmt-handle) + catalog-name schema-name table-name)) + +(import-lambda-definition odbc-sql-table-privileges-internal + (stmt-handle catalog-name schema-name table-name) + "odbc_sql_table_privileges") + +(define (odbc-sql-tables stmt-handle catalog-name schema-name table-name table-type) + (check-arg statement-handle? stmt-handle odbc-sql-tables) + (odbc-sql-tables-internal (statement-handle-handle stmt-handle) + catalog-name schema-name table-name table-type)) + +(import-lambda-definition odbc-sql-tables-internal + (stmt-handle catalog-name schema-name table-type table-type) + "odbc_sql_tables") + +;;; PART 9 + +(define (odbc-sql-free-statement stmt-handle option) + (check-arg statement-handle? stmt-handle odbc-sql-free-statement) + (odbc-sql-free-statement-internal (statement-handle-handle stmt-handle) option)) + +(import-lambda-definition odbc-sql-free-statement-internal + (stmt-handle option) + "odbc_sql_free_statement") + +(define (odbc-sql-close-cursor stmt-handle) + (check-arg statement-handle? stmt-handle odbc-sql-close-cursor) + (odbc-sql-close-cursor-internal (statement-handle-handle stmt-handle))) + +(import-lambda-definition odbc-sql-close-cursor-internal + (stmt-handle) + "odbc_sql_close_cursor") + +(define (odbc-sql-cancel stmt-handle) + (check-arg statement-handle? stmt-handle odbc-sql-cancel) + (odbc-sql-cancel-internal (statement-handle-handle stmt-handle))) + +(import-lambda-definition odbc-sql-cancel-internal + (stmt-handle) + "odbc_sql_cancel") + +(define (odbc-sql-num-result-cols stmt-handle) + (check-arg statement-handle? stmt-handle odbc-sql-num-result-cols) + (odbc-sql-num-result-cols-internal (statement-handle-handle stmt-handle))) + +(import-lambda-definition odbc-sql-num-result-cols-internal + (stmt-handle) + "odbc_sql_num_result_cols") + +(define (odbc-sql-describe-col stmt-handle column-number) + (check-arg statement-handle? stmt-handle odbc-sql-describe-col) + (odbc-sql-describe-col-internal (statement-handle-handle stmt-handle) column-number)) + +(import-lambda-definition odbc-sql-describe-col-internal + (stmt-handle column-number) + "odbc_sql_describe_col") + +(define (odbc-sql-col-attribute stmt-handle column-number field-id) + (check-arg statement-handle? stmt-handle odbc-sql-col-attribute) + (let ((pair (odbc-sql-col-attribute-internal + (statement-handle-handle stmt-handle) + column-number field-id))) + (if (zero? (string-length (car pair))) + (cdr pair) + (car pair)))) + +(import-lambda-definition odbc-sql-col-attribute-internal + (stmt-handle column-number field-id) + "odbc_sql_col_attribute") + +;;; PART 10 + +(define (odbc-sql-disconnect conn-handle) + (check-arg connection-handle? conn-handle odbc-sql-disconnect) + (let ((return-value (odbc-sql-disconnect-internal + (connection-handle-handle conn-handle)))) + (if (odbc-call-successful? return-value) + (set-connection-handle-connected?! conn-handle #f)) + return-value)) + +(import-lambda-definition odbc-sql-disconnect-internal + (conn-handle) + "odbc_sql_disconnect") + +(define (odbc-sql-free-handle handle) + (check-arg odbc-handle? handle odbc-sql-free-handle) + (odbc-sql-free-handle-internal (handle-record-type->c-handle-identifier handle) + (odbc-handle handle))) + +(import-lambda-definition odbc-sql-free-handle-internal + (handle-type handle) + "odbc_sql_free_handle") + +(define (odbc-sql-get-diag-recs handle) + (apply values + (odbc-sql-get-diag-recs-internal + (handle-record-type->c-handle-identifier handle) (odbc-handle handle)))) + +(import-lambda-definition odbc-sql-get-diag-recs-internal + (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) + (equal? odbc-return-value sql-success-with-info)))