tdbc_odbc.n 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. '\"
  2. .\" tdbc_odbc.n --
  3. .\"
  4. .\" Copyright (c) 2008 by Kevin B. Kenny.
  5. .\"
  6. .\" See the file "license.terms" for information on usage and redistribution of
  7. .\" this file, and for a DISCLAIMER OF ALL WARRANTIES.
  8. .TH "tdbc::odbc" n 8.6 Tcl "Tcl Database Connectivity"
  9. .\" .so man.macros
  10. .if t .wh -1.3i ^B
  11. .nr ^l \n(.l
  12. .ad b
  13. .\" # BS - start boxed text
  14. .\" # ^y = starting y location
  15. .\" # ^b = 1
  16. .de BS
  17. .br
  18. .mk ^y
  19. .nr ^b 1u
  20. .if n .nf
  21. .if n .ti 0
  22. .if n \l'\\n(.lu\(ul'
  23. .if n .fi
  24. ..
  25. .\" # BE - end boxed text (draw box now)
  26. .de BE
  27. .nf
  28. .ti 0
  29. .mk ^t
  30. .ie n \l'\\n(^lu\(ul'
  31. .el \{\
  32. .\" Draw four-sided box normally, but don't draw top of
  33. .\" box if the box started on an earlier page.
  34. .ie !\\n(^b-1 \{\
  35. \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  36. .\}
  37. .el \}\
  38. \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  39. .\}
  40. .\}
  41. .fi
  42. .br
  43. .nr ^b 0
  44. ..
  45. .\" # CS - begin code excerpt
  46. .de CS
  47. .RS
  48. .nf
  49. .ta .25i .5i .75i 1i
  50. ..
  51. .\" # CE - end code excerpt
  52. .de CE
  53. .fi
  54. .RE
  55. ..
  56. .BS
  57. .SH "NAME"
  58. tdbc::odbc \- TDBC-ODBC bridge
  59. .SH "SYNOPSIS"
  60. package require \fBtdbc::odbc 1.0\fR
  61. .sp
  62. \fBtdbc::odbc::connection create\fR \fIdb\fR \fIconnectionString\fR ?\fI-option value...\fR?
  63. .br
  64. \fBtdbc::odbc::connection new\fR \fIconnectionString\fR ?\fI-option value...\fR?
  65. .sp
  66. \fBtdbc::odbc::datasources\fR ?\fB-system\fR|\fB-user\fR?
  67. .sp
  68. \fBtdbc::odbc::drivers\fR
  69. .sp
  70. \fBtdbc::odbc::datasource\fR \fIcommand\fR \fIdriverName\fR ?\fIkeyword\fR-\fIvalue\fR?...
  71. .BE
  72. .SH "DESCRIPTION"
  73. .PP
  74. The \fBtdbc::odbc\fR driver provides a database interface that conforms
  75. to Tcl DataBase Connectivity (TDBC) and allows a Tcl script to connect
  76. to any SQL database presenting an ODBC interface. It is also provided
  77. as a worked example of how to write a database driver in C, so that
  78. driver authors have a starting point for further development.
  79. .PP
  80. Connection to an ODBC database is established by invoking
  81. \fBtdbc::odbc::connection create\fR, passing it the name to be used
  82. as a connection handle, followed by a standard ODBC
  83. connection string. As an alternative, \fBtdbc::odbc::connection new\fR
  84. may be used to create
  85. a database connection with an automatically assigned name. The return value
  86. from \fBtdbc::odbc::connection new\fR is the name that was chosen for the
  87. connection handle.
  88. .PP
  89. The connection string will include at least a
  90. \fBDRIVER\fR or \fBDSN\fR keyword, and may include others that are defined by a
  91. particular ODBC driver. (If the local ODBC system supports a graphical
  92. user interface, the \fB-parent\fR option (see below) may allow calling
  93. \fBtdbc::odbc::connection create\fR with an empty connection string.)
  94. .PP
  95. The side effect of \fBtdbc::odbc::connection create\fR is to create a
  96. new database connection.. See \fBtdbc::connection(n)\fR for the
  97. details of how to use the connection to manipulate a database.
  98. .PP
  99. In addition to a standard TDBC interface, \fBtdbc::odbc\fR supports
  100. three additional ccommands. The first of these,
  101. \fBtdbc::odbc::datasources\fR, which returns a Tcl
  102. list enumerating the named data sources available to the program (for
  103. connection with the \fBDSN\fR keyword in the connection string).
  104. The result of \fBtdbc::odbc::datasources\fR may be constrained to only
  105. system data sources or only user data sources by including the
  106. \fB-system\fR or \fB-user\fR options, respectively.
  107. .PP
  108. The \fBtdbc::odbc::drivers\fR command returns a dictionary whose keys
  109. are the names of drivers available for the \fBDRIVER\fR keyword in the
  110. connection string, and whose values are descriptions of the drivers.
  111. .PP
  112. The \fBtdbc::odbc::datasource\fR command allows configuration of named
  113. data sources on those systems that support the ODBC Installer
  114. application programming interface. It accepts a \fIcommand\fR, which
  115. specifies the operation to be performed, the name of a \fIdriver\fR
  116. for the database in question, and a set of keyword-value pairs that
  117. are interpreted by the given driver. The \fIcommand\fR must be one of
  118. the following:
  119. .IP \fBadd\fR
  120. Adds a user data source. The keyword-value pairs must include
  121. at least a \fBDSN\fR option naming the data source
  122. .IP \fBadd_system\fR
  123. Adds a system data source. The keyword-value pairs must include
  124. at least a \fBDSN\fR option naming the data source
  125. .IP \fBconfigure\fR
  126. Configures a user data source. The keyword-value pairs will usually
  127. include a \fBDSN\fR option naming the data source. Some drivers will
  128. support other options, such as the \fBCREATE_DB\fR option to the
  129. Microsoft Access driver on Windows.
  130. .IP \fBconfigure_system\fR
  131. Configures a system data source.
  132. .IP \fBremove\fR
  133. Removes a user data source. The keyword-value pairs must include a
  134. \fBDSN\fR option specifying the data source to remove.
  135. .IP \fBremove_system\fR
  136. Removes a system data source. The keyword-value pairs must include a
  137. \fBDSN\fR option specifying the data source to remove.
  138. .SH "CONNECTION OPTIONS"
  139. .PP
  140. The \fBtdbc::odbc::connection create\fR object command supports the
  141. \fB-encoding\fR, \fB-isolation\fR, \fB-readonly\fR and \fB-timeout\fR
  142. options common to all TDBC drivers. The \fB-encoding\fR option will
  143. succeed only if the requested encoding is the same as the system
  144. encoding; \fBtdbc::odbc\fR does not attempt to specify alternative
  145. encodings to an ODBC driver. (Some drivers accept encoding
  146. specifications in the connection string.)
  147. .PP
  148. In addition, if Tk is present in the requesting interpreter,
  149. and the local system's ODBC driver manager supports a graphical user
  150. interface, the \fBtdbc::odbc::connection create\fR object command
  151. supports a \fB-parent\fR option, whose value is the path name of
  152. a Tk window. If this option is specified, and a connection string does
  153. not specify all the information needed to connect to an interface, the
  154. ODBC driver manager will display a dialog box to request whatever
  155. additional information is required. The requesting interpreter will
  156. block until the user dismisses the dialog, at which point the
  157. connection is made.
  158. .SH EXAMPLES
  159. .PP
  160. Sincs ODBC connection strings are driver specific, it is often
  161. difficult to find the documentation needed to compose them. The
  162. following examples are known to work on most Windows systems and
  163. provide at least a few useful things that a program can do.
  164. .PP
  165. .CS
  166. tdbc::odbc::connection create db \\
  167. "DSN={PAYROLL};UID={aladdin};PWD={Sesame}"
  168. .CE
  169. Connects to a named data source "PAYROLL", providing "aladdin" as a
  170. user name and "Sesame" as a password. Uses \fBdb\fR as the name of the
  171. connection.
  172. .PP
  173. .CS
  174. set connString {DRIVER={Microsoft Access Driver (*.mdb)};}
  175. append connString {FIL={MS Access}\\;}
  176. append connString {DBQ=} \\
  177. [file nativename [file normalize $fileName]]
  178. tdbc::odbc::connection create db2 -readonly 1 $connString
  179. .CE
  180. Opens a connection to a Microsoft Access database file whose
  181. name is in \fI$fileName\fR. The database is opened in read-only
  182. mode. The resulting connection is called "db2".
  183. .PP
  184. .CS
  185. tdbc::odbc::connection create db3 \\
  186. "DRIVER=SQLite3;DATABASE=$fileName"
  187. .CE
  188. Opens a connection to a SQLite3 database whose name is in "$fileName".
  189. .PP
  190. .CS
  191. tdbc::odbc::datasource add \\
  192. {Microsoft Access Driver (*.mdb)} \\
  193. DSN=MyTestDatabase \\
  194. DBQ=[file native [file normalize $fileName]]
  195. .CE
  196. Creates a new user data source with the name, "MyTestDatabase" bound
  197. to a Microsoft Access file whose path name is in "$fileName". No
  198. connection is made to the data source until the program calls
  199. \fBtdbc::odbc::connection create\fR.
  200. .PP
  201. .CS
  202. tdbc::odbc::datasource configure \\
  203. {Microsoft Access Driver (*.mdb)} \\
  204. CREATE_DB=[file native [file normalize $fileName]] \\
  205. General
  206. .CE
  207. Creates a new, empty Microsoft Access database in the file identified
  208. by "$fileName". No connection is made to the database until the
  209. program calls \fBtdbc::odbc::connection create\fR.
  210. .SH "ADDITIONAL CONNECTION METHODS"
  211. In addition to the usual methods on the tdbc::connection(n) object,
  212. connections to an ODBC database support one additional method:
  213. .IP \fI$connection\fR \fBevaldirect\fR \fIsqlStatement\fR
  214. This method takes the given driver-native SQL code \fIsqlStatement\fR and
  215. evaluates it without preparing it. The statement is not tokenized and must
  216. not contain variable substitutions. Evaluating the \fIsqlStatement\fR
  217. produces a result set of zero or more rows. The result of the command is a
  218. list of dictionaries, with one list element per row in the result set (in
  219. a similar format to the list returned by \fI$connection allrows -as dicts\fR).
  220. \fIThis command is not recommended\fR for anything where the usual
  221. \fIprepare\fR or \fIpreparecall\fR methods work correctly. It is
  222. provided so that data management language statements that are not
  223. implemented by the driver's prepared statement API (such as \fBCREATE
  224. DATABASE\fR or \fBCREATE PROCEDURE\fR), or that contain characters that
  225. are reserved by the tokenizer, can be executed.
  226. .SH "SEE ALSO"
  227. tdbc(n), tdbc::connection(n), tdbc::resultset(n), tdbc::statement(n)
  228. .SH "KEYWORDS"
  229. TDBC, SQL, ODBC, database, connectivity, connection
  230. .SH "COPYRIGHT"
  231. Copyright (c) 2008 by Kevin B. Kenny.
  232. .\" Local Variables:
  233. .\" mode: nroff
  234. .\" End:
  235. .\"