firebird interbase udf l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Firebird / Interbase UDF PowerPoint Presentation
Download Presentation
Firebird / Interbase UDF

Loading in 2 Seconds...

play fullscreen
1 / 16

Firebird / Interbase UDF - PowerPoint PPT Presentation


  • 196 Views
  • Uploaded on

Firebird / Interbase UDF. What are UDF’s User Defined Functions are DLL’s that perform specialised functions inside the Firebird / Interbase engine. Firebird / Interbase UDF. What are UDF’s

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Firebird / Interbase UDF' - fathia


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
firebird interbase udf
Firebird / Interbase UDF
  • What are UDF’s
    • User Defined Functions are DLL’s that perform specialised functions inside the Firebird / Interbase engine.
firebird interbase udf2
Firebird / Interbase UDF
  • What are UDF’s
    • User Defined Functions are DLL’s that perform specialised functions inside the Firebird / Interbase engine.
  • Why do we need UDF’s
    • The Firebird is very limited in the range of functions available out of the box
firebird interbase udf3
Firebird / Interbase UDF
  • What are UDF’s
    • User Defined Functions are DLL’s that perform specialised functions inside the Firebird / Interbase engine.
  • Why do we need UDF’s
    • The Firebird is very limited in the range of functions available out of the box
    • Every application area has its own specific requirementse.g. Rounding a date back to a given day in the week Presenting a date as just the month name and year
firebird interbase udf4
Firebird / Interbase UDF
  • What are UDF’s
    • User Defined Functions are DLL’s that perform specialised functions inside the Firebird / Interbase engine.
  • Why do we need UDF’s
    • The Firebird is very limited in the range of functions available out of the box
    • Every application area has its own specific requirementse.g. Rounding a date back to a given day in the week Presenting a date as just the month name and year
    • String handling functionality is difficult to achieve in pure SQL
firebird interbase udf5
Firebird / Interbase UDF
  • Criteria for writing UDF’s
    • Control remains with UDF until completion
firebird interbase udf6
Firebird / Interbase UDF
  • Criteria for writing UDF’s
    • Control remains with UDF until completion
    • Should be regarded as a critical section
firebird interbase udf7
Firebird / Interbase UDF
  • Criteria for writing UDF’s
    • Control remains with UDF until completion
    • Should be regarded as a critical section
    • No state is preserved and the code should be thread safe
firebird interbase udf8
Firebird / Interbase UDF
  • Criteria for writing UDF’s
    • Control remains with UDF until completion
    • Should be regarded as a critical section
    • No state is preserved and the code should be thread safe
    • No database activity should take place as the DLL should run quickly to completion
firebird interbase udf9
Firebird / Interbase UDF
  • Key Issues when creating UDF’s
    • Most important - function must be exported and declared as cdeclFunction will work if cdecl is omitted, but the stack will be mashed on return from the function (DLL)
firebird interbase udf10
Firebird / Interbase UDF
  • Key Issues when creating UDF’s
    • Most important - function must be exported and declared as cdeclFunction will work if cdecl is omitted, but the stack will be mashed on return from the function (DLL)
    • Memory management is the next critical issuePassing integers / reals is the simple case
firebird interbase udf11
Firebird / Interbase UDF
  • Key Issues when creating UDF’s
    • Most important - function must be exported and declared as cdeclFunction will work if cdecl is omitted, but the stack will be mashed on return from the function (DLL)
    • Memory management is the next critical issuePassing integers / reals is the simple case
    • Strings can be passed two ways –
      • Via the ShareMem unit in the BorlandMM.dll
      • Via pchar or ShortString parameters
firebird interbase udf12
Firebird / Interbase UDF
  • Key Issues when creating UDF’s
    • Memory allocation for strings – only needed when returning string resultsib_util_malloc(size_of_memory_needed)
firebird interbase udf13
Firebird / Interbase UDF
  • Key Issues when creating UDF’s
    • Memory allocation for strings – only needed when returning string resultsib_util_malloc(size_of_memory_needed)Must have ib_util in the uses clause
firebird interbase udf14
Firebird / Interbase UDF
  • Key Issues when creating UDF’s
    • Timestamps are handled via the TM record structure. This must be defined as a typeTM = record

tm_sec : integer; // Seconds

tm_min : integer; // Minutes

tm_hour : integer; // Hour (0--23)

tm_mday : integer; // Day of month (1--31)

tm_mon : integer; // Month (0--11)

tm_year : integer; // Year (calendar year minus 1900)

tm_wday : integer; // Weekday (0--6) Sunday = 0)

tm_yday : integer; // Day of year (0--365)

tm_isdst : integer; // 0 if daylight savings time is not in effect)

end;PTM = ^TM

firebird interbase udf15
Firebird / Interbase UDF
  • Key Issues when creating UDF’s
    • Timestamps are defined as the typePISC_TIMESTAMPExample of two different function declarations function Date_align(varib_date: PISC_TIMESTAMP; varwk_end, day_no:integer): PISC_TIMESTAMP; cdecl; export;

function Date_mn_yr(varib_date: PISC_TIMESTAMP): pchar; cdecl; export;

    • Needed units in the uses clauseuses ib_util, IBHeader, Sysutils;
firebird interbase udf16
Firebird / Interbase UDF
  • Key Issues when creating UDF’s
    • Returning result by value or by pointerHow the function returns the result must be declared in the function definition in the actual database where the function is declaredTwo key wordsFREE_IT use when value returned on stack (malloc)BY VALUE use when simple value is returnedcontrol how the stack is cleaned after the execution of the function. Critical to get this right else memory leaks and or exceptions will occur