DevHeads.net

Trimming character columns

Hi,

I want to trimming character(char) columns via ODBC driver. I've done
something like this and it works, but I'm not satisfied.

file: convert.c

/*
* First convert any specific postgres types into more useable data.
*
* NOTE: Conversions from PG char/varchar of a date/time/timestamp value
* to SQL_C_DATE,SQL_C_TIME, SQL_C_TIMESTAMP not supported
*/
switch (field_type)
{
/*
* $$$ need to add parsing for date/time/timestamp strings in
* PG_TYPE_CHAR,VARCHAR $$$
*/

/*ADDED*/ case 1042:
/*ADDED*/ rtrim(value);
/*ADDED*/ break;

case PG_TYPE_DATE:
sscanf(value, "%4d-%2d-%2d", &std_time.y, &std_time.m, &std_time.d);
break;

case PG_TYPE_TIME:
{

BOOL bZone = FALSE; /* time zone stuff is unreliable */
int zone;
timestamp2stime(value, &std_time, &bZone, &zone);
}
break;

I have rtim function:

void rtrim(char *str) {
char *s;
s = str + strlen(str);
while (--s >= str) {
if (!isspace(*s)) break;
*s = 0;
}
}

How do I make it more stable?

Thank you.

Comments

Re: Trimming character columns

By Tsunakawa, Takayuki at 06/29/2016 - 20:32

I want to trimming character(char) columns via ODBC driver. I've done something like this and it works, but I'm not satisfied.
How do I make it more stable?

Could you elaborate on what you are unsatisfied with? How unstable?

Why don’t you use the SQL standard rtim() function in your SQL statements, instead of modifying the ODBC driver?

Regards
Takayuki Tsunakawa