Database - Maple Help

Home : Support : Online Help : Connectivity : Database Package : Database/ConnectionBuilder

Database

 ConnectionBuilder
 launch Connection Builder Assistant

 Calling Sequence ConnectionBuilder( opts ) Database( opts )

Parameters

 opts - (optional) equation of the form filename=file

Description

 • The ConnectionBuilder command opens a Assistant to help you create a database connection. You can enter driver and connection parameters in the interface. The parameters correspond to the arguments you can specify for the LoadDriver and OpenConnection commands. The Assistant opens a connection to the specified database.
 You can also use the Database package name as a top-level command to launch the Connection Builder Assistant.
 • If a connection is successfully established by the Assistant, it returns an expression sequence of length 2.  The first element is the driver module and the second is the connection module.
 • To facilitate specifying the files required for the connection, the Assistant allows you to search the file system.
 • The Connection Builder Assistant can also load and save connection settings to files.  These files are compatible with those used by the Save and LoadConnection commands.
 It is recommended that you save connection settings. This allows you to easily re-establish connections.
 • Each connection stored in a file is associated with an identifier. This identifier allows multiple connections to be stored in a single file. To specify the identifier for connection settings, use the Connection combination box.
 • The ConnectionBuilder command accepts the optional filename=file equation, which allows you to specify the connection file (as a string) to use when opening the Assistant.  If not specified, the Assistant opens $HOME/maple/toolbox/Database/data/default.con, where$HOME is the value returned by kernelopts( homedir ).  If this file does not exist, no file is loaded.
 If a file is successfully loaded, the connection with the identifier default is displayed by default. If no connection has the identifier default, the Assistant displays the connection properties for the connection with the alphabetically first identifier.
 • For more detailed information, see the Help menu in the Connection Builder Assistant.

Examples

The Connection Builder Assistant can be opened either by using the top-level Database command, as shown below, or by calling Database:-ConnectionBuilder.

 > $\mathrm{driver},\mathrm{conn}≔\mathrm{Database}\left(\right):$
 > $\mathrm{result}≔\mathrm{conn}:-\mathrm{ExecuteQuery}\left("SELECT * FROM animals"\right)$
 ${\mathrm{result}}{:=}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{option}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{unload}}{=}{\mathrm{Close}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{handle}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{export}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{Next}}{,}{\mathrm{Previous}}{,}{\mathrm{Last}}{,}{\mathrm{First}}{,}{\mathrm{GetRowNumber}}{,}{\mathrm{GotoRow}}{,}{\mathrm{GetRowCount}}{,}{\mathrm{InsertRow}}{,}{\mathrm{DeleteRow}}{,}{\mathrm{UpdateRow}}{,}{\mathrm{GetData}}{,}{\mathrm{UpdateData}}{,}{\mathrm{GetType}}{,}{\mathrm{GetName}}{,}{\mathrm{GetColumnCount}}{,}{\mathrm{SetOptions}}{,}{\mathrm{GetOptions}}{,}{\mathrm{Close}}{,}{\mathrm{ToMaple}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}$ (1)

Show the results.

 > $\mathbf{while}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}r:-\mathrm{Next}\left(\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}r:-\mathrm{GetData}\left("id"\right),r:-\mathrm{GetData}\left("name"\right),r:-\mathrm{GetData}\left("number"\right),r:-\mathrm{GetData}\left("mass"\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end do}$
 ${1}{,}{"fish"}{,}{100}{,}{0.0100000000000000002}$
 ${2}{,}{"dog"}{,}{10}{,}{20.5000000000000000}$
 ${3}{,}{"cat"}{,}{10}{,}{5.50000000000000000}$
 ${4}{,}{"rat"}{,}{50}{,}{0.500000000000000000}$
 ${5}{,}{"horse"}{,}{3}{,}{400.300000000000011}$
 ${6}{,}{"snake"}{,}{1}{,}{7.75000000000000000}$
 ${7}{,}{"lizard"}{,}{5}{,}{0.100000000000000004}$
 ${8}{,}{"parrot"}{,}{20}{,}{2.}$
 ${9}{,}{"pig"}{,}{4}{,}{10.}$
 ${10}{,}{"hamster"}{,}{30}{,}{0.200000000000000012}$ (2)

Perform a more complex SELECT and convert the output to a Maple table.

 > $c:-\mathrm{ExecuteQuery}\left("SELECT id, name FROM animals WHERE mass > 5",'\mathrm{output}'='\mathrm{table}'\right)$
 ${\mathrm{table}}{}\left(\left[\left({2}{,}{"id"}\right){=}{3}{,}\left({4}{,}{"id"}\right){=}{6}{,}\left({3}{,}{"name"}\right){=}{"horse"}{,}\left({1}{,}{"id"}\right){=}{2}{,}\left({5}{,}{"id"}\right){=}{8}{,}\left({4}{,}{"name"}\right){=}{"snake"}{,}\left({3}{,}{"id"}\right){=}{5}{,}\left({2}{,}{"name"}\right){=}{"cat"}{,}\left({1}{,}{"name"}\right){=}{"dog"}{,}\left({5}{,}{"name"}\right){=}{"pig"}\right]\right)$ (3)

Perform another SELECT and convert the output to a Maple Array.

 > $c:-\mathrm{ExecuteQuery}\left("SELECT name, mass FROM animals WHERE number BETWEEN 10 and 50",'\mathrm{output}'='\mathrm{Array}'\right)$
 $\left[\begin{array}{cc}{"dog"}& {20.5000000000000000}\\ {"cat"}& {5.50000000000000000}\\ {"rat"}& {0.500000000000000000}\\ {"parrot"}& {2.}\\ {"hamster"}& {0.200000000000000012}\end{array}\right]$ (4)