Documentos de Académico
Documentos de Profesional
Documentos de Cultura
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
Overview
Overview
[@ive a general description of t'e scope and purpose of t'e docu-ent 'ere.]
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.
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]]
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.
<'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
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 .
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
&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
+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
*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
<'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.
&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
&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.
*'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.
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
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
11
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.
12
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
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
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.
15
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
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
-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.
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.
Inde!
Inde'
2!
21
22
23