The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Archive for the ‘Firebird’ Category

Firebird – adjusting Delphi stored TDateTime (or OLE Automation date) fields that contain Dates, Times or DateTimes

Posted by jpluimers on 2017/02/15

Delphi programmers often store TDateTime (be it date, time or date+time values) as floating points in the database. They take the easy way out basically because TDateTime is nothing but a typed alias for the Delphi Double type (which is equivalent to the IEEE 754 double-precision binary floating-point format: binary64 type) .

Actually, TDateTime is equivalent to the OLE Automation date (which is described in the remarks of  DateTime.ToOADate Method (System)) which has an epoch of  midnight at 1899-12-30 (to be compatible with Lotus-123 including its leap-year-bug, background on that is at Why are the Microsoft Office file formats so complicated? (And some workarounds) – Joel on Software).

Anyway: the definition is this:

An OLE Automation date is implemented as a floating-point number whose integral component is the number of days before or after midnight, 30 December 1899, and whose fractional component represents the time on that day divided by 24. For example, midnight, 31 December 1899 is represented by 1.0; 6 A.M., 1 January 1900 is represented by 2.25; midnight, 29 December 1899 is represented by -1.0; and 6 A.M., 29 December 1899 is represented by -1.25.

The base OLE Automation Date is midnight, 30 December 1899. The minimum OLE Automation date is midnight, 1 January 0100. The maximum OLE Automation Date is the same as DateTime.MaxValue, the last moment of 31 December 9999.

The sample values are remarkably the same as the ones for TDateTime:

Value Description
0 December 30, 1899; 12:00 A.M.
2.75 January 1, 1900; 6:00 P.M.
-1.25 December 29, 1899; 6:00 A.M.
35065 January 1, 1996; 12:00 A.M.

The below SQL example uses the Firebird date/time/timestamp casting shortcuts:

select date      '1899-12-30'              + 42452.670590278 as Date20160323,
       timestamp '1899-12-30 00:00:00.000' + 42452.670590278 as DateTime20160323160539,
       time       '00:00:00'                + 60*60*24 * 0.5 as Noon,
       timestamp '1899-12-30 00:00:00.000' + 0          as DateTime18991230Midnight,
       timestamp '1899-12-30 00:00:00.000' + 2.75           as DateTime190001011800,
       timestamp '1899-12-30 00:00:00.000' + -1.25          as DateTime189912290600,
       timestamp '1899-12-30 00:00:00.000' + 35065          as DateTime19960101Midnight
from   rdb$database

Which – using DMY date format and 24 hour clock format settings – results in:

DATE20160323 DATETIME20160323160539 NOON       DATETIME18991230MIDNIGHT DATETIME190001011800 DATETIME189912290600 DATETIME19960101MIDNIGHT CONSTANT
---------------------------------------------------------------------------------------------------------------------------------------------------
24-3-2016    23-3-2016 16:05:39     12:00:00   30-12-1899               1-1-1900 18:00:00    28-12-1899 18:00:00  1-1-1996

Which basically taught me a new thing about firebird: Times are calculated in seconds, so date fractions need to be multiplied by 60 * 60 * 24.

You can see this in the following query and results:

select (cast('Now' as time) - cast('00:00:00.000' as time)) / (24 * 60 * 60) as DelphiTime,
        cast('Now' as time) - cast('00:00:00.000' as time) as SecondsSinceMidnight,
        cast('Now' as date) - cast('1899-12-30' as date) as DelphiDate,
        cast('Now' as timestamp) - cast('1899-12-30 00:00:00.000' as timestamp) as DelphiDateTime,
        24 * 60 * 60 as SecondsPerDay,
        cast('Now' as date) as "Date",
        cast('Now' as time) as "Time",
        cast('Now' as timestamp) as "TimeStamp"
