From f0fdf618fe2f59dba610a213533b3242914d8c5b Mon Sep 17 00:00:00 2001 From: eknauel Date: Tue, 3 Sep 2002 13:44:06 +0000 Subject: [PATCH] Support for SQLGetCursorName() and SQLSetCursorName() --- scsh/odbc/odbc.c | 79 ++++++++++++++++++++++++++++++++++++++++++++-- scsh/odbc/odbc.h | 7 +++- scsh/odbc/odbc.scm | 20 ++++++++++-- 3 files changed, 101 insertions(+), 5 deletions(-) diff --git a/scsh/odbc/odbc.c b/scsh/odbc/odbc.c index ef3cb7b..b9ecf7f 100644 --- a/scsh/odbc/odbc.c +++ b/scsh/odbc/odbc.c @@ -1224,6 +1224,79 @@ s48_value odbc_sql_bind_parameter_exec_out(s48_value stmt_handle, } +s48_value odbc_sql_get_cursor_name(s48_value stmt_handle) +{ + SQLHSTMT sh; + SQLRETURN retval; + SQLCHAR cursorname[ODBC_MAX_CURSOR_NAME_STR_LEN]; + SQLSMALLINT buffer_len; + + ODBC_DEBUG_PRINTF("odbc_sql_get_cursor_name\n"); + + sh = (SQLHSTMT) s48_extract_integer(stmt_handle); + + retval = SQLGetCursorName(sh, cursorname, ODBC_MAX_CURSOR_NAME_STR_LEN - 1, &buffer_len); + + switch (retval) + { + case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: + { + return s48_enter_string(cursorname); + } + 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; + } + } +} + +void odbc_sql_set_cursor_name(s48_value stmt_handle, s48_value cursorname) +{ + SQLHSTMT sh; + SQLCHAR *cn; + SQLRETURN retval; + + ODBC_DEBUG_PRINTF("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; + } + } +} /* * @@ -1460,10 +1533,10 @@ s48_value odbc_sql_num_result_cols(s48_value stmt_handle) SQLSMALLINT numcols; SQLRETURN retval; - ODBC_DEBUG_PRINTF("odbc_sql_num_result_cols\n"); - sh = (SQLHSTMT) s48_extract_integer(stmt_handle); + ODBC_DEBUG_PRINTF("odbc_sql_num_result_cols\n"); + retval = SQLNumResultCols(sh, &numcols); switch (retval) @@ -2101,6 +2174,8 @@ 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); /* PART 6 */ S48_EXPORT_FUNCTION(odbc_sql_execute); diff --git a/scsh/odbc/odbc.h b/scsh/odbc/odbc.h index 81ff10a..775f77e 100644 --- a/scsh/odbc/odbc.h +++ b/scsh/odbc/odbc.h @@ -13,6 +13,7 @@ #define ODBC_GET_STMT_ATTR_MAX_LEN 255 #define ODBC_GET_DATA_MAX_STR_LEN 255 #define ODBC_DESCRIBE_COL_MAX_STR_LEN 255 +#define ODBC_MAX_CURSOR_NAME_STR_LEN 255 #define ODBC_DEBUG_MSGS 1 @@ -205,7 +206,11 @@ s48_value odbc_sql_get_stmt_attr_string(s48_value stmt_handle, 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 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); /* * diff --git a/scsh/odbc/odbc.scm b/scsh/odbc/odbc.scm index 29c678c..2360d4d 100644 --- a/scsh/odbc/odbc.scm +++ b/scsh/odbc/odbc.scm @@ -576,7 +576,7 @@ "odbc_sql_prepare") (define (odbc-sql-bind-parameter-exec-out stmt-handle param-vals) - (check-arg statement-handle-handle stmt-handle odbc-sql-bind-parameter-exec-out) + (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)) @@ -584,6 +584,22 @@ (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))) + +(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)) + +(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) @@ -653,7 +669,7 @@ (define (odbc-sql-num-result-cols stmt-handle) (check-arg statement-handle? stmt-handle odbc-sql-num-result-cols) - (odbc-sql-num-result-cols (statement-handle-handle stmt-handle))) + (odbc-sql-num-result-cols-internal (statement-handle-handle stmt-handle))) (import-lambda-definition odbc-sql-num-result-cols-internal (stmt-handle)