NVL2( <value expr 1>, <value expr 2>, <value
expr 3> )
If <value expr 1>
is not null, returns
<value expr 2>
, otherwise returns
<value expr 3>
. The type of the return value is
the type of <value expr 2>
unless it is null.
(HyperSQL)
UUID
UUID ( [ { <char value expr> | <binary value
expr> ] } )
With no parameter, this function returns a new UUID value as a 16 byte binary value. With a UUID hexadecimal string argument, it returns the 16 byte binary value of the UUID. With a 16 byte binary argument, it returns the formatted UUID character representation. (HyperSQL)
CRYPT_KEY
CRYPT_KEY( <value expr 1>, <value expr 2>
)
Returns a binary string representation of a cryptography key for the
given cipher and cryptography provider. The cipher specification is
specified by <value expr 1>
and the provider by
<value expr 2>
. To use the default provider,
specify null for <value expr 2>
.
(HyperSQL)
DIAGNOSTICS
DIAGNOSTICS ( ROW_COUNT )
This is a convenience function for use instead of the GET
DIAGNOSTICS ...
statement. The argument specifies the name of
the diagnostics variable. Currently the only supported variable is the
ROW_COUNT
variable. The function returns the row count
returned by the last executed statement. The return value is 0 after most
statements. Calling this function immediately after executing an INSERT,
UPDATE, DELETE or MERGE statement returns the row count for the last
statement, as it is returned by the JDBC statement. (HyperSQL)
IDENTITY
IDENTITY ()
Returns the last IDENTITY value inserted into a row by the current session. The statement, CALL IDENTITY() can be made after an INSERT statement that inserts a row into a table with an IDENTITY column. The CALL IDENTITY() statement returns the last IDENTITY value that was inserted into a table by the current session. Each session manages this function call separately and is not affected by inserts in other sessions. The statement can be executed as a direct statement or a prepared statement. (HyperSQL)
DATABASE
DATABASE ()
Returns the file name (without directory information) of the database. (JDBC)
DATABASE_NAME
DATABASE_NAME ()
Returns the database name. This name is a 16 character, uppercase string. It is generated as a string based on the timestamp of the creation of the database, for example HSQLDB32438AEAFB. The name can be redefined by an admin user but the new name must be all uppercase and 16 characters long. This name is used in log messages with external logging frameworks. (HyperSQL)
DATABASE_VERSION
DATABASE_VERSION ()
Returns the full version string for the database engine. For example, 2.0.1. (JDBC)
USER
USER ()
Equivalent to the SQL function CURRENT_USER
.
(JDBC)
CURRENT_USER
CURRENT_USER
CURRENT_ROLE
CURRENT_ROLE
SESSION_USER
SESSION_USER
SYSTEM_USER
SYSTEM_USER
CURRENT_SCHEMA
CURRENT_SCHEMA
CURRENT_CATALOG
CURRENT_CATALOG
These functions return the named current session attribute. They are all SQL Standard functions.
The CURRENT_USER is the user that connected to the database, or a user subsequently set by the SET AUTHORIZATION statement.
SESSION_USER is the same as CURRENT_USER
SYSTEM_USER is the user that connected to the database. It is not changed with any command until the session is closed.
CURRENT_SCHEMA is default schema of the user, or a schema subsequently set by the SET SCHEMA command.
CURRENT_CATALOG is always the same within a given HyperSQL database and indicates the name of the catalog.
IS_AUTOCOMMIT
IS_AUTOCOMMIT()
Returns TRUE if the session is in autocommit mode. (HyperSQL)
IS_READONLY_SESSION
IS_READONLY_SESSION()
Returns TRUE if the session is in read only mode. (HyperSQL)
IS_READONLY_DATABASE
IS_READONLY_DATABASE()
Returns TRUE if the database is a read only database. (HyperSQL)
IS_READONLY_DATABASE_FILES
IS_READONLY_DATABASE_FILES()
Returns TRUE if the database is a read-only files database. In this kind of database, it is possible to modify the data, but the changes are not persisted to the database files. (HyperSQL)
ISOLATION_LEVEL
ISOLATION_LEVEL()
Returns the current transaction isolation level for the session. Returns either READ COMMITTED or SERIALIZABLE as a string. (HyperSQL)
SESSION_ID
SESSION_ID()
Returns the id of the session as a BIGINT value. Each session id is unique during the operational lifetime of the database. Id's are restarted after a shutdown and restart. (HyperSQL)
SESSION_ISOLATION_LEVEL
SESSION_ISOLATION_LEVEL()
Returns the default transaction isolation level for the current session. Returns either READ COMMITTED or SERIALIZABLE as a string. (HyperSQL)
DATABASE_ISOLATION_LEVEL
DATABASE_ISOLATION_LEVEL()
Returns the default transaction isolation level for the database. Returns either READ COMMITTED or SERIALIZABLE as a string. (HyperSQL)
TRANSACTION_SIZE
TRANSACTION_SIZE()
Returns the row change count for the current transaction. Each row change represents a row INSERT or a row DELETE operation. There will be a pair of row change operations for each row that is updated.
TRANSACTION_ID
TRANSACTION_ID()
Returns the current transaction ID for the session as a BIGINT value. The database maintains a global incremental id which is allocated to new transactions and new actions (statement executions) in different sessions. This value is unique to the current transaction. (HyperSQL)
ACTION_ID
ACTION_ID()
Returns the current action ID for the session as a BIGINT value. The database maintains a global incremental id which is allocated to new transactions and new actions (statement executions) in different sessions. This value is unique to the current action. (HyperSQL)
TRANSACTION_CONTROL
TRANSACTION_CONTROL()
Returns the current transaction model for the database. Returns LOCKS, MVLOCKS or MVCC as a string. (HyperSQL)
LOB_ID
LOB_ID( <column reference> )
Returns internal ID of a lob as a BIGINT value. Lob ID's are unique and never reused. The <column reference> is the name of the column (or variable, or argument) which is a CLOB or BLOB. Returns null if the value is null. (HyperSQL)
ROWNUM
ROWNUM()
ROW_NUMBER
ROW_NUMBER() OVER()
Returns the current row number (from 1) being processed in a select
statement. This has the same semantics as the ROWNUM pseudo-column in
Oracle syntax mode, but can be used in any syntax mode. The function is
used in a SELECT of DELETE statement. The ROWNUM of a row is incremented
as the rows are added to the result set. It is therefore possible to use a
condition such as WHERE ROWNUM() < 10, but not ROWNUM() > 10 or
ROWNUM = 10. The ROW_NUMBER() OVER()
alternative
performs the same function and is included for compatibility with other
database engines.(HyperSQL)
$Revision: 5252 $
Copyright 2002-2012 Fred Toussi. Permission is granted to distribute this document without any alteration under the terms of the HSQLDB license. Additional permission is granted to the HSQL Development Group to distribute this document with or without alterations under the terms of the HSQLDB license.
2013-07-08 15:31:27+0100
Table of Contents
HyperSQL has many modes of operation and features that allow it to be used in very different scenarios. Levels of memory usage, speed and accessibility by different applications are influenced by how HyperSQL is deployed.
The decision to run HyperSQL as a separate server process or as an in-process database should be based on the following:
When HyperSQL is run as a server on a separate machine, it is isolated from hardware failures and crashes on the hosts running the application.
When HyperSQL is run as a server on the same machine, it is isolated from application crashes and memory leaks.
Server connections are slower than in-process connections due to the overhead of streaming the data for each JDBC call.
You can reduce client/server traffic using SQL Stored procedures to reduce the number of JDBC execute calls.
During development, it is better to use a Server with server.silent=false, which displays the statements sent to the server on the console window.
To improve speed of execution for statements that are executed repeatedly, reuse a parameterized PreparedStatement for the lifetime of the connections.
There are three types of database, mem:
,
file:
and res:
. The mem: type is
stored all in memory and not persisted to file. The
file:
type is persisted to file. The
res:
type is also based on files, but the files are
loaded from the classpath, similar to resource and class files. Changes
to the data in file:
databases are persisted, unless
the database is readonly
, or
files_readonly
(using optional property settings).
Changes to res:
databases are not persisted.
A file: catalog can be made readonly
permanently, or it can be opened as readonly. To make the database
readonly, the property, value pair, readonly=true
can be added to the .properties
file of the
database. The SHUTDOWN command must be used to close the database
before making this change.
It is also possible to open a normal database as readonly. For this, the property can be included in the URL of the first connection to the database.
With readonly databases, it is still possible to insert and delete rows in TEMP tables.
There is another option which allows MEMORY tables to be
writeable, but without persisting the changes at SHUTDOWN. This option
is activated with the property, value pair,
files_readonly=true
, which can be added to the
.properties
file of the database, or included in
the URL of the first connection to the database.
A res: catalog, is a set of database
files on the classpath (inside a jar or alongside class files). The
database is opened with a URL in the form of
jdbc:hsqldb:res:<database path>
. These
databases are always files_readonly
and have the
same restrictions as files_readonly
file: catalogs.
CACHED tables and LOBS in these catalogs are readonly. It is not possible to create new LOBs in these catalogs, but you can use existing LOBs in new rows.
These options are useful for running application tests which operate on a predefined dataset.
TEXT tables are designed for special applications where the data has to be in an interchangeable format, such as CSV (comma separated values). TEXT tables should not be used for routine storage of data that changes a lot.
MEMORY tables and CACHED tables are generally used for data storage. The difference between the two is as follows:
The data for all MEMORY tables is read from the *.script file when the database is started and stored in memory. In contrast the data for cached tables is not read into memory until the table is accessed. Furthermore, only part of the data for each CACHED table is held in memory, allowing tables with more data than can be held in memory.
When the database is shutdown in the normal way, all the data for MEMORY tables is written out to the disk. In comparison, the data in CACHED tables that has changed is written out during operation and at shutdown.
The size and capacity of the data cache for all the CACHED tables is configurable. This makes it possible to allow all the data in CACHED tables to be cached in memory. In this case, speed of access is good, but slightly slower than MEMORY tables.
For normal applications it is recommended that MEMORY tables are used for small amounts of data, leaving CACHED tables for large data sets. For special applications in which speed is paramount and a large amount of free memory is available, MEMORY tables can be used for large tables as well.
You can change the type of the table with the SET
TABLE <table name> TYPE { CACHED | MEMORY
}
statement.
HyperSQL 2.0 supports dedicated storage and access to BLOB and CLOB objects. These objects can have huge sizes. BLOB or CLOB is specified as the type of a column of the table. Afterwards, rows can be inserted into the table using a PreparedStatement for efficient transfer of large LOB data to the database. In mem: catalogs, CLOB and BLOB data is stored in memory. In file: catalogs, this data is stored in a single separate file which has the extension *.lobs. The size of this file can grow to huge, terabyte figures. By default, a minimum 32 KB is allocated to each LOB. You can reduced this if your LOBs are generally smaller.
LOB data should be stored in the database using a JDBC PreparedStatement object. The streaming methods send the LOB to the database in one operation as a binary or character stream. Inside the database, the disk space is allocated as needed and the data is saved as it is being received. LOB data should be retrieved from the database using a JDBC ResultSet method. When a streaming method is used to retrieve a LOB, it is retrieved in large chunks in a transparent manner. LOB data can also be retrieved as String or byte[], but these methods use more memory and may not be practical for large objects.
LOB data is not duplicated in the database when a lob is copied from one table to another. The disk space is reused when a LOB is deleted and is no longer contained in any table. This happens only at the time of a CHECKPOINT.
By using a dedicated LOB store, HyperSQL achieves consistently high speeds (usually over 20MB / s) for both storage and retrieval of LOBs.
There is an internal LOBS schema in the database to store the id's, sizes and addresses of the LOBs (but not the actual LOBS) in a few system tables. This schema is stored in the database as MEMORY tables. Therefore the amount of JVM memory should be increased when more than tens of thousands of LOBs are stored in the database. If your database contains more than a few hundreds of thousands of LOBs and memory use becomes an issue, you can change one or all LOB schema tables to CACHED tables. See statements below:
Example 11.1. Using CACHED tables for the LOB schema
SET TABLE SYSTEM_LOBS.BLOCKS TYPE CACHED SET TABLE SYSTEM_LOBS.LOBS TYPE CACHED SET TABLE SYSTEM_LOBS.PARTS TYPE CACHED SET TABLE SYSTEM_LOBS.LOB_IDS TYPE CACHED
The files used for storing HyperSQL database data are all in the same directory. New files are always created and deleted by the database engine. Two simple principles must be observed:
The Java process running HyperSQL must have full privileges on the directory where the files are stored. This include create and delete privileges.
The file system must have enough spare room both for the 'permanent' and 'temporary' files. The default maximum size of the *.log file is 50MB. The *.data file can grow to up to 64GB (more if the default has been increased). The .backup file can be up to the size of the *.data file. The *.lobs file can grow to several terabytes. The temporary files created at the time of a SHUTDOWN can be equal in size to the *.script file and the .data file.
In desktop deployments, virus checker programs may interfere with the creation and modification of database files. You should exclude the directory containing the database files from virus checking.
HyperSQL 2.0 uses the same persistence mechanism as version 1.8, but with important enhancements. The code has proven reliable, as the last critical issue was fixed 2 years before the release of version 2.0.
There are further enhancements in version 2.2
More extensive locking mechanism has been added to code to support multithreaded access.
Incremental backup (an internal mechanism for crash protection) allows fast checkpoint and shutdown.
All files are synced at checkpoints and also just before closing.
The data file is enlarged in block increments
The NIO file access implementation has been improved
Persistence relies on the JVM, the operating system, and the computer hardware. A database system like HSQLDB can perform millions of read and write operations in an hour. As system hardware and software can go wrong, it is impossible to achieve zero failure rate. Therefore regular backups are recommended. HyperSQL 2.2 has built-in database backup and restore features, discussed elsewhere in this chapter.
A note regarding the NIO file access implementation: This
implementation applies only to CACHED table data in the
.data
file. Other files are not accessed via NIO. There
has been an issue with some JVM implementations of nio not releasing the
file buffers after they were closed. HyperSQL uses a workaround which is
recommended for Sun JVM's. This does not apply to other JVM's. In such
environments, it is therefore recommended to test the CHECKPOINT DEFRAG
operation and the shutting down and restarting the database inside the
same Java process extensively with NIO. Use of NIO can be turned off if
necessary.
Atomicity means a transaction either fails without changing the data, or succeeds. HyperSQL ensures atomicity both during operations and in the event of a system crash.
Consistency means all the implicit and explicit integrity constraints are always enforced. HyperSQL always enforces the constraints and at the same time does not allow unenforceable constraints (illegal forms of CHECK constraints) to be created.
Isolation means transactions do not interfere with each other. HyperSQL enforces isolation according to strict rules of the database isolation model (MVCC or LOCKS).
Durability means a committed transaction is protected in case of a system crash. HyperSQL ensures durability according to the setting for WRITE DELAY MILLIS. A zero delay setting results in an FileDescriptor#sync() call each time a transaction commits. A timed delay means the FileDescriptor#sync() call is executed in the given intervals and only the last transactions committed in the time interval may be lost. The default time interval is 0.5 second. The sync() call is also made at all critical points, including when a file is about to be closed. Durability of files requires a reliable JVM and disk storage system that stores the data safely with a sync() call. In practice, many systems are generally reliable in this respect.
A database is opened when the first connection is successfully
made. It remains open until the SHUTDOWN
command is
issued. If the connection property shutdown=true is used for the first
connection to the database, the database is shutdown when the last
connection is closed. Otherwise the database remains open and will
accept the next connection attempt.
The SHUTDOWN
command shuts down the database
properly and allows the database to be reopened quickly. This command
may take some seconds as it saves all the modified data in the
.script
and .data
files. Variants
of SHUTDOWN
such as SHUTDOWN
COMPACT
and SHUTDOWN SCRIPT
can be used
from time to time to reduce the overall size of the database files.
Another variant is SHUTDOWN IMMEDIATELY
which ensures
all changes to data are stored in the .log
file but
does not save the changes in .script
and
.data
files. The shutdown is performed quickly but
the database will take much longer to reopen.
During the lifetime of the database the checkpoint operation may
be performed from time to time. The SET FILES LOG SIZE <
value >
setting and its equivalent URL property determine
the frequency of automatic checkpoints. An online backup also performs a
checkpoint when the backup is not a hot backup. A checkpoint can be
performed by the user at any time using the
CHECKPOINT
statement. The main purpose of checkpoints
is to reduce the total size of database files and to allow a quick
restart in case the database is closed without a proper shutdown. The
CHECKPOINT DEFRAG
variant compacts the
.data
file the same way as SHUTDOWN
COMPACT
does. Obviously this variant takes much longer than a
normal CHECKPOINT
. A database setting allows a
CHECKPOINT DEFRAG
to be performed automatically when
wasted space in the .data
file exceeds the specified
percentage.
In a multi-user application, automatic or user-initiated
checkpoints are delayed until all other sessions have committed or
rolled back. During a checkpoint, other sessions cannot access the
database tables but can access the INFORMATION_SCHEMA
system tables.
The database engine saves the files containing all the data in a file catalog when a shutdown takes place. It automatically recovers from an abnormal termination and preserves the data when the catalog is opened next time. In an ideal operating environment, where there is no OS crash, disk failure, bugs in code, etc. there would be no need to backup a database. Backing up catalogs is an insurance policy against all sorts of misadventure that are not under the control of the database engine.
The data for each catalog consists of up to 5 files in the same
directory with the endings such as *.properties
,
*.script
, etc., as detailed in previous
chapters.
HyperSQL 2 includes commands to backup the database files into a
single .tar
or .tar.gz
file archive,
or alternatively as copies of the database files. The backup can be
performed by a command given in a JDBC session if the target database
catalog is running, or on the command-line if the target catalog has been
shutdown.
It is not recommended to backup the database file with an external file backup program while the database is running. The resulting backup will probably be inconsistent and not useful for restoring the database
To back up a running catalog, obtain a JDBC connection and
issue a BACKUP DATABASE
command in SQL. In its most
simple form, the command format below will backup the database as a
single .tar.gz
file to the given directory. This type
of backup performs a checkpoint immediately before backing up the
files.
BACKUP DATABASE TO <directory name> BLOCKING
The directory name must end with a slash
to distinguish it as a directory, and the whole string must be in single
quotes like so: 'subdir/nesteddir/'
.
Normal backup may take a long time with very large databases. Hot backup may be used in those situations. This type of backup does not perform a checkpoint and allows access to the database while backup is in progress.
BACKUP DATABASE TO <directory name> NOT BLOCKING
If you add AS FILES to the statements, the database files are backed up as separate files in the directory, without any gzip compression or tar archiving.
See the next section under Statements for details about the command and its options. See the sections below about restoring a backup.
To back up an offline catalog, the catalog must be in shut down state. You will run a Java command like this. In this example, the database is named dbname and is in the dbdir directory. The backup is saved to a file named backup.tar in the tardir directory.
Example 11.2. Offline Backup Example
java -cp hsqldb.jar org.hsqldb.lib.tar.DbBackup --save tardir/backup.tar dbdir/dbname
where tardir/backup.tar
is a file path
to the *.tar
or *.tar.gz
file to
be created in your file system, and dbdir/dbname
is
the file path to the catalog file base name (in same fashion as in
server.database.*
settings and JDBC URLs with catalog
type file:.
You can list the contents of backup tar files with
DbBackup
on your operating system command line,
or with any Pax-compliant tar or pax client (this includes GNU tar),
Example 11.3. Listing a Backup with DbBackup
java -cp hsqldb.jar org.hsqldb.lib.tar.DbBackup --list tardir/backup.tar
You can also give regular expressions at the end of the
command line if you are only interested in some of the file entries in
the backup. Note that these are real regular expressions, not shell
globbing patterns, so you would use .+script
to match
entries ending in "script", not *script
.
You can examine the contents of the backup in their entirety by restoring the backup, as explained in the following section, to a temporary directory.
You use DbBackup
on your operating system
command line to restore a catalog from a backup.
Example 11.4. Restoring a Backup with DbBackup
java -cp hsqldb.jar org.hsqldb.lib.tar.DbBackup --extract tardir/backup.tar dbdir
where tardir/backup.tar
is a file path
to the *.tar or *.tar.gz file to be read, and dbdir
is the target directory to extract the catalog files into. Note that
dbdir
specifies a directory path, without the
catalog file base name. The files will be created with the names stored
in the tar file (and which you can see as described in the preceding
section). After restoring the database, you can connect to it as
usual.
HyperSQL supports encrypted databases. Encryption services use the Java Cryptography Extensions (JCE) and uses the ciphers installed with the JRE. HyperSQL itself does not contain any cryptography code.
Three elements are involved in specifying the encryption method and key. A cipher, together with its configuration is identified by a string which includes the name of the cipher and optional parameters. A provider is the fully qualified class name of the cipher provider. A key is represented as a hexadecimal string.
First, a key must be created for the desired cipher and configuration. This is done by calling the function CRYPT_KEY(<cipher spec>, <provider>). If the default provider (the built-in JVM ciphers) is used, then NULL should be specified as the provider. The CRYPT_KEY function returns a hexadecimal key. The function call can be made in any HyperSQL database, so long as the provider class is on the classpath. This key can be used to create a new encrypted database. Calls to this function always return different keys, based on a generated random values.
As an example, a call to CRYPT_KEY('Blowfish', null) returned the string, '604a6105889da65326bf35790a923932'. To create a new database, the URL below is used:
jdbc:hsqldb:file:<database
path>;crypt_key=604a6105889da65326bf35790a923932;crypt_type=blowfish
The third property name is crypt_provider. This is specified only when the provider is not the default provider.
HyperSQL works with any symmetric cipher that may be available from the JVM.
The files that are encrypted include the .script, .data, .backup and .log files. The .lobs file is not encrypted by default. The property crypt_lobs=true must be specified to encrypt the .lobs file. When this property is used, the blobs and clobs are both compressed and encrypted.
General operations on an encrypted database are performed the same as with any database. However, some operations are significantly slower than with the equivalent cleartext database. With MEMORY tables, there is no difference to the speed of SELECT statements, but data change statements are slower. With CACHED tables, the speed of all statements is slower.
Security considerations for encrypted databases have been discussed at length in HSQLDB discussion groups. Development team members have commented that encryption is not a panacea for all security needs. The following issues should be taken into account:
Encrypted files are relatively safe in transport, but because databases contain many repeated values and words, especially known tokens such as CREATE, INSERT, etc., breaking the encryption of a database may be simpler than an unknown file.
Only the files are encrypted, not the memory image. Poking into computer memory, while the database is open, will expose the contents of the database.
HyperSQL is open source. Someone who has the key, can compile and use a modified version of the program that saves a full cleartext dump of an encrypted database
Therefore encryption is generally effective only when the users who have access to the crypt key are trusted.
Database operations can be monitored at different levels using internal HyperSQL capabilities or add-ons.
Statement level monitoring allows you to gather statistics about executed statements. HyperSQL is supported by the monitoring tool JAMon (Java Application Monitor). JAMon is currently developed as the SourceForge project, jamonapi.
JAMon works at the JDBC level. It can monitor and gather statistics on different types of executed statements or other JDBC calls.
Early versions of JAMon were developed with HSQLDB and had to be integrated into HSQLDB at code level. The latest versions can be added on as a proxy in a much simpler fashion.
The internally-generated, individual sql log for the database can
be enabled with the SET DATABASE EVENT LOG SQL LEVEL
statement, described in this chapter. As all the executed statements are
logged, there is an impact on speed. So you should only use this for
debugging. Two levels of sql logging are supported.
HyperSQL can log important internal events of the engine. These events occur during the operation of the engine, and are not always coupled with the exact type of statement being executed. Normal events such as opening and closing of files, or errors such as OutOfMemory conditions are examples of logged events.
HyperSQL supports two methods of logging. One method is specific to the individual database and is managed internally by HyperSQL. The other method is specific to JVM and is managed by a logging framework.
The internally-generated, individual log for the database can be
enabled with the SET DATABASE EVENT LOG LEVEL
statement, described in this chapter. This method of logging is very
useful for desktop application deployment, as it provides an ongoing
record of database operations.
HyperSQL also supports log4J and JDK logging. The same event information that is passed to the internal log, is passed to external logging frameworks. These frameworks are typically configured outside HyperSQL. The log messages include the string "hsqldb.db." followed by the unique id (a 16 character string) of the database that generated the message, so they can be identified in a multi-database server context.
As the default JDK logging framework has several shortcomings,
HyperSQL configures this logging framework for better operation. If you
do not want HyperSQL to configure the JDK logging framework, you should
include the system level property
hsqldb.reconfig_logging=false
in your
environment.
HyperSQL has extensive security features which are implemented at different levels and covered in different chapters of this guide.
The server can use SSL and IP address access control lists. See the HyperSQL Network Listeners (Servers) chapter.
You can define a system property to stop the database engine accessing the Java static functions that are on the classpath, apart from a limited set that you allow. See Securing Access to Classes in the SQL-Invoked Routines chapter.
You can define a system property to allow access to files on the file system outside the database directory and its children. This access is only necessary if you use TEXT tables. See the Text Tables chapter.
The database files can be encrypted. Discussed in this chapter.
Within the database, the DBA privileges are required for system and maintenance jobs.
You can define users and roles and grant them access on different database objects. Each user has a password and is granted a set of privileges. See the Access Control chapter.
You can define a password complexity check function for new and changed passwords. This is covered below under Authentication Settings.
You can use external authentication instead of internally stored password to authenticate users for each database. This is covered below under Authentication Settings.
HyperSQL security is multi-layered and avoids any loopholes to circumvent security. It is however the user's responsibility to enable the required level of security.
The default setting are generally adequate for most embedded use of the database or for servers on the host that are accessed from the same machine. For servers accessed within a network, and especially for those accessed from outside the network, additional security settings must be used.
The default settings for server and web server do not use SSL or IP access control lists. These features are enabled programatically, or with the properties used to start the server.
The default settings allow a database user with the DBA role or with schema creation role to access static functions on the classpath. You can disable this feature or limit it to specific classes and methods. This can be done programatically or by setting a system property when you start a server.
If access to specific static functions is granted, then these functions must be considered as part of the database program and checked for any security flaws before inclusion in the classpath.
The default settings do not allow a user to access files outside the database directory. This access is for TEXT table source files. You can override this programatically or with a system property when you start a server.
The encryption of database file does not utilise any user-supplied information for encryption keys. This level of security is outside the realm of users and passwords.
The first user for a new database has the DBA role. This user name was always SA in older versions of HSQLDB, but not in the latest versions. The name of the first DBA user and its password can be specified when the database is created by the first connection to the database. These settings are then stored in the database.
The initial user with the DBA role should be used for admin purposes only. At least one additional role should be created for normal database use in the application and at least one additional user should be created and granted this role. The new role should not be given the DBA role. It can be given the CREATE_SCHEMA role, which allows it to create and access multiple schemas. Alternatively, the user with the DBA role can create the schemas and their objects and then grant specific privileges on the objects to the non-DBA role.
Authentication is the mechanism that determines if a user can access the database at all. Once authentication is performed, the authorization mechanism is used to determine which database objects the particular user can access. The default authentication mechanism is password authentication. Each user is created with a password, which is stored in the database and checked each time a new database connection is created.
Password Complexity Check
HyperSQL allows you to define a function that checks the quality of the passwords defined in the database. The passwords are stored in the database. Each time a user connects, the user's name and password are checked against the stored list of users and passwords. The connection attempt is rejected if there is no match.
External Authentication
You can use an external authentication mechanism instead of the internal authentication mechanism. HyperSQL allows you to define a function that checks the combination of database unique name, user name, and password for each connection attempt. The function can use external resources to authenticate the user. For example, a directory server may be used. The password may be ignored if the external resource can verify the user's credential without it.
You can override external authentication for a user with the ALTER USER statement. See the Access Control chapter
HyperSQL is used more than any other database engine for application testing and development targeted at other databases. Over the years, this usage resulted in developers finding and reporting many obscure bugs in HyperSQL, which have all been fixed in the latest version. Also, HyperSQL 2 has been written to the SQL Standard and avoids the traps caused by superficial imitation of existing RDBMS.
HyperSQL has many property settings that relax conformance to the Standard in order to allow compatibility with other RDBMS, without breaking the core integrity of the database. These properties are modified with SET DATABASE SQL statements described in the SQL Conformance Settings section of this chapter
The SQL Standard has existed since 1989 and has been expanded over the years in several revisions. Also, the X-Open specification has defined a number of SQL functions which are implemented by most RDBMS.
Each RDBMS supports additional functions that are not covered by the standard. Some RDBMS use non-standard syntax for some operations. Fortunately, most popular RDBMS products have introduced better compatibility with the Standard in their recent versions, but there are still some portability issues. HyperSQL overcomes the potability issues using these strategies
An extensive set of functions cover the SQL Standard, X-Open, and most of the useful functions that other RDBMS may support.
Database properties, which can be specified on the URL or as SQL statements, relax conformance to the Standard in order to allow non-standard comparisons and assignments allowed by other RDBMS.
Specific SQL syntax compatibility modes allow syntax and type names that are supported by some popular RDBMS.
User-defined types and functions, including aggregate functions, allow any type or function that is supported by some RDBMS to be defined and used.
In the future, the supported compatibility modes with other RDBMS will be expanded further.
PostgreSQL is fairly compatible with the Standard, but uses some non-standard features.
Use <set database sql syntax PGS
statement>
to enable the PostgreSQL's non-standard
features. References to SERIAL, BIGSERIAL and TEXT data types, as
well as sequence functions, are translated into HSQLDB
equivalents.
Use MVCC if your application is multi-user
PostgreSQL functions are generally supported
For identity columns, PostgreSQL uses a non-standard linkage
with an external identity sequence. In most cases, this can be
converted to GENERATED BY DEFAULT AS IDENTITY
. In
those cases where the identity sequence needs to be shared by
multiple tables, you can use a new HyperSQL 2.2 feature
GENERATED BY DEFAULT AS SEQUENCE <sequence
name>
, which is the equivalent of the PostgreSQL
implementation.
In CREATE TABLE statements, the SERIAL and BIGSERIAL types are
translated into INTEGER or BIGINT, with GENERATED BY
DEFAULT AS IDENTITY
. Usage of DEFAULT NEXTVAL(<sequence
name>) is supported so long as the <sequence
name>
refers to an existing sequence. This usage is
translated into GENERATED BY DEFAULT AS SEQUENCE
<sequence name>
.
In SELECT and other statements, the
NEXTVAL(<sequence name>)
and
LASTVAL()
functions are supported and translated
into HyperSQL's NEXT VALUE FOR <sequence
name>
and IDENTITY()
expressions.
PostgreSQL uses a non-standard expression, SELECT 'A
Test String'
to return a single row table. The standard
form is VALUES('A Test String')
. In PGS syntax
mode, this type of SELECT is supported.
HyperSQL supports SQL Standard ARRAY types. PostgreSQL also supports this, but not entirely according to the Standard.
SQL routines are portable, but some syntax elements are different and require changes.
You may need to use SET DATABASE SQL TDC { DELETE |
UPDATE } FALSE
statements, as PostgreSQL does not enforce
the subtle rules of the Standard for foreign key cascading deletes
and updates.
MySQL had many incompatibilities with the Standard. The latest versions have introduced much greater compatibly, but some of these features have to be turned on via properties. You should therefore check the current Standard compatibility settings of your MySQL database and use the available HyperSQL properties to achieve closer results. If you avoid the few anti-Standard features of MySQL you can port your databases to HyperSQL.
HyperSQL does not have the following non-standard limitations of MySQL.
With HyperSQL, an UPDATE statement can update UNIQUE and PRIMARY KEY columns of a table without causing an exception due to temporary violation of constraints. These constraints are checked at the end of execution, therefore there is no need for an ORDER BY clause in an UPDATE statement.
MySQL foreign key constraints are not enforced by the default MyISAM engine. Be aware of the possibility of data being rejected by HyperSQL due to these constraints.
With HyperSQL INSERT or UPDATE statements either succeed or fail due to constraint violation. MySQL has the non-standard IGNORE overrides to ignore violations, which is not accepted by HyperSQL.
Unlike MySQL, HyperSQL allows you to modify a table with an INSERT, UPDATE or DELETE statement which selects from the same table in a subquery.
Follow the guidelines below for converting MySQL databases and applications.
Use <set database sql syntax MYS
statement>
to enable support for AUTO_INCREMENT and
TEXT data types. These type definitions are translated into HSQLDB
equivalents.
Use MVCC with <set database transaction control
statement>
if your application is multi-user.
Avoid storing invalid values, for example invalid dates such as '0000-00-00' or '2001-00-00' which are rejected by HyperSQL.
Avoid the MySQL feature that trims spaces at the end of CHAR values.
In MySQL, a database is the same as a schema. In HyperSQL several schemas can exist in the same database and accessed transparently. In addition a HyperSQL server supports multiple separate databases.
In MySQL, older, non-standard, forms of database object name case-sensitivity make is difficult to port applications. Use the latest form which encloses case-sensitive names in double quotes.
MySQL functions are generally supported, including GROUP_CONCAT.
For fine control over type conversion, check the settings for
<set database sql convert truncate
statement>
If you use concatenation of possibly NULL values in your
select statements, you may need to change the setting with the
<set database sql concat nulls
statement>
MySQL supports most SQL Standard types (except INTERVAL types), as well as non-standard types, which are also supported by HyperSQL. Supported types include SMALLINT, INT, BIGINT, DOUBLE, FLOAT, DECIMAL, NUMERIC, VARCHAR, CHAR, BINARY, VARBINARY, BLOB, DATE, TIMESTAMP (all Standard SQL) and TINYINT, DATETIME (non Standard).
MySQL uses a non-standard expression, SELECT 'A Test
String'
to return a single row table. The standard form is
VALUES('A Test String')
. In MYS syntax mode, this
type of SELECT is supported.
SQL user-defined function and procedure syntax is very similar to SQL Standard syntax. A few changes may still be required.
Firebird generally follows the SQL Standard. Applications can be ported to HyperSQL without difficulty.
Apache Derby supports a smaller subset of the SQL Standard compared to HyperSQL. Applications can be ported to HyperSQL without difficulty.
Use MVCC with <set database transaction control
statement>
if your application is multi-user.
HyperSQL supports Java language functions and stored procedures with the standard syntax, which is similar to the way Derby supports these features.
Recent versions of Oracle support Standard SQL syntax for outer joins and many other operations. In addition, HyperSQL features a setting to support Oracle syntax and semantics for the most widely used non-standard features.
Use <set database sql syntax ORA
statement>
to enable support for some non-standard
syntax of Oracle.
Use MVCC with <set database transaction control
statement>
if your application is multi-user.
Fine control over MVCC deadlock avoidance is provided by the
<set database transaction rollback on conflict
statement>
and the corresponding
hsqldb.tx_conflict_rollback
connection
property.
If your application relies on Oracle behaviour for nulls in
multi-column UNIQUE constraints, use <set database sql
unique nulls statement>
to change the default.
If your application relies on Oracle behaviour for ordering of
nulls in SELECT statements with ORDER BY, but without NULLS FIRST or
NULLS LAST, use both <set database sql nulls last
statement>
and <set database sql nulls
order statement>
to change the defaults.
If you use the non-standard concatenation of possibly NULL
values in your select statements, you may need to change the setting
for <set database sql concat nulls
statement>
.
Many Oracle functions are supported, including no-arg functions such as SYSDATE and SYSTIMESTAMP and more complex ones such as TO_DATE and TO_CHAR.
Non-standard data type definitions such as NUMBER, VARCHAR2, NVARCHAR2, BINARY_DOUBLE, BINARY_FLOAT, LONG, RAW are translated into the closest HyperSQL / SQL Standard equivalent in ORA mode.
The DATE type is interpreted as TIMESTAMP(0) in ORA syntax mode.
The DUAL table and the expressions, ROWNUM, CURRVAL, NEXTVAL are supported in ORA syntax mode.
HyperSQL natively supports operations involving datetime and interval values. These features are based on the SQL Standard.
Many subtle automatic type conversions, syntax refinements and other common features are supported.
SQL routines are generally portable, but some changes may be required.
DB2 is highly compatible with the SQL Standard (except its lack of support for the INFORMATION_SCHEMA). Applications can be ported to HyperSQL without difficulty.
Use <set database sql syntax DB2
statement>
to enable support for some non-standard
syntax of DB2.
Use MVCC with <set database transaction control
statement>
if your application is multi-user.
HyperSQL supports almost the entire syntax of DB2 together with many of the functions. Even local temporary tables using the SESSION pseudo schema are supported.
The DB2 binary type definition FOR BIT DATA, as well as empty definition of column default values are supported in DB2 syntax mode.
Many DB2 functions are supported.
The DUAL table and the expressions, ROWNUM, CURRVAL, NEXTVAL are supported in DB2 syntax mode.
SQL routines are highly portable with minimal change.
SQLServer has some incompatibilities with the Standard syntax. The most significant is the use of square brackets instead of double quotes for case-sensitive column names.
Use <set database sql syntax MSS
statement>
to enable support for the
CONVERT(<type definition>, <expression)
function with switched order of arguments
Use MVCC with <set database transaction control
statement>
if your application is multi-user.
If you use the non-standard concatenation of possibly NULL values in your select statements, you may need to change the setting for <set database sql concat nulls statement>.
HyperSQL supports + for string concatenation. It also supports many functions supported by these dialects.
SQLServer uses a non-standard expression, SELECT 'A
Test String'
to return a single row table. The standard
form is VALUES('A Test String')
. In MSS syntax
mode, this type of SELECT is supported.
SQL routines need quite a lot of changes.
System level statements are listed in this section. Statements that begin with SET DATABASE or SET FILES are for properties that have an effect on the normal operation of HyperSQL. The effects of these statements are also discussed in different chapters.
These statements perform a system level action.
SHUTDOWN
shutdown statement
<shutdown statement> ::= SHUTDOWN [IMMEDIATELY |
COMPACT | SCRIPT]
Shutdown the database. If the optional qualifier is not used, a normal SHUTDOWN is performed. A normal SHUTDOWN ensures all data is saved correctly and the database opens without delay on next use.
|
SHUTDOWN |
Normal shutdown saves all the database files, then deletes the .log file (and the .backup file in the default mode). This does the same thing as CHECKPOINT, but closes the database when it completes. The database opens without delay on next used. |
|
SHUTDOWN IMMEDIATELY |
Saves the *.log file and closes the database files. This is the quickest form of shutdown. This command should not be used as the routine method of closing the database, because when the database is accessed next time, it may take a long time to start. |
|
SHUTDOWN COMPACT |
This is similar to normal SHUTDOWN, but reduces the *.data file to its minimum size. It can take much longer than normal SHUTDOWN. This shouldn't be used as routine. |
|
SHUTDOWN SCRIPT |
This is similar to SHUTDOWN COMPACT, but it does not rewrite
the This command produces a full script of the database which can be edited for special purposes prior to the next startup. |
Only a user with the DBA role can execute this statement.
BACKUP DATABASE
backup database statement
<backup database statement> ::= BACKUP DATABASE
TO <file path> [SCRIPT] {[NOT] COMPRESSED} {[NOT] BLOCKING} [AS
FILES]
Backup the database to specified <file
path>
for archiving purposes.
The <file path>
can be in two forms.
If the <file path>
ends with a forward slash,
it specifies a directory. In this case, an automatic name for the
archive is generated that includes the date, time and the base name of
the database. The database is backed up to this archive file in the
specified directory. The archive is in .tar.gz
or
.tar
format depending on whether it is compressed or
not.
If the <file path>
does not end with a
forward slash, it specifies a user-defined file name for the backup
archive. The file extension must be either .tar.gz
or
.tar
and this must match the compression
option.
The default set of options is COMPRESSED BLOCKING.
If SCRIPT is specified, the backup will contain a
*.script
file, which contain all the data and
settings of the database. This type of backup is suitable for smaller
databases. With larger databases, this takes a long time. When the
SCRIPT option is no used, the backup set will consist of the current
snapshot of all database files.
If NOT COMPRESSED is specified, the backup is a tar file, without compression. Otherwise, it is in gzip format.
The qualifier, BLOCKING, means all database operations are suspended during backup. During backup, a CHECKPOINT command is silently executed. This mode is always used when SCRIPT is specified.
Hot backup is performed if NOT BLOCKING is specified. In this mode, the database can be used during backup. This mode should only be used with very large databases. A hot backup set is less compact and takes longer to restore and use than a normal backup set produced with the BLOCKING option. You can perform a CHECKPOINT just before a hot backup in order to reduce the size of the backup set.
If AS FILES is specified, the database files are copied to a directory specified by <file path> without any compression. The file path must be a directory. If the directory does not exist, it is created. The file path may be absolute or relative. If it is relative, it is interpreted as relative to the location of database files. When AS FILES is specified, SCRIPT or COMPRESSED options are not available. The backup can be performed as BLOCKING or NOT BLOCKING.
The HyperSQL jar also contains a program that creates an archive of an offline database. It also contains a program to expand an archive into database files. These programs are documented in this chapter under Backing up Database Catalogs.
Only a user with the DBA role can execute this statement.
CHECKPOINT
checkpoint statement
<checkpoint statement> ::= CHECKPOINT
[DEFRAG]
Closes the database files, rewrites the script file, deletes the log file and reopens the database.
If DEFRAG
is specified, also shrinks the
*.data
file to its minimum size. CHECKPOINT
DEFRAG
time depends on the size of the database and can take a
long time with huge databases.
A checkpoint on a multi-user database waits until all other sessions have committed or rolled back. While the checkpoint is in progress other sessions are kept waiting. Checkpoint does not close any sessions.
Only a user with the DBA role can execute this statement.
SCRIPT
script statement
<script statement> ::= SCRIPT [<file
name>]
Returns a script containing SQL statements that define the
database, its users, and its schema objects. If <file
name>
is not specified, the statements are returned in a
ResultSet, with each row containing an SQL statement. No data statements
are included in this form. The optional file name is a single-quoted
string. If <file name>
is specified, then the
script is written to the named file. In this case, all the data in all
tables of the database is included in the script as INSERT
statements.
Only a user with the DBA role can execute this statement.
These statements change the database settings.
SET DATABASE COLLATION
set database collation statement
<set database collation statement> ::= SET
DATABASE COLLATION <collation name> [ NO PAD | PAD SPACE
]
Each database can have its own default collation. Sets the collation from the set of collations supported by HyperSQL. Once this command has been issued, the database can be opened in any JVM and will retain its collation.
All collations pad the shorter string with spaces when two
strings are compared. If NO PAD is specified, comparison is performed
without padding. The default system collation is named
SQL_TEXT
. To use the default without padding use
SET DATABASE COLLATION SQL_TEXT NO PAD
.
After you change the collation for a database that contains
collated data, you must execute SHUTDOWN COMPACT
or
SHUTDOWN SCRIPT
in order to recreate the
indexes.
Only a user with the DBA role can execute this statement.
Collations are discussed in the Schemas and Database Objects chapter. Some examples of setting the database collation follow:
-- this collation is an ascii collation with Upper Case Comparison (coverts strings to uppercase for comparison) SET DATABASE COLLATION SQL_TEXT_UCC -- this collation is case-insensitive English SET DATABASE COLLATION "English 1" -- this collation is case-sensitive French SET DATABASE COLLATION "French 2"
SET DATABASE DEFAULT RESULT MEMORY ROWS
set database default result memory rows
statement
<set database default result memory rows> ::=
SET DATABASE DEFAULT RESULT MEMORY ROWS <unsigned integer
literal>
Sets the maximum number of rows of each result set and internal
temporary table that is held in memory. Temporary tables includes views,
schema-based and session-based TEMPORARY tables, transient tables for
subqueries, and INFORMATION_SCHEMA
tables.
This setting applies to all sessions. Individual sessions can
change the value with the SET SESSION RESULT MEMORY
ROWS
statement. The default is 0, meaning all result sets are
held in memory.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.result_max_memory_rows
.
SET DATABASE DEFAULT TABLE TYPE
set database default table type
statement
<set database default table type> ::= SET
DATABASE DEFAULT TABLE TYPE { CACHED | MEMORY }
Sets the type of table created when the next CREATE TABLE statement is executed. The default is MEMORY.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.default_table_type
.
SET DATABASE EVENT LOG LEVEL
set database event log level statement
<set database event log level> ::= SET DATABASE
EVENT LOG [ SQL ] LEVEL { 0 | 1 | 2 | 3 }
When the SQL option is not used, this statement sets the amount of information logged in the internal, database-specific event log. Level 0 means no log. Level 1 means only important (error) events. Level 2 means more events, including both important and less important (normal) events. Level 3 includes even more details. For readonly and mem: databases, if the level is set above 0, the log messages are directed to stderr.
The events are logged in a file with the extension
.app.log
alongside the main database files.
This is equivalent to the connection property
hsqldb.applog
.
When the SQL option is used, this statement logs the SQL statements as they are executed. Each log line contains the timestamp and the session number, followed by the SQL statement and JDBC arguments if any.
Levels 1, 2 and 3 are supported. Level 1 only logs commits and rollbacks, while Level 2 and 3 log all statements. Level 2 truncates long statements, while level 3 reports the full statement and parameter values.
The logged lines are stored in a file with the extension
.sql.log
alongside the main database files.
This is equivalent to the connection property
hsqldb.sqllog
.
Only a user with the DBA role can execute this statement.
In version 2.3, the equivalent URL properties,
hsqldb.app_log
and hsqldb.sql_log
,
can be used not only for a new database, but also when opening an
existing file database to change the event log level.
An extract from an .sql.log file created with log Level 3 is shown below. The numbers after the timestamp (10 and 1) show the session number. The values for prepared statement parameters are shown in parentheses at the end of the statement.
Example 11.5. SQL Log Example
2012-11-29 10:40:40.250 10 INSERT INTO TEST_CLOB VALUES (1,'Ut wisi enim ad minim veniam, quis nostrud exerci') 2012-11-29 10:40:40.250 1 INSERT INTO SYSTEM_LOBS.LOB_IDS VALUES(?, ?, ?, ?) (1,49,0,40) 2012-11-29 10:40:40.250 1 COMMIT 2012-11-29 10:40:40.265 1 CALL SYSTEM_LOBS.ALLOC_BLOCKS(?, ?, ?) (1,0,1) 2012-11-29 10:40:40.265 1 COMMIT
SET DATABASE GC
set database gc statement
<set database gc statement> ::= SET DATABASE GC
<unsigned integer literal>
An optional property which forces calls to System.gc()
after the specified number of row operations. The default
value for this property is 0, which means no System.gc() calls. Usual
values for this property range from 10000 depending on the system and
the memory allocation. This property may be useful in some in-process
deployments, especially with older JVM implementations.
Only a user with the DBA role can execute this statement.
SET DATABASE UNIQUE NAME
set database unique name
<set database unique name statement> ::= SET
DATABASE UNIQUE NAME <identifier>
Each HyperSQL catalog (database) has an engine-generated internal name. This name is a 16 character long string, beginning with HSQLDB and based on the time of creation of the database. The name is used for the log events that are sent to external logging frameworks. The new name must be exactly 16 characters long with no spaces.
Only a user with the DBA role can execute this statement.
SET DATABASE TRANSACTION CONTROL
set database transaction control statement
<set database transaction control statement> ::=
SET DATABASE TRANSACTION CONTROL { LOCKS | MVLOCKS | MVCC
}
Set the concurrency control system for the database. It can be issued only when all sessions have been committed or rolled back. This command and its modes is discussed in the Sessions and Transactions chapter.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.tx
.
SET DATABASE TRANSACTION ROLLBACK ON CONFLICT
set database transaction rollback on conflict statement
<set database transaction rollback on conflict
statement> ::= SET DATABASE TRANSACTION ROLLBACK ON CONFLICT { TRUE |
FALSE }
When a transaction deadlock or conflict is about to happen, the current transaction is rolled back and an exception is raised. When this property is set false, the transaction is not rolled back. Only the latest statement that would cause the conflict is undone and an exception is raised. The property should not be changed unless the application can quickly perform an alternative statement and complete the transaction. It is provided for compatibility with other database engines which do not roll back the transaction upon deadlock. This command is also discussed in the Sessions and Transactions chapter.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.tx_conflict_rollback
.
SET DATABASE DEFAULT ISOLATION LEVEL
set database default isolation level
statement
<set database default isolation level> ::= SET
DATABASE DEFAULT ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE
}
Sets the transaction isolation level for new sessions. The default is READ COMMITTED. Each session can also set its isolation level.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.tx_level
.
SET DATABASE TEXT TABLE DEFAULTS
set database text table defaults statement
<set database text table defaults statement> ::=
SET DATABASE TEXT TABLE DEFAULTS <character
literal>
An optional property to override default text table settings. The string literal has the same format as the string used for setting the data source of a text table, but without the file name. See the Text Tables chapter.
Only a user with the DBA role can execute this statement.
These statements modify the level of conformance to the SQL Standard in different areas. The settings that specify SQL SYNTAX are for compatibility with other database engines and are FALSE by default. For all the rest of the settings, TRUE means better conformance to the Standard (unless the Standard defines the behaviour as implementation dependent). The default value of a few of these settings is FALSE, due to widespread non-conforming statements that are already in use in user applications or statements generated by object relational tools. So long as it is practical, it is best to set the non-conforming defaults to TRUE in order to improve the quality of the database application.
SET DATABASE SQL SIZE
set database sql size statement
<set database sql size statement> ::= SET
DATABASE SQL SIZE { TRUE | FALSE }
Enable or disable enforcement of column sizes for CHAR and
VARCHAR columns. The default is TRUE, meaning table definition must
contain VARCHAR(n)
instead of
VARCHAR
.
SQL Standard requires enforcement.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.enforce_size
.
SET DATABASE SQL NAMES
set database sql names statement
<set database sql names statement> ::= SET
DATABASE SQL NAMES { TRUE | FALSE }
Enable or disable full enforcement of the rule that prevents
SQL keywords being used for database object names such as columns and
tables. The default is FALSE
, meaning
disabled.
SQL Standard requires enforcement. It is better to enable this check, in order to improve the quality and correctness of SQL statements.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.enforce_names
.
SET DATABASE SQL REGULAR NAMES
set database sql regular names statement
<set database sql regular names statement> ::=
SET DATABASE SQL REGULAR NAMES { TRUE | FALSE }
Enable or disable use of the underscore character at the
beginning, or the dollar character anywhere in database object names
such as columns and tables. The default is TRUE
,
meaning disabled.
SQL Standard does not allow the underscore character at the start of names, and does not allow the dollar character anywhere in a name. This setting can be changed for compatibility with existing database or for porting databases which include names that do not conform to the Standard.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.regular_names
.
SET DATABASE SQL REFERENCES
set database sql references statement
<set database sql references statement> ::= SET
DATABASE SQL REFERENCES { TRUE | FALSE }
This command can enable or disable full enforcement of the rule that prevents ambiguous column references in SQL statements (usually SELECT statements). A column reference is ambiguous when it is not qualified by a table name or table alias and can refer to more than one column in a JOIN list.
The property is FALSE
by default.
SQL Standard requires enforcement. It is better to enable this check, in order to improve the quality and correctness of SQL statements. When false, the first matching table is used to resolve the column reference.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.enforce_refs
.
SET DATABASE SQL TYPES
set database sql types statement
<set database sql types statement> ::= SET
DATABASE SQL TYPES { TRUE | FALSE }
This command can enable or disable full enforcement of the
rules that prevents illegal type conversions and parameters or nulls
without type in SQL statements (usually SELECT statements). For example
an INTEGER column or a DATE column cannot be compared to a character
string or searched with a LIKE expression when the property is
TRUE
.
The property is FALSE
by default.
SQL Standard requires enforcement. It is better to enable this check, in order to improve the quality and correctness of SQL statements.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.enforce_type
.
SET DATABASE SQL TDC DELETE
set database sql tdc delete statement
<set database sql tdc delete statement> ::= SET
DATABASE SQL TDC DELETE { TRUE | FALSE }
This command can enable or disable full enforcement of the SQL Standard rules that prevents triggered data change exceptions caused by ON DELETE CASCADE clauses of foreign key constraint.
When there are multiple constraints, a row may be updated by one constraint and deleted by another constraint in the same operation. This is not allowed by default. Changing this to false allows such violations of the Standard to pass without an exception.
The property is TRUE
by default.
SQL Standard requires enforcement, therefore this property shouldn't be changed unless an application written for a non-conforming RDBMS needs it.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.enforce_tdc_delete
.
SET DATABASE SQL TDC UPDATE
set database sql tdc update statement
<set database sql tdc update statement> ::= SET
DATABASE SQL TDC UPDATE { TRUE | FALSE }
This command can enable or disable full enforcement of the SQL
Standard rules that prevents triggered data change exceptions caused by
multiple ON UPDATE or ON DELETE SET clauses of foreign key constraint.
When there are multiple constraints, a field in a row may be updated by
two constraints to different values in the same operation. This is not
allowed by default. Changing this to FALSE
allows
such violations of the Standard to pass without an exception.
The property is TRUE
by default.
SQL Standard requires enforcement, therefore this property shouldn't be changed unless an application written for a non-conforming RDBMS needs it.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.enforce_tdc_update
.
SET DATABASE SQL TRANSLATE TTI TYPES
set database sql translate tti types statement
<set database sql translate tti types statement>
::= SET DATABASE SQL TRANSLATE TTI TYPES { TRUE | FALSE
}
The JDBC Specification up to version 4.1 does not support some SQL Standard built-in types, therefore these types must be translated to a supported type when accessed through JDBC ResultSet and PreparedStatement methods.
If the property is true, the TIME / TIMESTAMP WITH TIME ZONE
types and INTERVAL types are represented in JDBC methods of
ResultSetMetaData
and
DatabaseMetaData
as JDBC datetime types without
time zone and the VARCHAR type respectively. The original type names are
preserved.
The property is TRUE
by default. If set to
FALSE
, the type codes for WITH TIME ZONE types will
be SQL type codes as opposed to JDBC type codes.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
jdbc.translate_tti_types
.
SET DATABASE SQL CONCAT NULLS
set database sql concat nulls statement
<set database sql concat nulls statement> ::=
SET DATABASE SQL CONCAT NULLS { TRUE | FALSE }
When the property is TRUE
, concatenation of
a null value with a not-null value results in a null value. When the
property is FALSE
this type of concatenation result
in the not-null value.
Setting this property FALSE
results in
concatenation behaviour similar to Oracle or MS SQL Server.
SQL Standard requires a NULL result..
The property is TRUE
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.concat_nulls
.
SET DATABASE SQL UNIQUE NULLS
set database sql unique nulls statement
<set database sql unique nulls statement> ::=
SET DATABASE SQL UNIQUE NULLS { TRUE | FALSE }
When the property is TRUE
, with multi-column
UNIQUE constraints, it is possible to insert multiple rows for which one
or more of the values for the constraint columns is NULL. When the
property is FALSE
, if there is any not-null value in
the columns, then the set of values is compared to the existing rows and
if there is a match, an exception is thrown. The setting
FALSE
, makes the behaviour more restrictive. For
example, inserting (1, null) twice is possible by default, but not
possible when the property is FALSE
.
Setting this property FALSE
results in
UNIQUE constraint behaviour similar to Oracle.
SQL Standard requires the default (TRUE) behaviour.
The property is TRUE
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.unique_nulls
.
SET DATABASE SQL CONVERT TRUNCATE
set database sql convert truncate
<set database sql convert truncate statement>
::= SET DATABASE SQL CONVERT TRUNCATE { TRUE | FALSE
}
When the property is TRUE
, conversion from a
floating point value (a DOUBLE value) to an integral type always
truncates the fractional part. When the property is
FALSE
, rounding takes place instead of truncation.
For example, assigning the value 123456E-2 to an integer column will
result in 1234 by default, but 1235 when the property is
FALSE
.
Standard SQL considers this behaviour implementation dependent.
The property is TRUE
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.convert_trunc
.
SET DATABASE SQL AVG SCALE
set database sql avg scale
<set database sql avg scale> ::= SET DATABASE
SQL AVG SCALE <numeric value>
By default, the result of division and the AVG and MEDIAN aggregate functions has the same type as the aggregated type of the values. This includes the scale. The scale specified with this property is used if it is larger than the scale of the operation. For example, the average of 5 and 10 is 7 by default, but 7.50 if the scale is specified as 2. The result of 7/3 is 2 by default but 2.33 if the scale is specified as 2.
Standard SQL considers this behaviour implementation dependent. Some databases use a default scale larger than zero.
The property is 0
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.avg_scale
.
SET DATABASE SQL DOUBLE NAN
set database sql double nan
<set database sql double nan> ::= SET DATABASE
SQL DOUBLE NAN { TRUE | FALSE }
When the property is TRUE
, division of a
floating point value (a DOUBLE value) by zero raises an exception. When
the property is FALSE
, a Java
Double.NaN
, POSITIVE_INFINITY
or
NEGATIVE_INFINITY
value is returned.
Standard SQL requires an exception to be raised.
The property is TRUE
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.double_nan
.
SET DATABASE SQL NULLS FIRST
set database sql nulls first
<set database sql nulls first> ::= SET DATABASE
SQL NULLS FIRST { TRUE | FALSE }
When the property is TRUE
, nulls appear
before values in result sets with ORDER BY. When set FALSE, nulls appear
after the values. Some databases, including PostgreSQL, Oracle and MS
SQL Server, return nulls after the values.
The property is TRUE
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.nulls_first
.
SET DATABASE SQL NULLS ORDER
set database sql nulls order
<set database sql nulls order> ::= SET DATABASE
SQL NULLS ORDER { TRUE | FALSE }
When NULLS FIRST or NULLS LAST is used explicitly in the ORDER BY clause, this property is ignored.
When the property is TRUE
, nulls appear
according to the value of NULL FIRST property as described
above.
When set FALSE
, nulls appear according to
the value of NULLS FIRST property when DESC is not used in the ORDER BY
clause. But if DESC is used, the position of nulls is reversed. Some
databases, including MySQL and Oracle, return nulls in this manner when
DESC is used in ORDER BY.
The property is TRUE
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.nulls_order
.
SET DATABASE SQL IGNORECASE
set database sql ignorecase
<set database sql ignorecase> ::= SET DATABASE
SQL IGNORECASE { TRUE | FALSE }
This property is FALSE
by default and should
only be used in special circumstances where compatibility with a
different database is required.
When the property is TRUE
, all declarations
of VARCHAR
columns in tables or other database
objects are converted to VARCHAR_IGNORECASE
. This has
a global effect on the database, unlike the SET
IGNORECASE
statement which applies only to the current
session.
The property is FALSE
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.ignore_case
.
SET DATABASE SQL SYNTAX DB2
set database sql syntax DB2
<set database sql syntax DB2 statement> ::= SET
DATABASE SQL SYNTAX DB2 { TRUE | FALSE }
This property, when set TRUE, enables support for some elements
of DB2 syntax. Single-row SELECT statements (SELECT
<expression list>
without the FROM clause) are supported
and treated as the SQL Standard equivalent, VALUES
<expression list>
. The DUAL table is supported, as well
as the ROWNUM pseudo-column. BINARY type definitions such as VARCHAR(L)
FOR BIT DATA are supported. Empty DEFAULT clauses in column definitions
are supported.
The property is FALSE
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.syntax_db2
.
SET DATABASE SQL SYNTAX MSS
set database sql syntax MSS
<set database sql syntax MSS statement> ::= SET
DATABASE SQL SYNTAX MSS { TRUE | FALSE }
This property, when set TRUE, enables support for some elements
of SQLServer syntax. Single-row SELECT statements (SELECT
<expression list>
without the FROM clause) are supported
and treated as the SQL Standard equivalent, VALUES
<expression list>
. The parameters of CONVERT() function
are switched in this mode.
The property is FALSE
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.syntax_mss
.
SET DATABASE SQL SYNTAX MYS
set database sql syntax MYS
<set database sql syntax MYS statement> ::= SET
DATABASE SQL SYNTAX MYS { TRUE | FALSE }
This property, when set TRUE, enables support for some elements of MySQL syntax. The TEXT data type is translated to LONGVARCHAR.
In CREATE TABLE statements, [NOT NULL | NULL] can be used immediately after the column type name and before the DEFAULT clause. AUTO_INCREMENT is translated to the GENERATED BY DEFAULT AS IDENTITY clause.
Single-row SELECT statements (SELECT <expression
list>
without the FROM clause) are supported and treated as
the SQL Standard equivalent, VALUES <expression
list>
.
The property is FALSE
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.syntax_mys
.
SET DATABASE SQL SYNTAX ORA
set database sql syntax ORA
<set database sql syntax ORA statement> ::= SET
DATABASE SQL SYNTAX ORA { TRUE | FALSE }
This property, when set TRUE, enables support for some elements of Oracle syntax. The DUAL table is supported, together with ROWNUM, NEXTVAL and CURRVAL syntax and semantics.
The non-standard types are translated to supported standard types. BINARY_DOUBLE and BINARY_FLOAT are translated to DOUBLE. LONG RAW and RAW are translated to VARBINARY with long or medium length limits. LONG and VARCHAR2 are translated to VARCHAR with long or medium length limits. NUMBER is translated to DECIMAL. Some extra type conversions and no-arg functions are also allowed in this mode.
The property is FALSE
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.syntax_ora
.
SET DATABASE SQL SYNTAX PGS
set database sql syntax PGS
<set database sql syntax PGS statement> ::= SET
DATABASE SQL SYNTAX PGS { TRUE | FALSE }
This property, when set TRUE, enables support for some elements of PosgtreSQL syntax. The TEXT data type is translated to LONGVARCHAR, while the SERIAL data types is translated to BIGINT together with GENERATED BY DEFAULT AS IDENTITY.
Single-row SELECT statements (SELECT <expression
list>
without the FROM clause) are supported and treated as
the SQL Standard equivalent, VALUES <expression
list>
.
The functions NEXTVAL(<sequence name
string>)
, CURRVAL(<sequence name
string>)
and LASTVAL()
are supported in
this compatibility mode.
The property is FALSE
by default.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
sql.syntax_pgs
.
SET DATABASE REFERENTIAL INTEGRITY
set database referential integrity statement
<set database referential integrity statement>
::= SET DATABASE REFERENTIAL INTEGRITY { TRUE | FALSE
}
This command enables or disables the enforcement of referential integrity constraints (foreign key constraints), check constraints apart from NOT NULL and execution of triggers. By default, all constraints are checked.
The only legitimate use of this statement is before importing large amounts of external data into tables that have existing FOREIGN KEY constraints. After import, the statement must be used again to enable constraint enforcement.
If you are not sure the data conforms to the constraints, run queries to verify all rows conform to the FOREIGN KEY constraints and take appropriate actions for the rows that do not conform.
A query example to return the rows in a foreign key table that have no parent is given below:
Example 11.6. Finding foreign key rows with no parents after a bulk import
SELECT * FROM foreign_key_table LEFT OUTER JOIN primary_key_table ON foreign_key_table.fk_col = primary_key_table.pk_col WHERE primary_key_table.pk_col IS NULL
Only a user with the DBA role can execute this statement.
These statements control the memory and other settings for database persistence.
SET FILES BACKUP INCREMENT
set files backup increment statement
<set files backup increment statement> ::= SET
FILES BACKUP INCREMENT { TRUE | FALSE }
Older versions of HSQLDB perform a backup of the .data file before its contents are modified and the whole .data file is saved in a compressed form when a CHECKPOINT or SHUTDOWN is performed. This takes a long time when the size of the database exceeds 100 MB or so (on an average 2010 computer, you can expect a backup speed of 20MB per second or more).
The alternative is backup in increments, just before some part of the .data file is modified. In this mode, no backup is performed at CHECKPOINT or SHUTDOWN. This mode is preferred for large databases which are opened and closed frequently.
The default mode is TRUE
. If the old method
of backup is preferred, the mode can be set
FALSE
.
Warning: The old, non-incremental setting, FALSE, shouldn't be used at all when the data file is larger than 4GB. If it is used, the data file is not fully backed up and can result in corruption. The zip compression method is used in this mode and it is limited to 4GB size.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.inc_backup
.
SET FILES CACHE ROWS
set files cache rows statement
<set files cache rows statement> ::= SET FILES
CACHE ROWS <unsigned integer literal>
Sets the maximum number of rows (of CACHED tables) held in the memory cache. The default is 50000 rows.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.cache_rows
.
SET FILES CACHE SIZE
set files cache size statement
<set files cache size statement> ::= SET FILES
CACHE SIZE <unsigned integer literal>
Sets maximum amount of data (of CACHED tables) in kilobytes held in the memory cache. The default is 10000 kilobytes. Note the amount of memory used is larger than this amount, which does not account for Java object size overheads.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.cache_size
.
SET FILES DEFRAG
set files defrag statement
<set files defrag statement> ::= SET FILES
DEFRAG <unsigned integer literal>
Sets the threshold for performing a DEFRAG during a checkpoint.
The <unsigned integer literal>
is the
percentage of abandoned space in the *.data
file.
When a CHECKPOINT is performed either as a result of the
.log
file reaching the limit set by SET
FILES LOG SIZE m
, or by the user issuing a CHECKPOINT command,
the amount of space abandoned since the database was opened is checked
and if it is larger than specified percentage, a CHECKPOINT DEFRAG is
performed instead of a CHECKPOINT.
The default is 0, which indicates no DEFRAG. Useful values are between 10 to 50.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.defrag_limit
.
SET FILES LOG
set files log statement
<set files log statement> ::= SET FILES LOG {
TRUE | FALSE }
Sets logging of database operations on or off. Turning logging off is for special usage, such as temporary cache usage. The default is TRUE.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.log_data
.
SET FILES LOG SIZE
set files log size statement
<set files log size statement> ::= SET FILES LOG
SIZE <unsigned integer literal>
Sets the maximum size in MB of the *.log
file to the specified value. The default maximum size is 50 MB. If the
value is zero, no limit is used for the size of the file. When the size
of the file reaches this value, a CHECKPOINT is performed and the the
*.log
file is cleared to size 0.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.log_size
.
SET FILES NIO
set files nio
<set files nio statement> ::= SET FILES NIO {
TRUE | FALSE }
Sets the access method of the .data file. The default is TRUE and uses the Java nio classes to access the file via memory-mapped buffers.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.nio_data_file
.
SET FILES NIO SIZE
set files nio size
<set files nio size statement> ::= SET FILES NIO
SIZE <unsigned integer literal>
Sets The maximum size of .data file in megabytes that can use the nio access method. When the file gets larger than this limit, non-nio access methods are used. Values 64, 128, 256, 512, 1024 and larger multiples of 512 can be used. The default is 256MB.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.nio_max_size
.
SET FILES WRITE DELAY
set files write delay statement
<set files write delay statement> ::= SET FILES
WRITE DELAY {{ TRUE | FALSE } | <seconds value> | <milliseconds
value> MILLIS}
Set the WRITE DELAY property of the database. The WRITE DELAY controls the frequency of file sync for the log file. When WRITE_DELAY is set to FALSE or 0, the sync takes place immediately at each COMMIT. WRITE DELAY TRUE performs the sync once every 0.5 seconds (which is the default). A numeric value can be specified instead.
The purpose of this command is to control the amount of data loss in case of a total system crash. A delay of 1 second means at most the data written to disk during the last second before the crash is lost. All data written prior to this has been synced and should be recoverable.
A write delay of 0 impacts performance in high load situations, as the engine has to wait for the file system to catch up.
To avoid this, you can set write delay down to 10 milliseconds.
Each time the SET FILES WRITE DELAY statement is executed with any value, a sync is immediately performed.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection properties
hsqldb.write_delay
and
hsqldb.write_delay_millis
.
SET FILES SCALE
set files scale
<set files scale statement> ::= SET FILES SCALE
<scale value>
Changes the scale factor for the .data file. The default scale is 8 and allows 16GB of data storage capacity. The scale can be increased in order to increase the maximum data storage capacity. The scale values 8, 16, 32, 64, 128, 256, 512, 1024 are allowed. Scale value 1024 allows a maximum capacity of 2 TB.
This command can be used only when there is no data in CACHED
tables. This is equivalent to the connection property
hsqldb.cache_file_scale
.
The scale factor indicates the size of the unit of storage of data in bytes. For example, with a scale factor of 128, a row containing a small amount of data will use 128 bytes. Larger rows may use multiple units of 128 bytes.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.cache_file_scale
.
SET FILES LOB SCALE
set files lob scale
<set files lob scale statement> ::= SET FILES
LOB SCALE <scale value>
Changes the scale factor for the .lobs file. The scale is interpreted in kilobytes. The default scale is 32 and allows 64TB of lob data storage capacity. The scale can be reduced in order to improve storage efficiency. If the lobs are a lot smaller than 32 kilobytes, reducing the scale will reduce wasted space. The scale values 1, 2, 4, 8, 16, 32 are allowed. For example if the average size of lobs is 4 kilobytes, the default scale of 32 will result in 28KB wasted space for each lob. Reducing the lob scale to 2 will result in average 1KB wasted space for each lob.
This command can be used only when there is no lob in the database.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.lob_file_scale
.
SET FILES LOB COMPRESSED
set files lob compressed
<set files lob compressed statement> ::= SET
FILES LOB COMPRESSED { TRUE | FALSE }
By default, lobs are not compressed for storage. When this
setting is TRUE
, all BLOB and CLOB values stored in
the database are compressed. Compression reduces the storage size but
increases the access time.
This command can be used only when there is no lob in the database.
Only a user with the DBA role can execute this statement.
This is equivalent to the connection property
hsqldb.lob_compressed
.
SET FILES SCRIPT FORMAT
set files script format
<set files script format statement> ::= SET
FILES SCRIPT FORMAT { TEXT | COMPRESSED }
Changes the compression setting for database scripts. The default is text. Using COMPRESSED results in the storage of the .script file in gzip compressed form. Using this command causes a CHECKPOINT.
Only a user with the DBA role can execute this statement.
SET TABLE TYPE
set table type
<set table type statement> ::= SET TABLE
<table name> TYPE { MEMORY | CACHED }
Changes the storage type of an existing table between CACHED and MEMORY types.
Only a user with the DBA role can execute this statement.
Two settings are available for authentication control.
When the default password authentication is used, the passwords can be checked for complexity according to administrative rules
SET DATABASE PASSWORD CHECK FUNCTION
set database password check function
<set database password check function statement>
::= SET DATABASE PASSWORD CHECK FUNCTION { <routine body> | NONE
}
The routine body is the body of a function that has a VARCHAR
parameter and returns a BOOLEAN. This function checks the
PASSWORD
submitted as parameter and returns TRUE if
it conforms to complexity checks, or FALSE, if it does not.
The <routine body>
can be an SQL block
or an external Java function reference. This is covered in the SQL-Invoked Routines
chapter
To disable this mechanism, the token NONE
can be specified instead of the <routine
body>
.
Only a user with the DBA role can execute this statement.
In the examples below, an SQL function and a Java function are used.
SET DATABASE PASSWORD CHECK FUNCTION BEGIN ATOMIC IF CHAR_LENGTH(PASSWORD) > 6 THEN RETURN TRUE; ELSE RETURN FALSE; END IF; END SET DATABASE PASSWORD CHECK FUNCTION EXTERNAL NAME 'CLASSPATH:org.anorg.access.AccessClass.accessMethod' // the Java method is defined like this public static boolean accessMethod(String param) { return param != null && param.length > 6; }
It is possible to replace the default password authentication completely with a function that uses external authentication servers, such as LDAP. This function is called each time a user connects to the database.
SET DATABASE AUTHENTICATION FUNCTION
set database authentication function
<set database authentication function statement>
::= SET DATABASE AUTHENTICATION FUNCTION { <external body
reference> | NONE }
The routine body is an external Java function reference. This function has three String parameters. The first parameter is the unique name of the database, the second parameter the user name, and the third parameter the password.
External authentication can be used in two different patterns. In the first pattern, user names must be stored in the database. In the second pattern, user names shouldn't be stored in the database and any names that are stored in the database are ignored.
In both patterns, the username and password are checked by the authentication function. If the function throws a runtime exception then authentication fails.
In the first pattern, the function always returns null if authentication is successful.
In the second pattern, the function returns a list of role names that have been granted to the user. These roles must match the ROLE objects that have been defined in the database.
The Java function should return an instance of org.hsqldb.jdbc.JDBCArrayBasic constructed with a String[] argument that contains the role names.
Only a user with the DBA role can execute this statement.
SET DATABASE AUTHENTICATION FUNCTION EXTERNAL NAME 'CLASSPATH:org.anorg.access.AccessClass.accessExernalMethod' // the Java method is defined like this public static java.sql.Array accessExternalMethod(String database, String user, String password) { if (externalCheck(database, user, password) { return null; } throw new RuntimeException("failed to authenticate"); }
$Revision: 5260 $
Copyright 2002-2012 Fred Toussi. Permission is granted to distribute this document without any alteration under the terms of the HSQLDB license. Additional permission is granted to the HSQL Development Group to distribute this document with or without alterations under the terms of the HSQLDB license.
2013-07-08 15:31:27+0100
Table of Contents
The normal method of accessing a HyperSQL catalog is via the JDBC
Connection interface. An introduction to different methods of providing
database services and accessing them can be found in the SQL Language chapter.
Details and examples of how to connect via JDBC are provided in our
JavaDoc for
JDBCConnection
.
A uniform method is used to distinguish between different types of
connection. The common driver identifier is
jdbc:hsqldb:
followed by a protocol identifier
(mem: file: res: hsql: http: hsqls: https:
) then
followed by host and port identifiers in the case of servers, then
followed by database identifier. Additional property / value pairs can be
appended to the end of the URL, separated with semicolons.
Table 12.1. Memory Database URL
| Driver and Protocol | Host and Port Example | Database Example | ||
|---|---|---|---|---|
| not available |
|
||
|
Lowercase, single-word identifier creates the in-memory database when the first connection is made. Subsequent use of the same Connection URL connects to the existing DB. The old form for the
URL, |
Table 12.2. File Database URL
| Driver and Protocol | Host and Port Example | Database Example | ||||
|---|---|---|---|---|---|---|
| not available |
|
||||
|
The file path specifies the
database files. It should consist of a relative or absolute path
to the directory containing the database files, followed by a '/'
and the database name. In the above examples the first one refers
to a set of mydb.* files in the directory where the
|
Table 12.3. Resource Database URL
| Driver and Protocol | Host and Port Example | Database Example | ||
|---|---|---|---|---|
| not available |
|
||
Database files can be loaded from
one of the jars specified as part of the Java
command the same way as resource files are accessed in Java
programs. The /adirectory above stands for a
directory in one of the jars. |
Table 12.4. Server Database URL
| Driver and Protocol | Host and Port Example | Database Example | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
||||||||||
|
The host and port specify
the IP address or host name of the server and an optional port
number. The database to connect to is specified by an alias. This
alias is a lowercase string defined in the
The old form
for the server URL, e.g.,
|
Two types of variables are allowed for file: database URLs. These properties have an effect only if used for the first connection to the database (the connection which opens the database). When running a server, these variables have no effect on the connection URL but can be appended to the database path URL in server.properties or the server command line.
If the database part of a file: database begins with
~/
or ~\
the tilde character is
replaced with the value of the system property
"user.home"
resulting in the database being created or
accessed in this directory, or one of its subdirectories. In the examples
below, the database files for mydb
and
filedb
are located in the user's home directory.
jdbc:hsqldb:file:~/mydb jdbc:hsqldb:file:~/filedb;shutdown=true
If the database URL contains a string in the form of
${propname}
then the sequence of characters is replaced
with the system property with the given name. For example you can use this
in the URL of a database that is used in a web application and define the
system property, "propname" in the web application properties. In the
example below, the string ${mydbpath}
is replaced with
the value of the property, mydbpath
jdbc:hsqldb:file:${mydbpath}
Each JDBC Connection to a database can specify connection properties. The properties user and password are always required. The following optional properties can also be used.
Connection properties are specified either by establishing the connection via the method call below, or the property can be appended to the full Connection URL. The first three of these properties can be used for any connection, including connection to a Server but the other three have an effect only with the first connection to a file: or mem: database, or when appended to the database path URL in server.properties or the server command line.
DriverManager.getConnection (String url, Properties info);
Table 12.5. User and Password
| Name | Default | Description |
|---|---|---|
| user | SA | user name |
|
Standard property. This property is case sensitive. Example below: jdbc:hsqldb:file:enrolments;user=aUserName;ifexists=true |
||
| password | empty string | password for the user |
|
Standard property. This property is case sensitive. Example below: jdbc:hsqldb:file:enrolments;user=aUserName;password=3xLVz For compatibility with other engines, a non-standard form of specifying user and password is also supported. In this form, user name and password appear at the end of the URL string, prefixed respectively with the question mark and the ampersand: jdbc:hsqldb:file:enrolments;create=false?user=aUserName&password=3xLVz |
Table 12.6. Closing old ResultSet when Statement is reused
| Name | Default | Description |
|---|---|---|
| close_result | false | closing the old result set when a new ResultSet is created by a Statement |
|
This property is used for
compatibility with the JDBC specification. When true (the JDBC
specification), a The default is false as previous versions of HSQLDB did not close old result set. The user application should close old result sets when they are no longer needed and should not rely on auto-closing side effect of executing the Statement. The default is false. When the property is
true, the old jdbc:hsqldb:hsql://localhost/enrolments;close_result=true When
a |
Table 12.7. Column Names in JDBC ResultSet
| Name | Default | Description |
|---|---|---|
| get_column_name | true | column name in ResultSet |
|
This property is used for
compatibility with other JDBC driver implementations. When true
(the default), The default is true. When the property is
false, the above method returns the same value as
jdbc:hsqldb:hsql://localhost/enrolments;get_column_name=false When
a |
Table 12.8. Creating New Database
| Name | Default | Description |
|---|---|---|
| ifexists | false | connect only if database already exists |
|
Has an effect only with mem: and file: database. When true, will not create a new database if one does not already exist for the URL. When the property is false (the default), a new mem: or file: database will be created if it does not exist. Setting the property to true is useful when troubleshooting as no database is created if the URL is malformed. Example below: jdbc:hsqldb:file:enrolments;ifexists=true |
||
| create | true | create the database if it does not exist |
|
Similar to the ifexists property, but with opposite meaning. Has an effect only with mem: and file: database. When false, will not create a new database if one does not already exist for the URL. When the property is true (the default), a new mem: or file: database will be created if it does not exist. Setting the property to true is useful when troubleshooting as no database is created if the URL is malformed. Example below: jdbc:hsqldb:file:enrolments;create=false |
Table 12.9. Automatic Shutdown
| Name | Default | Description |
|---|---|---|
| shutdown | false | shut down the database when the last connection is closed |
|
If this property is
This command has two uses. One is for test suites, where connections to the database are made from one JVM context, immediately followed by another context. The other use is for applications where it is not easy to configure the environment to shutdown the database. Examples reported by users include web application servers, where the closing of the last connection coincides with the web app being shut down. jdbc:hsqldb:file:enrolments;shutdown=true |
In addition, when the first connection to an
in-process file:
or
mem:
database creates a new database all the
user-defined database properties can be specified as URL properties. See
the next section for details.
Each database has several default settings (properties) that are
listed in the System Management chapter. These properties can be
changed via SQL commands after a connection is made to the database. It is
possible to specify most of these properties in the connection properties
or as part of the URL string when the first connection is made to a new
file:
or mem:
database. This allows
the properties to be set without using any SQL commands. The corresponding
SQL command is given for each property. For a server, these properties can
be appended to the database path URL in server.properties or the server
command line.
Note the prefered method of setting database properties is by using a set of SQL statements. These statements can be used both for a new database or an existing database, unlike URL properties that are generally effective for new databases only.
If the properties are used for connection to an existing database, they are ignored.
The exceptions are the following property settings that are allowed
for the first connection to an existing database (the connection which
reopens the database): readonly=true
,
files_readonly=true
,
hsqldb.lock_file=false
,
hsqldb.sqllog=1-3
,
hsqldb.applog=1-3
. These specific property / value
pairs override the existing database properties. For example a normal
database is opened as readonly, or the lock file is not created, or the
sql log level is set to a value between 1 and 3.
Management of properties has changed since version 1.8. The old SET PROPERTY statement does not change a property and is ignored. The statement is retained to simplify application upgrades.
In the example URL below, two properties are set for the first connection to a new database.
jdbc:hsqldb:file:enrolments;hsqldb.cache_rows=10000;hsqldb.nio_data_file=false
In the table below, database properties that can be used as part of the URL or in connection properties are listed. For each property that can also be set with an SQL statement, the statement is also given. These statements are described more extensively in the System Management chapter.
Table 12.10. Validity Check Property
| Name | Default | Description |
|---|---|---|
| check_props | false | checks the validity of the connection properties |
|
If the property is true, every database property that is specified on the URL or in connection properties is checked and if it is not used correctly, an error is returned. this property cannot be set with an SQL statement |
Table 12.11. SQL Keyword Use as Identifier
| Name | Default | Description |
|---|---|---|
| sql.enforce_names | false | enforcing SQL keywords |
|
This property, when set true, prevents SQL keywords being used for database object names such as columns and tables. SET DATABASE SQL NAMES { TRUE | FALSE } |
Table 12.12. SQL Keyword Starting with the Underscore or Containing Dollar Characters
| Name | Default | Description |
|---|---|---|
| sql.regular_names | true | enforcing SQL keywords |
|
This property, when set true, prevents database object names such as columns and tables beginning with the underscore or containing the dollar character. SET DATABASE SQL REGULAR NAMES { TRUE | FALSE } |
Table 12.13. Reference to Columns Names
| Name | Default | Description |
|---|---|---|
| sql.enforce_refs | false | enforcing column reference disambiguation |
|
This property, when set true, causes an error when an SQL statement (usually a select statement) contains column references that can be resolved by more than one table name or alias. In effect forces such column references to have a table name or table alias qualifier. SET DATABASE SQL REFERENCES { TRUE | FALSE } |
Table 12.14. String Size Declaration
| Name | Default | Description |
|---|---|---|
| sql.enforce_size | true | size enforcement of string columns |
|
Conforms to SQL standards for size and precision of data types. When true, all VARCHAR column type declarations require a size. When the property is false and there is no size in the declaration, a default size is used. Note that all other types accept a declaration without a size, which is interpreted as a default size. SET DATABASE SQL SIZE { TRUE | FALSE } |
Table 12.15. Type Enforcement in Comparison and Assignment
| Name | Default | Description |
|---|---|---|
| sql.enforce_types | false | enforcing type compatibility |
|
This property, when set true, causes an error when an SQL statements contains comparisons or assignments that are non-standard due to type mismatch. Most illegal comparisons and assignments will cause an exception regardless of this setting. This setting applies to a small number of comparisons and assignments that are possible, but not standard conformant, and were allowed in previous versions of HSQLDB. SET DATABASE SQL TYPES { TRUE | FALSE } |
Table 12.16. Foreign Key Triggered Data Change
| Name | Default | Description |
|---|---|---|
| sql.enforce_tdc_delete | true | enforcing triggered data change violation for deletes |
|
The ON DELETE and ON UPDATE clauses of constraints cause data changes in rows in different tables or the same table. When there are multiple constraints, a row may be updated by one constraint and deleted by another constraint in the same operation. This is not allowed by default. Changing this property to false allows such violations of the Standard to pass without an exception. Used for porting from database engines that do not enforce the constraints. SET DATABASE SQL TDC DELETE { TRUE | FALSE } |
||
| sql.enforce_tdc_update | true | enforcing triggered data change violation for updates |
|
The ON DELETE and ON UPDATE clauses of foreign key constraints cause data changes in rows in different tables or the same table. With multiple constraint, a field may be updated by two constraints and set to different values. This is not allowed by default. Changing this property to false allows such violations of the Standard to pass without an exception. Used for porting from database engines that do not enforce the constraints properly. SET DATABASE SQL TDC UPDATE { TRUE | FALSE } |
Table 12.17. Use of LOB for LONGVAR Types
| Name | Default | Description |
|---|---|---|
| sql.longvar_is_lob | false | translating longvarchar and longvarbinary to lob |
|
This property, when set true, causes type declarations using LONGVARCHAR and LONGVARBINARY to be translated to CLOB and BLOB respectively. By default, they are translated to VARCHAR and VARBINARY. SET DATABASE SQL LONGVAR IS LOB { TRUE | FALSE } |
Table 12.18. Concatenation with NULL
| Name | Default | Description |
|---|---|---|
| sql.concat_nulls | true | behaviour of concatenation involving one null |
|
This property, when set false, causes the concatenation of a null and a not null value to return the not null value. By default, it returns null. SET DATABASE SQL CONCAT NULLS { TRUE | FALSE } |
Table 12.19. NULL in Multi-Column UNIQUE Constraints
| Name | Default | Description |
|---|---|---|
| sql.unique_nulls | true | behaviour of multi-column UNIQUE constraints with null values |
|
This property, when set false, causes multi-column unique constrains to be more restrictive for value sets that contain a mix of null and not null values. SET DATABASE SQL UNIQUE NULLS { TRUE | FALSE } |
Table 12.20. Truncation or Rounding in Type Conversion
| Name | Default | Description |
|---|---|---|
| sql.convert_trunc | true | behaviour of type conversion from DOUBLE to integral types |
|
This property, when set false, causes type conversions from DOUBLE to any integral type to use rounding. By default truncation is used. SET DATABASE SQL CONVERT TRUNCATE { TRUE | FALSE } |
Table 12.21. Decimal Scale of Division and AVG Values
| Name | Default | Description |
|---|---|---|
| sql.avg_scale | 0 | decimal scale of values returned by division and the AVG and MEDIAN aggregate functions |
|
By default, the result of a division or an AVG or MEDIAN aggregate has the same type and scale as the aggregated value. For INTEGER types, the scale is 0. When this property is set to a value other than the default 0, then the scale is used if it is greater than the scale of the divisor or aggregated value. This property does not affect DOUBLE values. Values between 0 - 10 can be used for this property. SET DATABASE SQL AVG SCALE <numeric value> |
Table 12.22. Support for NaN values
| Name | Default | Description |
|---|---|---|
| sql.double_nan | true | behaviour of expressions returning DOUBLE NaN |
|
This property, when set false, causes division of DOUBLE values by Zero to return a Double.NaN value. By default an exception is thrown. SET DATABASE SQL DOUBLE NAN { TRUE | FALSE } |
Table 12.23. Sort order of NULL values
| Name | Default | Description |
|---|---|---|
| sql.nulls_first | true | ordering of NULL values |
|
By default, nulls appear before not-null values when a result set is ordered without specifying NULLS FIRST or NULLS LAST. This property, when set false, causes nulls to appear by default after not-null values in result sets with ORDER BY SET DATABASE SQL NULLS FIRST { TRUE | FALSE } |
Table 12.24. Sort order of NULL values with DESC
| Name | Default | Description |
|---|---|---|
| sql.nulls_order | true | ordering of NULL values when DESC is used |
|
By default, when an ORDER
BY clause that does not specify NULLS FIRST or NULLS LAST is
used, nulls are ordered according to the
SET DATABASE SQL NULLS ORDER { TRUE | FALSE } |
Table 12.25. String comparison with padding
| Name | Default | Description |
|---|---|---|
| sql.pad_space | true | ordering of strings with trailing spaces |
|
By default, when two strings are compared, he shorter string is padded with spaces before comparison. When this property is set false, no padding takes place before comparison. Without padding, the shorter string is never equal to the longer one. Before version 2.0, HSQLDB used NO PAD comparison. If you need the old behaviour, use this property when opening an older database. SET DEFAULT COLLATION <collation name> [ NO PAD | PAD SPACE ] |
Table 12.26. Case Insensitive Varchar columns
| Name | Default | Description |
|---|---|---|
| sql.ignore_case | false | case-insensitive VARCHAR |
|
When this propery is set true, all VARCHAR declarations in CREATE TABLE and other statemenst are assigned an Upper Case Comparison collation, SQL_TEXT_UCC. This is designed for compatibility with some databases that use case-insensitive comparison. It is better to specify the collation selectively for specific columns that require it. SET DATABASE COLLATION SQL_TEXT_UCC |
Table 12.27. DB2 Style Syntax
| Name | Default | Description |
|---|---|---|
| sql.syntax_db2 | false | support for DB2 style syntax |
|
This property, when set true, allows compatibility with some aspects of this dialect. SET DATABASE SQL SYNTAX DB2 { TRUE | FALSE } |
Table 12.28. MSSQL Style Syntax
| Name | Default | Description |
|---|---|---|
| sql.syntax_mss | false | support for MS SQL Server style syntax |
|
This property, when set true, switches the arguments of the CONVERT function and also allow compatibility with some other aspects of this dialect. SET DATABASE SQL SYNTAX MSS { TRUE | FALSE } |
Table 12.29. MySQL Style Syntax
| Name | Default | Description |
|---|---|---|
| sql.syntax_mys | false | support for MySQL style syntax |
|
This property, when set true, enables support for TEXT and AUTO_INCREMENT types and also allow compatibility with some other aspects of this dialect. SET DATABASE SQL SYNTAX MYS { TRUE | FALSE } |
Table 12.30. Oracle Style Syntax
| Name | Default | Description |
|---|---|---|
| sql.syntax_ora | false | support for Oracle style syntax |
|
This property, when set true, enables support for non-standard types. It also enables DUAL, ROWNUM, NEXTVAL and CURRVAL syntax and and also allow compatibility with some other aspects of this dialect. SET DATABASE SQL SYNTAX ORA { TRUE | FALSE } |
Table 12.31. PostgreSQL Style Syntax
| Name | Default | Description |
|---|---|---|
| sql.syntax_pgs | false | support for PostgreSQL style syntax |
|
This property, when set true, enables support for TEXT and SERIAL types. It also enables NEXTVAL, CURRVAL and LASTVAL syntax and also allow compatibility with some other aspects of this dialect. SET DATABASE SQL SYNTAX PGS { TRUE | FALSE } |
Table 12.32. Default Table Type
| Name | Default | Description |
|---|---|---|
| hsqldb.default_table_type | memory | type of table created with unqualified CREATE TABLE |
|
The CREATE TABLE command results in a MEMORY table by default. Setting the value cached for this property will result in a cached table by default. The qualified forms such as CREATE MEMORY TABLE or CREATE CACHED TABLE are not affected at all by this property. SET DATABASE DEFAULT TABLE TYPE { CACHED | MEMORY } |
Table 12.33. Transaction Control Mode
| Name | Default | Description |
|---|---|---|
| hsqldb.tx | locks | database transaction control mode |
|
Indicates the transaction control mode for the database. The values, locks, mvlocks and mvcc are allowed. SET DATABASE TRANSACTION CONTROL { LOCKS | MVLOCKS | MVCC } |
Table 12.34. Default Isolation Level for Sessions
| Name | Default | Description |
|---|---|---|
| hsqldb.tx_level | read_commited | database default transaction isolation level |
|
Indicates the default transaction isolation level for each new session. The values, read_committed and serializable are allowed. Individual sessions can change their isolation level. SET DATABASE DEFAULT ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } |
Table 12.35. Transaction Rollback in Deadlock
| Name | Default | Description |
|---|---|---|
| hsqldb.tx_conflict_rollback | true | effect of deadlock or other conflicts on transaction |
|
When a transaction deadlock or other unresolvable conflict is about to happen, the current transaction is rolled back and an exception is raised. When this property is set false, the transaction is not rolled back. Only the latest action that would cause the conflict is undone and an error is returned. The property should not be changed unless the application can quickly perform an alternative statement and complete the transaction. It is provided for compatibility with other database engines which do not roll back the transaction upon deadlock. SET DATABASE TRANSACTION ROLLBACK ON CONFLICT { TRUE | FALSE } |
Table 12.36. Time Zone and Interval Types
| Name | Default | Description |
|---|---|---|
| hsqldb.translate_tti_types | true | usage of type codes for advanced datetime and interval types |
|
If the property is true,
the TIME / TIMESTAMP WITH TIME ZONE types and INTERVAL types are
represented in JDBC methods of
SET DATABASE SQL TRANSLATE TTI TYPES { TRUE | FALSE } |
Table 12.37. Opening Database as Read Only
| Name | Default | Description |
|---|---|---|
| readonly | false | readonly database - is used to open an existing
file: database |
|
This property is a special property that can be added manually to the .properties file, or included in the URL or connection properties. When this property is true, the database becomes readonly. This can be used with an existing database to open it for readonly operation. this property cannot be set with an SQL statement - it can be used in the .properties file |
Table 12.38. Opening Database Without Modifying the Files
| Name | Default | Description |
|---|---|---|
| files_readonly | false | readonly files database - is used to open an existing
file: database |
|
This property is used similarly to the hsqldb.readonly property. When this property is true, CACHED and TEXT tables are readonly but memory tables are not. Any change to the data is not persisted to database files. this property cannot be set with an SQL statement - it can be used in the .properties file |
Table 12.39. Huge database files and tables
| Name | Default | Description |
|---|---|---|
| hsqldb.large_data | false | enable huge database files - can also be used to open an
existing file: database |
|
By default, up to 2 billion rows can be stored in disk-based CACHED tables. Setting this property to true increases the limit to 256 billion rows. This property is used as a connection property. this property cannot be set with an SQL statement - it can be used as a connection property for the connection that opens the database |
Table 12.40. Event Logging
| Name | Default | Description |
|---|---|---|
| hsqldb.applog | 0 | application logging level - can also be used when
openning an existing file: database |
|
The default level 0 indicates no logging. Level 1 results in minimal logging, including any failures. Level 2 indicates all events, including ordinary events. LEVEL 3 adds details of some of the normal operations. The events are logged in a file ending with ".app.log". SET DATABASE EVENT LOG LEVEL { 0 | 1 | 2 | 3} |
Table 12.41. SQL Logging
| Name | Default | Description |
|---|---|---|
| hsqldb.sqllog | 0 | sql logging level - can also be used when openning an
existing file: database |
|
The default level 0 indicates no logging. Level 1 logs only commits and rollbacks. Level 2 logs all the SQL statements executed, together with their parameter values. Long statements and parameter values are truncated. Level 3 is similar to Level 2 but does not truncate long statements and values. The events are logged in a file ending with ".sql.log". This property applies to existing file: databases as well as new databases. SET DATABASE EVENT LOG SQL LEVEL { 0 | 1 | 2 | 3} |
Table 12.42. Temporary Result Rows in Memory
| Name | Default | Description |
|---|---|---|
| hsqldb.result_max_memory_rows | 0 | storage of temporary results and tables in memory or on disk |
|
This property can be set to specify how many rows of each results or temporary table are stored in memory before the table is written to disk. The default is zero and means data is always stored in memory. If this setting is used, it should be set above 1000. SET DATABASE DEFAULT RESULT MEMORY ROWS <numeric value> |
Table 12.43. Rows Cached In Memory
| Name | Default | Description |
|---|---|---|
| hsqldb.cache_free_count | 512 | maximum number of unused space recovery - can also be
used when openning an existing file:
database |
|
The default indicates 512 unused spaces are kept for later use. The value can range between 0 - 8096. When rows are deleted, the space is recovered and kept for reuse for new rows. If too many rows are deleted, the smaller recovered spaces are lost and the largest ones are retained for later use. Normally there is no need to set this property. this property cannot be set with an SQL statement |
Table 12.44. Rows Cached In Memory
| Name | Default | Description |
|---|---|---|
| hsqldb.cache_rows | 50000 | maximum number of rows in memory cache |
|
Indicates the maximum number of rows of cached tables that are held in memory. The value can range between 100- 4 billion. If the value is set via SET FILES CACHE ROWS then it becomes effective after the next database SHUTDOWN. SET FILES CACHE ROWS <numeric value> |
Table 12.45. Size of Rows Cached in Memory
| Name | Default | Description |
|---|---|---|
| hsqldb.cache_size | 10000 | memory cache size |
|
Indicates the total size (in kilobytes) of rows in the memory cache used with cached tables. This size is calculated as the binary size of the rows, for example an INTEGER is 4 bytes. The actual memory size used by the objects is 2 to 4 times this value. This depends on the types of objects in database rows, for example with binary objects the factor is less than 2, with character strings, the factor is just over 2 and with date and timestamp objects the factor is over 3. The value can range between 100 KB - 4 GB. The default is 10,000, representing 10,000 kilobytes. If the value is set via SET FILES then it becomes effective after the next database SHUTDOWN or CHECKPOINT. SET FILES CACHE SIZE <numeric value> |
Table 12.46. Size Scale of Disk Table Storage
| Name | Default | Description |
|---|---|---|
| hsqldb.cache_file_scale | 32 | unit used for storage of rows in the .data file |
|
The default value corresponds to a maximum size of 64 GB for the .data file. This can be increased to 64, 128, 256, 512, or 1024 resulting in up to 2 TB GB storage. Settings below 32 in older databases are preserved until a SHUTDOWN COMPACT. SET FILES SCALE <numeric value> |
Table 12.47. Size Scale of LOB Storage
| Name | Default | Description |
|---|---|---|
| hsqldb.lob_file_scale | 32 | unit used for storage of lobs in the .lobs file |
|
The default value represents units of 32KB. When the average size of individual lobs in the database is smaller, a smaller unit can be used to reduce the overall size of the .lobs file. Values 1, 2, 4, 8, 16, 32 can be used. SET FILES LOB SCALE <numeric value> |
Table 12.48. Compression of BLOB and CLOB data
| Name | Default | Description |
|---|---|---|
| hsqldb.lob_compressed | false | use of compression for storage of blobs and clobs |
|
The default value is false, indicating no compression. When the value is true at the time of creation of a new database, blobs and clobs are stored as compressed parts. SET FILES LOB COMPRESSED { TRUE | FALSE } |
Table 12.49. Internal Backup of Database Files
| Name | Default | Description |
|---|---|---|
| hsqldb.inc_backup | true | incremental backup of data file |
|
During updates, the contents of the .data file are modified. When this property is true, the modified contents are backed up gradually. This causes a marginal slowdown in operations, but allows fast checkpoint and shutdown. When the property is false, the .data file is backed up entirely at the time of checkpoint and shutdown. Up to version 1.8, HSQLDB supported only full backup. SET FILES BACKUP INCREMENT { TRUE | FALSE } |
Table 12.50. Use of Lock File
| Name | Default | Description |
|---|---|---|
| hsqldb.lock_file | true | use of lock file - can also be used with an existing
file: database |
|
By default, a lock file is created for each file database that is opened for read and write. This property can be specified with the value false to prevent the lock file from being created. This usage is not recommended but may be desirable when flash type storage is used. This property applies to existing file: databases as well as new databases. this property cannot be set with an SQL statement |
Table 12.51. Logging Data Change Statements
| Name | Default | Description |
|---|---|---|
| hsqldb.log_data | true | logging data change |
|
This property can be set
to SET FILES LOG { TRUE | FALSE } |
Table 12.52. Automatic Checkpoint Frequency
| Name | Default | Description |
|---|---|---|
| hsqldb.log_size | 50 | size of log when checkpoint is performed |
|
The value is the size (in
megabytes) that the SET FILES LOG SIZE <numeric value> |
Table 12.53. Automatic Defrag at Checkpoint
| Name | Default | Description |
|---|---|---|
| hsqldb.defrag_limit | 0 | percentage of unused space causing a defrag at checkpoint |
|
When a checkpoint is performed, the percentage of wasted space in the .data file is calculated. If the wasted space is above the specified limit, a defrag operation is performed. The default is 0, which means no automatic checkpoint. The numeric value must be between 0 and 100 and is interpreted as a percentage of the current size of the .data file. SET FILES DEFRAG <numeric value> |
Table 12.54. Compression of the .script file
| Name | Default | Description |
|---|---|---|
| hsqldb.script_format | 0 | compressed .script file |
|
If the property is set
with the value 3, the .script file is stored in compressed
format. This is useful for large script files. The .script is no
longer readable when the
This property cannot be set with an SQL statement |
Table 12.55. Logging Data Change Statements Frequency
| Name | Default | Description |
|---|---|---|
| hsqldb.write_delay | true | write delay performing fsync of log file entries |
|
If the property is true, the default WRITE DELAY property of the database is used, which is 500 milliseconds. If the property is false, the WRITE DELAY is set to 0 seconds. The log is written to file regardless of this property. The property controls the fsync that forces the written log to be persisted to disk. The SQL command for this property allows more precise control over the property. SET FILES WRITE DELAY {{ TRUE | FALSE } | <seconds value> | <milliseconds value> MILLIS |
Table 12.56. Logging Data Change Statements Frequency
| Name | Default | Description |
|---|---|---|
| hsqldb.write_delay_millis | 500 | write delay for performing fsync of log file entries |
|
If the property is used, the WRITE DELAY property of the database is set the given value in milliseconds. The property controls the fsync that forces the written log to be persisted to disk. The SQL command for this property allows the same level of control over the property. SET FILES WRITE DELAY {{ TRUE | FALSE } | <seconds value> | <milliseconds value> MILLIS |
Table 12.57. Use of NIO for Disk Table Storage
| Name | Default | Description |
|---|---|---|
| hsqldb.nio_data_file | true | use of nio access methods for the .data file |
|
Setting this property to
SET FILES NIO { TRUE | FALSE } |
Table 12.58. Use of NIO for Disk Table Storage
| Name | Default | Description |
|---|---|---|
| hsqldb.nio_max_size | 256 | nio buffer size limit |
|
The maximum size of .data file in mega bytes that can use the nio access method. When the file gets larger than this limit, non-nio access methods are used. Values 64, 128, 256, 512, 1024, and larger multiples of 512 can be used. The default is 256MB. SET FILES NIO SIZE <numeric value> |
Table 12.59. Recovery Log Processing
| Name | Default | Description |
|---|---|---|
| hsqldb.full_log_replay | false | recovery log processing |
|
The .log file is processed during recovery after a forced shutdwon. Out of memory conditions always abort the startup. Any other exception stops the processing of the .log file and by default, continues the startup process. If this property is true, the startup process is stopped if any exception occurs. Exceptions are usually caused by incomplete lines of SQL statements near the end of the .log file, which were not fully synced to disk when an abnormal shutdown occurred. This property cannot be set with an SQL statement |
Table 12.60. Default Properties for TEXT Tables
| Name | Default | Description |
|---|---|---|
| textdb.* | 0 | default properties for new text tables |
|
Properties that override
the database engine defaults for newly created text tables.
Settings in the text table |
Table 12.61. Forcing Garbage Collection
| Name | Default | Description |
|---|---|---|
| runtime.gc_interval | 0 | forced garbage collection |
|
This setting forces garbage collection each time a set number of result set row or cache row objects are created. The default, "0" means no garbage collection is forced by the program. SET DATABASE GC <numeric value> |
Table 12.62. Crypt Property For LOBs
| Name | Default | Description |
|---|---|---|
| crypt_lobs | false | encryption of lobs |
|
If the property is true, the contents of the .lobs file is encrypted as well. this property cannot be set with an SQL statement |
Table 12.63. Cipher Key for Encrypted Database
| Name | Default | Description |
|---|---|---|
| crypt_key | none | encryption |
|
The cipher key for an encrypted database. this property cannot be set with an SQL statement |
Table 12.64. Crypt Provider Encrypted Database
| Name | Default | Description |
|---|---|---|
| crypt_provider | none | encryption |
|
The fully-qualified class name of the cryptography provider. This property is not used for the default security provider. this property cannot be set with an SQL statement |
Table 12.65. Cipher Specification for Encrypted Database
| Name | Default | Description |
|---|---|---|
| crypt_type | none | encryption |
|
The cipher specification. this property cannot be set with an SQL statement |
When connecting to an in-process database creates a new database, or opens an existing database (i.e. it is the first connection made to the database by the application), all the user-defined database properties listed in this section can be specified as URL properties.
When HSQLDB is used with OpenOffice.org as an external database, the property "default_schema=true" must be set on the URL, otherwise the program will not operate correctly as it does with its built-in hsqldb instance.
A few system properties are used by HyperSQL. These are set on the Java command line or by calling System.setProperty() from the user's program. They are not valid as URL or connection properties.
Table 12.66. Logging Framework
| Name | Default | Description |
|---|---|---|
| hsqldb.reconfig_logging | true | configuring the framework logging |
|
Setting this system property false avoids reconfiguring the framework logging system such as Log4J or java.util.Logging. If the property does not exist or is true, reconfiguration takes place. |
Table 12.67. Text Tables
| Name | Default | Description |
|---|---|---|
| textdb.allow_full_path | false | text table file locations |
|
Setting this system property true allows text table sources and files to be opened on all available paths. It also allows pure mem: databases to open such files. By default, only the database directory and its subdirectories are allowed. See the Text Tables chapter. |
Table 12.68. Java Functions
| Name | Default | Description |
|---|---|---|
| hsqldb.method_class_names | none | allowed Java classes |
|
This property needs to be set with the names (including wildcards) of Java classes that can be used for routines based on Java static methods. See the SQL Invoked Routines chapter. |
$Revision: 5212 $
Copyright 2002-2012 Fred Toussi. Permission is granted to distribute this document without any alteration under the terms of the HSQLDB license. Additional permission is granted to the HSQL Development Group to distribute this document with or without alterations under the terms of the HSQLDB license.
2013-07-08 15:31:27+0100