from rdb$database
DELPHITIME           SECONDSSINCEMIDNIGHT DELPHIDATE  DELPHIDATETIME       SECONDSPERDAY        Date       Time         TimeStamp          
------------------------------------------------------------------------------------------------------------------------------------------------
0,4366               37722,284            42835       42835,436600509      86400                10-4-2017  10:28:42     10-4-2017 10:28:42      

Note this post is complementary to Date format converter from Text or Unix/Mac/Filetime/Microsoft to virtually any readable form (which mentions the wrong Microsoft epoch as it should be 1899-12-30 midnight): the above shows how to do the conversion to readable dates in Firebird (might work in InterBase as well, but I’ve not used that for a long time).

–jeroen

PS: for Microsoft SQL Server: passing dates to the sql server: pass it as float – 2. -2 is the difference between delphi tdatetime start date and mssql start date.

 

Posted in Algorithms, Database Development, Development, Firebird, Floating point handling, Software Development | 2 Comments »

How to speed up Count(*) in InterBase/Firebird – Stack Overflow

Posted by jpluimers on 2017/02/14

The drawback of how the multigenerational architecture is implemented:

Even when an index is available on the column or columns included in the COUNT, all records must be visited in order to see if they are visible under the current transaction isolation.

The benefits of the MGA (multi-generational architecture) having far less locking than other architectures means you need to be careful using the COUNT operator on large result-sets.

In many systems the exact result of a COUNT isn’t very important, so you can use the workaround referred from How to speed up Count(*) in Interbase/Firebird – Stack Overflow

See also:

–jeroen

via: Select count(*) is slow

Posted in Database Development, Development, Firebird, InterBase | Leave a Comment »

Firebird – date and time literals, conversion to ISO-8601 compatible strings

Posted by jpluimers on 2016/12/28

For my reference:

select 'Date literal values' as description
      , (cast('now' as timestamp)) as nowTimeStamp
      , (cast('today' as timestamp)) as todayTimeStamp
      , (cast('tomorrow' as timestamp)) as tomorrowTimeStamp
      , (cast('yesterday' as timestamp)) as yesterdayTimeStamp
      , cast(cast('Now' as date) as varchar(10)) as nowDateCast
      , replace(cast(cast('Now' as date) as varchar(10)), '-', '') nowDateIso8601
      , cast(cast('Now' as time) as varchar(13)) as nowTimeCast
      , replace(cast(cast('Now' as time) as varchar(13)), ':', '') nowTimeIso8601
      , cast(cast('Now' as timestamp) as varchar(24)) as nowTimeStampCast
      , substring(replace(replace(replace(cast(cast('Now' as timestamp) as varchar(24)), '-', '') , ' ', 'T'), ':', '') from 1 for 15) as nowTimeStampIso8601
from rdb$database 
;

Output and transposed output:

DESCRIPTION         NOWTIMESTAMP            TODAYTIMESTAMP          TOMORROWTIMESTAMP       YESTERDAYTIMESTAMP      NOWDATECAST NOWDATEISO8601 NOWTIMECAST   NOWTIMEISO8601 NOWTIMESTAMPCAST         NOWTIMESTAMPISO8601     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Date literal values 3-8-2016 8:45:12        3-8-2016                4-8-2016                2-8-2016                2016-08-03  20160803       08:45:12.3860 084512.3860    2016-08-03 08:45:12.3860 20160803T084512         

DESCRIPTION             Date literal values
NOWTIMESTAMP            2016-08-03 8:45:12
TODAYTIMESTAMP          2016-08-03
TOMORROWTIMESTAMP       2016-08-04
YESTERDAYTIMESTAMP      2016-08-02
NOWDATECAST             2016-08-03
NOWDATEISO8601          20160803
NOWTIMECAST             08:45:12.3860
NOWTIMEISO8601          084512.3860
NOWTIMESTAMPCAST        2016-08-03 08:45:12.3860
NOWTIMESTAMPISO8601     20160803T084512

References:

–jeroen

Posted in Database Development, Development, Firebird | Leave a Comment »

