Making ODBC easier By Dave Doulton University of Southampton.
-
Upload
juniper-hamilton -
Category
Documents
-
view
221 -
download
1
Transcript of Making ODBC easier By Dave Doulton University of Southampton.
![Page 1: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/1.jpg)
Making ODBC easier
By
Dave Doulton
University of Southampton
![Page 2: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/2.jpg)
Agenda
• Introduction
• Setting up ODBC sources
• ODBC import
• ODBC pql
• ODBC members
• Conclusion
![Page 3: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/3.jpg)
Introduction
• ODBC Open DataBase Connectivity
• This session will show you how to set up ODBC sources and use them from SIR.
• It will show the simplest way to go about this with PQL members available from SUG website.
![Page 4: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/4.jpg)
Setting up ODBC sources
• ODBC sources are set up using Data Sources from the Administrative Tools Menu
• Sources can be User, available to that user only or System, available to all users both are configured in exactly the same way but from different tabs
![Page 5: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/5.jpg)
![Page 6: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/6.jpg)
![Page 7: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/7.jpg)
Setting up ODBC sources
• I shall show the steps in setting up some System DSNs
• I have previously set them all up as User DSNs for use in the demonstrations
• Click add on the screen shown prior to this
![Page 8: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/8.jpg)
![Page 9: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/9.jpg)
Setting up ODBC sources
• Choose the source and click Finish.
• You will then get a configuration screen which will vary according to the source.
• The next screens will show various different types
![Page 10: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/10.jpg)
SIR
![Page 11: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/11.jpg)
SIR different server
![Page 12: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/12.jpg)
CSV
![Page 13: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/13.jpg)
CSV options
![Page 14: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/14.jpg)
CSV Define Format
![Page 15: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/15.jpg)
Excel with options
![Page 16: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/16.jpg)
Access with options
![Page 17: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/17.jpg)
Access advanced options
![Page 18: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/18.jpg)
FoxPro with options
![Page 19: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/19.jpg)
dBase with options
![Page 20: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/20.jpg)
Paradox with options
![Page 21: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/21.jpg)
Oracle
![Page 22: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/22.jpg)
All defined
![Page 23: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/23.jpg)
ODBC import
• Data can be imported into a SIR database from an ODBC source very easily especially into a caseless database as there is no Case Id to worry about.
• Create a caseless database in this case TESTODBC and choose import records from the database menu
![Page 24: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/24.jpg)
![Page 25: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/25.jpg)
Choose ODBC and choose data source
![Page 26: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/26.jpg)
Select Source
![Page 27: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/27.jpg)
This gives
![Page 28: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/28.jpg)
Clicking Next gives:- note sheet name with a $ and a range
![Page 29: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/29.jpg)
Clicking Next gives
![Page 30: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/30.jpg)
Change record name and choose roword as sortid. This gives each row a new number
![Page 31: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/31.jpg)
Clicking OK creates record and imports.
![Page 32: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/32.jpg)
ODBC import
• This is fine if you want all the data in a database.
• But I find that I want to read a data file select some data from that file and then do something with it without storing it in another database. E.g. for running procedures on an Oracle database.
• In these cases PQL is the answer.
![Page 33: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/33.jpg)
ODBC pql
• The ODBC import is based on a set of pql statements.
• These seem a bit daunting at first.
• See the next screens for details.
![Page 34: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/34.jpg)
Connect and Disconnect
• CONNECT conid SERVER name {DATABASE name | TABFILE name} [USER name] [PASSWORD name] [PREFIX name] [UPDATE | READ] [ERROR errid]
• DISCONNECT conid [ERROR name]
![Page 35: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/35.jpg)
Statement, Prepare Bind Execute and Delete• STATEMENT statid CONNECT conid [ERROR name]
• PREPARE STATEMENT statid CONNECT conid {COMMAND text_expression | BUFFER buffer_name} [ERROR name]
• BIND STATEMENT statid CONNECT conid (param_no,value)
• EXECUTE STATEMENT statid CONNECT conid [ERROR name]
• DELETE STATEMENT statid CONNECT conid [ERROR name]
![Page 36: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/36.jpg)
An Example
See the bottom of the help on ODBC at
file:///C:/Program%20Files/SIR2002/help/visualpql_odbc.htm
Something easier would clearly be nice.
![Page 37: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/37.jpg)
ODBC members
• I have created a simple set of members that can be put in the sysproc ODBC family and make life a lot easier.
• It includes a simple template member as shown on the next screen
![Page 38: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/38.jpg)
Template
• program• call sysproc.odbc.header• compute srce=''• compute user=''• compute pwd=''• call sysproc.odbc.connect• compute qtext=''• call sysproc.odbc.loop ($C $)• write cname(1) 5e• write fields(1) 5e• call sysproc.odbc.endloop ($C $)• call sysproc.odbc.disconn• call sysproc.odbc.tail• end program
![Page 39: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/39.jpg)
The template filled in
• program• call sysproc.odbc.header• compute srce='1 CSV'• compute user='dcd'• compute pwd='dcd'• call sysproc.odbc.connect• compute qtext='select * from employee.csv'• call sysproc.odbc.loop ($C $)• write cname(1) 5e• write fields(1) 5e• call sysproc.odbc.endloop ($C $)• call sysproc.odbc.disconn• call sysproc.odbc.tail• end program
![Page 40: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/40.jpg)
A more complicated example
• program• DEFINE PROCEDURE VARIABLES ARRAYS• string ofns• call sysproc.odbc.header• execute subroutine sysproc.menu.odbclist returning(srce)
• display textbox "Enter output filename" response ok,ofns• if(ok <=0) exit program• if(srst(ofns,".csv")=0)compute ofns=ofns+'.csv'
• display textbox "Enter username" response ok,user• if(ok <=0) exit program• display textbox "Enter password" secret response ok,pwd• if(ok <=0) exit program
• call sysproc.ODBC.CONNECT• display textbox "Enter query" response ok,qtext• if(ok <=0) exit program
• call sysproc.odbc.loop | ($C $)• perform procs• call sysproc.odbc.endloop• call sysproc.odbc.disconn• call sysproc.odbc.tail• report filename=consol/sort=rnum
![Page 41: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/41.jpg)
before reportstring*4000 outlineopen ofn/dsnvar=ofns/write/lrecl=4000compute outline=""for k=1,cnumcompute outline=outline+'"'+trim(cname(k))+'"'if(k<cnum)compute outline=outline+','end forwrite(ofn)outlinebreak level 1, rnumdetail blockcompute outline=""for k=1,cnumifthen(exists(fields(k)))compute outline=outline+'"'+trim(fields(k))+'"'elsecompute outline=outline+'" "'endifif(k <cnum)compute outline=outline+','end forwrite(ofn) outlineend break levelafter reportclose ofnpql escape ['"c:\windows\system32\cmd" /c "start '+ofns+'" '] wait 0 minimize 1end reportend program
![Page 42: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/42.jpg)
An update example
• program• call sysproc.odbc.header• compute srce=''• compute user=''• compute pwd='‘• Compute utext=‘’• call sysproc.odbc.connect• call sysproc..odbc.update• call sysproc.odbc.disconn• call sysproc.odbc.tail• end program
![Page 43: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/43.jpg)
Update filled in
• program• call sysproc.odbc.header• compute srce=‘3 Access'• compute user=‘dcd'• compute pwd=‘dcd‘• Compute utext=‘update employee set ndepends=4’• call sysproc.odbc.connect• call sysproc..odbc.update• call sysproc.odbc.disconn• call sysproc.odbc.tail• end program
![Page 44: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/44.jpg)
Web access
• With slight alterations these can be used via the web as well.
• See the following example.
![Page 45: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/45.jpg)
programDEFINE PROCEDURE VARIABLES ARRAYSstring ofnscall sysproc.odbc.headercompute srce=cgivarpn("srce")compute user=cgivarpn("user")compute pwd=cgivarpn("pwd")call sysproc.ODBC.CONNECTcompute qtext=cgivarpn("qtext")call sysproc.odbc.loop ($C $)perform procscall sysproc.odbc.endloop ($C $)call sysproc.odbc.disconncall sysproc.odbc.tailreport filename=consol/sort=rnum
![Page 46: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/46.jpg)
before reportstring*4000 outlinewrite(cgi)['<h2 >Output from '+srce+'</h2>']write(cgi)['<h3 >Using query '+qtext+'</h3>']compute outline="<table border=><tr >"for k=1,cnumcompute outline=outline+'<th >'+trim(cname(k))+'</th>'end forcompute outline=outline+'</tr>'write(cgi)outlinebreak level 1, rnumdetail blockcompute outline="<tr >"for k=1,cnumifthen(exists(fields(k)))compute outline=outline+'<td >'+trim(fields(k))+'</td>'elsecompute outline=outline+'<td > </td>'endifend forcompute outline=outline+'</tr>'write(cgi) outlineat end blockend break levelafter reportwrite(cgi)'</table>'end reportend program
![Page 47: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/47.jpg)
Notes
• When using sources that can have different file extensions then use the extension in the tablename for select.
• In Excel use the sheet name with a $ or a named range
• In SIR the password can be all 4 passwords separated by commas
• i.e. userpass,company,high,high userpass can be anything but is needed always
![Page 48: Making ODBC easier By Dave Doulton University of Southampton.](https://reader030.fdocuments.net/reader030/viewer/2022020800/56649e355503460f94b23ff8/html5/thumbnails/48.jpg)
Conclusion
• I hope you will all have a try of these routines to speed up your access to other data.
• I know it has speeded up my development work no end.