Thursday 24 September 2015

Job Interview Firebird Interview Questions and Answers

36. How to write UDF s in Delphi? 
It’s quite simple. the only thing you need to remember is that you must always use ib_util_mallocOto allocate memory if your UDF returns string result. The UDF must be declared as FREE IT. so that Firebird releases the memory after it reads the string.
To use ib_util_mallocO, you need to import it from ib_utildil into your program - and make sure you use it instead of regular memory alocating functions. Here’s a simple example of Delphi UDF:
function ib uti l_rnalloc(l: integer): pointer; cdecl: external ‘ib_util.dll;
function ChangeMyString(const p: PChar). PChar; cdecl:
var
s: string;
begin
s := DoSomething(string(p));
Result := ib_util_malloc(Length(s) + 1);
StrPCopy(Result, s);
end;
Declaration in Firebird:
DECLARE EXTERNAL FUNCTION ChangeMyString
CString(255)
RETURNS CString(255) FREE_IT
ENTRY_POINT ‘ChangeMyString’ MODULE_NAME ‘……’‘

37. Is it possible to determine clients IP address? 
To get it from SQL. you need to use Firebird 2.0 (own address), or Firebird 2.1 (anyone’s):
If you use Firebird 2.0 or higher, use the GET_RDB$Context function with (‘SYSTEM’, ‘CLIENT_ADDRESS’) parameters.
If you use Firebird 2.1 or higher, you can get address of any client by selecting from the monitoring tables.
With Firebird I .x you can try to get the information from TCP/IP stack, using netstat or

38. Is there a way to automate SQL execution from the command-line, batch job or shell script? 
Yes. You can use isql for this. It is located in the ‘bin’ directory of your Firebird installation. If you wish to try it interactively, run isql and then type:
isql  localhost:my_database -user sysdba -pass “‘
SQL> input my_script.sql;
SQL> commit;
SQL>
To run it from a batch (.bat) file or a shell script, use -i switch:
isql -i my_script.sql localhost:my_database -user sysdba -pass ******
If you have some DM1. statements in your script, make sure you put the COMMIT command at the end of the file. Also, make sure the file ends with a newline, as isql executes the commands on the line only after it gets the newline character.

39. Is there a way to detect whether fbclient.dll or tbembed.dll is loaded? 
There are some ways to detect it:
- check the size of DLL file
- if you are using different versions of Firebird (for example 1.5.4 and 2.0.1, you can query the server version via Services API)
You should understand that fbembed can be used as a regular Firebird client. Checking whether embedded or fbclient is loaded for licensing or similar needs is really not useful. You could use the connection string as guide, but super server can establish direct local connections without localhost  prefix.
If you combine all this information, you could get some conclusions:
- if DLL size matches fbembed and connection string doesn’t have hostname, you are
using embedded
- if DLL size matches fbembed and connection string does have hosmame. you are using
either super server or classic
- if DDL size matches fbclient and connection string doesn’t have hostname, you are
using super server via local connection (IPC. XNET)
- if DLL size matches fbclient and connection string does have hostname, you are using
either super server or classic

40. Is there an example how to configure ExternalFileAccess setting in fi rebird.conf? 
Firebird’s config file (firebird.conf) does have descriptions inside that explain everything, but sometimes they are confusing and hard to understand what should  you do exactly if you don’t have examples. One of such settings is ExternalFileAccess. Some people are even tempted to put Full as it is much easier than trying to guess what’s the correct format Here are the basic settings (‘None’ to disallow external tables and ‘Full’ to allow them anywhere) which you probably understood yourself
ExtemalFileAccess = None
ExtemalFileAccess = Full
And here are those tricky Restrict settings:
ExtemalFileAccess Restrict C :\some\directory
For multiple directories, use something like this:
ExtemalFileAccess = Restrict C :\some\directory,C :some\other\directory
For Linux users:
ExtemalFileAccess= Restrict /some/directory

More Questions & Answers:-

No comments:

Post a Comment