Openoffice.org with SQL Databases: Difference between revisions
(some more screenshots) |
|||
(31 intermediate revisions by 7 users not shown) | |||
Line 3: | Line 3: | ||
== Usage of OpenOffice-Base with various drivers == | == Usage of OpenOffice-Base with various drivers == | ||
* See [http://dba.openoffice.org/drivers/index.html Database drivers] page for overview. There are drivers for PostgreSQL, SQLite and MS-Access mdb files. | * See [http://dba.openoffice.org/drivers/index.html Database drivers] page for overview. There are drivers for PostgreSQL, SQLite and MS-Access mdb files. Also you can check an expanded list of [https://www.devart.com/odbc/ ODBC drivers] for Oracle, SQL Server, PostgreSQL, MySQL, SQLite. | ||
=== PostgreSQL (LibreOffice.org 3.x) === | |||
The version LibreOffice 3.5 introduces a new PostgreSQL driver: | |||
http://www.libreoffice.org/download/3-5-new-features-and-fixes/ | |||
Alternative [https://www.devart.com/odbc/postgresql/ PostgreSQL ODBC driver] perfectly works with the latest LibreOffice. | |||
=== PostgreSQL (OpenOffice.org 2.x) === | === PostgreSQL (OpenOffice.org 2.x) === | ||
Line 31: | Line 37: | ||
Please use the [http://jdbc.postgresql.org/download.html JDBC driver]. | Please use the [http://jdbc.postgresql.org/download.html JDBC driver]. | ||
There are not mac OSX version of official SDBC driver, you can connect your postgreSQL database using the JDBC driver. But there is unofficial [https://www.devart.com/odbc/postgresql/download.html PosgreSQL ODBC driver] for MAC OS X which you can download for free. | |||
<br> | |||
1)Download the JDBC driver at : | |||
[http://jdbc.postgresql.org/download.html PosgreSQL] | |||
<br> | |||
(select the driver for your pgsql version) | |||
for example with postgreSQL-8.2 (postgresql framework installation - until 20/3/2008) we need to download this driver: | |||
[http://jdbc.postgresql.org/download/postgresql-8.2-508.jdbc2.jar pgsql_8.2_driver] | |||
2) Open Neooffice | |||
- preferences: | |||
http://img118.imageshack.us/img118/109/preferenzeap3.png | |||
select : | |||
Java | |||
http://img236.imageshack.us/img236/6004/javaqr9.png | |||
click on : | |||
classpath | |||
http://img50.imageshack.us/img50/3504/immagine1tb1.png | |||
click on : | |||
add archive ( aggiungi archivio ) | |||
select the downloaded driver | |||
click on : | |||
ok | |||
3) Come back to : | |||
neooffice - database | |||
http://img67.imageshack.us/img67/2043/databasevn2.png | |||
In the database configuration window: | |||
http://img54.imageshack.us/img54/3386/selezionadatabnv6.png | |||
at the point : connect to an existing database (collega a un database esistente), select the option : | |||
JDBC | |||
click on : | |||
next (avanti) | |||
http://img111.imageshack.us/img111/2128/immagine3uw6.png | |||
insert the url to your pgsql database (in this example we have host=localhost, dbname=grassdb): | |||
postgresql://localhost/grassdb | |||
class driver JDBC : | |||
org.postgresql.Driver | |||
click on : | |||
try class (classe di prova) | |||
if oll is ok : | |||
http://img125.imageshack.us/img125/9330/immagine2kw6.png | |||
click on : | |||
ok | |||
go to the next step | |||
http://img67.imageshack.us/img67/8527/immagine13dv9.png | |||
insert : | |||
user name | |||
chek the flag 'request password' | |||
click on : | |||
try connection ( connessione di prova ) | |||
http://img300.imageshack.us/img300/9965/immagine6ck5.png | |||
insert : | |||
password | |||
click on : | |||
ok | |||
if all is ok : | |||
http://img64.imageshack.us/img64/896/immagine7ak2.png | |||
click on : | |||
next (avanti) | |||
http://img103.imageshack.us/img103/8379/immagine8kf6.png | |||
click on | |||
end ( fine ) | |||
to save the database | |||
http://img109.imageshack.us/img109/815/immagine9ph2.png | |||
database successfully created: | |||
http://img113.imageshack.us/img113/686/immagine10di9.png | |||
[[Category: FAQ]] | |||
[[Category:database]] | |||
=== MySQL (OpenOffice.org 2.x) === | === MySQL (OpenOffice.org 2.x) === | ||
* Connection via JODBC driver: http://kienlein.com/pages/mysql-jdbc-howto-en.html | * Connection via JODBC driver: http://kienlein.com/pages/mysql-jdbc-howto-en.html | ||
* Connection via [https://www.devart.com/odbc/mysql/docs/using_odbc_driver.htm MySQL ODBC driver] | |||
=== DBF files (OpenOffice.org 2.x) === | === DBF files (OpenOffice.org 2.x) === | ||
Line 41: | Line 180: | ||
No installation needed, the driver is included in the standard version of OpenOffice.org. | No installation needed, the driver is included in the standard version of OpenOffice.org. | ||
'''Usage:''' | |||
* File -> New -> Database -> "Connect to an existing database" -> dBASE | |||
* -> NEXT button | |||
* Set path to dBASE files (Browse if needed: only the path to the right directory) | |||
* -> NEXT button | |||
* -> FINISH button, this asks you to enter a new name for the ODF file which stores the connection (call it "test" or else) | |||
Now the graphical user interface appears. In the lower part the tables are listed which are available in above selected path. | |||
* to change a DBF definition: right-click the table of interest from the list and select "Edit". Then you can modify column definitions and save | |||
* to modify table content: double-click the table | |||
=== MS-Access mdb files (OpenOffice.org 2.x) === | === MS-Access mdb files (OpenOffice.org 2.x) === | ||
* http://dba.openoffice.org/drivers/mdb/index.html | <strike> | ||
* http://dba.openoffice.org/drivers/mdb/index.html Note that the driver is somewhat behind the mdbtools.sf.net development. | |||
</strike> | |||
* Connect through ODBC based connection: http://www.openoffice.org/FAQs/ms-access/ms-access.html . For Linux, you need [http://www.unixodbc.org/ unixODBC] to be installed (your preferred distribution most likely contains this package). Get also the [http://mdbtools.sourceforge.net/ MDB Tools] (preferably fresh from CVS since the 0.5 release is old; compile with unixodbc support enabled). Then follow instructions at http://www.gdal.org/ogr/drv_pgeo.html (or add them here). | |||
=== SQLite files (OpenOffice.org 2.x) === | |||
* <strike>[http://dba.openoffice.org/drivers/sqlite/index.html OO-Base SQLite driver] (driver still in alpha state)</strike> | |||
* Tested and working [https://www.devart.com/odbc/sqlite SQLite ODBC driver]. Connection string and installation guide of SQLite ODBC driver https://www.devart.com/odbc/sqlite/docs/using_odbc_driver.htm | |||
* [http://www.ch-werner.de/sqliteodbc/ SQLite ODBC Driver] (wrapped SQLite library into an ODBC driver). Installation: | |||
After installation of 'sqliteodbc', add the driver to /etc/odbcinst.ini (either add next lines or create as new file if the file does not yet exist): | |||
[SQLite] | |||
Description=SQLite ODBC Driver | |||
Driver=/usr/local/lib/libsqlite3odbc.so | |||
Setup=/usr/local/lib/libsqlite3odbc.so | |||
Now the SQLite driver is available for ODBC. The next step is to add the definition(s) of the database you want to connect to. Add an ODBC Data Source Name (DSN) to your definition file at $HOME/.odbc.ini (replace 'user' and 'mymapset' with the correct entries): | |||
[nc_sqlite] | |||
Description=North Carolina SQLite DB | |||
Driver=SQLite | |||
Database=/home/user/grassdata/nc_spm/mymapset/sqlite.db | |||
# optional lock timeout in milliseconds | |||
Timeout=2000 | |||
== Converting Excel, CSV, ... to PostgreSQL/MySQL/... via OO-Base == | == Converting Excel, CSV, ... to PostgreSQL/MySQL/... via OO-Base == | ||
Line 85: | Line 251: | ||
[[Image:oo_base_paste_small.png|none]] (see also [[media:oo_base_paste.png|larger screenshot]]) | [[Image:oo_base_paste_small.png|none]] (see also [[media:oo_base_paste.png|larger screenshot]]) | ||
'''4. A wizard opens, define a table name | '''4. A wizard opens, define a table name:''' | ||
When connecting to PostgreSQL, be sure to write a prefix for the schema, usually "public.": | |||
[[Image:oo_base_newtable1_small.png|none]] (see also [[media:oo_base_newtable1.png|larger screenshot]]) | [[Image:oo_base_newtable1_small.png|none]] (see also [[media:oo_base_newtable1.png|larger screenshot]]) | ||
Line 94: | Line 262: | ||
'''6. Define primary key (right mouse button on desired column) and all column types:''' | '''6. Define primary key (right mouse button on desired column) and all column types:''' | ||
WARNING: If you make a mistake in defining the column types, all rows after the first failing conversion will be silently ignored. Verify later that all rows arrived in the final SQL table. | |||
[[Image:oo_base_newtable3_small.png|none]] (see also [[media:oo_base_newtable3.png|larger screenshot]]) | [[Image:oo_base_newtable3_small.png|none]] (see also [[media:oo_base_newtable3.png|larger screenshot]]) | ||
Line 105: | Line 275: | ||
=== Step by step DB import procedure (MacOSX) === | === Step by step DB import procedure (MacOSX) === | ||
There are not difference between osx and linux. | |||
<br/>Look for 'Step by step DB import procedure (MS-Windows and Linux)'. |
Latest revision as of 09:07, 14 September 2015
Do you also dislike it to manually convert Excel tables into PostgreSQL? Not having real fun in exporting to CSV, then manually writing the SQL header and importing the stuff in PG? This article here explains how to convert a table into an SQL database via OpenOffice. Essentially you open the Excel (or whatever) table with OpenOffice-Calc, select and copy the full table or a subset to the clipboard, and simply paste it into OpenOffice-Base with the right mouse button. A wizard pops up which let's you define the type of each column and a primary key. Save & done. Can't be easier!
Usage of OpenOffice-Base with various drivers
- See Database drivers page for overview. There are drivers for PostgreSQL, SQLite and MS-Access mdb files. Also you can check an expanded list of ODBC drivers for Oracle, SQL Server, PostgreSQL, MySQL, SQLite.
PostgreSQL (LibreOffice.org 3.x)
The version LibreOffice 3.5 introduces a new PostgreSQL driver: http://www.libreoffice.org/download/3-5-new-features-and-fixes/ Alternative PostgreSQL ODBC driver perfectly works with the latest LibreOffice.
PostgreSQL (OpenOffice.org 2.x)
Installation of PostgreSQL driver (MS-Windows and Linux)
- download postgresql-sdbc-X.Y.Z.zip driver (take the "recommended" file) and save the file to your disk.
- Start OpenOffice, choose 'Tools/Package Manager'. Click on the add button and select the downladed file (DO NOT EXTRACT IT !) in the upcoming File dialog. The driver gets installed now, afterwards, the file is listed in the dialog with state enabled. In case you have installed an older version of the driver, remove it now. Close the dialog.
- Restart openoffice (even the quickstarter on windows must be shut down !!!).
- Done (did you really close openoffice? Please do.)
Usage of PostgreSQL driver (MS-Windows and Linux)
After starting OpenOffice.org again, use: File -> New -> Database to enter the DB dialog.
- Connect to existing database (select driver): postgresql
- Connection settings: We have to define the server ("host") name and the name of the database, probably also the user name in case you have to connect with a different user name. To find out, ask your DB administrator or use in a terminal "psql -l " or, if the database is on a remote server, "psql -h host.mydomain.org -l". An entry may look like this:
dbname=pgtest host=my.databaseserver.org
- User name (the login name): yourname
- Finish brings you to a 'Save as' dialog for the connection, saves these settings as file. This file you can use later to re-establish the connection (instead of defining all again).
- Then click on 'Tables' in the next screen to see the existing PG tables in the database. Usually the 'public' scheme contains the user tables.
- The 'Queries' button takes you to the query mode, it contains a graphical query designer.
Installation of PostgreSQL driver (MacOSX)
Please use the JDBC driver.
There are not mac OSX version of official SDBC driver, you can connect your postgreSQL database using the JDBC driver. But there is unofficial PosgreSQL ODBC driver for MAC OS X which you can download for free.
1)Download the JDBC driver at :
PosgreSQL
(select the driver for your pgsql version)
for example with postgreSQL-8.2 (postgresql framework installation - until 20/3/2008) we need to download this driver:
2) Open Neooffice
- preferences:
http://img118.imageshack.us/img118/109/preferenzeap3.png
select :
Java
http://img236.imageshack.us/img236/6004/javaqr9.png
click on :
classpath
http://img50.imageshack.us/img50/3504/immagine1tb1.png
click on :
add archive ( aggiungi archivio )
select the downloaded driver
click on :
ok
3) Come back to :
neooffice - database
http://img67.imageshack.us/img67/2043/databasevn2.png
In the database configuration window:
http://img54.imageshack.us/img54/3386/selezionadatabnv6.png
at the point : connect to an existing database (collega a un database esistente), select the option :
JDBC
click on :
next (avanti)
http://img111.imageshack.us/img111/2128/immagine3uw6.png
insert the url to your pgsql database (in this example we have host=localhost, dbname=grassdb):
postgresql://localhost/grassdb
class driver JDBC :
org.postgresql.Driver
click on :
try class (classe di prova)
if oll is ok :
http://img125.imageshack.us/img125/9330/immagine2kw6.png
click on :
ok
go to the next step
http://img67.imageshack.us/img67/8527/immagine13dv9.png
insert :
user name
chek the flag 'request password'
click on :
try connection ( connessione di prova )
http://img300.imageshack.us/img300/9965/immagine6ck5.png
insert :
password
click on :
ok
if all is ok :
http://img64.imageshack.us/img64/896/immagine7ak2.png
click on :
next (avanti)
http://img103.imageshack.us/img103/8379/immagine8kf6.png
click on
end ( fine )
to save the database
http://img109.imageshack.us/img109/815/immagine9ph2.png
database successfully created:
http://img113.imageshack.us/img113/686/immagine10di9.png
MySQL (OpenOffice.org 2.x)
- Connection via JODBC driver: http://kienlein.com/pages/mysql-jdbc-howto-en.html
- Connection via MySQL ODBC driver
DBF files (OpenOffice.org 2.x)
No installation needed, the driver is included in the standard version of OpenOffice.org.
Usage:
- File -> New -> Database -> "Connect to an existing database" -> dBASE
- -> NEXT button
- Set path to dBASE files (Browse if needed: only the path to the right directory)
- -> NEXT button
- -> FINISH button, this asks you to enter a new name for the ODF file which stores the connection (call it "test" or else)
Now the graphical user interface appears. In the lower part the tables are listed which are available in above selected path.
- to change a DBF definition: right-click the table of interest from the list and select "Edit". Then you can modify column definitions and save
- to modify table content: double-click the table
MS-Access mdb files (OpenOffice.org 2.x)
- http://dba.openoffice.org/drivers/mdb/index.html Note that the driver is somewhat behind the mdbtools.sf.net development.
- Connect through ODBC based connection: http://www.openoffice.org/FAQs/ms-access/ms-access.html . For Linux, you need unixODBC to be installed (your preferred distribution most likely contains this package). Get also the MDB Tools (preferably fresh from CVS since the 0.5 release is old; compile with unixodbc support enabled). Then follow instructions at http://www.gdal.org/ogr/drv_pgeo.html (or add them here).
SQLite files (OpenOffice.org 2.x)
OO-Base SQLite driver (driver still in alpha state)- Tested and working SQLite ODBC driver. Connection string and installation guide of SQLite ODBC driver https://www.devart.com/odbc/sqlite/docs/using_odbc_driver.htm
- SQLite ODBC Driver (wrapped SQLite library into an ODBC driver). Installation:
After installation of 'sqliteodbc', add the driver to /etc/odbcinst.ini (either add next lines or create as new file if the file does not yet exist):
[SQLite] Description=SQLite ODBC Driver Driver=/usr/local/lib/libsqlite3odbc.so Setup=/usr/local/lib/libsqlite3odbc.so
Now the SQLite driver is available for ODBC. The next step is to add the definition(s) of the database you want to connect to. Add an ODBC Data Source Name (DSN) to your definition file at $HOME/.odbc.ini (replace 'user' and 'mymapset' with the correct entries):
[nc_sqlite] Description=North Carolina SQLite DB Driver=SQLite Database=/home/user/grassdata/nc_spm/mymapset/sqlite.db # optional lock timeout in milliseconds Timeout=2000
Converting Excel, CSV, ... to PostgreSQL/MySQL/... via OO-Base
- Bringing data into OpenOffice 2.0's database: You can for example open an Excel file with OpenOffice, select contents, then open a DB connection in OpenOfficeBase and paste the table into it. The wizard allows to define the type of each column before creating the table. Using the right mouse button on a column name, you can define it as primary key. Important: If generating a PostgreSQL table, prefix the new table name with "public." (example: public.table1) to avoid that the user name is used as schema name.
Step by step DB import procedure (MS-Windows and Linux)
Here we show how to get a spreadsheet table into a SQL database.
1. Mark and copy to clipboard the relevant table parts in the Excel/CSV/whatever table (OO-Calc):
Open the original table with OpenOffice-Calc. For CSV files, they need the .csv extension.
(see also larger screenshot)
2. Open OO-Base and establish a connection to the database (see above for driver installation):
Go File -> New -> Database to launch OO-Base.
(see also larger screenshot)
(see also larger screenshot)
(see also larger screenshot)
3. In the table wizard, paste (right mouse button) earlier selected OO-Calc spreadsheet into the table section:
First select "table" from left menu, then paste into it:
(see also larger screenshot)
4. A wizard opens, define a table name:
When connecting to PostgreSQL, be sure to write a prefix for the schema, usually "public.":
(see also larger screenshot)
5. Select the columns you want to transfer:
(see also larger screenshot)
6. Define primary key (right mouse button on desired column) and all column types:
WARNING: If you make a mistake in defining the column types, all rows after the first failing conversion will be silently ignored. Verify later that all rows arrived in the final SQL table.
(see also larger screenshot)
7. Save and enjoy. The table is now written into your SQL database.
Note that the conversion can take some time.
You can now connect the table to GRASS, R-stats, ... as you like.
Step by step DB import procedure (MacOSX)
There are not difference between osx and linux.
Look for 'Step by step DB import procedure (MS-Windows and Linux)'.