Firebird [# CORE-3558] server reports that DB file is used by another application on secondary attachment attempt through a symlink

Posted by jpluimers on 2016/12/15

It took quite a while to find out what happened, but this is the underlying issue: [# CORE-3558] FB server reports that DB file is used by another application on secondary attachment attempt through a symlink – Firebird RDBMS Issue Tracker.

The error you get in Windows is this one: I/O error during “CreateFile (open)” “The process cannot access the file because it is being used by another process.”

When you look with Process Explorer or handle.exe (both from SysInternals) they will show exactly the same filename (the canonical name to which the SymLink points).

But when you look in the config files of the applications, the database connections point to different filenames. Either (or both) are a symlink themselves or have a directory in their path that is a symlink.

 

In my case it was the latter: one of the directories in the path had an mklink.exe created link to another directory that had a directory contained the final file. There is even an API function that gets the canonical file name: GetFinalPathNameByHandle function (Windows)

Firebird doesn’t use that API on Windows (probably because it’s only available as of Windows Vista and Windows Server 2008) but does use a similar POSIX function (so on Mac OS X and Linux you don’t get this error).

Note that the above error messages can also happen when you use an embedded connection to a database (i.e. a connection string without a network address). There it is normal you get an exclusive file lock.

–jeroen

via: ADO.NET – a problem with multiple connections to the database (Russian) with Google Translate

Posted in Database Development, Development, Firebird, Software Development | Leave a Comment »

Firebird gbak backing up a remote database that has spaces in the path and is on a remote Windows machine

Posted by jpluimers on 2016/09/13

I will likely need a batch file like this again:

setlocal
set gbakExe=C:\Program Files (x86)\Firebird\Firebird_2_5\bin\gbak.exe
set dbPart=MyDatabase
set dbSource=192.168.199.24:C:\Path with spaces\%dbPart%.fdb
set dbUser=sysdba
set dbPassword=masterkey
"%gbakExe%" -verify -transportable -user %dbUser% -password %dbPassword% "%dbSource%" %dbPart%.fbk
endlocal

You need the quotes around %gbakExe% and %dbSource% to ensure spaces in paths are preserved.

–jeroen

Sources:

Posted in Batch-Files, Database Development, Development, Firebird, Scripting, Software Development | Leave a Comment »

Im memoriam: Gwan Tan, friend, Delphi, Firebird, EKON and Delphi-Tage supporter

Posted by jpluimers on 2016/07/11

Overlijdensbericht Swie Gwan Tan; Eindhovens Dagblad; 20160711

Overlijdensbericht Swie Gwan Tan Eindhovens Dagblad; 20160711

Last friday, my good friend Swie Gwan Tan suddenly passed away. Like most good friends, we didn’t see each other often enough, but when we did it always was like we had last seen each other the day before.

We first met ages ago at early BorCon and EKON conferences: I remember them: Gwan, a little chine guy and a really really tall guy (Edwin) on many conferences. It didn’t take long before we chatted and became friends. It must have been the mid 199os, not even sure which year.

Was it the way he was a people person and both Edwin and me very technical? Or he deep into the database side of things and Edwin/me on the Delphi (and later .NET) side? Or were it the long (usually nights) of discussing all sorts of topics (way beyond software development) with some moderate alcohol intake?

I’m still not sure why. These things happen. The beauty of friendships.

Of course I knew Gwan was ill. More than a decade ago walking became more difficult because of a progressive muscle disease that would not affect his heart. Over time he got bound to a wheel-chair. Somewhere in-between he got a heart condition too.

Gwan stayed imperturbable and optimistic. He was enjoying watching sports (Gwan was – despite living near Eindhoven – a huge fan of AJAX, Edwin of Feyenoord, I didn’t care about soccer at all: we had so much fun!) current affairs and movies keeping in touch with so many people. Irregularly he even managed to visit both German and soccer matches. It was so good to see how he enjoyed those. He was also a great family guy: organising events was his thing. His siblings, nephews and nieces always had a great time when meeting him. And then there were the yearly summer BBQ events in the party: awesome!

So it was only natural that – after we started cooperating with better office Germany – Gwan would organise the Dutch “Knowledge Days” events and the technical guys (usually Edwin and me from the Dutch side and Daniel Magin from better office Germany) would present the sessions.

When better office Germany got in trouble (long story) Gwan asked if I could financially help him to take a stake so at least the German personnel could be payed. We did, lost financially but earned life long friendships (and learned a thing or two on how banks operate).

One of the things with Gwan was that there never was a dull moment and always an opportunity to learn. Even from mistakes. Of course we had words once every now and then. But never a really big fight. I guess that’s part of a good friendship.

Another thing was the combination of being modest about himself and proud about others. For example he always proudly named one of his sisters” my little sister” as he was so fond of what she accomplished.

I vividly remember spring 2009 when – right after the Delphi Live 2009 conference – some USA friends, Edwin and me organised a surprise 50th birthday dinner party for Gwan. Despite his condition, Gwan was really happy that he made it to the conference. So having a party like that was a total blast.

He attended way more conferences and seminars than I did, especially an Germany. Unlike me, Gwan loved driving long distance. So he attended many Firebird, Delphi-Tage and other events I didn’t make it to. When I was at events, I could always spot Gwan with lots of people around him. usually near a bar (:

Around the time Gwan’s mom died about 3.5 months ago he spent some time in hospital to treat the edema that came with his muscle condition. It took a while, but the medicines worked, he attended the funeral and moved to an apartment with facilities for disabled and direct access to care.

Last week he had was hospitalised and his conditions worsened faster than anyone expected. Friday morning he quietly passed away. No more pain. No more sorrow.

Sadly we are left behind, but also pleased that his ordeal is over.

A dear, generous, modest and positive friend is gone.

Attending the funeral service

If you want to attend the funeral service, please let me know so I can inform the family of an attendance estimate.

The funeral service will be held on Thursday morning July 14 at 11:30 at this location (they begin 11:30 sharp, be early!):

Onze Lieve Vrouw Presentatiekerk AalstEindhovenseweg 63
5582 HP Aalst -Waalre
The Netherlands

Phone: +31 40 221 22 85 (preferably between 10:00 and 12:00)

The above catholic church is easy to find as it is right in the center of Aalst-Waalre (see the church icon on the map). They welcome everyone: non-catholics and atheist are equally welcome.

There are parking spots nearby on the south side of “de Leesakker” (right behind Greek restaurant Olympia) or in the street next to Restaurant Lugar (for both, see the P markings on the map).

To stay: look for Hotels near Aalst-Waalre. I can recommend the Van der Valk Hotel Eindhoven as Gwan and I have organised some workshops and seminars there.

Sending flowers

Gwan in 2010

Gwan in 2010

If you want to send flowers, make sure they arrive Wednesday afternoon July 13 at this funeral service:

Monuta Sol funeral service
attn. family of Swie Gwan Tan
Felix Timmermanslaan 2
5644 RN  Eindhoven
The Netherlands

Phone: +31 40 212 9800

Monday (today) opportunity to condole

Today, Monday July 11 there will be a brief opportunity to condole the family from 16:30 till 17:30 at this funeral service:

Monuta Sol funeral service
Felix Timmermanslaan 2
5644 RN  Eindhoven
The Netherlands

Phone: +31 40 212 9800

Dutch “overlijdensbericht”

Op 8 juli 2016 is onze lieve, gulle, dappere broer en oom overleden.

Swie Gwan Tan

* Eindhoven, 16 mei 1959           ✝ Veldhoven, 8 juli 2016

zoon van

Sing Liong Tan en Polly Tan-The

  • Voorschoten: Swie Tjiang en Ida
  • Waalre: Yu Kai
  • Voorschoten: Li Sha en Jordi
  • Amstelveen: Swie Han en Marion
  • Amsterdam: Li Mai en Derek; Yu Ri en Marre
  • Amsterdam: Ingkie en Loes
  • Parijs: Xiu Lin en Bart; Qi Bo, Qi Mo, Qi San

Correspondentieadres:
Monuta Sol, t.a.v. familie Tan
Felix Timmermanslaan 2, 5644 RN  Eindhoven

De uitvaartdienst wordt gehouden op donderdag 14 juli a.s. om 11:30 uur in de Onze Lieve Vrouw Presentatiekerk, aan de Eindhovenseweg 63 te Waalre.

Later die dag brengen we Gwan in besloten krijg naar het crematorium te Heeze

Indien U geen persoonlijk bericht heeft ontvangen, gelieve deze aankondiging als zodanig te beschouwen.

English translation:

On July 8, 2016, our dear, generous, brave brother and uncle deceased.

Swie Gwan Tan

* Eindhoven, May 16, 1959           ✝ Veldhoven, July 8, 2016

son of

Sing Liong Tan and Polly Tan-The

  • Voorschoten: Swie Tjiang en Ida
  • Waalre: Yu Kai
  • Voorschoten: Li Sha en Jordi
  • Amstelveen: Swie Han en Marion
  • Amsterdam: Li Mai en Derek; Yu Ri en Marre
  • Amsterdam: Ingkie en Loes
  • Parijs: Xiu Lin en Bart; Qi Bo, Qi Mo, Qi San

Mailing address:
Monuta Sol funeral service
attn. Tan family
Felix Timmermanslaan 2
5644 RN  Eindhoven
The Netherlands

The funeral service will be held on Thursday, July 14 a.s. at 11:30 pm in the Onze Lieve Vrouw Presentatiekerk, Eindhovenseweg 63 Waalre.

Later that day we will privately bring over Gwan to the cremation center in Heeze.

–jeroen

Posted in About, Database Development, DB2, Delphi, Development, Firebird, History, InterBase, Personal, Software Development | 5 Comments »

Firebird News » Migration Guide to Firebird 3

Posted by jpluimers on 2016/05/02

Reminder to self so I buys this: Firebird News » Migration Guide to Firebird 3

–jeroen

via: Ondrej Kelle

Posted in Database Development, Development, Firebird | Leave a Comment »

Great Unicode presentation by

Posted by jpluimers on 2015/01/21

Stefan Heymann did a great presentation Character Sets and Unicode in Firebird at fbcon11. About 90% of it is not about Firebird, but about Unicode: a highly recommended presentation.

There is also a PDF version of the same presentation for easier reading/searching.

If you like Firebird, there is a whole bunch of Firebird related presentations from various authors shared by MindTheBird.

–jeroen

Posted in Ansi, Database Development, Development, Encoding, Firebird, ISO-8859, ISO8859, Software Development, Unicode, UTF-8, UTF8 | Leave a Comment »

Venn Diagrams of SQL Join queries (via: Data Visualization – Google+)

Posted by jpluimers on 2014/04/08

Some great venn diagrams of SQL JOINs via Data Visualization – Google+ of which I wish they were PNG:

Thanks to that link, I found the original article and images by C.L. Moffat!

Click on the image to view a larger version.

–jeroen Read the rest of this entry »

Posted in Access, Database Development, DB2, Development, Firebird, InterBase, MySQL, OracleDB, PostgreSQL, SQL, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 7 | Leave a Comment »

Database Workbench v4 – version: 4.4.5. got released (via: News @ Upscene Productions)

Posted by jpluimers on 2014/03/19

Today, Version 4.4.5 of Database Workbench got released.

It mainly is a bugfix release (15 out of 18 issues were bugfixes, of the rest, 2 are feature requests, 1 enhancement): List of items new/enhanced/fixed in Product: Database Workbench v4 – version: 4.4.5.

Download from the trial/lite download page, or from the customer download page.

Enjoy (:

–jeroen

via: News @ Upscene Productions.

Posted in Database Development, Delphi, Development, Firebird, InterBase, MySQL, NexusDB, OracleDB, Software Development, SQL Server, Sybase SQL Anywhere | Leave a Comment »