Some (for me important) scalar function for UnifiedSQL seems not to be implemented in SQLite-Provider. Have implemented this functions in SQLiteUniProvider.pas. May some other users need them too. Hope to see this changes in the next release.
Functions: YEAR,MONTH,DAY, DATEDIFF(second,minute,hour,day,month,year)
Implementation:
Code: Select all
LiteFunctions.AddObject('YEAR', TObject(PChar('CAST(strftime(''%%Y'', %s) AS INTEGER)'))); // EZ: implemented according to http://www.sqlite.org/lang_datefunc.html
LiteFunctions.AddObject('MONTH', TObject(PChar('CAST(strftime(''%%m'', %s) AS INTEGER)'))); // EZ: implemented according to http://www.sqlite.org/lang_datefunc.html
LiteFunctions.AddObject('DAY', TObject(PChar('CAST(strftime(''%%d'', %s) AS INTEGER)'))); // EZ: implemented according to http://www.sqlite.org/lang_datefunc.html
//LiteFunctions.AddObject('DATEDIFF', TObject(PChar('EXTRACT(%s FROM (%2:s - %1:s))')));
LiteFunctions.AddObject('DATEDIFF', TObject(PChar('CASE ''%s''' + // EZ: partially implemented
' WHEN ''year'' THEN (julianday(%2:s) - julianday(%1:s)) / 365.25' + // Delphi.DateUtils.pas.ApproxDaysPerYear
' WHEN ''month'' THEN (julianday(%2:s) - julianday(%1:s)) / 30.4375' + // Delphi.DateUtils.pas.ApproxDaysPerMonth
' WHEN ''day'' THEN julianday(%2:s) - julianday(%1:s)' +
' WHEN ''hour'' THEN (julianday(%2:s) - julianday(%1:s)) * 24' +
' WHEN ''minute'' THEN (julianday(%2:s) - julianday(%1:s)) * 24 * 60' +
' WHEN ''second'' THEN (julianday(%2:s) - julianday(%1:s)) * 24 * 60 * 60' +
' ELSE NULL' +
' END')));Elias