Skip to Content.
Sympa Menu

freetds - [freetds] Chamber tydy up

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddyz77 AT tin.it>
  • To: FreeTDS <freetds AT lists.ibiblio.org>
  • Subject: [freetds] Chamber tydy up
  • Date: 06 Apr 2003 12:24:59 +0200

Tidying up my chamber I founded some printed and annotated listing
(mainly token.c file) so I decided to include changes into CVS (many of
them was already applied but there wasn't many comments left).

Just to discuss some of them (comment begin with ***)...

diff -u -u -1 -0 -b -r1.167 token.c
--- src/tds/token.c 6 Apr 2003 09:20:55 -0000 1.167
+++ src/tds/token.c 6 Apr 2003 09:51:36 -0000
@@ -308,20 +312,21 @@
* present on failure */
if (ack == 5 || ack == 1)
succeed = TDS_SUCCEED;
break;
default:
if (tds_process_default_tokens(tds, marker) ==
TDS_FAIL) return TDS_FAIL;
break;
}
} while (marker != TDS_DONE_TOKEN);
+ /* TODO why ?? */
tds->spid = tds->rows_affected;

*** why server return spid in rows_affected? And which servers ??
*** is this right ??

if (tds->spid == 0) {
if (tds_set_spid(tds) != TDS_SUCCEED) {
tdsdump_log(TDS_DBG_ERROR, "%L tds_set_spid()
failed\n");
succeed = TDS_FAIL;
}
}
tdsdump_log(TDS_DBG_FUNC, "%L leaving tds_process_login_tokens()
returning %d\n", succeed);
return succeed;
}
@@ -622,21 +629,21 @@
tds->curr_resinfo = info;
tds_process_compute(tds);
if (computeid)
*computeid = compute_id;

return TDS_SUCCEED;

case TDS_DONE_TOKEN:
case TDS_DONEPROC_TOKEN:
case TDS_DONEINPROC_TOKEN:
-
+ /* FIXME should we just return without reading
token ?? */

*** (inside tds_process_row_results)
*** in tds_process_result_tokens we return these as results
*** while here we discard is... is this correct??

tds_process_end(tds, marker, NULL);
*rowtype = TDS_NO_MORE_ROWS;
return TDS_NO_MORE_ROWS;

default:
if (tds_process_default_tokens(tds, marker) ==
TDS_FAIL) return TDS_FAIL;
break;
}
}
@@ -1730,20 +1741,21 @@
return TDS_SUCCEED;
}

/**
* tds_process_end() processes any of the DONE, DONEPROC, or DONEINPROC
* tokens.
* @param marker TDS token number
* @param flags_parm filled with bit flags (see TDS_DONE_ constants).
* Is NULL nothing is returned
*/
+/* FIXME this should be static, not public */
TDS_INT
tds_process_end(TDSSOCKET * tds, int marker, int *flags_parm)
{

*** IMHO this function should be static...
*** why client library should process end ??

int more_results, was_cancelled, error, done_count_valid;
int tmp;

tmp = tds_get_smallint(tds);

more_results = (tmp & TDS_DONE_MORE_RESULTS) != 0;
was_cancelled = (tmp & TDS_DONE_CANCELLED) != 0;
@@ -1772,21 +1784,21 @@
/* rows affected is in the tds struct because a query may affect
rows but
* have no result set. */

if (done_count_valid)
tds->rows_affected = tds_get_int(tds);
else {
tmp = tds_get_int(tds); /* throw it away */
tds->rows_affected = TDS_NO_COUNT;
}

-
+ /* TODO return only success and client should check flags */

*** (inside tds_process_end)
*** in may tds_process_* functions we return TDS_FAIL only on
** connection problems. Why tds_process_end behavior is different ??

if (error)
return TDS_FAIL;
else
return TDS_SUCCEED;
}



/**
* tds_client_msg() sends a message to the client application from the
CLI or
@@ -1811,20 +1823,21 @@
msg_info.msg_state = state;
/* TODO is possible to avoid copy of strings ? */
msg_info.server = strdup("OpenClient");
msg_info.line_number = line;
msg_info.message = strdup(message);
ret = tds_ctx->err_handler(tds_ctx, tds, &msg_info);
tds_free_msg(&msg_info);
/* message handler returned FAIL/CS_FAIL
* mark socket as dead */
if (ret && tds) {
+ /* TODO close socket too ?? */

*** why setting state TDS_DEAD and do not close connection ??

tds->state = TDS_DEAD;
}
}
return 0;
}

/**
* tds_process_env_chg()
* when ever certain things change on the server, such as database,
character
* set, language, or block size. A environment change message is
generated
@@ -1947,20 +1960,21 @@
len_sqlstate = tds_get_byte(tds);
msg_info.sql_state = (char *) malloc(len_sqlstate + 1);
tds_get_n(tds, msg_info.sql_state, len_sqlstate);
msg_info.sql_state[len_sqlstate] = '\0';

/* do a better mapping using native errors */
if (strcmp(msg_info.sql_state, "ZZZZZ") == 0)
TDS_ZERO_FREE(msg_info.sql_state);

/* junk status and transaction state */
+ /* TODO if status == 1 clear cur_dyn and param_info ??
*/
tds_get_byte(tds);
tds_get_smallint(tds);

/* EED can be followed to PARAMFMT/PARAMS, do not store
it in dynamic */
tds->cur_dyn = NULL;
break;
case TDS_INFO_TOKEN:
msg_info.priv_msg_type = 0;
break;
case TDS_ERROR_TOKEN:
@@ -2049,20 +2063,22 @@
if (marker == TDS_DONE_TOKEN) {
tds_process_end(tds, marker, &done_flags);
} else if (marker == 0) {
done_flags = TDS_DONE_CANCELLED;
} else {
tds_process_default_tokens(tds, marker);
}
} while (!(done_flags & TDS_DONE_CANCELLED));
tds->state = TDS_COMPLETED;

+ /* TODO clear cancelled results */
+

*** (inside tds_process_cancel)
*** This function had a long story of changes...
*** I think after processing cancel we should discard
*** all results...
*** Also, what's the best time to free results?
*** on TDS_DONE* or on query send ??


return 0;
}

/**
* set the null bit for the given column in the row buffer
*/
void
tds_set_null(unsigned char *current_row, int column)
{
int bytenum = ((unsigned int) column) / 8u;
@@ -2326,20 +2348,22 @@
break;
case SYBMONEY:
case SYBDATETIME:
tds_swap_bytes(buf, 4);
tds_swap_bytes(&buf[4], 4);
break;
case SYBDATETIME4:
tds_swap_bytes(buf, 2);
tds_swap_bytes(&buf[2], 2);
break;
+ /* should we place numeric conversion in another place ??
+ * this is not used for big/little-endian conversion... */

*** (inside tds_swap_datatype)
*** tds_swap_datatype in mainly used in big-endian->little-endian
*** conversions (or viceversa) but the following conversion is used
*** to convert from MS wire type to TDS internal type...

case SYBNUMERIC:
case SYBDECIMAL:
num = (TDS_NUMERIC *) buf;
/* swap the sign */
num->array[0] = (num->array[0] == 0) ? 1 : 0;
/* swap the data */
tds_swap_bytes(&(num->array[1]),
tds_numeric_bytes_per_prec[num->precision] - 1);
break;
case SYBUNIQUE:
tds_swap_bytes(buf, 4);


freddy77




  • [freetds] Chamber tydy up, Frediano Ziglio, 04/06/2003

Archive powered by MHonArc 2.6.24.

Top of Page