2 '\" Copyright (c) 2009 by Kevin B. Kenny.
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 .TH Tdbc_Init 3 8.6 Tcl "Tcl Database Connectivity"
15 . ie !"\\$2"" .TP \\n()Cu
20 \&\\$1 \\fI\\$2\\fP (\\$3)
33 .\" # define tabbing values for .AP
36 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
39 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
40 .nr )C \\n()Bu+\\w'(in/out)'u+2n
42 .AS Tcl_Interp Tcl_CreateInterp in/out
43 .\" # BS - start boxed text
44 .\" # ^y = starting y location
55 .\" # BE - end boxed text (draw box now)
62 .\" Draw four-sided box normally, but don't draw top of
63 .\" box if the box started on an earlier page.
65 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
68 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
75 .\" # CS - begin code excerpt
81 .\" # CE - end code excerpt
89 Tdbc_Init, Tdbc_MapSqlState, Tdbc_TokenizeSql \- C procedures to facilitate writing TDBC drivers
92 \fB#include <tdbc.h>\fR
95 \fBTdbc_Init\fR(\fIinterp\fR)
98 \fBTdbc_TokenizeSql\fR(\fIinterp, sqlcode\fR)
101 \fBTdbc_MapSqlState\fR(\fIstate\fR)
104 .AS "Tcl_Interp" statement in/out
105 .AP Tcl_Interp *interp in/out
106 Pointer to a Tcl interpreter.
107 .AP "const char" *state in
108 Pointer to a character string containing a 'SQL state' from a database error.
109 .AP "const char" *sqlcode in
110 Pointer to a character string containing a SQL statement.
115 The TDBC library provides several C procedures that simplify writing a TDBC
116 driver. They include a procedure that tokenizes a SQL statement, locating
117 variables to be substituted, and a procedure that accepts a SQL state and
118 returns an error class for the interpreter error information.
120 \fBTdbc_Init\fR must be invoked prior to any other TDBC call. It accepts
121 a pointer to a Tcl interpreter, and arranges to load the TDBC library. It
122 returns \fBTCL_OK\fR if the Tcl library was loaded successfully, and
123 \fBTCL_ERROR\fR otherwise. If \fBTCL_ERROR\fR is returned, the
124 interpreter's result contains the error message.
126 \fBTdbc_TokenizeSql\fR accepts a pointer to a Tcl interpreter, and a
127 pointer to a character string containing one or more SQL
128 statements. It tokenizes the SQL statements, and returns a pointer to
129 a Tcl_Obj that contains a list of the tokens that make up the
130 statement. Concatenating the tokens together will yield the original
131 SQL code. The returned Tcl_Obj has a reference count of zero. The
132 caller is responsible for managing the reference count as needed.
133 See \fBTOKENS\fR below for a description of what may be in the
134 returned list of tokens.
136 \fBTdbc_MapSqlState\fR accepts a pointer to a string, usually five
137 characters long, that is the 'SQL state' that resulted from a database
138 error. It returns a character string that is suitable for inclusion as
139 the error class when constructing the error code for an error in a
140 TDBC driver. (By convention, the error code is a list having at least
141 four elements: "\fBTDBC\fR \fIerrorClass\fR \fIsqlstate\fR
142 \fIdriverName\fR \fIdetails...\fR".)
144 Each token returned from \fBTdbc_TokenizeSql\fR may be one of the
147 A bound variable, which begins with one of the
148 characters '\fB:\fR', '\fB@\fR', or '\fB$\fR'. The
149 remainder of the string is the variable
150 name and will consist of alphanumeric characters and underscores. (The
151 leading character will be be non-numeric.)
153 A semicolon that separates two SQL statements.
155 Something else in a SQL statement. The tokenizer does not attempt to
156 parse SQL; it merely identifies bound variables (distinguishing them
157 from similar strings appearing inside quotes or comments) and
158 statement delimiters.
160 tdbc(n), tdbc::mapSqlState(n), tdbc::tokenize(n)
162 TDBC, SQL, database, tokenize
164 Copyright (c) 2009 by Kevin B. Kenny.