Skip to content
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

Assorted improvements from NCBI as of May 2024 #559

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ucko
Copy link
Contributor

@ucko ucko commented May 30, 2024

This PR contains seven (mostly formally) interdependent commits from #555; I've split off what I cleanly could, and in particular split the bulk.c changes from 1512645 into e6facc4 so that I can have a separate BCP-focused PR, leaving b6ab56f for here.

Comment on lines -1542 to +1535
void tdsdump_log(const char* file, unsigned int level_line, const char *fmt, ...)
void tdsdump_do_log(const char* file, unsigned int level_line,
const char *fmt, ...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is an ABI and must be exported with this name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought tds* were generally internal; I do see that libsybdb exposes tdsdump_open, but that function's not in play here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, usually yes. BTW, it's only tdsdump_open (and tdsdbopen) that are in ABI, so tdsdump_log can be changed.

Comment on lines -776 to +815
#define cs_dt_crack cs_dt_crack_v2
#ifndef _FREETDS_LIBRARY_SOURCE
# undef cs_dt_crack
# define cs_dt_crack cs_dt_crack_v2
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the previous style. Shorter and does not require adding a new _FREETDS_LIBRARY_SOURCE definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, but it interacts poorly with mass renaming (e.g., tacking on _ftds14 suffixes across the board) that would otherwise allow coexistence with commercial MS/SAP libraries and/or other analogously patched FreeTDS versions. I'm obviously not proposing to push any such renaming, just the changes that make it fully possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the need for mass renaming. I don't think it's possible to use both proprietary library and FreeTDS without breaking ABI (Windows and ODBC excluded), the 2 libraries will clash.
Usually to allow this usually libraries use symbol prefixes instead of suffix (for instance adding ftds_ before all exported functions, I know libiconv is adding lib prefix to functions).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is a special case -- the C++ Toolkit performs mass renaming for the FreeTDS versions it bundles, with each version's wrapper in a separate namespace but all wrappers implementing the same base classes.

Comment on lines 23 to 22
#include <config.h>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including config.h is pretty standard in the source files, not in headers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. I would like for it to land before any declarations, but another look appears to indicate that adjusting src/ctlib/unittest/common.h to include config.h ahead of ctpublic.h should suffice at this point.

SQLSMALLINT sql_desc_count;
SQLUSMALLINT sql_desc_count;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this structure the types matches the relative type in descriptors, in this case SQL_DESC_COUNT from SQLSetDescField.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. As it stands, the type doesn't match desc_alloc_records's count argument, but I suppose that can and should change instead.

src/tds/data.c Outdated
@@ -723,6 +722,22 @@ tds_generic_get(TDSSOCKET * tds, TDSCOLUMN * curcol)
tdsdump_log(TDS_DBG_INFO1, "tds_get_data: type %d, varint size %d\n", curcol->column_type, curcol->column_varint_size);
switch (curcol->column_varint_size) {
case 4:
if (!is_blob_type(curcol->column_type)) {
/* Any other non-BLOB type (e.g., XSYBCHAR) */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Varint for XSYBCHAR is 2, not 4.
Is not this if handling also below case (SYBLONGBINARY) ?
To be honest I would invert varint 4 and 5, meaning "old" blobs (SYBTEXT, SYBNTEXT, SYBIMAGE) having a length for pointer (1 byte) and one for data (4 bytes) marked with 5 (1+4) and "new" blobs (SYBLONGBINARY and similar) with 4.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yeah, in retrospect I should have called out SYBLONG{BINARY,CHAR} here, and the SYBLONGBINARY code was indeed unused.

src/tds/ncbi_strerror.c Outdated Show resolved Hide resolved
src/tds/sspi.c Outdated Show resolved Hide resolved
src/tds/util.c Outdated Show resolved Hide resolved
ucko added 5 commits February 13, 2025 11:42
This distinction will initially be useful only for ctlib and dblib,
but applying it across the board may avoid possible confusion if it
turns out to be useful elsewhere too.

Signed-off-by: Aaron M. Ucko <ucko@ncbi.nlm.nih.gov>
* Account for possible renaming of cs_dt_crack (not just aliasing it
  to ..._v2), dbopen, tdsdump_dump_buf, and tdsdump_log; for the
  latter two, change the underlying functions' names to
  tdsdump_do_... modulo possible mass renaming.
* ctlib/unittests/common.h: Include config.h even earlier to avoid any
  possibility that such renaming lands too late; config.h should at
  this point precede any declarations.
* odbc_sql2tds: Treat SYB5INT8 like other numeric types.
* tds_generic_get: Handle non-blob types with four-byte sizes (e.g.,
  SYBLONG{BINARY,CHAR}).
* tds_generic_put_info: Send size 255 (0xff) for NULL short character
  types in output columns.

Signed-off-by: Aaron M. Ucko <ucko@ncbi.nlm.nih.gov>
* tds.h (is_blob_col): Consider column_type in addition to column_varint_size.
* Retire 5 as a nominal column_varint_size value in favor of unified logic.

Signed-off-by: Aaron M. Ucko <ucko@ncbi.nlm.nih.gov>
Signed-off-by: Aaron M. Ucko <ucko@ncbi.nlm.nih.gov>
@ucko ucko force-pushed the ncbi-2024-05-misc-improvements branch from 58c9ae5 to cc03c6d Compare February 14, 2025 20:35
ucko added 2 commits February 14, 2025 16:29
- Harmonize variable, parameter, etc. data types more fully.
- Adjust system API usage accordingly:
-- For some string constants, use sizeof() - 1 in lieu of strlen,
   taking care to ensure they come from array variables.
-- Keep format specifiers for printf et al. in sync with argument types.
-- dbprrow: Account for the fact that printf always uses int for
   dynamic widths by substituting memchr + fwrite.
-- odbc/prepare_query.c (prepared_rpc): Substitute atoi for strtol
   (already used with no endptr) when populating TDSINT4.
- Cast away some remaining discrepancies where safe, in some cases by
  taking advantage of TDS_PUT_* macros.
- ctlib.h: Explicitly define _CS_CURS_TYPE_* in terms of
  TDS_CURSOR_STATE_* rather than duplicating their values.
- odbc_util.c: #include <stddef.h> for ptrdiff_t (now used in
  odbc_set_string_flag).
- tds_parse_conf_section: To legitimize a cast, tighten debug_flags'
  range check on systems where int is narrower than long.

Signed-off-by: Aaron M. Ucko <ucko@ncbi.nlm.nih.gov>
All could at least potentially receive updates, but they were never
consulted or even logged.

Signed-off-by: Aaron M. Ucko <ucko@ncbi.nlm.nih.gov>
@ucko ucko force-pushed the ncbi-2024-05-misc-improvements branch from cc03c6d to c86e6ee Compare February 14, 2025 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants