removed parameter 'direction' for odbc_sql_data_sources

support for SQLNumResultCols and SQLDescribeCol
This commit is contained in:
eknauel 2002-05-21 13:48:37 +00:00
parent 5ab07b6398
commit f70889ccc8
1 changed files with 120 additions and 3 deletions

View File

@ -243,7 +243,7 @@ s48_value odbc_sql_connect(s48_value connection_handle,
*/ */
/* Returns a list of available data sources. */ /* Returns a list of available data sources. */
s48_value odbc_sql_data_sources(s48_value env_handle, s48_value direction) s48_value odbc_sql_data_sources(s48_value env_handle)
{ {
SQLHENV eh; SQLHENV eh;
@ -257,7 +257,6 @@ s48_value odbc_sql_data_sources(s48_value env_handle, s48_value direction)
int first; int first;
eh = (SQLHENV) s48_extract_integer(env_handle); eh = (SQLHENV) s48_extract_integer(env_handle);
dir = (SQLUSMALLINT) s48_extract_integer(direction);
ODBC_DEBUG_PRINTF("odbc_sql_data_sources\n"); ODBC_DEBUG_PRINTF("odbc_sql_data_sources\n");
@ -267,7 +266,7 @@ s48_value odbc_sql_data_sources(s48_value env_handle, s48_value direction)
while (1) { while (1) {
retval = SQLDataSources(eh, retval = SQLDataSources(eh,
(first ? dir : SQL_FETCH_NEXT), (first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT),
server_name, SQL_MAX_DSN_LENGTH+1, &server_name_len, server_name, SQL_MAX_DSN_LENGTH+1, &server_name_len,
driver_descr, ODBC_MAX_DRIVER_NAME_LEN, &driver_descr_len); driver_descr, ODBC_MAX_DRIVER_NAME_LEN, &driver_descr_len);
first = 0; first = 0;
@ -1607,6 +1606,122 @@ s48_value odbc_sql_fetch(s48_value stmt_handle)
} }
} }
s48_value odbc_sql_num_result_cols(s48_value stmt_handle)
{
SQLHSTMT sh;
SQLSMALLINT numcols;
SQLRETURN retval;
ODBC_DEBUG_PRINTF("odbc_sql_num_result_cols\n");
sh = (SQLHSTMT) s48_extract_integer(stmt_handle);
retval = SQLNumResultCols(sh, &numcols);
switch (retval)
{
case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO:
{
if (retval == SQL_SUCCESS_WITH_INFO)
ODBC_DEBUG_DIAGREC(SQL_HANDLE_STMT, sh);
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_DEBUG_DIAGREC(SQL_HANDLE_STMT, sh);
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;
}
}
}
s48_value odbc_sql_describe_col(s48_value stmt_handle, s48_value column_number)
{
SQLHSTMT sh;
SQLSMALLINT cn;
SQLCHAR column_name[ODBC_DESCRIBE_COL_MAX_STR_LEN];
SQLSMALLINT buf_len, data_type, digits, nullable;
SQLUINTEGER col_size;
s48_value col_rec;
SQLRETURN retval;
ODBC_DEBUG_PRINTF("odbc_sql_describe_col\n");
sh = (SQLHSTMT) s48_extract_integer(stmt_handle);
cn = (SQLSMALLINT) s48_extract_integer(column_number);
retval = SQLDescribeCol(sh, cn,
column_name,
ODBC_DESCRIBE_COL_MAX_STR_LEN - 1,
&buf_len,
&data_type,
&col_size,
&digits,
&nullable);
switch (retval)
{
case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO:
{
if (retval == SQL_SUCCESS_WITH_INFO)
ODBC_DEBUG_DIAGREC(SQL_HANDLE_STMT, sh);
col_rec = s48_make_record(odbc_column_record_type);
S48_RECORD_SET(col_rec, SR_ODBC_COLUMN_NAME,
s48_enter_string(column_name));
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));
return col_rec;
}
case SQL_STILL_EXECUTING:
{
ODBC_RAISE_EXCEPTION("SQLDescribeCol returned SQL_STILL_EXECUTING, not yet implemented");
break;
}
case SQL_ERROR:
{
ODBC_DEBUG_DIAGREC(SQL_HANDLE_STMT, sh);
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;
}
}
}
/* /*
* *
* PART 8 * PART 8
@ -2108,6 +2223,8 @@ void s48_init_odbc(void)
/* PART 7 */ /* PART 7 */
S48_EXPORT_FUNCTION(odbc_sql_get_data); S48_EXPORT_FUNCTION(odbc_sql_get_data);
S48_EXPORT_FUNCTION(odbc_sql_fetch); S48_EXPORT_FUNCTION(odbc_sql_fetch);
S48_EXPORT_FUNCTION(odbc_sql_num_result_cols);
S48_EXPORT_FUNCTION(odbc_sql_describe_col);
/* PART 8 */ /* PART 8 */