Está en la página 1de 27

Using SQLite Database with OpenOffice.

org
Version 2.0

[Utilisation d'une base de donnes SQLite avec OpenOffice.org] [1.0] First edition [0!"0#"$00%] First &nglis' edition [0("0)"$00%]

Contents

Contents
*ontents...........................................................................................................................................1 Overvie+..........................................................................................................................................$ *op,rig't and trade-ar. infor-ation.........................................................................................$ Feedbac......................................................................................................................................$ /c.no+ledg-ents.......................................................................................................................$ 0odifications and updates..........................................................................................................$ 1ntroduction......................................................................................................................................1 2'at is SQLite 3.........................................................................................................................1 2', use SQLite +it' OpenOffice.org3......................................................................................1 1nstalling t'e O45* 4river for SQLite...........................................................................................6 Under Linu7................................................................................................................................6 Under 2indo+s..........................................................................................................................) *reating a 4ata File.........................................................................................................................8 Using 9s:lite;..............................................................................................................................8 Using SQLite 4atabase 5ro+ser................................................................................................! *onfiguring O45*........................................................................................................................10 Under Linu7..............................................................................................................................10 Under 2indo+s........................................................................................................................11 *onfiguring t'e 4ata Source in OpenOffice.org...........................................................................1$ *reating 4atabase <ables in OpenOffice.org................................................................................16 Using a 4atabase +it' OpenOffice.org.........................................................................................1( /ccessing databases via 4ata Sources......................................................................................1( *reating Queries........................................................................................................................1) *reating For-s..........................................................................................................................18 &7c'anging databases bet+een users........................................................................................18 *redits ...........................................................................................................................................1! 1nde7..............................................................................................................................................$0 =ublic 4ocu-entation License> ?ersion 1.0..................................................................................$1

Using SQLite Database with OpenOffice.org

Overview

Overview
[@ive a general description of t'e scope and purpose of t'e docu-ent 'ere.]

Copyright and trademark information


<'e contents of t'is 4ocu-entation are subAect to t'e =ublic 4ocu-entation License> ?ersion 1.0 Bt'e CLicenseCDE ,ou -a, onl, use t'is 4ocu-entation if ,ou co-pl, +it' t'e ter-s of t'is License. / cop, of t'e License is available at 'ttp ""+++.openoffice.org"licenses"=4L.rtf <'e Original 4ocu-entation is 9Utilisation d'une base de donnes SQLite avec OpenOffice.org;. <'e 1nitial 2riterBsD of t'e Original 4ocu-entation is"are Yves Chaufour $00%. /ll Fig'ts Feserved. B1nitial 2riter contactBsD Gves *'aufour.D *ontributorBsD HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH. =ortions created b, @. Foderic. Singleton are *op,rig't B*DH$00% /ll Fig'ts Feserved. B*ontributor contactBsD @. Foderic. SingletonD. /ll trade-ar.s +it'in t'is guide belong to legiti-ate o+ners. [Iote a cop, of t'e =4L is included in t'is te-plate and is also available at 'ttp ""+++.openoffice.org"licenses"=4L.rtf.]

Feedback
=lease direct an, co--ents or suggestions about t'is docu-ent to grsingletonJopenoffic.org

Acknowledgments
Yves Chaufour for creating t'e original docu-ent.

Modifications and updates


Version
[1.0] [2.0]

Date
06/07/2004 09/12/2004

Description of Change
[grs: Initial translation issued for comment] [grs: Updated to include SDBC driver info and minor corrections]]

Using SQLite Database with OpenOffice.org

ii

Introduction

Introduction
<'e ai- of t'is guide is to 'elp OpenOffice.org users to ta.e advantage of t'e SQLite database engine as a data source.

What is S !ite "


SQLite B'ttp ""+++.s:lite.org"D is a basic database engine t'at i-ple-ents -ost of t'e features of SQL!$. Unli.e =ostgreSQL and 0,SQL> SQLite stores a +'ole data base +it' all its tables a single file. Ot'er benefits are database access re:uires no database server> database files can be freel, s'ared bet+een -ac'ines +it' different b,te orders and databases can be up to $ terab,tes B$K%1 b,tesD in siLe. =lus it is fast Bt+ice as -uc' as =ostgreSQL and 0,SQL for -ost operationsD and 'as a s-all -e-or, footprint. 4ata -anage-ent can be ac'ieved in t'e follo+ing +a,s 1. ?ia a *"*MM Linu7 librar, or 2indo+s 4LL. $. ?ia an inNline progra- Bs:lite available under Linu7 and 2indo+sD t'at -a.es it possible to create and to -anage t'e files of data bases. 6. ?ia t'e SQLite =O= -odule or> if ,ou 'ave> =O= version # internall, to a SQLite database. %. ?ia O45* BLinu7 and 2indo+sD +'ic' allo+s an, application supporting t'is standard to reac' a SQLite database. #. Using t'e e7peri-ental S45* SQLite driver fro'ttp ""dba.openoffice.org"drivers"s:lite"inde7.'t<'is guide addresses O45* +'ic' OpenOffice.org uses to attac' to databases and SQLite> in particular.

Why use S !ite with OpenOffice#org"


<'e use of SQLite 'as -an, advantages

<'e data base is in onl, one file> in contrast to d5/S& +'ic' creates a file per table> -a.ing it eas, to e7c'ange databases bet+een various users. Pava PF& or S4Q is not re:uired to support SQLite. Io server is needed Blocal or re-oteD to access a database. O45* drivers e7ist for RI1S and for 2indo+s> t'us enabling users of bot' environ-ents to access data and e7c'ange t'e-. / ne+ S45* driver Bnative to OpenOffice.orgD is available for e7peri-entation. BSee
1

Using SQLite Database with OpenOffice.org

Introduction

'ttp ""dba.openoffice.org"drivers"s:lite"inde7.'t-lD

Sop'isticated grap'ic interfaces > suc' as t'ose of -saccess> can be easil, developed using t'e for-s> :ueries> states and -acros of OpenOffice.org. <'ese interfaces are stored separatel, in OpenOffice separate and can also be e7c'anged bet+een users under RI1S or 2indo+s. 0odif,ing t'e structure of a SQLite table after its creation is not directl, possible. <'is -eans t'at ,ou cannot easil, add fields nor to -odif, t'eir properties once t'at t'e table is created. <'erefore ,ou -ust prepare t'e structure of ,our tables before creating t'e-. OpenOffice.org re:uires t'e use of t'e O45* driver for accessing a SQLite database t'us -a.ing t'is operation so-e+'at co-plicated. First it -ust be declared in O45* and t'en in OpenOffice.org. <'e native S45* driver s'ould correct t'is situation +'en it is production read,. <'e initial database file cannot be created +it' OpenOffice.org but b, using ot'er tools .

and so-e disadvantages

1n s'ort> t'e principal advantages of t'e use of SQLite +it' OpenOffice.org are t'e for-at of data storage and t'e portabilit, fro- one environ-ent to anot'er. 1n t'e list of disadvantages> t'e t+o last are not specific to SQLite> but are re:uire-ents of using O45*. Oo+ever> t'ese are not as a+.+ard as t'e, do not ta.e place during t'e initial creation of t'e database.
Note: SQLite appeals to anyone frustrated with using MDB files under Linux, or who has had difficulty installing MySQL or other RDBMS server on their workstation

Using SQLite Database with OpenOffice.org

Installing the ODBC Driver for SQLite

Installing the O$%C $river for S !ite


For OpenOffice.org to access a SQLlite database in production> it is reco--ened t'at ,ou install t'e O45* driver. O45* drivers for SQLite are independent of t'e SQLite proAect. Oo+ever ,ou can obtain a driver specificall, developed b, *'ristian 2erner Bc'+Jc'N+erner.deD for OpenOffice.org fro- 'is site B'ttp ""+++.c'N+erner.de"s:liteO45*"D. <'is O45* driver +raps t'e SQLite librar, and is available for Linu7 and 2indo+s Bfor ot'er RI1S> use t'e sourcesD.

&nder !inu'
1n order to be able to install t'e SQLite O45* driver> uni7O45* and SQLite -ust be installed first. &ni'O$%C ( Gou +ill find -ost of t'e needed pac.ages preNinstalled in t'e -aAorit, of Linu7 distributions. For 0andra.e> for e7a-ple> install t'e follo+ing rp- files
libunixODBC2-2.2.x-xmdk.i586.rpm libunixODBC2-devel-2.2.x-xmdk.i586.rpm libunixODBC2-qt-2.2.x-xmdk.i586.rpm unixODBC-2.2.x-xmdk.i586.rpm unixODBC-GUI-qt-2.2.x-xmdk.i586.rpm.

Warning: Check that your version of unixODBC is at least version 2.2.5. An older version ill cause O!enOffice.org to hang hen using the ODBC for "#$ite driver. %f your version is one of the older versions hich is the case for De&ian or 'andrake (.)* it ill &e necessary for you to do nload and install a +ore recent version of unixODBC. 1f ,ou do not find pac.ages t'at are sufficientl, recent in ,our distribution> do+nload fro'ttp ""+++.uni7odbc.org" and co-pile t'e sources. Caution: Co+!iling fro+ the sources does not install the gra!hic utility ODBCConfig. ,hus you ill have to +anually configure ODBC. S !ite ( 5efore starting> users of 0andra.e> FedOat and ot'er distributions using rp- distribution> s'ould c'ec. t'at t'e distribution does not currentl, 'ave t'e SQLite rp- alread, installed. Caution: "#$ite evolves very -uickly and the !ackages !resent in any $inux distri&ution often !rovide a version of "#$ite hich is dated* .for exa+!le 'andrake )/./ integrates "#$ite 2.0.12. At the ti+e of riting* the latest versions of the ODBC driver +ay include a +ore recent version of "#$ite .2.0.)3 for version /.1.2 of the driver24 ho ever* it is to &etter to get and install a
Using SQLite Database with OpenOffice.org 3

Installing the ODBC Driver for SQLite

+ore recent version than that in your distri&ution. %n theory* the "#$ite driver for ODBC can &e co+!iled ith "#$ite 2.0.1* &ut the using this version ill introduce so+e li+itations * such as no su!!ort auto5incre+ented fields. 1f t'ere is a :uestion of versioning> be careful and do+nload fro'ttp ""+++.s:lite.org"do+nload.'t-l and install pac.ages Csqlite-x.x.x-x.i386.rpmC and Csqlite-devel-x.x.x-x.i386.rpmC. <'is +ill also install t'e co--andline version of CsqliteC. Caution: 6or 'andrake .(.)* (.2 or )/./2 users* the installation of these r!+ ill issue arnings that 7libreadline.so.47 is +issing even though it is installed. ,his is &ecause the r!+ referred to a&ove does not look for this li&rary here 'andrake installs it. Check initially ith rpmdrake that the li&rary 7libreadline47 is installed .if not install it2* then install the r!+ sqlite fro+ the co++andline and force the no de!endencies check: # rpm -ivh sqlite-devel-2.8.x-x.i386.rpm nodeps # rpm -ivh sqlite-2.8.x-x.i386.rpm --nodeps 1f ,ou 'ave 4ebian or anot'er distribution t'at +ill not install t'e rp-> do+nload sqlitex.x.x.tar.gz fro- 'ttp ""+++.s:lite.org"do+nload.'t-l and co-pile t'e sources. s)liteO$%C ( Since t'ere are no preco-piled binar, pac.ages BF=0 or ot'erD of sqliteODBC> do+nload t'e source code fro- t'e aut'or's site B 'ttp ""+++.c'N+erner.de"s:liteO45*" D. 4o+nload a version at least e:ual to t'e 0.(.1> to avoid li-itations +it' OpenOffice.org. 1f ,ou 'ave do+nloaded t'e .tar.gz> unco-press and unpac. it using tar xvzf <filename>> +'ic' +ill create a director, sqliteODBC-0.6.x containing all t'e files. *'ange into t'is director, and t,pe t'e follo+ing co--ands for co-pilation and installation $ ./configure prefix=/usr $ make $ su # make install
Note: --prefix=/usr is optional, !ut is especially useful with Mandrake distri!utions, to install the driver in /usr/lib rather than in the default location, /usr/local/lib Note: "ertain dependences are necessary to the co#pilation of the driver $or exa#ple, if co#pilation fails !y saying that ltdl.h is not found, it will !e necessary for you to install the corresponding li!rary%develop#ent package &libltdl3-devel under Mandrake' !efore restarting the co#pilation process

<o co-plete installation> t'e driver s'ould be integrated into unixODBC. <o do t'is> launc' t'e ODBCC nfig utilit, as root in an open ter-inal +indo+ or 7ter- and t,pe +'at follo+s $ su
Using SQLite Database with OpenOffice.org 4

Installing the ODBC Driver for SQLite

# ODBCConfig <'is co--and brings up t'e follo+ing +indo+

*lic. t'e CDriversC tab and c'oose C!dd...C. <'en fill t'e fields in t'e propert, +indo+ e7actl, as on t'e follo+ing grap'ic

<'en confir- using t'e icon on t'e left in top of t'e +indo+. Gour ne+ driver +ill no+ appear in t'e CDriversC tab

Using SQLite Database with OpenOffice.org

Installing the ODBC Driver for SQLite

<'e driver installation under Linu7 is no+ finis'ed and ,ou can e7it ODBCC nfig.
Note: $or those who do not have ODBCConfig or who prefer to carry out this configuration #anually, it is necessary to edit the file (/etc/odbcinst.ini ( as root and add the following lines: )SQLite* Description Driver Setup $ile.sage "01i#eout "0Reuse + ,DB" for SQLite + %usr%li!%li!s-lite,DB" so + %usr%li!%li!s-lite,DB" so +/ + +

1f ,ou are co-fortable co-piling> t'e eas, +a, is to get t'e source rp- of sqliteODBC fro- 'ttp ""+++.c'N+erner.de"s:liteO45*". Once ,ou 'ave t'e srp-> it is eas, to create a rp- for ,our distribution b, t,ping t'e follo+ing instruction # rpmbuild --rebuild sqliteODBC-0.60-1.src.rpm Gou no+ s'ould 'ave a preNco-piled binar, rp- read, for installation t'at> according to t'e aut'or> selfNconfigures t'e driver in O45* t'us avoiding t'e above -anual procedures.

Using SQLite Database with OpenOffice.org

Installing the ODBC Driver for SQLite

&nder Windows
Under 2indo+s installation and configuration is easier. Si-pl, do+nload t'e file sqliteODBC.exe and e7ecute it. <'e driver installs auto-aticall, and is also configured auto-aticall, in O45*. Gou +ill be able to c'ec. it b, launc'ing Cdata " ur#e ODBCC fro- t'e control panel

Note: 2 second, experi#ental driver is installed &.tf34' !ut you are cautioned to only use standard driver

Using SQLite Database with OpenOffice.org

Creating a Data File

Creating a $ata File


/n initial database file cannot be created directl, in OpenOffice.org but> rat'er> t'is is acco-plis'ed b, using eit'er t'e utilit, 9sqlite; on t'e co--and line> or b, using t'e tool sqlite$r %ser +'ic' is grap'ic> ver, si-ple and available for bot' Linu7 and for 2indo+s. 1f ,ou +is' to use sqlite$r %ser> ,ou +ill find it as t'e t'ird entr, in t'e list at 'ttp ""+++.s:lite.org"cvstrac"+i.i3pTS:lite<ools> <'e utilit, CsqliteC s'ould be alread, installed if ,ou use Linu7 and 'ave installed SQLite fro- rp-. For ot'er RI1S s,ste-s> ,ou -ust build SQLite fro- source +'ic' ,ou can find at 'ttp ""+++.s:lite.org"do+nload.'t-l . =erfor-ance and usage under Linu7 and 2indo+s is identical.

&sing *s)lite+
Open a ter-inal +indo+ or 7ter- and c'ange to t'e director, +'ere ,ou +ant to create ,our database and t'en enter t'e follo+ing instructions $ sqlite <name of the database> SQLite version 2.8.12 Enter ".help" for instructions sqlite> .database sqlite> .exit Gou can t'en c'ec. t'at t'e file +as> indeed> created in ,our files,ste-. <'e na-e of t'e file does not re:uire a file e7tension> but ,ou can give it t'e e7tension Cd$C so t'at is eas, to locate as a database. Using CsqliteC on t'e co--and line progra- also -a.es it possible to create tables and indices> to enter and post data> and to -a.e :ueries providing ,ou .no+ t'e SQL language E 'o+ever> it is -ore practical for beginners to carr, out t'ese operations using OpenOffice.org.

Using SQLite Database with OpenOffice.org

Creating a Data File

&sing S !ite $atabase %rowser


/fter unpac.ing t'e file> launc' sqlite$r %ser and select C&ile'(e% Data$aseC or t'e corresponding icon

*'oose t'e director, in +'ic' to place file and t'en enter na-e of t'e database file and clic. on C"aveC. Using t'is progra-> ,ou can also create t'e tables> t'e fields and t'e indices> to access data and to visualiLe t'e-. 2'ile sqlite$r %s%er is suitable for t'ese actions> t'ere is t'e disadvantage t'at it does not s'o+ t'e full list of field t,pes during field creation. 1n t'is case> it -a, be preferable to do it later using OpenOffice.org.

Using SQLite Database with OpenOffice.org

Configuring ODBC

Configuring O$%C
<'is step de-onstrates 'o+ to define ,our ne+ database in O45* and to set t'at t'e driver to be used s'ould be ")*ite so t'at OpenOffice.org can access it. <'is operation 'as to be repeated for eac' ne+ ")*ite database t'at -ust be accessed t'roug' O45*.

&nder !inu'
Launc' CODBCC nfigC> go in t'e tab C+ser D"(C and c'oose C!dd...C. / +indo+ appears t'en in +'ic' ,ou -ust c'oose t'e ")*ite driver. 1n t'e ne7t +indo+> as s'o+n belo+> ,ou enter a na-e for t'is connection Bfor e7a-ple t'e na-e of ,our databaseD and enter t'e co-plete access pat' to t'e file +'ic' ,ou created previousl,.

?alidate t'e data on t'e screen> clic. and ,ou s'ould see ,our ne+ data source in t'e tab C+ser D"(C. Caution: %f in the !lace of this indo you o&tain an error +essage .7Could not construct has !ro!erty list for ."#$ite272* your version of the driver is too old. %nstall version /.1.)* or higher* hich corrects this &ug. 1f ,ou do not 'ave ODBCC nfig or si-pl, prefer to configure -anuall,> launc' ,our favorite editor> open Bor createD t'e file C d$#.iniC in ,our 'o-e director,> and add t'e follo+ing lines to it [My Base] Description Driver Database Timeout = SQLite = /home/<user>/basename.db = 1000 = My test database

Using SQLite Database with OpenOffice.org

1!

Configuring ODBC

StepAPI

= No

Note: 5f this data source #ust !y other users on the syste#, launch ODBCConfig as root and add this source in the ta! (Syste DS!( or (data Source syste#(, or create a (/etc/odbc.ini( file

Gou are no+ read, to access ,our data base +it' OpenOffice.orgU

&nder Windows
Open Cdata " ur#e ODBCC and go to t'e tab C" ur#e data userC. *'oose C< add...C and start b, selecting t'e driver C")*ite ODBC DriverC. 1n t'e follo+ing +indo+> enter t'e na-e of t'is data source BData " ur#e (ame D and t'e co-plete access pat' to ,our data file BData$ase (ameD> or select it b, using t'e CBr %se...C. button ?alidate t'e data and e7it O45*. Iot'ing -ore is needed and ,ou -a, launc' OpenOffice.org and be able to reac' ,our databaseU

Using SQLite Database with OpenOffice.org

11

Configuring the Data Source in OpenOffice.org

Configuring the $ata Source in OpenOffice#org


Io+ ,ou can finall, start using OpenOffice.org +it' SQLite. 1n order to -a.e use of ,our ne+ SQLite database and to add tables> it is necessar, to configure t'e Cdata s ur#eC. <o do t'is> use t'e -enu ,ools 8 Data "ources.... 1n t'e +indo+ s'o+n belo+> clic. on C(e% data s ur#eC

1n t'e (ame field> replace Bi$li grap,- +it' t'e na-e of ,our data source. 1n Data$ase t-pe> select ODBC. For Data s ur#e +.*> select t'e button +it' t'e t'ree dots Bon t'e rig'tN'and side of t'e fieldD. <'is opens a +indo+ in +'ic' ,ou see all t'e data sources alread, declared in O45*. *'oose t'at +'ic' ,ou created in t'e preceding c'apter.

?oilV> ,our SQLite database is no+ accessible fro- OpenOffice.orgU Io+ clic. on !ppl- +it'out leaving t'is +indo+> so t'at +e can create t'e tables and t'e fields of t'e database as described in t'e ne7t section.

Using SQLite Database with OpenOffice.org

12

Creating Database Tables in OpenOffice.org

Creating $atabase ,ables in OpenOffice#org


1n t'e +indo+> Data " ur#e !dministrati n> go in t'e tab /a$les. <o create ,our first table> select (e% icon in /a$le Designer to get a +indo+ in +'ic' create t'e fields for t'e ne+ table

1. &nter t'e na-e of t'e ne+ field in t'e &ield (ame colu-n. $. Select its field t,pe fro- t'e dropNdo+n list. 6. 1n t'e &ield 0r perties Lone> set t'e *engt, as necessar,> default value of t'is field and c'oose t'e for-at. %. Fepeat steps 1N6 for all fields . Caution: ,he creation of a !ri+ary key on a field ty!e of integer is availa&le only ith version /.1.)* or later* of s-liteODBC driver. 9ri+ary keys are useful in assuring that O!enOffice.org can add records to your ta&le*. %n a ta&le* the first field is often a uni-ue identifier .id2 that can &e defined as the !ri+ary key. :::;ight click on the heading of line of this field ill reveal a contextual +enu in hich it is necessary to select key !ri+ary education7. 6ields defined as ty!e 7integer7* auto+atically incre+ent the value of the field
Using SQLite Database with OpenOffice.org 13

Creating Database Tables in OpenOffice.org

at the addition of each ne record in this ta&le . Once ,ou 'ave created all ,our fields> c'ec.ed t'at all is good and selected ,our pri-ar, .e,> save ,our ne+ table b, clic.ing on t'e icon representing a dis.ette B3D and enter t'e na-e of ,our table Caution: Once you have saved your ta&le* you cannot +odify it< %.e. you ill not &e a&le to +odify the !ro!erties of the fields any +ore* nor add or re+ove < <'is rat'er a+.+ard constraint is specific to SQLite> +'ic' does not 'andle t'e SQL co--and !*/1. CO+(/"> and not t'e O45* driver. <'is li-itation is designed in b, t'e aut'ors in order to -a.e t'e basic database engine as lig't as possible. Oo+ever> t'is li-itation -a, be eli-inated in a future version. <'erefore ,ou are advised to c'ec. ,our table structure ver, carefull, before recording it. 1f ,ou -ust -odif, a table> t'e onl, solution is to create a ne+ table and save it under different na-e. 5, doing do> ,ou can transfer t'e data fro- t'e original table to t'e ne+ table. Once a table is created> ,ou can create an inde7 to speed up :ueries and sorting on large volu-es of data. <o do t'is> select ,our table fro- t'e tab C/a$lesC in t'e Data " ur#e !dministrati n +indo+ and clic. on t'e icon C<o publis' t'e tableC. Gou are again in t'e +indo+ +'ic' posts t'e fields of ,our table. Select t'e fourt' icon t'en COutlines inde7...C and ,ou +ill obtain t'e follo+ing +indo+ 3333

*lic. on t'e first icon CIe+ inde7C and enter a na-e for t'is inde7. 1n t'e colu-n C2ndex &ield>C c'oose t'e fieldBsD to be inde7ed> t'e order of sorting> and c'ec. t'e C"ingleC bo7. Save t'is b, clic.ing on t'e fourt' icon C/ re# rd t,e a#tive indexC. Caution: When saving the index* you +ay see an error +essage* 7Error connecting to the data source7. ,o check if the +essage is valid* exit
Using SQLite Database with OpenOffice.org 14

Creating Database Tables in OpenOffice.org

the index indo then the ta&le indo . ;e5o!en the index indo * and check that your index is created in s!ite of the error= You +ay find that it is &ut that the 7Single7 &ox is no longer checked. ,his is a kno n inco+!ati&ility &et een the s-liteODBC driver and the ay in hich O!enOffice.org dis!atches a create index ith ODBC< ,his !ro&le+ has &een identified and a !atch already !ro!osed that should a!!ear in the next version of O!enOffice.org. Where you a&solutely +ust create an index* use 7sqlite7 or 7sqlitebrowser7 hich do so ith no !ro&le+s. Io+ ,our database structure is created and ,ou can use OpenOffice.org to connect> add data et cetera.

Using SQLite Database with OpenOffice.org

15

sing a Database with OpenOffice.org

&sing a $atabase with OpenOffice#org


<'is c'apter is not specific to SQLite databases but its purpose is to succinctl, present t'e various e7isting possibilities and 'o+ t', relates to t'e li-itations and possibilities of SQLite.

Accessing databases via $ata Sources


<'e si-plest -et'od to access ,our databases in OpenOffice.org is to open 4ata Sources dialogue using t'e icon on t'e 0ain toolbar +'ic' is t'e vertical bar on t'e left in 2riter and *alc.

Gou can find t'e na-e of ,our database> na-ed as ,ou declared it in OpenOffice.org> in t'e left part of t'e panel b, traversing t'e tree structure +'ile clic.ing on C3C. Gou +ill find a 'eading C/a$lesC fro- +'ic' ,ou can select ,our table and 'ave t'e contents displa,ed in t'e panel to t'e rig't. 1n t'is panel> ,ou +ill be able to -odif, eac' record directl, in t'e table> or to create ne+ records b, adding t'e- in t'e line +it' t'e C4C s,-bol.
Note: 5f the first field of your ta!le is of type (integer( and you defined it as the pri#ary key , it will contain (6 auto-incre ent 7( provided you have not selected the co#plete line &i e 8ou pressed ("nter(after each field' 1his #eans that this field will take the value of the preceding record9s auto3incre#ent field plus /
Using SQLite Database with OpenOffice.org 16

sing a Database with OpenOffice.org

Caution: ,his feature of auto5incre+enting !ri+ary keys ith ty!e 7integer7 is not !ossi&le unless you use a version of the s-liteODBC driver that is* at least* version /.1./ or higher.

Creating

ueries

*reating :ueries can also be done t'roug' t'e data sources panel. <o post t'e 'eading C)ueriesC of ,our base in t'e panel of rig'tN'and side and clic. above +it' t'e rig't button of t'e -ouse. 1n t'e conte7tual -enu> c'oose C(e% )uer- 5Design 6ie%7C and ,ou +ill open a ne+ +indo+

Gou -ust start b, selecting all t'e tables> t'at are to be included in ,our :uer,> b, c'oosing t'e- fro- t'e list t'en +'ile clic.ing C!ddC. <'en ,ou can create connections b, dragging one field of a table on to t'e corresponding field in t'e ot'er table. <o define ,our :uer,> select t'e fields +'ic' are to be part of t'e :uer, and drag t'e- to t'e table located in t'e lo+er part of t'e +indo+> oneNatNaNti-e. For eac' field added to t'e :uer,> t'is table +ill enable ,ou to c'oose t'e order of sorting> grouping> criteria> et cetera. <'e various icons +ill t'en enable ,ou to post t'e result of ,our :uer,> to save it> publis' it in
Using SQLite Database with OpenOffice.org 17

sing a Database with OpenOffice.org

-ode SQL... Fe-e-ber creating :ueries offers so -an, possibilities t'at it is not possible to detail t'e'ereE 'o+ever> a good guide to using SQL s'ould 'elp. Caution: ,he !ossi&ility of adding several ta&les during creation of a -uery on a "#$ite data&ase* and thus of -uerying +ulti5ta&les* is not !ossi&le ith s-liteODBC driver* version /.1./.

Creating Forms
*reating for-s +it' 2riter or *alc is a ver, po+erful feature of OpenOffice.org t'at -a.es it possible to create a true grap'ic presentation fro- ,our data base. For- features and applications are so nu-erous t'at it is not possible to describe t'e- in t'is docu-ent. Oo+ever> ,ou +ill find infor-ation on 'o+ to -a.e for-s in OpenOffice.org Oelp and on 'ttp ""docu-entation.openoffice.org". 5, creating subfor-s ,our options are -ultiplied tenfold. Caution: ,o create su&for+s in for+s* it is necessary to use 7na+ed !ara+eters 7 in order to esta&lish the link &et een the various ta&les. 6or this you ill have to use a +acro hose installation and use are descri&ed in the follo ing docu+ent: htt!:==d&a.o!enoffice.org=ho to=!ara+>su&st.ht+l.

-'changing databases between users


<'an.s to t'e availabilit, of driver s:liteO45* driver for bot' Linu7 and 2indo+s BAust as for OpenOffice.org> of courseUD> a SQLite database SQLite can be easil, e7c'anged bet+een users of t'e t+o environ-ents. 1t is necessar,> of course> t'at eac' 'as an installed O45* driver t'at is a+are of t'e target SQLite file and +'ic' is defined as a data source in OpenOffice.org. Li.e+ise> 2riter and *alc files Bs7+ and s7cD containing for-s and -acros can also be e7c'anged bet+een users of t'e t+o environ-ents. Caution: %f for+s are to function correctly for each user* it is a&solutely necessary that each user a!!lies exactly the sa+e na+e to the data source during its creation.

Using SQLite Database with OpenOffice.org

18

Credits

Credits
Original /ut'or Yves Chaufour &nglis' <ranslation /ut'or ?. ;oderick "ingleton <'an.s to *'ristian 2erner> t'e aut'or of driver O45* for SQLite t'e S45* driver. <on, @al-ic'e and Serge Louarne +'o tested t'e use of a SQLite base ='ilippe Lefevre for 'is tests and its second reading.

Using SQLite Database with OpenOffice.org

Inde!

Inde'

Using SQLite Database with OpenOffice.org

2!

"ublic Docu#entation License$ %ersion &.'

.ublic $ocumentation !icense/ 0ersion 1#2


1.0 DEFINITIONS. 1.1. "Commercial Use" means distribution or otherwise making the Documentation available to a third party. 1.2. "Contributor" means a person or entity who creates or contributes to the creation of Modifications. 1.3. "Documentation" means the Original Documentation or Modifications or the combination of the Original Documentation and Modifications, in each case including portions thereof. 1.4. "Electronic Distribution Mechanism" means a mechanism generally accepted for the electronic transfer of data. 1.5. "Initial Writer" means the individual or entity identified as the Initial Writer in the notice required by the Appendix. 1.6. "Larger Work" means a work which combines Documentation or portions thereof with documentation or other writings not governed by the terms of this License. 1.7. "License" means this document. 1.8. "Modifications" means any addition to or deletion from the substance or structure of either the Original Documentation or any previous Modifications, such as a translation, abridgment, condensation, or any other form in which the Original Documentation or previous Modifications may be recast, transformed or adapted. A work consisting of editorial revisions, annotations, elaborations, and other modifications which, as a whole represent an original work of authorship, is a Modification. For example, when Documentation is released as a series of documents, a Modification is: A. Any addition to or deletion from the contents of the Original Documentation or previous Modifications. B. Any new documentation that contains any part of the Original Documentation or previous Modifications. 1.9. "Original Documentation" means documentation described as Original Documentation in the notice required by the Appendix, and which, at the time of its release under this License is not already Documentation governed by this License. 1.10. "Editable Form" means the preferred form of the Documentation for making Modifications to it. The Documentation can be in an electronic, compressed or archival form, provided the appropriate decompression or de-archiving software is widely available for no charge. 1.11. "You" (or "Your") means an individual or a legal entity exercising rights under, and complying with all of the terms of this License or a future version of this License issued under Section 5.0 ("Versions of the License"). For legal entities, "You" includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. 2.0 LICENSE GRANTS. 2.1 Initial Writer Grant. The Initial Writer hereby grants You a world-wide, royaltyfree, non-exclusive license to use, reproduce, prepare Modifications of, compile, publicly perform, publicly display, demonstrate, market, disclose and distribute the Documentation in any form, on any media or via any Electronic Distribution Mechanism or other method now known or later discovered, and to sublicense the foregoing rights to third parties through multiple tiers of sublicensees in accordance with the terms of this License. The license rights granted in this Section 2.1 ("Initial Writer Grant") are effective on the date Initial Writer first distributes Original Documentation under the terms of this License. 2.2. Contributor Grant. Each Contributor hereby grants You a world-wide, royaltyfree, non-exclusive license to use, reproduce, prepare Modifications of, compile, publicly perform, publicly display, demonstrate, market, disclose and distribute the Documentation in any form, on any media or via any Electronic Distribution Mechanism or other method now known or later discovered, and to sublicense the foregoing rights to third parties through multiple tiers of sublicensees in accordance with the terms of this License. The license rights granted in this Section 2.2 ("Contributor Grant") are effective on the date Contributor first makes Commercial Use of the Documentation. 3.0 DISTRIBUTION OBLIGATIONS. 3.1. Application of License. The Modifications which You create or to which You contribute are governed by the terms of this License, including without limitation Section 2.2 ("Contributor Grant"). The Documentation may be distributed only under the terms of this License or a future version of this License released in accordance with Section 5.0 ("Versions of the License"), and You must include a copy of this License with every copy of the Documentation You distribute. You may not offer or impose any terms that alter or restrict the applicable version of this License or the recipients' rights hereunder. However, You may include an additional document offering the additional rights described in Section 3.5 ("Required Notices"). 3.2. Availability of Documentation. Any Modification which You create or to which You contribute must be made available publicly in Editable Form under the terms of this License via a fixed medium or an accepted Electronic Distribution Mechanism. 3.3. Description of Modifications. All Documentation to which You contribute must identify the changes You made to create that Documentation and the date

Using SQLite Database with OpenOffice.org

21

"ublic Docu#entation License$ %ersion &.'


of any change. You must include a prominent statement that the Modification is derived, directly or indirectly, from Original Documentation provided by the Initial Writer and include the name of the Initial Writer in the Documentation or via an electronic link that describes the origin or ownership of the Documentation. The foregoing change documentation may be created by using an electronic program that automatically tracks changes to the Documentation, and such changes must be available publicly for at least five years following release of the changed Documentation. 3.4. Intellectual Property Matters. Contributor represents that Contributor believes that Contributor's Modifications are Contributor's original creation (s) and/or Contributor has sufficient rights to grant the rights conveyed by this License. 3.5. Required Notices. You must duplicate the notice in the Appendix in each file of the Documentation. If it is not possible to put such notice in a particular Documentation file due to its structure, then You must include such notice in a location (such as a relevant directory) where a reader would be likely to look for such a notice, for example, via a hyperlink in each file of the Documentation that takes the reader to a page that describes the origin and ownership of the Documentation. If You created one or more Modification(s) You may add your name as a Contributor to the notice described in the Appendix. You must also duplicate this License in any Documentation file (or with a hyperlink in each file of the Documentation) where You describe recipients' rights or ownership rights. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Documentation. However, You may do so only on Your own behalf, and not on behalf of the Initial Writer or any Contributor. You must make it absolutely clear than any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Writer and every Contributor for any liability incurred by the Initial Writer or such Contributor as a result of warranty, support, indemnity or liability terms You offer. 3.6. Larger Works. You may create a Larger Work by combining Documentation with other documents not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Documentation. 4.0 APPLICATION OF THIS LICENSE. This License applies to Documentation to which the Initial Writer has attached this License and the notice in the Appendix. 5.0 VERSIONS OF THE LICENSE. 5.1. New Versions. Initial Writer may publish revised and/or new versions of the License from time to time. Each version will be given a distinguishing version number. 5.2. Effect of New Versions. Once Documentation has been published under a particular version of the License, You may always continue to use it under the terms of that version. You may also choose to use such Documentation under the terms of any subsequent version of the License published by______________________ [Insert name of the foundation, company, Initial Writer, or whoever may modify this License]. No one other than ________________________[Insert name of the foundation, company, Initial Writer, or whoever may modify this License] has the right to modify the terms of this License. Filling in the name of the Initial Writer, Original Documentation or Contributor in the notice described in the Appendix shall not be deemed to be Modifications of this License. 6.0 DISCLAIMER OF WARRANTY. DOCUMENTATION IS PROVIDED UNDER THIS LICENSE ON AN "AS IS'' BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE DOCUMENTATION IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY, ACCURACY, AND PERFORMANCE OF THE DOCUMENTATION IS WITH YOU. SHOULD ANY DOCUMENTATION PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL WRITER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY DOCUMENTATION IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. 7.0 TERMINATION. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. All sublicenses to the Documentation which are properly granted shall survive any termination of this License. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive. 8.0 LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER IN TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE INITIAL WRITER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF DOCUMENTATION, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER DAMAGES OR LOSSES ARISING OUT OF OR RELATING TO THE USE OF THE DOCUMENTATION, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. 9.0 U.S. GOVERNMENT END USERS.

Using SQLite Database with OpenOffice.org

22

"ublic Docu#entation License$ %ersion &.'


If Documentation is being acquired by or on behalf of the U.S. Government or by a U.S. Government prime contractor or subcontractor (at any tier), then the Government's rights in Documentation will be only as set forth in this Agreement; this is in accordance with 48 CFR 227.7201 through 227.7202-4 (for Department of Defense (DOD) acquisitions) and with 48 CFR 2.101 and 12.212 (for non-DOD acquisitions). 10.0 MISCELLANEOUS. This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by California law, excluding its conflict-of-law provisions. With respect to disputes or any litigation relating to this License, the losing party is responsible for costs, including without limitation, court costs and reasonable attorneys' fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. Appendix Public Documentation License Notice The contents of this Documentation are subject to the Public Documentation License Version 1.0 (the "License"); you may only use this Documentation if you comply with the terms of this License. A copy of the License is available at http://www.openoffice.org/licenses/PDL.rtf. The Original Documentation is _________________. The Initial Writer of the Original Documentation is ______________________ (C) ____. All Rights Reserved. (Initial Writer contact(s):_______________[Insert hyperlink/alias].) Contributor(s): ______________________________________. Portions created by ______ are Copyright (C)_________[Insert year(s)]. All Rights Reserved. (Contributor contact(s): ________________[Insert hyperlink/alias]). Note: The text of this Appendix may differ slightly from the text of the notices in the files of the Original Documentation. You should use the text of this Appendix rather than the text found in the Original Documentation for Your Modifications.

Using SQLite Database with OpenOffice.org

23

También podría gustarte