Difference between revisions of "User:Cibes"
Line 78: | Line 78: | ||
===Under Windows=== | ===Under Windows=== | ||
− | {{Documentation/Windows|Under Windows the installation and configuration is much easier. Simply [http://ch-werner.de/sqliteodbc/ | + | {{Documentation/Windows|Under Windows the installation and configuration is much easier. Simply [http://ch-werner.de/sqliteodbc/ download the sqliteODBC.exe], the installer will automatically setup the ODBC drivers including the SQLite configurations for it and also provides you with the sqlite command line tool to create and modify SQLite databases.}} |
Line 90: | Line 90: | ||
Performance and usage under Linux and Windows is identical. | Performance and usage under Linux and Windows is identical. | ||
− | ====Using sqlite | + | ====Using sqlite==== |
{{Documentation/Linux|Open a terminal window and change to the directory where you want to create your database. Run <tt>sqlite</tt> with the filename of your database as argument (e.g. ''$ sqlite mydatabase''}} | {{Documentation/Linux|Open a terminal window and change to the directory where you want to create your database. Run <tt>sqlite</tt> with the filename of your database as argument (e.g. ''$ sqlite mydatabase''}} | ||
{{Documentation/Windows|Run <tt>sqlite</tt> from the start menu or where it was installed. A standard file open dialog box will open and ask you to select a database file.}} | {{Documentation/Windows|Run <tt>sqlite</tt> from the start menu or where it was installed. A standard file open dialog box will open and ask you to select a database file.}} | ||
Line 166: | Line 166: | ||
{{Documentation/Windows|'''Under Windows:''' | {{Documentation/Windows|'''Under Windows:''' | ||
Before you will find your database listed here you need to register it with ODBC as mentioned above. Click on ''Organize...'' in the bottom right of the window. | Before you will find your database listed here you need to register it with ODBC as mentioned above. Click on ''Organize...'' in the bottom right of the window. | ||
− | [[Image:doc_howto_sqlite_odbcdriver-windows-1.png | + | |
+ | [[Image:doc_howto_sqlite_odbcdriver-windows-1.png]] | ||
+ | |||
In the ''User DSN'' (or the ''System DSN'') tab click on ''Add...'' to setup your database file. | In the ''User DSN'' (or the ''System DSN'') tab click on ''Add...'' to setup your database file. | ||
− | [[Image:doc_howto_sqlite_odbcdriver-windows-2.png | + | |
+ | [[Image:doc_howto_sqlite_odbcdriver-windows-2.png]] | ||
+ | |||
Give your database a meaningful name as ''Data Source Name'' - this will be the name you find your database listed as. For ''Database Name'' browse to the SQLite database file you have created earlier. Leave the rest on its default values and press ok. | Give your database a meaningful name as ''Data Source Name'' - this will be the name you find your database listed as. For ''Database Name'' browse to the SQLite database file you have created earlier. Leave the rest on its default values and press ok. | ||
− | [[Image:doc_howto_sqlite_odbcdriver-windows-3.png | + | |
+ | [[Image:doc_howto_sqlite_odbcdriver-windows-3.png]] | ||
+ | |||
+ | |||
The database will now be listed in the ''ODBC Data Source Administrator'' and leaving this window you should now also be able to select this database in the ''OpenOffice Base'' dialog. | The database will now be listed in the ''ODBC Data Source Administrator'' and leaving this window you should now also be able to select this database in the ''OpenOffice Base'' dialog. | ||
}} | }} |
Revision as of 14:44, 29 June 2010
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.
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.
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
Now the a GUI to manage the configuration shows up.
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:
Then confirm using the checkmark icon on the left in top of the window. Your new driver will now appear in the Drivers tab:
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=
Under Windows
Template:Documentation/Windows
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 a graphical management tool, a list of GUIs is available at SQLite.org
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 [1]
Performance and usage under Linux and Windows is identical.
Using sqlite
Template:Documentation/Linux Template:Documentation/Windows If this database file does not exist yet it will be created automatically. Using sqlite you can also 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
Using sqlite on the command line program makes it possible to create tables and indices, to enter and post data and to make queries provided you know the SQL language - however, it is more practical for beginners to carry out these operations later on using OpenOffice.
Using SQLite Database Browser
After unpacking the file, launch sqlitebrowser and select File/New Database or the corresponding icon:
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.
Template:Documentation/Windows
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.
Template:Documentation/Windows
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.
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.