Thread: Trimming character columns

Trimming character columns

From
Cem ÇÖLGEÇEN
Date:
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.

Re: Trimming character columns

From
"Tsunakawa, Takayuki"
Date:

From: pgsql-odbc-owner@postgresql.org [mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of Cem COLGECEN
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