Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

Writing UDFs for Firebird Embedded SQL Server

, , 23 Oct 2009
We will describe how to create your own native Firebird extension and show some approaches how to use it in managed code applications
UDFSample.zip
UDFSample
Firebird
fbembed.dll
firebird.msg
FirebirdSql.Data.FirebirdClient.dll
GDS32.DLL
ib_util.dll
icudt30.dll
icuin30.dll
icuuc30.dll
include
lib
ib_util_ms.lib
MainApp
Properties
SampleUdf
DECLARE EXTERNAL FUNCTION CreateParser
	BLOB
    RETURNS INTEGER BY VALUE
  ENTRY_POINT 'SampleUdf_CreateParser'  MODULE_NAME 'SampleUdf'
#
DECLARE EXTERNAL FUNCTION DestroyParser
	INTEGER
	RETURNS INTEGER BY VALUE
  ENTRY_POINT 'SampleUdf_DestroyParser'  MODULE_NAME 'SampleUdf'
#
DECLARE EXTERNAL FUNCTION GetName
	INTEGER
	RETURNS CSTRING(256)
  ENTRY_POINT 'SampleUdf_GetName'  MODULE_NAME 'SampleUdf'
#
DECLARE EXTERNAL FUNCTION GetFullPath
	INTEGER
	RETURNS CSTRING(256)
  ENTRY_POINT 'SampleUdf_GetFullPath'  MODULE_NAME 'SampleUdf'
#
DECLARE EXTERNAL FUNCTION GetCreationTime
	INTEGER
	RETURNS TIMESTAMP FREE_IT
  ENTRY_POINT 'SampleUdf_GetCreationTime'  MODULE_NAME 'SampleUdf'
#
DECLARE EXTERNAL FUNCTION GetAttributes
	INTEGER
	RETURNS INTEGER
  ENTRY_POINT 'SampleUdf_GetAttributes'  MODULE_NAME 'SampleUdf'
#
DECLARE EXTERNAL FUNCTION GetSize
	INTEGER
	RETURNS BIGINT
  ENTRY_POINT 'SampleUdf_GetSize'  MODULE_NAME 'SampleUdf'
#
CREATE TABLE RowDataTable (
	Id INTEGER NOT NULL PRIMARY KEY
  , Data BLOB
  )
#
CREATE TABLE FSTable
 (
	Id INTEGER NOT NULL PRIMARY KEY
  , FileName VARCHAR(256)
  , FullPath VARCHAR(256)
  , CreationTime TIMESTAMP 
  , Attributes INTEGER
  , FileSize BIGINT
  )
#
CREATE GENERATOR RowDataTable_Generator
#
CREATE GENERATOR FSTable_Generator
#
CREATE PROCEDURE AddRawData
(
  Data BLOB
)
RETURNS (newId INTEGER)
AS
BEGIN
    newId = GEN_ID(RowDataTable_Generator, 1);
    INSERT INTO RowDataTable (Id, Data) VALUES (:newId, :Data);
    SUSPEND;
END
#
CREATE PROCEDURE TransferData
RETURNS (counter INTEGER)
AS
DECLARE VARIABLE tmp INTEGER;
DECLARE VARIABLE parserPtr INTEGER;
DECLARE VARIABLE Data BLOB;
DECLARE VARIABLE FileName VARCHAR(256);
DECLARE VARIABLE FullPath VARCHAR(256);
DECLARE VARIABLE CreationTime TIMESTAMP;
DECLARE VARIABLE Attributes INTEGER;
DECLARE VARIABLE FileSize BIGINT;
BEGIN
	counter = 0;
	FOR SELECT Data FROM RowDataTable INTO :Data DO	BEGIN
		parserPtr = CreateParser(:Data);
		IF (parserPtr IS NOT NULL) THEN BEGIN
			FileName = GetName(:parserPtr);
			FullPath = GetFullPath(:parserPtr);
			CreationTime = GetCreationTime(:parserPtr);
			Attributes = GetAttributes(:parserPtr);
			FileSize = GetSize(:parserPtr);
			
			tmp = GEN_ID(FSTable_Generator, 1);
			INSERT INTO FSTable (Id, FileName, FullPath, CreationTime, Attributes, FileSize)
			VALUES (:tmp, :FileName, :FullPath, :CreationTime, :Attributes, :FileSize);
			counter = counter + 1;

			tmp = DestroyParser(:parserPtr);
		END
	END
	SUSPEND;
END

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Authors

Ivan_Komarov

Ukraine Ukraine
No Biography provided

Apriorit Inc
Apriorit Inc.
Ukraine Ukraine
ApriorIT is a Software Research and Development company that works in advanced knowledge-intensive scopes.
 
Company offers integrated research&development services for the software projects in such directions as Corporate Security, Remote Control, Mobile Development, Embedded Systems, Virtualization, Drivers and others.
 
Official site http://www.apriorit.com
Group type: Organisation

31 members

Follow on   LinkedIn

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 24 Oct 2009
Article Copyright 2009 by Ivan_Komarov, Apriorit Inc
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid