21.08.2013 Views

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Types of Database Access<br />

database table and a database import performed.<br />

Finally, <strong>OpenOffice</strong>.<strong>org</strong> provides a mechanism for forms based on databases. To do this, you first create a<br />

standard <strong>OpenOffice</strong>.<strong>org</strong> Writer or <strong>OpenOffice</strong>.<strong>org</strong> Calc form and then link the fields to a database.<br />

All the options specified here are based on the user interface from <strong>OpenOffice</strong>.<strong>org</strong>. No programming knowledge<br />

is needed to use the corresponding functions.<br />

This section, however, provides little information about the functions specified, but instead concentrates on the<br />

programming interface from SDBC, which allows for automated database querying and therefore permits a much<br />

greater range of applications to be used.<br />

Basic knowledge of the way in which databases function and the SQL query language is however needed to fully<br />

understand the following sections.<br />

Data Sources<br />

A database is incorporated into <strong>OpenOffice</strong>.<strong>org</strong> by creating what is commonly referred to as a data source. The<br />

user interface provides a corresponding option for creating data sources in the Extras menu. You can also create<br />

data sources and work with them using <strong>OpenOffice</strong>.<strong>org</strong> Basic.<br />

A database context object that is created using the createUnoService function serves as the starting point for<br />

accessing a data source. This based on the com.sun.star.sdb.DatabaseContext service and is the root object for all<br />

database operations.<br />

The following example shows how a database context can be created and then used to determine the names of all<br />

data sources available. It displays the names in a message box.<br />

Dim DatabaseContext As Object<br />

Dim Names<br />

Dim I As Integer<br />

DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")<br />

Names = DatabaseContext.getElementNames()<br />

For I = 0 To UBound(Names())<br />

MsgBox Names(I)<br />

Next I<br />

The individual data sources are based on the com.sun.star.sdb.DataSource service and can be determined from<br />

the database context using the getByName method:<br />

Dim DatabaseContext As Object<br />

Dim DataSource As Object<br />

DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")<br />

DataSource = DatabaseContext.getByName("Customers")<br />

The example creates a DataSource object for a data source called Customers.<br />

Data sources provide a range of properties, which in turn provide general information about the origin of the data<br />

and information about access methods. The properties are:<br />

Name (String)<br />

name of data source<br />

URL (String)<br />

URL of data source in the form of jdbc: subprotocol : subname or sdbc: subprotocol : subname<br />

Settings (Array)<br />

array containing PropertyValue-pairs with connection parameters (usually at least user name and<br />

password)<br />

144 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!