Skip to content

Commit 634c0ea

Browse files
authored
document functions (#129)
* document code * more documentation * remove some extraneous comments
1 parent 453a8bd commit 634c0ea

File tree

4 files changed

+736
-40
lines changed

4 files changed

+736
-40
lines changed

odbcapi30.c

Lines changed: 143 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,35 @@ SQLGetDescField(SQLHDESC DescriptorHandle,
313313
return ret;
314314
}
315315

316-
/* new function */
316+
/*
317+
* SQLGetDescRec
318+
*
319+
* Description:
320+
* This function retrieves the current settings or values of fields in a descriptor record.
321+
* It's the ANSI version of the function that works with descriptor records.
322+
*
323+
* Parameters:
324+
* DescriptorHandle - Handle to the descriptor
325+
* RecNumber - The descriptor record number (1-based)
326+
* Name - Buffer to store the descriptor name (ANSI)
327+
* BufferLength - Length of the Name buffer in bytes
328+
* StringLength - Pointer to store the actual length of the name
329+
* Type - Pointer to store the SQL data type
330+
* SubType - Pointer to store the data type subcode
331+
* Length - Pointer to store the data length
332+
* Precision - Pointer to store the numeric precision
333+
* Scale - Pointer to store the numeric scale
334+
* Nullable - Pointer to store the nullability attribute
335+
*
336+
* Returns:
337+
* SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE
338+
*
339+
* Comments:
340+
* This function is a thin wrapper around PGAPI_GetDescRec, which contains
341+
* the actual implementation. Unlike the wide-character version (SQLGetDescRecW),
342+
* this function doesn't need to perform character set conversion since it
343+
* works directly with ANSI strings.
344+
*/
317345
RETCODE SQL_API
318346
SQLGetDescRec(SQLHDESC DescriptorHandle,
319347
SQLSMALLINT RecNumber, SQLCHAR *Name,
@@ -326,9 +354,11 @@ SQLGetDescRec(SQLHDESC DescriptorHandle,
326354

327355
MYLOG(0, "Entering h=%p rec=%d name=%p blen=%d\n", DescriptorHandle, RecNumber, Name, BufferLength);
328356
MYLOG(0, "str=%p type=%p sub=%p len=%p prec=%p scale=%p null=%p\n", StringLength, Type, SubType, Length, Precision, Scale, Nullable);
357+
329358
ret = PGAPI_GetDescRec(DescriptorHandle, RecNumber, Name, BufferLength,
330359
StringLength, Type, SubType, Length, Precision,
331360
Scale, Nullable);
361+
332362
return ret;
333363
}
334364

@@ -416,7 +446,28 @@ SQLGetConnectAttr(HDBC ConnectionHandle,
416446
return ret;
417447
}
418448

419-
/* SQLGetStmtOption -> SQLGetStmtAttr */
449+
/*
450+
* SQLGetStmtAttr
451+
*
452+
* Description:
453+
* This function retrieves the current setting of a statement attribute.
454+
* This is the ANSI version of the function.
455+
*
456+
* Parameters:
457+
* StatementHandle - Handle to the statement
458+
* Attribute - The attribute to retrieve (SQL_ATTR_* constant)
459+
* Value - Buffer to store the attribute value
460+
* BufferLength - Length of the Value buffer in bytes
461+
* StringLength - Pointer to store the actual length of string data
462+
*
463+
* Returns:
464+
* SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE
465+
*
466+
* Comments:
467+
* This function replaces the deprecated SQLGetStmtOption function.
468+
* It provides thread-safe access to statement attributes by using
469+
* critical sections to protect shared resources.
470+
*/
420471
RETCODE SQL_API
421472
SQLGetStmtAttr(HSTMT StatementHandle,
422473
SQLINTEGER Attribute, PTR Value,
@@ -426,13 +477,20 @@ SQLGetStmtAttr(HSTMT StatementHandle,
426477
StatementClass *stmt = (StatementClass *) StatementHandle;
427478

428479
MYLOG(0, "Entering Handle=%p " FORMAT_INTEGER "\n", StatementHandle, Attribute);
480+
429481
ENTER_STMT_CS(stmt);
482+
430483
SC_clear_error(stmt);
484+
431485
StartRollbackState(stmt);
486+
432487
ret = PGAPI_GetStmtAttr(StatementHandle, Attribute, Value,
433488
BufferLength, StringLength);
434-
ret = DiscardStatementSvp(stmt,ret, FALSE);
489+
490+
ret = DiscardStatementSvp(stmt, ret, FALSE);
491+
435492
LEAVE_STMT_CS(stmt);
493+
436494
return ret;
437495
}
438496

@@ -455,7 +513,27 @@ SQLSetConnectAttr(HDBC ConnectionHandle,
455513
return ret;
456514
}
457515

458-
/* new function */
516+
/*
517+
* SQLSetDescField
518+
*
519+
* Description:
520+
* This function sets the value of a field in a descriptor record.
521+
* This is the ANSI version of the function.
522+
*
523+
* Parameters:
524+
* DescriptorHandle - Handle to the descriptor
525+
* RecNumber - The descriptor record number (1-based, 0 for header fields)
526+
* FieldIdentifier - The field identifier (SQL_DESC_* constant)
527+
* Value - The value to set for the field
528+
* BufferLength - Length of the Value buffer in bytes (for string data)
529+
*
530+
* Returns:
531+
* SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE
532+
*
533+
* Comments:
534+
* This function simply passes through to the core implementation function
535+
* PGAPI_SetDescField without any additional processing.
536+
*/
459537
RETCODE SQL_API
460538
SQLSetDescField(SQLHDESC DescriptorHandle,
461539
SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier,
@@ -464,12 +542,39 @@ SQLSetDescField(SQLHDESC DescriptorHandle,
464542
RETCODE ret;
465543

466544
MYLOG(0, "Entering h=%p rec=%d field=%d val=%p\n", DescriptorHandle, RecNumber, FieldIdentifier, Value);
545+
467546
ret = PGAPI_SetDescField(DescriptorHandle, RecNumber, FieldIdentifier,
468547
Value, BufferLength);
548+
469549
return ret;
470550
}
471551

472-
/* new function */
552+
/*
553+
* SQLSetDescRec
554+
*
555+
* Description:
556+
* This function sets multiple descriptor fields with a single call.
557+
* This is the ANSI version of the function.
558+
*
559+
* Parameters:
560+
* DescriptorHandle - Handle to the descriptor
561+
* RecNumber - The descriptor record number (1-based)
562+
* Type - SQL data type
563+
* SubType - Datetime or interval subcode
564+
* Length - Maximum data length
565+
* Precision - Precision of numeric types
566+
* Scale - Scale of numeric types
567+
* Data - Pointer to data buffer
568+
* StringLength - Pointer to buffer length
569+
* Indicator - Pointer to indicator variable
570+
*
571+
* Returns:
572+
* SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE
573+
*
574+
* Comments:
575+
* This function provides a more efficient way to set multiple descriptor
576+
* fields that are commonly used together.
577+
*/
473578
RETCODE SQL_API
474579
SQLSetDescRec(SQLHDESC DescriptorHandle,
475580
SQLSMALLINT RecNumber, SQLSMALLINT Type,
@@ -482,9 +587,11 @@ SQLSetDescRec(SQLHDESC DescriptorHandle,
482587

483588
MYLOG(0, "Entering h=%p rec=%d type=%d sub=%d len=" FORMAT_LEN " prec=%d scale=%d data=%p\n", DescriptorHandle, RecNumber, Type, SubType, Length, Precision, Scale, Data);
484589
MYLOG(0, "str=%p ind=%p\n", StringLength, Indicator);
590+
485591
ret = PGAPI_SetDescRec(DescriptorHandle, RecNumber, Type,
486592
SubType, Length, Precision, Scale, Data,
487593
StringLength, Indicator);
594+
488595
return ret;
489596
}
490597
#endif /* UNICODE_SUPPORTXX */
@@ -550,7 +657,27 @@ SQLSetEnvAttr(HENV EnvironmentHandle,
550657
}
551658

552659
#ifndef UNICODE_SUPPORTXX
553-
/* SQLSet(Param/Scroll/Stmt)Option -> SQLSetStmtAttr */
660+
/*
661+
* SQLSetStmtAttr
662+
*
663+
* Description:
664+
* This function sets the current setting of a statement attribute.
665+
* This is the ANSI version of the function.
666+
*
667+
* Parameters:
668+
* StatementHandle - Handle to the statement
669+
* Attribute - The attribute to set (SQL_ATTR_* constant)
670+
* Value - The value to set for the attribute
671+
* StringLength - Length of the Value buffer in bytes (for string data)
672+
*
673+
* Returns:
674+
* SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE
675+
*
676+
* Comments:
677+
* This function replaces the deprecated SQLSetStmtOption function.
678+
* It provides thread-safe access to statement attributes by using
679+
* critical sections to protect shared resources.
680+
*/
554681
RETCODE SQL_API
555682
SQLSetStmtAttr(HSTMT StatementHandle,
556683
SQLINTEGER Attribute, PTR Value,
@@ -560,12 +687,21 @@ SQLSetStmtAttr(HSTMT StatementHandle,
560687
RETCODE ret;
561688

562689
MYLOG(0, "Entering Handle=%p " FORMAT_INTEGER "," FORMAT_ULEN "\n", StatementHandle, Attribute, (SQLULEN) Value);
690+
563691
ENTER_STMT_CS(stmt);
692+
564693
SC_clear_error(stmt);
694+
565695
StartRollbackState(stmt);
696+
697+
/* Call the core implementation function */
566698
ret = PGAPI_SetStmtAttr(StatementHandle, Attribute, Value, StringLength);
567-
ret = DiscardStatementSvp(stmt,ret, FALSE);
699+
700+
/* Handle transaction state and cleanup */
701+
ret = DiscardStatementSvp(stmt, ret, FALSE);
702+
568703
LEAVE_STMT_CS(stmt);
704+
569705
return ret;
570706
}
571707
#endif /* UNICODE_SUPPORTXX */

0 commit comments

Comments
 (0)