Recent

Author Topic: from Firebird Database, SqlDb show Time as TDateTime  (Read 11187 times)

clauslack

  • Sr. Member
  • ****
  • Posts: 275
from Firebird Database, SqlDb show Time as TDateTime
« on: August 31, 2009, 08:37:11 pm »
I have a time field in Firebird 2.1
Flamerobin (with IBPP) show fine it as '10:47:22.000'

SqlDb with
- showmessage(SQLQuery1.FieldByName('hora').asstring);
and with DBGrid

show  '30/12/1899 10:47:22'

Any idea?
Some workarround for show fine in DBGrid?
Tested with Lazarus 0.9.27 svn 21317 fpc 2.3.1 svn 13383 under Windows 2000 SP4.

eDITED (2 SECONDS)
Thanks.
« Last Edit: August 31, 2009, 09:26:13 pm by clauslack »

Loesje

  • Full Member
  • ***
  • Posts: 168
    • Lazarus Support website
Re: from Firebird Database, SqlDb show Time as TDateTime
« Reply #1 on: August 31, 2009, 09:20:04 pm »
Are you sure both times differ two seconds?

To get rid of the date-part, you have to format the date (.asdatetime) as a time.

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: from Firebird Database, SqlDb show Time as TDateTime
« Reply #2 on: August 31, 2009, 09:41:38 pm »
showmessage(TimeToStr(SQLQuery1.FieldByName('hora').AsDateTime));
show fine the time.

Any idea for show fine in the DBGrid?

Thanks

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: from Firebird Database, SqlDb show Time as TDateTime
« Reply #3 on: September 05, 2009, 11:23:44 pm »
I found two workarround for this issue

- use firebird timestamp field.
- use fixed column in DBGrid with display format = hh:nn:ss


clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: from Firebird Database, SqlDb show Time as TDateTime
« Reply #4 on: October 23, 2009, 04:24:06 am »
I found the best solution for DBGrid without fixed column.
At runtime.
Code: [Select]
TColumn(DBGrid1.Columns[k]).DisplayFormat:='hh:mm:ss';
k= is the column with the time field.
So I can use the same DBGrid with many querys.

Regards
 :)

 

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: from Firebird Database, SqlDb show Time as TDateTime
« Reply #5 on: October 23, 2009, 02:40:22 pm »
The root of problem may be, that Firebird SQL type of TIME is translated to ftDateTime field in ibconnection.pp

SQL_TYPE_TIME :
      TrType := ftDateTime; //here we should use ftTime


clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: from Firebird Database, SqlDb show Time as TDateTime
« Reply #6 on: October 23, 2009, 02:56:37 pm »
I will test that, because under Delphi time field show fine(for create a bugreport)


Thanks

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: from Firebird Database, SqlDb show Time as TDateTime
« Reply #7 on: October 23, 2009, 03:30:46 pm »
I recompile ibconnection.pp with
SQL_TYPE_TIME :
      TrType := ftTime;

now dbgrid show
10:14
before showed
30/12/1899 10:14:31

with TColumn(DBGrid1.Columns[4]).DisplayFormat:='hh:mm:ss';
show 10:14:31

For me your patch is better, later I will create a a bug report.
What do you think?

Regards
« Last Edit: October 23, 2009, 10:03:48 pm by clauslack »

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: from Firebird Database, SqlDb show Time as TDateTime
« Reply #8 on: October 26, 2009, 07:52:14 am »
Default DispalyFormat for ftTime fields is formated using global variable ShortTimeFormat (look in fields.inc) , which is "hh:mm" by default.

In Delphi is for same purpose used LongTimeFormat, so you can submit also bug report - feature request to change default formating for ftTime fields from ShortTimeFormat to LongTimeFormat.

You can change global varible ShortTimeFormat (ShortTimeFormat:=LongTimeFormat), in you program and you will get what you want. (I hope ;-)))

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: from Firebird Database, SqlDb show Time as TDateTime
« Reply #9 on: October 26, 2009, 05:06:54 pm »
Report
SqlDb show Time as TDateTime

http://bugs.freepascal.org/view.php?id=14901




clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: from Firebird Database, SqlDb show Time as TDateTime
« Reply #10 on: November 01, 2009, 12:18:31 am »
Report
http://bugs.freepascal.org/view.php?id=14960

About LongTimeFormat in time fields with SQLdb

 

TinyPortal © 2005-2018