File: Tdbc_Init.3

package info (click to toggle)
tdbc 1.1.13-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 948 kB
  • sloc: sh: 2,258; tcl: 1,486; ansic: 978; makefile: 77
file content (168 lines) | stat: -rw-r--r-- 4,573 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
'\"
'\" Copyright (c) 2009 by Kevin B. Kenny.
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
.TH Tdbc_Init 3 8.6 Tcl "Tcl Database Connectivity"
'\" .so man.macros
'\" IGNORE
.if t .wh -1.3i ^B
.nr ^l \n(.l
.ad b
.de AP
.ie !"\\$4"" .TP \\$4
.el \{\
.   ie !"\\$2"" .TP \\n()Cu
.   el          .TP 15
.\}
.ta \\n()Au \\n()Bu
.ie !"\\$3"" \{\
\&\\$1 \\fI\\$2\\fP (\\$3)
.\".b
.\}
.el \{\
.br
.ie !"\\$2"" \{\
\&\\$1	\\fI\\$2\\fP
.\}
.el \{\
\&\\fI\\$1\\fP
.\}
.\}
..
.\"	# define tabbing values for .AP
.de AS
.nr )A 10n
.if !"\\$1"" .nr )A \\w'\\$1'u+3n
.nr )B \\n()Au+15n
.\"
.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
.nr )C \\n()Bu+\\w'(in/out)'u+2n
..
.AS Tcl_Interp Tcl_CreateInterp in/out
.\"	# BS - start boxed text
.\"	# ^y = starting y location
.\"	# ^b = 1
.de BS
.br
.mk ^y
.nr ^b 1u
.if n .nf
.if n .ti 0
.if n \l'\\n(.lu\(ul'
.if n .fi
..
.\"	# BE - end boxed text (draw box now)
.de BE
.nf
.ti 0
.mk ^t
.ie n \l'\\n(^lu\(ul'
.el \{\
.\"	Draw four-sided box normally, but don't draw top of
.\"	box if the box started on an earlier page.
.ie !\\n(^b-1 \{\
\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.el \}\
\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.\}
.fi
.br
.nr ^b 0
..
.\"	# CS - begin code excerpt
.de CS
.RS
.nf
.ta .25i .5i .75i 1i
..
.\"	# CE - end code excerpt
.de CE
.fi
.RE
..
'\" END IGNORE
.BS
.SH "NAME"
Tdbc_Init, Tdbc_MapSqlState, Tdbc_TokenizeSql \- C procedures to facilitate writing TDBC drivers
.SH SYNOPSIS
.nf
\fB#include <tdbc.h>\fR

int
\fBTdbc_Init\fR(\fIinterp\fR)

Tcl_Obj *
\fBTdbc_TokenizeSql\fR(\fIinterp, sqlcode\fR)

const char *
\fBTdbc_MapSqlState\fR(\fIstate\fR)
.fi
.SH ARGUMENTS
.AS "Tcl_Interp" statement in/out
.AP Tcl_Interp *interp in/out
Pointer to a Tcl interpreter.
.AP "const char" *state in
Pointer to a character string containing a 'SQL state' from a database error.
.AP "const char" *sqlcode in
Pointer to a character string containing a SQL statement.
.BE

.SH DESCRIPTION
.PP
The TDBC library provides several C procedures that simplify writing a TDBC
driver. They include a procedure that tokenizes a SQL statement, locating
variables to be substituted, and a procedure that accepts a SQL state and
returns an error class for the interpreter error information.
.PP
\fBTdbc_Init\fR must be invoked prior to any other TDBC call.  It accepts
a pointer to a Tcl interpreter, and arranges to load the TDBC library. It
returns \fBTCL_OK\fR if the Tcl library was loaded successfully, and
\fBTCL_ERROR\fR otherwise. If \fBTCL_ERROR\fR is returned, the
interpreter's result contains the error message.
.PP
\fBTdbc_TokenizeSql\fR accepts a pointer to a Tcl interpreter, and a
pointer to a character string containing one or more SQL
statements. It tokenizes the SQL statements, and returns a pointer to
a Tcl_Obj that contains a list of the tokens that make up the
statement. Concatenating the tokens together will yield the original
SQL code. The returned Tcl_Obj has a reference count of zero. The
caller is responsible for managing the reference count as needed.
See \fBTOKENS\fR below for a description of what may be in the
returned list of tokens.
.PP
\fBTdbc_MapSqlState\fR accepts a pointer to a string, usually five
characters long, that is the 'SQL state' that resulted from a database
error. It returns a character string that is suitable for inclusion as
the error class when constructing the error code for an error in a
TDBC driver. (By convention, the error code is a list having at least
four elements: "\fBTDBC\fR \fIerrorClass\fR \fIsqlstate\fR
\fIdriverName\fR \fIdetails...\fR".)
.SH TOKENS
Each token returned from \fBTdbc_TokenizeSql\fR may be one of the
following:
.IP [1]
A bound variable, which begins with one of the
characters '\fB:\fR', '\fB@\fR', or '\fB$\fR'. The
remainder of the string is the variable
name and will consist of alphanumeric characters and underscores. (The
leading character will be be non-numeric.)
.IP [2]
A semicolon that separates two SQL statements.
.IP [3]
Something else in a SQL statement. The tokenizer does not attempt to
parse SQL; it merely identifies bound variables (distinguishing them
from similar strings appearing inside quotes or comments) and
statement delimiters.
.SH "SEE ALSO"
tdbc(n), tdbc::mapSqlState(n), tdbc::tokenize(n)
.SH "KEYWORDS"
TDBC, SQL, database, tokenize
.SH "COPYRIGHT"
Copyright (c) 2009 by Kevin B. Kenny.
.\" Local Variables:
.\" mode: nroff
.\" End:
.\"