Trimming character columns

From: Cem ÇÖLGEÇEN <ccolgecen(at)gmail(dot)com>
To: pgsql-odbc(at)postgresql(dot)org
Subject: Trimming character columns
Date: 2016-06-29 15:23:34
Message-ID: CACVVsG28AEJaU5ts4tEq1+ivNm__Qm4iQ4ziFWuZnf16O6M+FA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-odbc

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.

Responses

Browse pgsql-odbc by date

  From Date Subject
Next Message Tsunakawa, Takayuki 2016-06-30 00:32:12 Re: Trimming character columns
Previous Message Tsunakawa, Takayuki 2016-06-29 05:47:32 Re: PostgreSQL: SQLSetPos fails with SetPos update return error.