The database package is based on Warren Gay's APQ Postgres
binding. For full details on these routines, consult the APQ documentation.
There is an enumerated type that controls the verbosity of tracing:
type db.trace_mode_type is ( db.trace_none, db.trace_db, db.trace_apq, db.trace_full );
There is an enumerated type that controls file access:
type db.mode_type is ( db.read, db.write, db.read_write );
There is an enumerated type that controls fetch order:
type db.fetch_mode_type is ( db.sequential_fetch, db.random_fetch );
There is an enumerated type that identifies the database engine:
type db.database_type is ( db.engine_postgresql, db.engine_mysql, db.engine_oracle, db.engine_sybase, db.engine_db2 );
db.append( s [, a] )
Append text to an SQL query s after a (?)
Example: db.append( " where customer_no > 5" );
Ada Equivalent: APQ.Append
Parameters:
s
in
string
required
SQL query
a
in
string
empty string
after (not quite sure)
db.append_line( s )
Start a new line and append line to SQL query s
Example: db.append_line( "where customer_no > 5" );
Ada Equivalent: APQ.Append_Line
Parameters:
s
in
string
required
SQL query text
db.append_quoted( s )
Append text to SQL query s and surrounded text with single quotes.
Example: db.append_quoted( "customer_name" );
Ada Equivalent: APQ.Append_Quoted
Parameters:
s
in
string
required
SQL query text
a
in
string
""
after what query text
db.begin_work
Start a database transaction, marking the position of a possible rollback.
Example: db.begin_work;
Ada Equivalent: APQ.Begin_Work
Parameters:
none
in_abort_state exception may be raised
db.clear
Erase the current query.
Example: db.clear;
Ada Equivalent: APQ.Clear
Parameters:
none
If a connection doesn't exist, an error will occur.
db.close_db_trace
Stop tracing the database activity and close the trace file.
Example: db.close_db_trace;
Ada Equivalent: APQ.Close_DB_Trace
Parameters:
none
If a connection doesn't exist, an error will occur.
i := db.column_index( s )
Return the position of a query result column. This is the position
in the query, not the database table.
Example: third_column_position := db.column_index( "first name" );
Ada Equivalent: APQ.Column_Name
Parameters:
c
in
string
the column heading
i
return value
column_index_type
the column position in the query
no_column exception may be raised
s := db.column_name( c )
Return the name of a query result column. The number is the position
in the query, not the database table.
Example: third_column_heading := db.column_name( 3 );
Ada Equivalent: APQ.Column_Name
Parameters:
c
in
column_index_type
the column position in the query results
s
return value
string
the column heading
no_column exception may be raised
n := db.columns
Return the number of columns (fields) from the last query.
Example: number_of_columns := db.columns;
Ada Equivalent: APQ.Columns
Parameters:
n
return value
natural
the number of columns
no_result exception may be raised
db.commit_work
Complete a database transaction.
Example: db.commit_work;
Ada Equivalent: APQ.Commit_Work
Parameters:
none
in_abort_state exception may be raised
db.connect( d [, u, p ][, h][, p] )
Connect to database d using username u, path p, hostname h and port p.
If no hostname or port are specified, connection is made by a UNIX socket
instead of a network socket.
Example: db.connect( "ken" );
Ada Equivalent: combines several APQ functions
Parameters:
d
in
string
required
the database name
u
in
string
your username
the username to connect with
p
in
string
default password
username's password
h
in
string
UNIX Socket
hostname for network socket
p
in
string
default port
network socket port
If a connection cannot be made, an error will occur.
db.databases
Show a list of the databases available with the current connection. This
is the equivalent of PostgreSQL "\l".
Example: db.databases;
Ada Equivalent: none (AdaScript extension)
Parameters:
none
If a connection doesn't exist, an error will occur.
db.disconnect
Close a connection created by connect.
Example: db.disconnect;
Ada Equivalent: APQ.Disconnect;
Parameters:
none
If a connection doesn't exist, an error will occur.
b := db.end_of_query
True if there are no more result (tuple) rows.
Example: b := db.end_of_query;
Ada Equivalent: APQ.End_Of_Query
Parameters:
b
return value
boolean
true if no more rows
b := db.engine_of
Return the identity of the database engine
Example: b := db.engine_of;
Ada Equivalent: APQ.Engine_Of
Parameters:
b
return value
db.database_type
db.engine_postgresql, etc.
s := db.error_message
Last error message returned by database server.
Example: err := db.error_message;
Ada Equivalent: APQ.Error_Message;
Parameters:
b
return value
string
last server message
db.execute
Run a prepared database query.
Example: db.execute;
Ada Equivalent: APQ.Execute
Parameters:
none
If a connection doesn't exist, an error will occur.
db.execute_checked( [ s ] )
not sure the difference with execute.
Example: db.execute_checked( "message" );
Ada Equivalent: APQ.Execute_Checked
Parameters:
s
in
string
empty string
a message
db.fetch [ (i) ]
Fetch the next query result tuple row, or a specific result row.
Example: db.fetch;
Ada Equivalent: APQ.Fetch
Parameters:
i
in
tuple_index_type
optional
a specific result row
no_result or no_tuple exceptions may be raised.
s := db.in_abort_state
True if in abort state.
Example: b := db.in_abort_state;
Ada Equivalent: APQ.In_Abort_State;
Parameters:
b
return value
boolean
true if in abort state
If a connection doesn't exist, a not connected exception will occur.
b := db.is_connected
True if Bush is connected to a database.
Example: b := db.is_connected;
Ada Equivalent: APQ.Is_Connected;
Parameters:
b
return value
boolean
true if connected
If a connection doesn't exist, an error will occur.
b := db.is_null( c )
True if column in the fetch result is undefined.
Example: b := db.is_null;
Ada Equivalent: APQ.Is_Null
Parameters:
c
in
db.column_index_type
the field to check
b
return value
boolean
true if null
no_column and no_result exceptions may be raised
b := db.is_trace
True if set_trace was true (that is, if debug tracing is enabled).
Example: b := db.is_trace;
Ada Equivalent: APQ.Is_Trace
Parameters:
b
return value
boolean
tracing is enabled
db.list
Show a list of the tables available in the current database. This is the
equivalent of PostgreSQL's "\dt".
Example: db.list;
Ada Equivalent: none (AdaScript extension)
Parameters:
none
If a connection doesn't exist, an error will occur.
s := db.notice_message
Last notice message returned by database server.
Example: err := db.notice_message;
Ada Equivalent: APQ.Notice_Message;
Parameters:
b
return value
string
last server message
db.open_db_trace( f )
Begin tracing the database activity, storing the results at pathname f.
Example: db.open_db_trace( "./trace.out" );
Ada Equivalent: APQ.Open_DB_Trace
Parameters:
f
in
string
required
trace file pathname
If a connection doesn't exist, an error will occur.
not_connected, file already open, file not found exceptions may be raised
s := db.options
Return database options.
Example: b := db.options;
Ada Equivalent: APQ.Options
Parameters:
b
return value
string
database options
db.prepare( s [, a] )
Prepare a SQL statement to execute. If a is included, insert the
next statement after the statement named a.
Example: db.prepare( "select * from customers" );
Ada Equivalent: APQ.Prepare
Parameters:
s
in
string
required
SQL statement
a
in
string
after all others
insert SQL statement after statement a
If a connection cannot be made, an error will occur.
db.raise_exceptions( [ b ] )
True to raise exceptions on query.
Example: db.raise_exceptions( false );
Ada Equivalent: APQ.Raise_Exceptions
Parameters:
b
in
boolean
true
whether or not exceptions will occur
db.report_errors( b )
True to report errors on query.
Example: db.report_errors( false );
Ada Equivalent: APQ.Report_Errors
Parameters:
b
in
boolean
true
whether or not errors will be reported
db.reset
APQ reset command (not quite sure...). Reset the database connection.
Example: db.reset;
Ada Equivalent: APQ.Reset;
Parameters:
none
If a connection doesn't exist, an error will occur.
db.rewind
Return to the start of a query's results.
Example: db.rewind;
Ada Equivalent: APQ.Rewind
Parameters:
none
db.rollback_work
Rollback a database transaction, undoing all work since begin_work.
Example: db.rollback_work;
Ada Equivalent: APQ.Rollback_Work
Parameters:
none
in_abort_state exception may be raised
db.schema( t )
Show information about the columns available in a table. This is the
equivalent of PostgreSQL's "\d table".
Example: db.schema( "table" );
Ada Equivalent: none (AdaScript extension)
Parameters:
t
in
string
required
name of the table
db.set_rollback_on_finalize( b )
Determine if a rollback will be issued when the script ends and the
database connection is still open (true) or no rollback (false). Default
is true.
Example: db.set_rollback_on_finalize( false );
Ada Equivalent: APQ.Set_Rollback_On_Finalize
Parameters:
b
in
boolean
true
whether or not rollback will occur
db.set_trace( b )
Determine if debug tracing is enabled.
Example: db.set_trace( false );
Ada Equivalent: APQ.Set_Trace
Parameters:
b
in
boolean
true
whether or not tracing will occur
db.show
Run the prepared query and show the results in a table on standard output.
This is often used to show the results of a SQL SELECT statement.
Example: db.show;
Ada Equivalent: none (AdaScript extension)
Parameters:
none
If a connection doesn't exist, an error will occur.
t := db.tuple
Return the result row (tuple) number from the last fetch.
Example: row_number := db.tuple;
Ada Equivalent: APQ.Tuple
Parameters:
t
return value
db.tuple_index_type
the current row number
no_tuple exception may be raised
n := db.tuples
Return the number of rows (tuples) from the last query.
Example: row_number := db.tuples;
Ada Equivalent: APQ.Tuples
Parameters:
t
return value
db.tuple_count_type
the number of rows
no_result exception may be raised
db.users
Show a list of database users. This is similar to PostgreSQL's "\du". The
columns in the list depend on the database engine.
Example: db.users;
Ada Equivalent: none (AdaScript extension)
Parameters:
none
If a connection doesn't exist, an error will occur.
s := db.value( c )
Return the column value as a string.
Example: first_name := db.value( 3 );
Ada Equivalent: APQ.Value
Parameters:
c
in
db.column_index_type
the field to return
s
return value
universal_typeless
the value of the field
no_column, no_result, null_value and no_tuple exceptions may be raised
b := db.will_rollback_on_finalize
True if set_rollback_on_finalize was true (that is, that when the script
finishes, a rollback will be issued if the connection is still open).
Example: b := db.will_rollback_on_finalize;
Ada Equivalent: APQ.Will_Rollback_On_Finalize
Parameters: