User:Cibes

From Apache OpenOffice Wiki
Revision as of 08:02, 29 June 2010 by Cibes (Talk | contribs)

Jump to: navigation, search

Project

Updating: Documentation/How_Tos/Using_SQLite_With_OpenOffice.org

OpenOffice Base provides functions to connect to other databases than the default HSQL database. This Tutorial should guide you through the steps to connect OpenOffice to a SQLite database file.


Template:Documentation/Linux

Installation

ODBC drivers

Connection to a SQLite database will be established through ODBC drivers. ODBC drivers for SQLite are independent of the SQLite project.


You can install unixodbc with your packetmanager - or download the sources from the unixODBC website. The unixodbc-dev and unixodbc-bin packages will also be required to complete the configuration for OpenOffice.

sudo apt-get unixodbc unixodbc-dev unixodbc-bin


SQLite

Obviously you will need to install SQLite if it is not installed already as this will be the database you want to connect to.


There will likely be a version in the repositories although it might be dated. You can always download and install the latest version from source.


sqliteODBC

For SQLite to work through the ODBC standards you will also need to install and configure a special set of drivers.


There are no precompiled packages so you will need to download the source and compile it yourself:

tar xvzf sqliteodbc-0.XX.tar.gz
./configure –prefix=/usr
make
sudo make install

--prefix=/usr is optional, but is especially useful with Mandrake distributions, to install the driver in /usr/lib rather than in the default location, /usr/local/lib.

Template:Documentation/Note


To complete the installation the driver has to be integrated into unixODBC. To do this, launch the ODBCConfig utility as root in an terminal window:

sudo ODBCConfig

Template:Documentation/Note

Now the a GUI to manage the configuration shows up. Doc howto sqlite odbcadmin.png

Click the Drivers tab and choose Add... Then fill the fields as follows:

Name: SQLite
Description: SQLite for ODBC
Driver: /usr/lib/libsqlite3odbc.so
Driver64:
Setup: /usr/lib/libsqlite3odbc.so
Setup64:

Template:Documentation/Note

Then confirm using the checkmark icon on the left in top of the window. Your new driver will now appear in the Drivers tab: Doc howto sqlite odbcadmin-2.png

The driver installation under Linux is now finished and you can exit ODBCConfig.


For those who do not have ODBCConfig or who prefer to carry out this configuration manually, it is necessary to edit the file /etc/odbcinst.ini as root and add the following lines:

[SQLite]
Description= ODBC for SQLite
Driver= /usr/lib/libsqliteODBC.so
Setup= /usr/lib/libsqliteODBC.so
FileUsage= 1
CPTimeout= 
CPReuse= 


Setup of SQLite database

Creating a SQLite database file

An initial database file cannot be created directly in OpenOffice.org but rather this is accomplished by using either the utility “sqlite” on the command line, or by using the tool sqlitebrowser which is graphic, very simple and available for both Linux and for Windows. If you wish to use sqlitebrowser, you will find it as the third entry in the list at: http://www.sqlite.org/cvstrac/wiki?p=SqliteTools,

The utility "sqlite" should be already installed if you use Linux and have installed SQLite from rpm. For other *NIX systems, you must build SQLite from source which you can find at http://www.sqlite.org/download.html .

Performance and usage under Linux and Windows is identical.

Using sqlite

Open a terminal window and change to the directory where you want to create your database. Run sqlite with the filename of your database as argument. If this database file does not exist it will be created now automatically. Using sqlite you can create tables and modify your database with standard SQL-commands:

$ sqlite <filename of database>
SQLite version 2.8.12
Enter ".help" for instructions
sqlite> CREATE TABLE mytable (id INT, text VARCHAR(100));
sqlite> .exit

Template:Documentation/Note

Using sqlite on the command line program also makes it possible to create tables and indices, to enter and post data, and to make queries providing you know the SQL language ; however, it is more practical for beginners to carry out these operations using OpenOffice.org.

Using SQLite Database Browser

After unpacking the file, launch sqlitebrowser and select File/New Database or the corresponding icon:

Doc howto sqlite dbbrowser.png

Choose the directory in which to place file and then enter name of the database file and click on Save.

Using this program, you can also create the tables, the fields and the indices, to access data and to visualize them. While sqlitebrowswer is suitable for these actions, there is the disadvantage that it does not show the full list of field types during field creation. In this case, it may be preferable to do it later using OpenOffice.org.


ODBC-setup of new database

After creating a new SQLite database above you now have to configure this database in ODBC so you can connect to it in OpenOffice later on.

Launch ODBCConfig again and go to the tab User DSN. Here add a new entry. A window appears in which you must choose the SQLite driver you have configured earlier. In the next window, as shown below, you enter a name for this connection (for example the name of your database) and the complete access path to the database file which you created previously.

Doc howto sqlite driverproperties-2.png

Validate the data on the screen, click the checkmark and you should see your new data source in the tab User DSN.


If you do not have ODBCConfig or simply prefer to configure manually, launch your favorite editor, open (or create) the file odbc.ini in your home directory, and add the following lines to it:

[My Base]
Description= My test database
Driver= SQLite
Database= /home/<user>/basename.db
Timeout= 1000
StepAPI= No

Template:Documentation/Note


You are now ready to access your data base with OpenOffice.org!


Connecting OpenOffice to a SQLite database

You had to spend a lot of time installing and configuring other things but finally we can move on to OpenOffice. Only a few more configuration windows and you will be done.

Start OpenOffice Base and in the first step 1. Select database chose the third option, connect to an existing database using ODBC.

Connect to an existing database
 ODBC

In the second step 2. Set up ODBC connection you can select your SQLite database. Clicking on Browse you should get a list of all databases you have configured in ODBC. If nothing is showing up here you have a problem. Check that you actually set up the database in ODBC and that the drivers are properly configured as described.

Working on database with OpenOffice

The rest is OpenOffice Base just as you know it.

Only note a few things: Creating new tables using OpenOffice is possible. Those tables - along with all data you enter in them - are saved in the external SQLite database file to which you connected your OpenOffice .odb file.

Fields defined as type "integer" are auto-increment, that is they automatically increment the value of the field when adding a new record in this table.

Documentation caution.png Once you have saved your table, you cannot modify it! I.e. you will not be able to modify the properties of the fields any more, nor add or remove!

This rather awkward constraint is specific to SQLite, which does not handle the SQL command ALTER COUNTS, and not the ODBC driver. This limitation is designed in by the authors in order to make the basic database engine as light as possible. However, this limitation may be eliminated in a future version. Therefore you are advised to check your table structure very carefully before recording it.

If you must modify a table, the only solution is to create a new table and save it under different name. By doing do, you can transfer the data from the original table to the new table.


Creating and using Forms, Queries and Reports are all independent of the datasource you use. They will function just as with the default integrated HSQL-database and will still be saved in your odb-file.

Personal tools