Problems with Date in Firebird / Problemas con fechas en Firebird lazarus / 16-Databases ---------------------------------------------------------------------- egbaquela · 2010-07-05 01:44 **************************************** In (bad) english **************************************** Hello everyone. I am having a problem with the data type "Date" in Firebird. I created a database in Firebird and I imported massively data from another database in MS Access. The field of type "Date" in MS Access was captured in the next way: Code: [Select]procedure ExportarDatos var          DTFecha: string;          Dia, Mes, Anio : word;          ... begin          ...          if  dmdDataMod.SQLTabla.FieldByName('DTFecha').AsString = '' then             DTFecha:= 'NULL'          else          begin             DecodeDate(dmdDataMod.SQLITabla.FieldByName('DTFecha').AsDateTime, Anio, Mes, Dia);             DTFecha :=  '''' + inttostr(Dia) + '.' + inttostr(Mes) + '.' + inttostr(Anio) + '''';          end;         ... And to load the firebird data base I used the following SQL query (within the procedure above): Code: [Select]      with SQLEjecutable do begin          close;          sql.clear;          sql.add('INSERT INTO tblTabla(..., DTFecha,... ) VALUES (... +', ' + DTFecha +',  ' ...);          readonly:= true;          usePrimaryKeyAsKey:= false;       end;       if SQLTransaction.Active then SQLTransaction.Commit;       SQLTransaction.StartTransaction;       SQLEjecutable.ExecSQL;       SQLTransaction.Commit; The data is recorded correctly, and when I use a SELECT for show the data in a TdbGrid, it display the correct value. The problem is when I update records from the client application (not Access, but from Lazarus). The registers are updated with the following code: Code: [Select]procedure actualizarRegistro var    strFecha: string;    Dia, Mes, Anio : word; begin    DecodeDate(deFecha.Date  , Anio, Mes, Dia);    strFecha := '''' + inttostr(Dia) + '.' + inttostr(Mes) + '.' + inttostr(Anio) + '''';    with SqlQuery do begin       close;       sql.clear;       sql.add('UPDATE tblIsometricos SET dtFecha = ' + strFecha + ' WHERE IDReg = ' +  SQLTabla.FieldByName('IDReg').AsString);       readonly:= true;       usePrimaryKeyAsKey:= false;    end;    if SQLTransaction.Active then SQLTransaction.Commit;    SQLTransaction.StartTransaction;    SQLQuery.open ; end; Where "deFecha" is aTDateEdit, "SQLQuery", "SQLTables" and "SQLEjecutable" are TSQLQuery,  and "SqlTransaction" is a SqlTransaction. When I do a SELECT and show the results in a TDBGrid, the dates are showing in format the operating system (Windows XP in my case), which is DD / MM / YYYY. But when I export the table contents to a file "TXT", the dates massively loaded in Firebird from MS ACCESS respect the format DD / MM / YYYY, but the dates updated from the client are changing the format MM / DD / YYYY (but in the TDBGrid they are displayed as DD / MM / YYYY). I get the date for export with the following code: Code: [Select]var     strFecha: string;     ... begin     ...     strFecha:= SQLTabla.FieldByName('dtFecha').AsString;     ... end; Any export records has both "new" as the bulk load. What baffles me is that this format change is done only for the "new" records, massively loaded records behave correctly (ie, both TDBGrid as in the generated text file have the same format). Does anyone know why this happen?. Greetings, Gabriel. PD: sorry by my english, is very poor. www.egbaquela.com.ar **************************************** En Español **************************************** Hola a todos. Estoy teniendo un problema con el tipo de datos "Date" en Firebird. Cree una base de datos en Firebird y exporté masivamente datos de otra base de datos de MS Access. Los campos de tipo "Date" del MS Access los capturé así: Code: [Select]procedure ExportarDatos var          DTFecha: string;          Dia, Mes, Anio : word;          ... begin          ...          if  dmdDataMod.SQLTabla.FieldByName('DTFecha').AsString = '' then             DTFecha:= 'NULL'          else          begin             DecodeDate(dmdDataMod.SQLITabla.FieldByName('DTFecha').AsDateTime, Anio, Mes, Dia);             DTFecha :=  '''' + inttostr(Dia) + '.' + inttostr(Mes) + '.' + inttostr(Anio) + '''';          end;         ... Y para cargar los datos a la base firebird utilicé la siguiente consulta SQL (dentro del mismo procedimiento anterior): Code: [Select]      with SQLEjecutable do begin          close;          sql.clear;          sql.add('INSERT INTO tblTabla(..., DTFecha,... ) VALUES (... +', ' + DTFecha +',  ' ...);          readonly:= true;          usePrimaryKeyAsKey:= false;       end;       if SQLTransaction.Active then SQLTransaction.Commit;       SQLTransaction.StartTransaction;       SQLEjecutable.ExecSQL;       SQLTransaction.Commit; Los datos se graban correctamente, y al utilizar un SELECT también me aparecen con el valor correcto. El problema es cuando actualizo registros desde el cliente de la aplicación (ya no de Access, sinó desde Lazarus). Los registros los actualizo con el siguiente código: Code: [Select]procedure actualizarRegistro var    strFecha: string;    Dia, Mes, Anio : word; begin    DecodeDate(deFecha.Date  , Anio, Mes, Dia);    strFecha := '''' + inttostr(Dia) + '.' + inttostr(Mes) + '.' + inttostr(Anio) + '''';    with SqlQuery do begin       close;       sql.clear;       sql.add('UPDATE tblIsometricos SET dtFecha = ' + strFecha + ' WHERE IDReg = ' +  SQLTabla.FieldByName('IDReg').AsString);       readonly:= true;       usePrimaryKeyAsKey:= false;    end;    if SQLTransaction.Active then SQLTransaction.Commit;    SQLTransaction.StartTransaction;    SQLQuery.open ; end; Donde "deFecha" es un TDateEdit de form que ejecuta el procedimiento, "SQLQuery", "SQLTabla" y "SQLEjecutable" son TSQLQuery, "SQLTransaction" es un SQLTransaction. Cuando hago un SELECT y muestro los resultados en un TDBGrid, las fechas me parecen en el formato del sistema operativo (Windows XP en mi caso), el cual es DD/MM/YYYY. Pero, cuando exporto el contenido de la tabla a un archivo "TXT", las fechas que se cargaron en forma masiva siguen respetanto el formato DD/MM/YYYY pero la que se agregaron desde el cliente se cambian al formato MM/DD/YYYY, por mas que en el TDBGrid se muestren como DD/MM/YYYY. La obtención de la fecha para la  exportación la realizo con el siguiente código: Code: [Select]var     strFecha: string;     ... begin     ...     strFecha:= SQLTabla.FieldByName('dtFecha').AsString;     ... end; Cualquier exportación dispone tanto de registros "nuevos" como de los cargados masivamente. Lo que me desconcierta es que este cambio de formato lo realiza solo para los registros "nuevos", los registros cargados masivamente se comportan correctamente (es decir, tanto en el TDBGrid como en el archivo de texto generado mantienen el mismo formato). ¿Alguien sabe por que puede estar pasando esto?. Saludos, Gabriel. www.egbaquela.com.ar ---------------------------------------------------------------------- egbaquela · 2010-07-06 02:04 ******************* In (bad) English ******************* Well, at finish, I could solve my problem, but not ortodoxily: I did not make a query over the table, I made a query over a view. This view has a day field, a month field and a year field, all of them calculated by Firebird's Functions. Then, I join these field in a string var in my Lazarus's program. But, I continue question to me why Lazarus generate the error ¿? Greetings, Gabriel. ******************* En Español ******************* Bueno, al final lo pude solucionar pero no muy ortodoxamente: en vez de consultar la tabla, consulto una vista de SQL que en vez del campo fecha tiene los campos día, mes y año extraidos con las funciones Day, Month y Year de Firebird. Después, concateno los valores en un string. Igual, me quedó la duda de porque Lazarus se comporta así. Saludos, Gabriel.