DATABASELINK 教程

Examples
This feature is not supported on the Wolfram Cloud.

Command Cache

This example shows how to use a private database to store Wolfram Language commands and query the data from Java and the Wolfram Language.

If you find that the examples in this section do not work as shown, you may need to install or restore the example database with the package, as described in "Using the Example Databases".

The example code is loaded from the Examples subdirectory of DatabaseLink.

In[1]:=
Click for copyable input

The command cache allows you to store Wolfram Language expressions as typeset box expressions data in a database. is used to store the boxes in the database.

In[2]:=
Click for copyable input
Out[2]=

The data can then be retrieved from the database using .

In[3]:=
Click for copyable input
Out[3]=

Several attributes of each command are stored in the database. Each command is given an ID, generated when it is stored. The expression is stored as a string formatted with FullForm; this allows it to be reused in the Wolfram Language. In addition, an image of the expression is saved, as well as the time at which the data was stored. can be used to get the attribute names. These can be used to filter the data returned.

In[4]:=
Click for copyable input
Out[4]=
In[5]:=
Click for copyable input
Out[5]=

The following example finds all results that contain Power.

In[6]:=
Click for copyable input
Out[6]=
In[7]:=
Click for copyable input
Out[7]=
In[8]:=
Click for copyable input
Out[8]=

A command can also be retrieved using its ID.

In[9]:=
Click for copyable input
Out[9]=

Another feature of this package is a Java GUI you can use to browse the data. It provides functionality for managing the data and pasting the data into a notebook.

In[10]:=
Click for copyable input
Out[10]=

The GUI is automatically updated when new commands are added to the database.

In[11]:=
Click for copyable input

Likewise, the GUI is automatically updated when commands are removed. can be used to remove all the data in the command cache.

In[12]:=
Click for copyable input
Out[12]=

Graph Database

This example shows a database that stores material generated by the Wolfram Language. Here the material involves graphs and a number of properties of these graphs. Even though the number of graphs is not extremely large, generating the properties of these graphs can take a significant amount of time. This demonstrates the value of a database for persistent storage of the results of computations.

Using the Graph Database

To use the graph database you need to load the package.

In[1]:=
Click for copyable input

The first time the package is used you will need to run the command. If you find that the examples in this section do not work as shown, you should also run this command. This command can take a long time to run, but is only necessary once.

Click for copyable input

The properties of the graphs stored in the database are given by the function.

In[2]:=
Click for copyable input
Out[2]=

Now you can make a query from the database. This is done with the command. The following returns all complete graphs.

In[3]:=
Click for copyable input

Out[3]=

The format used for the graphs is that provided by the Combinatorica package. This draws a picture of the graph and also returns a symbolic object that could be used for further computation by the Wolfram Language.

The following returns the first three regular graphs.

In[4]:=
Click for copyable input

Out[4]=

The following finds Hamiltonian graphs, returning their diameter, girth, and edge information. As before, a picture of the graph is also drawn.

In[5]:=
Click for copyable input

Out[5]=

One important aspect of this example package is that it shows commands that are specific to the issue of finding graphs rather than general database commands. The details of the database interactions are all placed in the implementation.

The Graph Database Package

The graph database package provides three functions.

GraphProperties[]list all graph properties within the database
GraphQuery[{props}]search the database for graphs that match props
RestoreGraphDatabase[]restore the data in the database (can be slow)

Graph database package functions.

The function recomputes all the data in the database and can take some time to complete. Generally, you do not want to run this, unless you have corrupted the database in some way.