Re: [gnome-db]Problems with a field date



I think that I found the problem, someone know why is this in the code?.

In the gda-postgres-provider
In the file:  gda-postgres-recordset.c

In the function:

static struct tm *
str_to_tmstruct_date(gchar *date)
{
  int day, month, year;
  char *ptr;
  char mdate[11];
  struct tm *stm;

  stm = (struct tm *) g_malloc(sizeof(struct tm));
  if ((date==NULL) || (*date=='\0'))
    {
      g_free(stm);
      return NULL;
    }

  strncpy(mdate, date, 10);
  mdate[10] = '\0';
  ptr=(char *) strtok(mdate, "-/.");
  month = atoi(ptr);
 if (!(ptr=(char *) strtok(NULL, "-/.")))
    {
      g_free(stm);
      return NULL; /* Error */
    }
  day=atoi(ptr);
  if (!(ptr=(char *) strtok(NULL, "-/.")))
    {
      g_free(stm);
      return NULL; /* Error */
    }
  year=atoi(ptr);

  stm->tm_mday = day;
  stm->tm_mon = month -1;
  stm->tm_year = year - 1900;

  return stm;
}

In the last part the assigment is month-1 and year-1900. I don't know the
reazon.

After this in the funcion

static void
fill_field_values (Gda_ServerRecordset *recset, POSTGRES_Recordset *prc)

case GDA_TypeDbDate:
              /* the date is DD-MM-YYYY, as set at connection opening */
              stm = NULL;
              if (native_value)
                {
                  stm = str_to_tmstruct_date(native_value);
                  if (stm)
                    {
                      GDate *date;

                      date = g_date_new_dmy(stm->tm_mday, stm->tm_mon,
                                            stm->tm_year+1900);
                      gda_server_field_set_date(field, date);
                      g_date_free(date);
                    }
                  else
                    gda_server_field_set_date(field, NULL);
                }
              if (!native_value || !stm)
                gda_server_field_set_date(field, NULL);


              if (stm)
                g_free(stm);
              break;

There is a call to g_date_new_dmy with stm->tm_year+1900. I don't know the
reazon.

I change in my code and after this the values with the dates are OK.

Thank you



----- Original Message -----
From: "Rodrigo Moya" <rodrigo gnome-db org>
To: "Branly Abendano" <babendan tecnopro net>
Cc: <gnome-db-list gnome org>; "Branly Abendano" <babendan tecnopro net>
Sent: Friday, May 18, 2001 1:42 PM
Subject: Re: [gnome-db]Problems with a field date


> On 18 May 2001 12:04:20 -0500, Branly Abendano wrote:
> > I found the problem.
> >
> > I think that the problem is with glib
> > I am using glib-1.2.10
> >
> > I checked this with code:
> >
> > day=31
> > month=12
> > year=2001
> >
> > g_date_valid_day (day))       // Return True    This is OK
> > g_date_valid_month (month)      // Return True    This is OK
> > g_date_valid_year (year)     // Return True       This is OK
> >
> > g_date_valid_dmy (day,month, year)    // Return False
> >
> > g_date_days_in_month(month,year)      // Return 30 and must return 31
> >                                                            // because
> > december has 31 days
> >
> > LIBGDA/providers/gda-postgres-server/gda-postgres-recordset.c call to
> > g_date_new_dmy(stm->tm_mday, stm->tm_mon, stm->tm_year+1900)
> >
> > This function g_date_new_dmy valid the dates with the function
> > g_date_valid_dmy(day,month,year)
> > and here is the problem because to LIBGDA return FALSE
> >
> > I proved with other date:
> >
> > day=30
> > month=12
> > year=2001
> >
> > And the result is OK. I don't know if just with day=31 is the problem
> >
> >
> > If someone knows the list of glib to ask about the problem
> >
> try in gtk-devel-list gnome org
>
> cheers
> --
> Rodrigo Moya <rodrigo gnome-db org> <rodrigo ximian com>
> http://www.gnome-db.org/
>
>
> _______________________________________________
> gnome-db-list mailing list
> gnome-db-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-db-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]