A package for opening multiple connections and having mutiple open queries
to a MySQL database. The subprograms here are similar to the mysql package
accept that they also require a connection, query or both.
New data types:
mysqlm.connection - a connection id to a database
mysqlm.query - a database id query
The database package is based on a modified version of Warren Gay's APQ MySQL binding. For full details on these routines, consult the APQ documentation.
There is an enumerated type in the db package that controls the verbosity of tracing:
type db.trace_mode_type is ( db.trace_none, db.trace_db, db.trace_apq, db.trace_full );
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 mysqlm.mode_type is ( mysqlm.read, mysqlm.write, mysqlm.read_write );
There is an enumerated type in the db package that controls fetch order:
type db.fetch_mode_type is ( db.sequential_fetch, db.random_fetch );
There is an enumerated type in the db package 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 );
mysqlm.append( q, s [, a] )
Append text s to the SQL query. The text is on the same line.
Example
mysqlm.append( q, s, " where customer_no > 5" );
Parameters
Param
Mode
Type
Default
Description
q
in
mysqlm.query
required
SQL query id
s
in
string
required
SQL query text
a
in
string
empty string
additional text to place after the text
Exceptions
An exception is thrown when out of memory.
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
See Also
-
Compare With
Ada: APQ.Append
mysqlm.append_for_insert( q, c, r )
Append the fields of record r to the query in the format of an ANSI SQL
insert (that is, " ( a, b, ... ) VALUES ( 'a', 'b', ... )"). The record fields may be
boolean, string, numeric or universal (treated as a string). String values
are appended with Append_Quoted.
Example
type row is record
b : boolean;
i : integer;
s : string;
end record;
r : row;
...
mysqlm.append_for_insert( q, c, r ); -- (b,i,s) values (...)
Parameters
Param
Mode
Type
Default
Description
q
in
mysqlm.query
required
SQL query id
c
in
mysqlm.connection
required
MySQL connection id
r
in
record type
required
The record type to use for insert data
Exceptions
-
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
Append the fields of record r to the query in the format of an ANSI SQL
update (that is," SET a = 'a', b = 'b', ..." ). The record fields may be
boolean, string, numeric or universal (treated as a string). String values
are appended with Append_Quoted.
Example
type row is record
b : boolean;
i : integer;
s : string;
end record;
r : row;
...
mysqlm.append_for_update( q, c, r ); -- SET b = ..., i = ... etc.
Parameters
Param
Mode
Type
Default
Description
q
in
mysqlm.query
required
SQL query id
c
in
mysqlm.connection
required
MySQL connection id
r
in
record type
required
The record type to use for update data
Exceptions
-
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
Connect to database d using username u, password w, 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
mysqlm.connect( c, "db", "user", "password" );
Parameters
Param
Mode
Type
Default
Description
c
in
mysqlm.connection
required
MySQL connection id
d
in
string
required
the database name
u
in
string
your username
the username to connect with
w
in
string
default password
username's password
h
in
string
UNIX Socket
hostname for network socket
p
in
string
default port
network socket port
Exceptions
If a connection cannot be made, an error will occur.
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
See Also
-
Compare With
Ada: combines several APQ functions
mysqlm.databases( c )
Show a list of the databases available with the current connection. This
is the equivalent of MySQL "show databases".
Example
mysqlm.databases( c );
Parameters
Param
Mode
Type
Default
Description
c
in
mysqlm.connection
required
MySQL connection id
Exceptions
If a connection doesn't exist, an error will occur.
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
Execute the query. If an error occurs, display the message s on
standard error and raise an exception. If an error occurs and there is
no error message s, display the query on standard error and raise an
exception.
Example
mysqlm.execute_checked( q, c, "message" );
Parameters
Param
Mode
Type
Default
Description
q
in
mysqlm.query
required
SQL query id
c
in
mysqlm.connection
required
MySQL connection id
s
in
string
empty string
a message
Exceptions
An exception is thrown if an error occurs.
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
Fetch the next query result tuple row into a record.
The record's
fields may be boolean, numeric, string or typeless types and the names of
the record's fields must be the same as the column names returned by the
query. The number of fields must match the number of columns, though the
order may be different.
Example
type row is record
b : boolean;
i : integer;
s : string;
end record;
r : row;
...
mysqlm.prepare( Q, "SELECT b, i, s FROM sometable" );
mysqlm.execute( Q, C );
if not mysqlm.end_of_query( Q ) then
mysqlm.fetch_values( Q, C, r );
Parameters
Param
Mode
Type
Default
Description
q
in
mysqlm.query
required
SQL query id
c
in
mysqlm.connection
required
MySQL connection id
r
in
a record
required
a result row
Exceptions
no_result, no_column exceptions may be raised. no_tuple may be raised if there's no more data. Assigning a
string to a numeric or boolean field may raise an exception. A field that is not in the query raises an exception. A column that is not in the record raises an exception. The wrong number of fields raises an exception.
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
See Also
-
Compare With
Ada: APQ.Options
mysqlm.prepare( q, s [, a] )
Prepare a SQL statement to execute. If a is included, insert the next statement after the statement named a.
Example
mysqlm.prepare( q, "select * from customers" );
Parameters
Param
Mode
Type
Default
Description
q
in
mysqlm.query
required
SQL query id
s
in
string
required
SQL statement
a
in
string
after all others
insert SQL statement after statement a
Exceptions
If a connection cannot be made, an error will occur.
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
See Also
-
Compare With
Ada: APQ.Prepare
mysqlm.raise_exceptions( q, [ b ] )
True to raise exceptions on query errors.
Example
mysqlm.raise_exceptions( q, false );
Parameters
Param
Mode
Type
Default
Description
q
in
mysqlm.query
required
SQL query id
b
in
boolean
true
whether or not exceptions will occur
Exceptions
-
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
See Also
-
Compare With
Ada: APQ.Raise_Exceptions
mysqlm.report_errors( q, b )
True to report errors on query.
Example
mysqlm.report_errors( q, false );
Parameters
Param
Mode
Type
Default
Description
q
in
mysqlm.query
required
SQL query id
b
in
boolean
true
whether or not errors will be reported
Exceptions
-
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
See Also
-
Compare With
Ada: APQ.Report_Errors
mysqlm.reset( c )
Reset the database connection: close open files, rollback query (if
necessary) and disconnect. Use disconnect instead unless you know what
you are doing.
Example
mysqlm.reset( c );
Parameters
Param
Mode
Type
Default
Description
c
in
mysqlm.connection
required
MySQL connection id
Exceptions
If a connection doesn't exist, an error will occur.
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
See Also
-
Compare With
Ada: APQ.Reset
mysqlm.rewind( q )
Return to the start of a query's results.
Example
mysqlm.rewind( q );
Parameters
Param
Mode
Type
Default
Description
q
in
mysqlm.query
required
SQL query id
Exceptions
If a connection doesn't exist, an error will occur.
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
See Also
-
Compare With
Ada: APQ.Rewind
mysqlm.rollback_work( q, c )
Rollback a database transaction, undoing all work since begin_work. The query will be erased.
Example
mysqlm.rollback_work( q, c );
Parameters
Param
Mode
Type
Default
Description
q
in
mysqlm.query
required
SQL query id
c
in
mysqlm.connection
required
MySQL connection id
Exceptions
If a connection doesn't exist, an error will occur.
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
Determine if a rollback will be issued when the connection is deallocated while the connection is still open (true) or no rollback (false). Default is true.
Example
mysqlm.set_rollback_on_finalize( c, false );
Parameters
Param
Mode
Type
Default
Description
c
in
mysqlm.connection
required
MySQL connection id
b
in
boolean
required
true to rollback
Exceptions
-
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
See Also
-
Compare With
Ada: APQ.Set_Rollback_On_Finalize
mysqlm.set_trace( c, b )
Enable or disable query tracing. The trace file will remain open.
Example
mysqlm.set_trace( c, false );
Parameters
Param
Mode
Type
Default
Description
c
in
mysqlm.connection
required
MySQL connection id
b
in
boolean
true
whether or not tracing will occur
Exceptions
-
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
no_column, no_result, null_value and no_tuple exceptions may be raised
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction
See Also
-
Compare With
Ada: APQ.Value
b := mysqlm.will_rollback_on_finalize( c )
True if set_rollback_on_finalize was true (that is, that when the connection is deallocated, a rollback will be issued if the connection is still open).
Example
b := mysqlm.will_rollback_on_finalize( c );
Parameters
Param
Mode
Type
Default
Description
b
return value
boolean
required
rollback will be issued on finalize
Exceptions
-
Restrictions
Not allowed in a restricted shell Not allowed with no_mysql_database restriction