Skip to content

document functions #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 70 additions & 3 deletions odbcapi30.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,35 @@ SQLGetDescField(SQLHDESC DescriptorHandle,
return ret;
}

/* new function */
/*
* SQLGetDescRec
*
* Description:
* This function retrieves the current settings or values of fields in a descriptor record.
* It's the ANSI version of the function that works with descriptor records.
*
* Parameters:
* DescriptorHandle - Handle to the descriptor
* RecNumber - The descriptor record number (1-based)
* Name - Buffer to store the descriptor name (ANSI)
* BufferLength - Length of the Name buffer in bytes
* StringLength - Pointer to store the actual length of the name
* Type - Pointer to store the SQL data type
* SubType - Pointer to store the data type subcode
* Length - Pointer to store the data length
* Precision - Pointer to store the numeric precision
* Scale - Pointer to store the numeric scale
* Nullable - Pointer to store the nullability attribute
*
* Returns:
* SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE
*
* Comments:
* This function is a thin wrapper around PGAPI_GetDescRec, which contains
* the actual implementation. Unlike the wide-character version (SQLGetDescRecW),
* this function doesn't need to perform character set conversion since it
* works directly with ANSI strings.
*/
RETCODE SQL_API
SQLGetDescRec(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber, SQLCHAR *Name,
Expand All @@ -324,11 +352,15 @@ SQLGetDescRec(SQLHDESC DescriptorHandle,
{
RETCODE ret;

/* Log function entry with important parameters */
MYLOG(0, "Entering h=%p rec=%d name=%p blen=%d\n", DescriptorHandle, RecNumber, Name, BufferLength);
MYLOG(0, "str=%p type=%p sub=%p len=%p prec=%p scale=%p null=%p\n", StringLength, Type, SubType, Length, Precision, Scale, Nullable);

/* Call the core implementation function */
ret = PGAPI_GetDescRec(DescriptorHandle, RecNumber, Name, BufferLength,
StringLength, Type, SubType, Length, Precision,
Scale, Nullable);

return ret;
}

Expand Down Expand Up @@ -416,7 +448,28 @@ SQLGetConnectAttr(HDBC ConnectionHandle,
return ret;
}

/* SQLGetStmtOption -> SQLGetStmtAttr */
/*
* SQLGetStmtAttr
*
* Description:
* This function retrieves the current setting of a statement attribute.
* This is the ANSI version of the function.
*
* Parameters:
* StatementHandle - Handle to the statement
* Attribute - The attribute to retrieve (SQL_ATTR_* constant)
* Value - Buffer to store the attribute value
* BufferLength - Length of the Value buffer in bytes
* StringLength - Pointer to store the actual length of string data
*
* Returns:
* SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE
*
* Comments:
* This function replaces the deprecated SQLGetStmtOption function.
* It provides thread-safe access to statement attributes by using
* critical sections to protect shared resources.
*/
RETCODE SQL_API
SQLGetStmtAttr(HSTMT StatementHandle,
SQLINTEGER Attribute, PTR Value,
Expand All @@ -425,14 +478,28 @@ SQLGetStmtAttr(HSTMT StatementHandle,
RETCODE ret;
StatementClass *stmt = (StatementClass *) StatementHandle;

/* Log function entry with important parameters */
MYLOG(0, "Entering Handle=%p " FORMAT_INTEGER "\n", StatementHandle, Attribute);

/* Enter critical section to ensure thread safety */
ENTER_STMT_CS(stmt);

/* Clear any previous errors on the statement */
SC_clear_error(stmt);

/* Set up savepoint for transaction safety */
StartRollbackState(stmt);

/* Call the core implementation function */
ret = PGAPI_GetStmtAttr(StatementHandle, Attribute, Value,
BufferLength, StringLength);
ret = DiscardStatementSvp(stmt,ret, FALSE);

/* Handle transaction state and cleanup */
ret = DiscardStatementSvp(stmt, ret, FALSE);

/* Exit critical section */
LEAVE_STMT_CS(stmt);

return ret;
}

Expand Down
80 changes: 77 additions & 3 deletions odbcapi30w.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@
#include "misc.h"


/*
* SQLGetStmtAttrW
*
* Description:
* This function retrieves the current setting of a statement attribute.
* This is the Unicode (wide-character) version of SQLGetStmtAttr.
*
* Parameters:
* hstmt - Handle to the statement
* fAttribute - The attribute to retrieve (SQL_ATTR_* constant)
* rgbValue - Buffer to store the attribute value
* cbValueMax - Length of the rgbValue buffer in bytes
* pcbValue - Pointer to store the actual length of string data
*
* Returns:
* SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE
*
* Comments:
* Unlike some other Unicode functions, this function doesn't need to perform
* character set conversion since statement attributes are not string-based
* or already handle Unicode conversion internally. It simply passes through
* to the core implementation function PGAPI_GetStmtAttr.
*/
RETCODE SQL_API
SQLGetStmtAttrW(SQLHSTMT hstmt,
SQLINTEGER fAttribute,
Expand All @@ -33,14 +56,28 @@ SQLGetStmtAttrW(SQLHSTMT hstmt,
RETCODE ret;
StatementClass *stmt = (StatementClass *) hstmt;

/* Log function entry */
MYLOG(0, "Entering\n");

/* Enter critical section to ensure thread safety */
ENTER_STMT_CS((StatementClass *) hstmt);

/* Clear any previous errors on the statement */
SC_clear_error((StatementClass *) hstmt);

/* Set up savepoint for transaction safety */
StartRollbackState(stmt);

/* Call the core implementation function */
ret = PGAPI_GetStmtAttr(hstmt, fAttribute, rgbValue,
cbValueMax, pcbValue);

/* Handle transaction state and cleanup */
ret = DiscardStatementSvp(stmt, ret, FALSE);

/* Exit critical section */
LEAVE_STMT_CS((StatementClass *) hstmt);

return ret;
}

Expand Down Expand Up @@ -417,7 +454,29 @@ SQLGetDiagFieldW(SQLSMALLINT fHandleType,
return ret;
}

/* new function */
/*
* SQLGetDescRecW
*
* Description:
* This function retrieves the current settings or values of fields in a descriptor record.
* It's the wide-character (Unicode) version of SQLGetDescRec.
*
* Parameters:
* DescriptorHandle - Handle to the descriptor
* RecNumber - The descriptor record number (1-based)
* Name - Buffer to store the descriptor name (Unicode)
* BufferLength - Length of the Name buffer in characters
* StringLength - Pointer to store the actual length of the name
* Type - Pointer to store the SQL data type
* SubType - Pointer to store the data type subcode
* Length - Pointer to store the data length
* Precision - Pointer to store the numeric precision
* Scale - Pointer to store the numeric scale
* Nullable - Pointer to store the nullability attribute
*
* Returns:
* SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE
*/
RETCODE SQL_API
SQLGetDescRecW(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber, SQLWCHAR *Name,
Expand All @@ -427,35 +486,50 @@ SQLGetDescRecW(SQLHDESC DescriptorHandle,
SQLSMALLINT *Scale, SQLSMALLINT *Nullable)
{
RETCODE ret;
char *NameA = NULL;
SQLSMALLINT nlen;
char *NameA = NULL; /* Temporary buffer for ANSI version of name */
SQLSMALLINT nlen; /* Length of the name string */

/* Log function entry with important parameters */
MYLOG(0, "Entering h=%p rec=%d name=%p blen=%d\n", DescriptorHandle, RecNumber, Name, BufferLength);
MYLOG(0, "str=%p type=%p sub=%p len=%p prec=%p scale=%p null=%p\n", StringLength, Type, SubType, Length, Precision, Scale, Nullable);

/* Allocate temporary buffer for ANSI version if buffer length is provided */
if (BufferLength > 0)
NameA = malloc(BufferLength);

/* Call the core implementation with ANSI parameters */
ret = PGAPI_GetDescRec(DescriptorHandle, RecNumber, (SQLCHAR *) NameA, BufferLength,
&nlen, Type, SubType, Length, Precision,
Scale, Nullable);

if (SQL_SUCCEEDED(ret))
{
/* Convert ANSI name to Unicode if we have a valid name and buffer */
if (NameA && nlen <= BufferLength)
{
/* Try UTF-8 to UCS-2 conversion first */
SQLULEN ulen = utf8_to_ucs2_lf(NameA, nlen, FALSE, Name, BufferLength, TRUE);

if (ulen == (SQLULEN) -1)
/* Fall back to locale-based conversion if UTF-8 conversion fails */
nlen = (SQLSMALLINT) locale_to_sqlwchar((SQLWCHAR *) Name, NameA, BufferLength, FALSE);
else
nlen = (SQLSMALLINT) ulen;

/* If the name was truncated, return success with info */
if (nlen >= BufferLength)
ret = SQL_SUCCESS_WITH_INFO;
}

/* Return the actual string length if the caller wants it */
if (StringLength)
*StringLength = nlen;
}

/* Clean up the temporary buffer */
if (NameA)
free(NameA);

return ret;
}

Expand Down
Loading