1 |
<?xml version="1.0" encoding="UTF-8"?> |
2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><!--This file was converted to xhtml by LibreOffice - see http://cgit.freedesktop.org/libreoffice/core/tree/filter/source/xslt for the code.--><head profile="http://dublincore.org/documents/dcmi-terms/"><meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/><title xml:lang="en-US">- no title specified</title><meta name="DCTERMS.title" content="" xml:lang="en-US"/><meta name="DCTERMS.language" content="en-US" scheme="DCTERMS.RFC4646"/><meta name="DCTERMS.source" content="http://xml.openoffice.org/odf2xhtml"/><meta name="DCTERMS.creator" content="Tony Whyman"/><meta name="DCTERMS.issued" content="2015-05-09T13:42:29.879795800" scheme="DCTERMS.W3CDTF"/><meta name="DCTERMS.contributor" content="Tony Whyman"/><meta name="DCTERMS.modified" content="2015-05-09T14:02:35.720604839" scheme="DCTERMS.W3CDTF"/><meta name="DCTERMS.provenance" content="" xml:lang="en-US"/><meta name="DCTERMS.subject" content="," xml:lang="en-US"/><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" hreflang="en"/><link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" hreflang="en"/><link rel="schema.DCTYPE" href="http://purl.org/dc/dcmitype/" hreflang="en"/><link rel="schema.DCAM" href="http://purl.org/dc/dcam/" hreflang="en"/><style type="text/css"> |
3 |
@page { } |
4 |
table { border-collapse:collapse; border-spacing:0; empty-cells:show } |
5 |
td, th { vertical-align:top; font-size:12pt;} |
6 |
h1, h2, h3, h4, h5, h6 { clear:both } |
7 |
ol, ul { margin:0; padding:0;} |
8 |
li { list-style: none; margin:0; padding:0;} |
9 |
<!-- "li span.odfLiEnd" - IE 7 issue--> |
10 |
li span. { clear: both; line-height:0; width:0; height:0; margin:0; padding:0; } |
11 |
span.footnodeNumber { padding-right:1em; } |
12 |
span.annotation_style_by_filter { font-size:95%; font-family:Arial; background-color:#fff000; margin:0; border:0; padding:0; } |
13 |
* { margin:0;} |
14 |
.P1 { font-size:12pt; line-height:120%; margin-bottom:0.0972in; margin-top:0in; font-family:Liberation Serif; writing-mode:page; } |
15 |
.P2 { font-size:12pt; line-height:120%; margin-bottom:0.0972in; margin-top:0in; font-family:Liberation Serif; writing-mode:page; } |
16 |
.P3 { font-size:12pt; line-height:120%; margin-bottom:0.0972in; margin-top:0in; font-family:Liberation Serif; writing-mode:page; } |
17 |
.P4 { font-size:12pt; line-height:120%; margin-bottom:0.0972in; margin-top:0in; font-family:Liberation Serif; writing-mode:page; } |
18 |
.P5 { font-size:130%; font-weight:bold; margin-bottom:0.0835in; margin-top:0.1665in; font-family:Liberation Sans; writing-mode:page; } |
19 |
.P6 { font-size:115%; font-weight:bold; margin-bottom:0.0835in; margin-top:0.139in; font-family:Liberation Sans; writing-mode:page; } |
20 |
.P7 { font-size:115%; font-weight:bold; margin-bottom:0.0835in; margin-top:0.139in; font-family:Liberation Sans; writing-mode:page; } |
21 |
.Preformatted_20_Text { font-size:10pt; font-family:Liberation Mono; writing-mode:page; margin-top:0in; margin-bottom:0in; } |
22 |
.Text_20_body { font-size:12pt; font-family:Liberation Serif; writing-mode:page; margin-top:0in; margin-bottom:0.0972in; line-height:120%; } |
23 |
<!-- ODF styles with no properties representable as CSS --> |
24 |
.T1 .T2 { } |
25 |
</style></head><body dir="ltr" style="max-width:8.2681in;margin-top:0.7874in; margin-bottom:0.7874in; margin-left:0.7874in; margin-right:0.7874in; writing-mode:lr-tb; "><h1 class="P5"><a id="a__Setting_the_FIREBIRD_Environment_Variables_from_within_your_Program"><span/></a>Setting the FIREBIRD Environment Variables from within your Program</h1><p class="P1">If you are using a local database and the embedded Firebird Server then you also need to set the environment variables correctly to avoid conflicts with other users, or just so that Firebird works correctly. The <span class="T2">can</span> be set outside of the program – but this is not always that user friendly. They can be set from within a program except that on a Linux/Unix hosts this requires some extra code as for some unknown reason, FPC does not have a native interface that allows you to change environment variables. </p><p class="P1">The following code snippet should work for most people. It also makes it easier to uses standard Firebird packages.</p><p class="Preformatted_20_Text">{$IFDEF Unix}</p><p class="Preformatted_20_Text">function setenv(name:Pchar; value:Pchar; replace:integer):integer;cdecl;external clib name 'setenv';</p><p class="Preformatted_20_Text">function unsetenv(name:Pchar):integer;cdecl;external clib name 'unsetenv';</p><p class="Preformatted_20_Text">function SetEnvironmentVariable(name:PChar; value:PChar):boolean;</p><p class="Preformatted_20_Text">begin</p><p class="Preformatted_20_Text"> result:=false; //assume failure</p><p class="Preformatted_20_Text"> if value = '' then</p><p class="Preformatted_20_Text"> begin</p><p class="Preformatted_20_Text"> // Assume user wants to remove variable.</p><p class="Preformatted_20_Text"> if unsetenv(name)=0 then result:=true;</p><p class="Preformatted_20_Text"> end</p><p class="Preformatted_20_Text"> else</p><p class="Preformatted_20_Text"> begin</p><p class="Preformatted_20_Text"> // Non empty so set the variable</p><p class="Preformatted_20_Text"> if setenv(name, value, 1)=0 then result:=true;</p><p class="Preformatted_20_Text"> end;</p><p class="Preformatted_20_Text">end;</p><p class="Preformatted_20_Text">{$ENDIF} </p><p class="Preformatted_20_Text"> </p><p class="Preformatted_20_Text">procedure SetupFirebirdEnv;</p><p class="Preformatted_20_Text">var TmpDir: string;</p><p class="Preformatted_20_Text">begin</p><p class="Preformatted_20_Text"> TmpDir := GetTempDir +</p><p class="Preformatted_20_Text"> DirectorySeparator + 'firebird_' + GetEnvironmentVariable('USER');</p><p class="Preformatted_20_Text"> if GetEnvironmentVariable('FIREBIRD_TMP') = '' then</p><p class="Preformatted_20_Text"> begin</p><p class="Preformatted_20_Text"> if not DirectoryExists(tmpDir) then</p><p class="Preformatted_20_Text"> mkdir(tmpDir);</p><p class="Preformatted_20_Text"> SetEnvironmentVariable('FIREBIRD_TMP',PChar(TmpDir));</p><p class="Preformatted_20_Text"> end;</p><p class="Preformatted_20_Text"> if GetEnvironmentVariable('FIREBIRD_LOCK') = '' then</p><p class="Preformatted_20_Text"> begin</p><p class="Preformatted_20_Text"> if not DirectoryExists(tmpDir) then</p><p class="Preformatted_20_Text"> mkdir(tmpDir);</p><p class="Preformatted_20_Text"> SetEnvironmentVariable('FIREBIRD_LOCK',PChar(TmpDir));</p><p class="Preformatted_20_Text"> end;</p><p class="Preformatted_20_Text"> {$IFDEF WINDOWS}</p><p class="Preformatted_20_Text"> if FileExists(Application.Location + 'firebird.msg') then</p><p class="Preformatted_20_Text"> SetEnvironmentVariable('FIREBIRD',PChar(ExtractFileDir(Application.ExeName)));</p><p class="Preformatted_20_Text"> {$ENDIF}</p><p class="Preformatted_20_Text">end; </p><p class="Text_20_body"> </p><h2 class="P6"><a id="a__Under_Linux"><span/></a>Under Linux</h2><p class="P1">The procedure SetupFirebirdEnv does most of the work. An underlying assumption is that the Firebird embedded server has been installed from a standard package, such as libfbembed2.5 (Debian/Ubuntu). The Firebird files are thus all in standard locations and there is no need to set the FIREBIRD environment variable. However, using the default TMP or LOCK directories could give rise to conflicts or access rights issues.</p><p class="P1">The procedure will create, if necessary a temporary directory for the FIREBIRD_TMP and FIREBIRD_LOCK environment variables to point to <span class="T1">and then set those Environment Variable to the path to that directory. It will not, however, overwrite existing values for either variable.</span></p><p class="P3">The problem is that “SetEnvironmentVariable” only exists under Windows. We thus have to include our own version which makes direct use of “libc”. You will have also to include “Initc” your “uses” list in order to use libc.</p><h2 class="P7"><a id="a__Under_Windows_"><span/></a>Under Windows.</h2><p class="P2">The procedure SetupFirebirdEnv does most of the work. An underlying assumption is that the Firebird embedded server has been installed <span class="T1">in the same directory as your program. </span></p><p class="P4"><span class="T1">The procedure SetupFirebirdEnv does the same as for Linux. Additionally, it has to point the FIREBIRD environment variable at the directory holding the Firebird messages file. However, there is no need here for your own SetEnvironmentVariable as this is available under Windows.</span>Y ou do have to include the "Windows" unit in your "uses" list.</p></body></html> |