NetBEUI connection strings
Support for NetBEUI (named pipes, a.k.a. WNET) connections was removed in Firebird 5.
Server configuration and management
Support for NetBEUI (named pipes, a.k.a. WNET) connections was removed in Firebird 5.
Please be aware that some third-party client programs may have different requirements for the composition of connection strings.Refer to their documentation or online help to find out.
A sample database named employee.fdb
is located in the examples/empbuild
subdirectory of your Firebird installation.It is also reachable under its alias employee
.You can use this database to “try your wings”.
If you move or copy the sample database, be sure to place it on a hard disk that is physically attached to your server machine.Shares, mapped drives or (on Unix) mounted SMB (Samba) file systems will not work.The same rule applies to any databases that you create or use.
Connecting to a Firebird database requires — implicit or explicit — authentication.To work with objects inside the database, such as tables, views and functions, you (i.e. the Firebird user you’re logged in as) need explicit permissions on those objects, unless you own them (you own an object if you have created it) or if you’re connected as user SYSDBA
or with the role RDB$ADMIN
.In the example database employee.fdb
, sufficient permissions have been granted to PUBLIC
(i.e. any authenticated user) to enable you to view and modify data to your heart’s content.
For simplicity here, we will look at authenticating as SYSDBA
using the password masterkey
.Also, to keep the lines in the examples from running off the right edge, we will work with local databases and use aliases wherever possible.Of course, everything you’ll learn in these sections can also be applied to remote databases, simply by supplying a TCP/IP connection string.
isql
Firebird ships with a text-mode client named isql (Interactive SQL utility).You can use it in several ways to connect to a database.One of them, shown below, is to start it in interactive mode.Go to the directory where the Firebird tools reside (see [qsg5-disk-locations] if necessary) and type isql
(Windows) or ./isql
(Linux) at the command prompt.
Note
|
In the following examples, [chevron circle left] means “hit kbd:[Enter]” |
C:\Programmas\Firebird\Firebird_3_0>isql[chevron circle left] Use CONNECT or CREATE DATABASE to specify a database SQL>connect xnet://employee user sysdba password masterkey;[chevron circle left]
Important
|
|
Note
|
You can optionally enclose the path, the username and/or the password in single ( |
At this point, isql
will inform you that you are connected:
Database: xnet://employee, User: SYSDBA SQL>
You can now continue to play about with the employee
database.With isql
you can query data, get information about the metadata, create database objects, run data definition scripts and much more.
To get back to the OS command prompt, type:
SQL>quit;[chevron circle left]
You can also type EXIT
instead of QUIT
, the difference being that EXIT
will first commit any open transactions, making your modifications permanent.
Some GUI client tools take charge of composing the CONNECT
string for you, using server, path (or alias), username and password information that you type into prompting fields.Supply the various elements as described in the preceding topic.
Note
|
|
isql
There is more than one way to create a database with isql
.Here, we will look at one simple way to create a database interactively — although, for your serious database definition work, you should create and maintain your metadata objects using data definition scripts.
isql
To create a database interactively using the isql
command shell, type isql
(Windows) or ./isql
(Linux) at the command prompt in the directory where the Firebird tools are.
Note
|
In the following examples, [chevron circle left] means “hit kbd:[Enter]” |
C:\Programmas\Firebird\Firebird_3_0>isql[chevron circle left]
Use CONNECT or CREATE DATABASE to specify a database
Now you can create your new database interactively.Let’s suppose that you want to create a database named test.fdb
and store it in a directory named data
on your D
drive:
SQL>create database 'D:\data\test.fdb' page_size 8192[chevron circle left] CON>user 'sysdba' password 'masterkey';[chevron circle left]
Important
|
|
The database will be created and, after a few moments, the SQL prompt will reappear.You are now connected to the new database and can proceed to create some test objects in it.
To verify that there really is a database there, let’s first type in this query:
SQL>select * from rdb$relations;[chevron circle left]
Although you haven’t created any tables yet, the screen will fill up with a large amount of data!This query selects all rows in the system table RDB$RELATIONS
, where Firebird stores the metadata for tables.An “empty” database is not really empty: it contains a number of system tables and other objects.The system tables will grow as you add more user objects to your database.
To get back to the command prompt type QUIT
or EXIT
, as explained in the section on connecting.
In Firebird 5, if you try to create a database other than in embedded mode as someone who is not a Firebird admin (i.e. SYSDBA
or an account with equal rights), you may be in for a surprise:
SQL>create database 'xnet://D:\data\mydb.fdb' user 'john' password 'lennon';[chevron circle left]
Statement failed, SQLSTATE = 28000
no permission for CREATE access to DATABASE D:\DATA\MYDB.FDB
Non-admin users must explicitly be granted the right to create databases by a Firebird admin:
SQL>grant create database to user john;[chevron circle left]
After that, they can create databases.
Notice that with a serverless connection, i.e. without specifying a host name or protocol before the database name (and Engine13
enabled!), Firebird won’t deny any CREATE DATABASE
statement.It will only fail if the client process doesn’t have sufficient rights in the directory where the database is to be created.
Every database management system has its own idiosyncrasies in the ways it implements SQL.Firebird adheres to the SQL standard more rigorously than most other RDBMSes.Developers migrating from products that are less standards-compliant often wrongly suppose that Firebird is quirky, whereas many of its apparent quirks are not quirky at all.
Firebird accords with the SQL standard by truncating the result (quotient) of an integer/integer calculation to the next lower integer.This can have bizarre results unless you are aware of it.
For example, this calculation is correct in SQL:
1 / 3 = 0
If you are upgrading from an RDBMS which resolves integer/integer division to a float quotient, you will need to alter any affected expressions to use a float or scaled numeric type for either dividend, divisor, or both.
For example, the calculation above could be modified thus to produce a non-zero result:
1.000 / 3 = 0.333
Strings in Firebird are delimited by a pair of single quote (apostrophe) symbols: 'I am a string'
(ASCII code 39, not 96).If you used earlier versions of Firebird’s relative, InterBase®, you might recall that double and single quotes were interchangeable as string delimiters.Double quotes cannot be used as string delimiters in Firebird SQL statements.
If you need to use an apostrophe inside a Firebird string, you can “escape” the apostrophe character by preceding it with another apostrophe.
For example, this string will give an error:
'Joe's Emporium'
because the parser encounters the apostrophe and interprets the string as 'Joe'
followed by some unknown keywords.To make it a legal string, double the apostrophe character:
'Joe''s Emporium'
Notice that this is two single quotes, not one double-quote.
You can also use the alternative quote string literal, allowing you to embed the quote without escaping:
q'{Joe's Emporium}'
The concatenation symbol in SQL is two “pipe” symbols (“||
”, or a pair of ASCII 124 without space between).In SQL, the “+” symbol is an arithmetic operator, and it will cause an error if you attempt to use it for concatenating strings.The following expression prefixes a character column value with the string “Reported by:
”:
'Reported by: ' || LastName
Firebird will raise an error if the result of a string concatenation exceeds the maximum (var)char size of 32 Kb.If only the potential result — based on variable or field size — is too long you’ll get a warning, but the operation will be completed successfully.(In pre-2.0 Firebird, this too would cause an error and halt execution.)
See also the section below, [qsg5-nulls], about concatenating in expressions involving NULL
.
Before the SQL-92 standard, it was not legal to have object names (identifiers) in a database that duplicated keywords in the language, were case-sensitive or contained spaces or special characters[1].SQL-92 introduced a new syntax to make any of them legal, provided that the identifiers are defined within pairs of double-quote symbols (ASCII 34) and were always referred to using double-quote delimiters (so called quoted or delimited identifiers).
The purpose of this “gift” was to make it easier to migrate metadata from non-standard RDBMSes to standards-compliant ones.The downside is that, if you choose to define an identifier in double quotes, its case-sensitivity and the enforced double-quoting will remain mandatory.
Firebird does permit a slight relaxation under a very limited set of conditions.If the identifier which was defined in double-quotes:
is defined as all upper-case,
is not a keyword, and
conforms to the other rules of regular identifiers[1],
...then it can be used in SQL unquoted and case-insensitively.(But as soon as you put double-quotes around it, you must match the case again!)
Warning
|
Don’t get too smart with this!For instance, if you have tables “ SQL>select * from TestTable; ...you will get the records from “ |
Unless you have a compelling reason to define quoted identifiers, it is recommended that you avoid them.Firebird happily accepts a mix of quoted and unquoted identifiers — so there is no problem including that keyword which you inherited from a legacy database, if you need to.
Tip
|
Some database admin tools enforce double-quoting of all identifiers by default.Try to choose a tool which makes double-quoting optional. |
a
-z
, A
-Z
, 0
-9
and _
are allowed in regular identifiers, Firebird also allows $
, and the first character must be a
-z
or A
-Z
NULL
In SQL, NULL
is not a value.It is a condition, or state, of a data item, in which its value is unknown.Because it is unknown, NULL
cannot behave like a value.When you try to perform arithmetic on NULL
, or involve it with values in other expressions, the result of the operation will almost always be NULL
.It is not zero or blank or an “empty string”, and it does not behave like any of these values.
Below are some examples of the types of surprises you will get if you try to perform calculations and comparisons with NULL
.
The following expressions all return NULL
:
1 + 2 + 3 + NULL
not (NULL)
'Home ' || 'sweet ' || NULL
You might have expected 6 from the first expression and “Home sweet
” from the third, but as we just said, NULL
is not like the number 0 or an empty string — it’s far more destructive!
The following expression:
FirstName || ' ' || LastName
will return NULL
if either FirstName
or LastName
is NULL
.Otherwise, it will nicely concatenate the two names with a space in between — even if any one of the variables is an empty string.
Tip
|
Think of |
Now let’s examine some PSQL (Procedural SQL) examples with if
-constructs:
Equals (‘=
’)
if (a = b) then
MyVariable = 'Equal';
else
MyVariable = 'Not equal';
After executing this code, MyVariable
will be 'Not equal'
if both a
and b
are NULL
.The reason is that a = b
yields NULL
if at least one of them is NULL
.If the test expression of an “if
” statement is NULL
, it behaves like false
: the ‘then
’ block is skipped, and the ‘else
’ block executed.
Warning
|
Although the expression may behave like |
Not equals (‘<>
’)
if (a <> b) then
MyVariable = 'Not equal';
else
MyVariable = 'Equal';
Here, MyVariable
will be 'Equal'
if a
is NULL
and b
isn’t, or vice versa.The explanation is analogous to that of the previous example.
DISTINCT
keyword comes to the rescue!Firebird 2 and above implement IS [NOT] DISTINCT
allowing you to perform (in)equality tests that take NULL
into account.The semantics are as follows:
Two expressions are DISTINCT
if they have different values or if one is NULL
and the other isn’t;
They are NOT DISTINCT
if they have the same value or if they are both NULL
.
Notice that if neither operand is NULL
, IS DISTINCT
works exactly like the “<>
” operator, and IS NOT DISTINCT
like the “=
” operator.
IS DISTINCT
and IS NOT DISTINCT
always return true
or false
, never NULL
.
Using DISTINCT
, you can rewrite the first PSQL example as follows:
if (a is not distinct from b) then
MyVariable = 'Equal';
else
MyVariable = 'Not equal';
And the second as:
if (a is distinct from b) then
MyVariable = 'Not equal';
else
MyVariable = 'Equal';
These versions will give you the results that a normal (i.e. not SQL-brainwashed) human being would expect, whether there are NULL
s involved or not.
NULL
sA lot more information about NULL
behaviour can be found in the Firebird Null Guide, at these locations:
Firebird comes with two utilities for backing up and restoring your databases: gbak and nbackup.Both can be found in the Firebird installation directory (Windows) or its bin
subdirectory (Linux).Firebird databases can be backed up while users are connected to the system and going about their normal work.The backup will be taken from a snapshot of the database at the time the backup began.
Regular backups and occasional restores should be a scheduled part of your database management activity.
Warning
|
Except in nbackup’s lock mode, do not use external proprietary backup utilities or file-copying tools such as WinZip, |
Important
|
Study the warnings in the next section about database activity during restores! |
More information about gbak
can be found here (HTML and PDF version, same content):
https://www.firebirdsql.org/file/documentation/html/en/firebirddocs/gbak/firebird-gbak.html
https://www.firebirdsql.org/file/documentation/pdf/en/firebirddocs/gbak/firebird-gbak.pdf
The nbackup
manual is here (again same content in HTML and PDF):
The following sections constitute a summary of things not to do if you want to keep your Firebird databases in good health.
Firebird is installed with forced writes (synchronous writes) enabled by default.Modifications are written to disk immediately upon posting.
It is possible to configure a database to use asynchronous data writes — whereby modified or new data are held in the memory cache for periodic flushing to disk by the operating system’s I/O subsystem.The common term for this configuration is forced writes off (or disabled).It is sometimes resorted to in an attempt to improve performance during large batch operations.
The big warning here is: do not disable forced writes on a Windows server.It has been observed that the Windows server platforms do not flush the write cache until the Firebird service is shut down.Apart from power interruptions, there is just too much that can go wrong on a Windows server.If it should hang, the I/O system goes out of reach and your users' work will be lost in the process of rebooting.
Linux servers are safer for running an operation with forced writes disabled temporarily.Still, do not leave it disabled once your large batch task is completed, unless you have a very robust fall-back power system.
One of the restore options in the gbak
utility (gbak -rep[lace_database]
) allows you to restore a gbak file over an existing database.It is possible for this style of restore to proceed without warning while users are logged in to the database.Database corruption is almost certain to be the result.
Note
|
Notice that the shortest form of this command is These changes have been made because many users thought that the |
Warning
|
Be aware that you will need to design your admin tools and procedures to prevent any possibility for any user (including |
If is practicable to do so, it is recommended to restore to spare disk space using the gbak -c
option and test the restored database using isql
or your preferred admin tool.If the restored database is good, shut down the old database (you can use the gfix
command-line tool for this;see Firebird Database Housekeeping Utility (HTML) or Firebird Database Housekeeping Utility (PDF)).Make a filesystem copy of the old database just in case and then copy the restored database file(s) over their existing counterparts.
If you do not block access to users while performing a restore using gbak -rep
then users may be able to log in and attempt to do operations on data.Corrupted structures will result.
The community of willing helpers around Firebird goes a long way back, to many years before the source code for its ancestor, InterBase® 6, was made open source.Collectively, the Firebird community does have all the answers!It even includes some people who have been involved with it since it was a design on a drawing board in a bathroom in Boston.
Visit the official Firebird Project site at https://www.firebirdsql.org and join the user support lists, in particular firebird-support
.Look at https://www.firebirdsql.org/en/mailing-lists/ for instructions.
Use the Firebird documentation index at https://www.firebirdsql.org/en/documentation/.
Visit the Firebird knowledge site at https://www.ibphoenix.com to look up a vast collection of information about developing with and using Firebird.IBPhoenix also sells a Developer CD with the Firebird binaries and lots of documentation.
Order the official three-volume Firebird Book, Second Edition at https://www.ibphoenix.com/products/books/firebird_book, for more than 1200 pages jam-packed with Firebird information.(Notice: at the time of this writing, the Firebird Book is not yet up-to-date with Firebird 3 and higher.)
Read the Release Notes for your Firebird version!
Firebird exists, and continues to be improved, thanks to a community of volunteers who donate their time and skills to bring you this wonderful piece of software.But volunteer work alone is not enough to keep an enterprise-level RDBMS such as Firebird up-to-date.The Firebird Foundation supports Firebird development financially by issuing grants to designers and developers.If Firebird is useful to you, and you’d like to give something back, please visit the Foundation’s pages and consider making a donation or becoming a member or sponsor.