[freetds] some small patches...

Thompson, Bill D (London) ThompBil at exchange.uk.ml.com
Tue Apr 15 08:38:21 EDT 2003


Hi,

I have some small patches to apply.

I am currently working with code as of 19th March. 
As I am about to go into production with freetds in the next few weeks, I
don't want to take the latest snapshot with all the charset stuff, so these
patches are a bit *manual* in nature.
However, here goes:

There are a couple of patches to dblibrary (src/dblib/dblib.c)

The first concerns when datetime data is bound to a DBDATETIME structure and
a null date is returned from the database.
We are not "nulling" the host variable appropriately:

patch:

static void
_set_null_value(DBPROCESS * dbproc, BYTE * varaddr, int datatype, int
maxlen)
{
    switch (datatype) {
    case SYBINT8:
        memset(varaddr, '\0', 8);
        break;
    case SYBINT4:
        memset(varaddr, '\0', 4);
        break;
    case SYBINT2:
        memset(varaddr, '\0', 2);
        break;
    case SYBINT1:
        memset(varaddr, '\0', 1);
        break;
    case SYBFLT8:
        memset(varaddr, '\0', 8);
        break;
    case SYBREAL:
        memset(varaddr, '\0', 4);
        break;
+    case SYBDATETIME:
+        memset(varaddr, '\0', 8);
+        break;
    case SYBCHAR:
    case SYBVARCHAR:
        varaddr[0] = '\0';
        break;
    }
}

The next patches are to do with cleaning up on exit. 
Unfortunately my application in some circumstances calls dbexit() twice, and
we don't like that!
I have a new version of dbexit, which looks like this:

void
dbexit()
{
    TDSSOCKET *tds;
    DBPROCESS *dbproc;
    int i;
    const int list_size = g_dblib_ctx.connection_list_size;

    /* FIX ME -- this breaks if ctlib/dblib used in same process */
    for (i = 0; i < list_size; i++) {
        tds = g_dblib_ctx.connection_list[i];
        if (tds) {
            dbproc = (DBPROCESS *) tds->parent;
            if (dbproc) {
                dbclose(dbproc);
            }
        }
    }
    if (g_dblib_ctx.connection_list) {
       TDS_ZERO_FREE(g_dblib_ctx.connection_list);
        g_dblib_ctx.connection_list_size = 0;
    }
    if (g_dblib_ctx.tds_ctx) {
        tds_free_context(g_dblib_ctx.tds_ctx);
        g_dblib_ctx.tds_ctx = NULL;
    }
}

This goes along with a couple of changes to some cleanup functions in
src/tds/mem.c
I have amended the functions tds_free_context() and tds_free_locale(). My
new versions look like this

void tds_free_context(TDSCONTEXT *context)
{
    if (context && context->locale) {
        tds_free_locale(context->locale);
        context->locale = NULL;
    }
    if (context)
        TDS_ZERO_FREE(context);
}


void tds_free_locale(TDSLOCALE *locale)
{
    if (locale) {
        if (locale->language) TDS_ZERO_FREE(locale->language);
        if (locale->char_set) TDS_ZERO_FREE(locale->char_set);
        if (locale->date_fmt) TDS_ZERO_FREE(locale->date_fmt);
        TDS_ZERO_FREE(locale);
    }
}


If I can give these patches over in a better format, just ask.
Otherwise thanks as ever,

Bill


¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø¤º°`°º¤ø,¸¸,ø¤

Bill Thompson
Securities Services Division
Merrill Lynch Europe

For very important information relating to this e-mail please click on this
link:  http://www.ml.com/legal_info.htm





More information about the FreeTDS mailing list