Charles.Forsyth20060303-partialeea662d19 years agoHistory
266 lines · 5.9 KB · Text
RawDownload
.TH ODBC 10.4.SH NAMEODBC \- A Windows ODBC file server.SH SYNOPSIS.B odbc.exe[.B -d] [.BI -p " port"].SH DESCRIPTION.I Odbcis a file server that runs under Windows andexports a Styx namespace(see.IR intro (5)).An Inferno process that mounts the namespacecan use it to manipulate Windows ODBC databases..PPThe.B -doption causes.I odbcto print debugging information..PPThe.B -poption gives the port number to listen on for connections. The default is 6700..SS Name space.I Odbcpresents the following name space:.PP.nf.BI /nclients.BI /db.BI /db/new.BI /db/ n.BI /db/ n /cmd.BI /db/ n /ctl.BI /db/ n /data.BI /db/ n /error.BI /db/ n /format.BI /db/ n /sources.BI /db/ n /status.fi.PPThe top level read-only file.B nclientscontains the current number of active clients on the server..PPThe top level.B dbdirectory contains a.B newfile and subdirectories numbered.B nfrom zero to the maximum number ofconfigured conversations..PPOpening the.B newfile reserves a conversation, representedby one of the numbered directories. The resulting file descriptor will be openon the control file,.BR ctl ,of the newly allocated conversation.Reading the.B ctlfile returns a text string representing thenumber of the conversation.A conversation is used to converse with the server - in ODBC termsit is equivalent to obtaining a connection handle. This is the level atwhich ODBC transactions are managed..PPA conversation is controlled by writing text strings to theassociated.B ctlfile. ODBC commands may be sent to theserver by writing them, as text strings, to the.B cmdfile.For commands that return a record set, the results may be readfrom the.B datafile; each read returning a single record.If a command results in an error, the write to the.B cmdfilewill fail. The full ODBC error message can be obtained by readingthe.B errorfile.A conversation remains open while at least one of the.BR ctl ,.B cmdor.B datafiles remains open..PPThe following commands can be written to the.B ctlfile:.TP.B  connect " datasource" " [user!auth]"Connect to the ODBC datasource using the username and authentication, if given..TP.B disconnectDisconnect from the datasource..TP.B fixedReads from the.B datafile will return data in a fixed format. The format canbe read from the.B formatfile after writing the command to the.B cmdfile and before reading the data from the.B datafile..TP.B float " [fs< [rs<]]"Reads from the data file will return data using the character.B fsto separate fields and the character.B rsto separate records.The default values for.B fs and .B rsare the pipe symbol '|'and the newline character..TP.B trans " begin"Enter ODBC manual-commit mode for transactions. A transaction willnot complete until one of.B trans commitor.B trans rollbackis written to the.B ctlfile..TP.B trans " auto"Enter ODBC auto-commit mode for transactions (the default).Each database statement is wrapped by a transaction that is automaticallycommited when the statement is executed..TP.B trans " commit"Commit a transaction when in manual-commit mode..TP.B trans " rollback"Rollback a transation when in manual-commit mode..PPOnce a conversation has been established and transaction mode andoutput formats determined the.B cmdfile isused to send ODBC commands to the server.The following commands can be written to the.B cmdfile:.TP.B tablesThe result of calling the ODBC API function SQLTables is returnedin the.B datafile..TP.B columns " tablename"The result of calling the ODBC API function SQLColumns with thegiven.B tablenameas a parameter is returned in the.B datafile..TP.B any " ODBC" " command"Any ODBC command written to the.B cmdfile is passedto the ODBC API function SQLExecDirect. This most commonly includesselect, update, insert, and deletecommands..PPThe.B formatfile is used to determine column names and how to extractindividual columns from the record read from the.B datafile when usingfixed format output. A read of it givesa single record read returning one linefor each column in the result data. Each line has three components separatedby a single space: a number giving the character position of the start of the fieldin the result data, a number giving the character position one beyond theend of the field in the result data, and the field name..PPThe result of database enquiries can be read from the.B datafile.After writing a command that returns data to the.B cmdfile,reads from the.B datafile will return the results one record at a time.When the last record has been read the following read will return zerobytes indicating the end of the data..PPThe read-only file.B sourcesgives a newline separated list of sources. Each line consistsof the source name and the source type separated by a colon..PPThe read-only file.B statusreturn the status of the current conversation..SH EXAMPLEFor example, the Inferno shell can be used to retrievevalues from a database. The shell commands:.PP.EXmount -A tcp!localhost!6700 /n/remote{	d=/n/remote/db/`{cat}	echo -n 'float' > $d/ctl	echo -n 'connect cellar' > $d/ctl	echo -n 'select name from wine' > $d/cmd	cat $d/data} < /n/remote/db/new.EE.PPproduces the output:.PP.EXChardonnayJo. RieslingFume BlancWh. BurgundyGewurztraminerCab. SauvignonPinot NoirZinfandelGamay.EE.PPHere the server has been started on the local machine, listening on port6700 for network connections.The braced block and the redirection from.B /n/remote/db/newreserve a conversation with the server and ensures that it remains openfor the duration of the execution of the set of commands within the block.The.B -Aoption to mount is used because this server can notauthenticate a connection..SH SOURCE.B /tools/odbc/odbc.c.SH SEE ALSO.IR bind (1),.IR sys-bind (2),.IR intro (5),.IR db (7),.IR dbsrv (7),.IR svc (8)