add padding function to imgScalePadding()

This commit is contained in:
ton
2023-04-14 03:23:43 +00:00
parent c43d949309
commit 39b417dd94
15256 changed files with 525519 additions and 1048290 deletions

View File

@@ -1,14 +0,0 @@
# Index file to load the TDBC ODBC package.
if {![package vsatisfies [package provide Tcl] 8.6-]} {
return
}
if {[package vsatisfies [package provide Tcl] 9.0-]} {
package ifneeded tdbc::odbc 1.1.3 \
"[list source [file join $dir tdbcodbc.tcl]]\;\
[list load [file join $dir tcl9tdbcodbc113t.dll] [string totitle tdbcodbc]]"
} else {
package ifneeded tdbc::odbc 1.1.3 \
"[list source [file join $dir tdbcodbc.tcl]]\;\
[list load [file join $dir tdbcodbc113t.dll] [string totitle tdbcodbc]]"
}

View File

@@ -1,219 +0,0 @@
'\"
.\" tdbc_odbc.n --
.\"
.\" Copyright (c) 2008 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::odbc" n 8.6 Tcl "Tcl Database Connectivity"
.\" .so man.macros
.if t .wh -1.3i ^B
.nr ^l \n(.l
.ad b
.\" # 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
..
.BS
.SH "NAME"
tdbc::odbc \- TDBC-ODBC bridge
.SH "SYNOPSIS"
package require \fBtdbc::odbc 1.0\fR
.sp
\fBtdbc::odbc::connection create\fR \fIdb\fR \fIconnectionString\fR ?\fI-option value...\fR?
.br
\fBtdbc::odbc::connection new\fR \fIconnectionString\fR ?\fI-option value...\fR?
.sp
\fBtdbc::odbc::datasources\fR ?\fB-system\fR|\fB-user\fR?
.sp
\fBtdbc::odbc::drivers\fR
.sp
\fBtdbc::odbc::datasource\fR \fIcommand\fR \fIdriverName\fR ?\fIkeyword\fR-\fIvalue\fR?...
.BE
.SH "DESCRIPTION"
.PP
The \fBtdbc::odbc\fR driver provides a database interface that conforms
to Tcl DataBase Connectivity (TDBC) and allows a Tcl script to connect
to any SQL database presenting an ODBC interface. It is also provided
as a worked example of how to write a database driver in C, so that
driver authors have a starting point for further development.
.PP
Connection to an ODBC database is established by invoking
\fBtdbc::odbc::connection create\fR, passing it the name to be used
as a connection handle, followed by a standard ODBC
connection string. As an alternative, \fBtdbc::odbc::connection new\fR
may be used to create
a database connection with an automatically assigned name. The return value
from \fBtdbc::odbc::connection new\fR is the name that was chosen for the
connection handle.
.PP
The connection string will include at least a
\fBDRIVER\fR or \fBDSN\fR keyword, and may include others that are defined by a
particular ODBC driver. (If the local ODBC system supports a graphical
user interface, the \fB-parent\fR option (see below) may allow calling
\fBtdbc::odbc::connection create\fR with an empty connection string.)
.PP
The side effect of \fBtdbc::odbc::connection create\fR is to create a
new database connection.. See \fBtdbc::connection(n)\fR for the
details of how to use the connection to manipulate a database.
.PP
In addition to a standard TDBC interface, \fBtdbc::odbc\fR supports
three additional ccommands. The first of these,
\fBtdbc::odbc::datasources\fR, which returns a Tcl
list enumerating the named data sources available to the program (for
connection with the \fBDSN\fR keyword in the connection string).
The result of \fBtdbc::odbc::datasources\fR may be constrained to only
system data sources or only user data sources by including the
\fB-system\fR or \fB-user\fR options, respectively.
.PP
The \fBtdbc::odbc::drivers\fR command returns a dictionary whose keys
are the names of drivers available for the \fBDRIVER\fR keyword in the
connection string, and whose values are descriptions of the drivers.
.PP
The \fBtdbc::odbc::datasource\fR command allows configuration of named
data sources on those systems that support the ODBC Installer
application programming interface. It accepts a \fIcommand\fR, which
specifies the operation to be performed, the name of a \fIdriver\fR
for the database in question, and a set of keyword-value pairs that
are interpreted by the given driver. The \fIcommand\fR must be one of
the following:
.IP \fBadd\fR
Adds a user data source. The keyword-value pairs must include
at least a \fBDSN\fR option naming the data source
.IP \fBadd_system\fR
Adds a system data source. The keyword-value pairs must include
at least a \fBDSN\fR option naming the data source
.IP \fBconfigure\fR
Configures a user data source. The keyword-value pairs will usually
include a \fBDSN\fR option naming the data source. Some drivers will
support other options, such as the \fBCREATE_DB\fR option to the
Microsoft Access driver on Windows.
.IP \fBconfigure_system\fR
Configures a system data source.
.IP \fBremove\fR
Removes a user data source. The keyword-value pairs must include a
\fBDSN\fR option specifying the data source to remove.
.IP \fBremove_system\fR
Removes a system data source. The keyword-value pairs must include a
\fBDSN\fR option specifying the data source to remove.
.SH "CONNECTION OPTIONS"
.PP
The \fBtdbc::odbc::connection create\fR object command supports the
\fB-encoding\fR, \fB-isolation\fR, \fB-readonly\fR and \fB-timeout\fR
options common to all TDBC drivers. The \fB-encoding\fR option will
succeed only if the requested encoding is the same as the system
encoding; \fBtdbc::odbc\fR does not attempt to specify alternative
encodings to an ODBC driver. (Some drivers accept encoding
specifications in the connection string.)
.PP
In addition, if Tk is present in the requesting interpreter,
and the local system's ODBC driver manager supports a graphical user
interface, the \fBtdbc::odbc::connection create\fR object command
supports a \fB-parent\fR option, whose value is the path name of
a Tk window. If this option is specified, and a connection string does
not specify all the information needed to connect to an interface, the
ODBC driver manager will display a dialog box to request whatever
additional information is required. The requesting interpreter will
block until the user dismisses the dialog, at which point the
connection is made.
.SH EXAMPLES
.PP
Sincs ODBC connection strings are driver specific, it is often
difficult to find the documentation needed to compose them. The
following examples are known to work on most Windows systems and
provide at least a few useful things that a program can do.
.PP
.CS
tdbc::odbc::connection create db \\
"DSN={PAYROLL};UID={aladdin};PWD={Sesame}"
.CE
Connects to a named data source "PAYROLL", providing "aladdin" as a
user name and "Sesame" as a password. Uses \fBdb\fR as the name of the
connection.
.PP
.CS
set connString {DRIVER={Microsoft Access Driver (*.mdb)};}
append connString {FIL={MS Access}\\;}
append connString {DBQ=} \\
[file nativename [file normalize $fileName]]
tdbc::odbc::connection create db2 -readonly 1 $connString
.CE
Opens a connection to a Microsoft Access database file whose
name is in \fI$fileName\fR. The database is opened in read-only
mode. The resulting connection is called "db2".
.PP
.CS
tdbc::odbc::connection create db3 \\
"DRIVER=SQLite3;DATABASE=$fileName"
.CE
Opens a connection to a SQLite3 database whose name is in "$fileName".
.PP
.CS
tdbc::odbc::datasource add \\
{Microsoft Access Driver (*.mdb)} \\
DSN=MyTestDatabase \\
DBQ=[file native [file normalize $fileName]]
.CE
Creates a new user data source with the name, "MyTestDatabase" bound
to a Microsoft Access file whose path name is in "$fileName". No
connection is made to the data source until the program calls
\fBtdbc::odbc::connection create\fR.
.PP
.CS
tdbc::odbc::datasource configure \\
{Microsoft Access Driver (*.mdb)} \\
CREATE_DB=[file native [file normalize $fileName]] \\
General
.CE
Creates a new, empty Microsoft Access database in the file identified
by "$fileName". No connection is made to the database until the
program calls \fBtdbc::odbc::connection create\fR.
.SH "SEE ALSO"
tdbc(n), tdbc::connection(n), tdbc::resultset(n), tdbc::statement(n)
.SH "KEYWORDS"
TDBC, SQL, ODBC, database, connectivity, connection
.SH "COPYRIGHT"
Copyright (c) 2008 by Kevin B. Kenny.
.\" Local Variables:
.\" mode: nroff
.\" End:
.\"

View File

@@ -1,515 +0,0 @@
# tdbcodbc.tcl --
#
# Class definitions and Tcl-level methods for the tdbc::odbc bridge.
#
# Copyright (c) 2008 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.
#
# RCS: @(#) $Id: tdbcodbc.tcl,v 1.47 2008/02/27 02:08:27 kennykb Exp $
#
#------------------------------------------------------------------------------
package require tdbc
::namespace eval ::tdbc::odbc {
namespace export connection datasources drivers
# Data types that are predefined in ODBC
variable sqltypes [dict create \
1 char \
2 numeric \
3 decimal \
4 integer \
5 smallint \
6 float \
7 real \
8 double \
9 datetime \
12 varchar \
91 date \
92 time \
93 timestamp \
-1 longvarchar \
-2 binary \
-3 varbinary \
-4 longvarbinary \
-5 bigint \
-6 tinyint \
-7 bit \
-8 wchar \
-9 wvarchar \
-10 wlongvarchar \
-11 guid]
}
#------------------------------------------------------------------------------
#
# tdbc::odbc::connection --
#
# Class representing a connection to a database through ODBC.
#
#-------------------------------------------------------------------------------
::oo::class create ::tdbc::odbc::connection {
superclass ::tdbc::connection
variable statementSeq typemap
# The constructor is written in C. It takes the connection string
# as its argument It sets up a namespace to hold the statements
# associated with the connection, and then delegates to the 'init'
# method (written in C) to do the actual work of attaching to the
# database. When that comes back, it sets up a statement to query
# the support types, makes a dictionary to enumerate them, and
# calls back to set a flag if WVARCHAR is seen (If WVARCHAR is
# seen, the database supports Unicode.)
# The 'statementCreate' method forwards to the constructor of the
# statement class
forward statementCreate ::tdbc::odbc::statement create
# The 'tables' method returns a dictionary describing the tables
# in the database
method tables {{pattern %}} {
set stmt [::tdbc::odbc::tablesStatement create \
Stmt::[incr statementSeq] [self] $pattern]
set status [catch {
set retval {}
$stmt foreach -as dicts row {
if {[dict exists $row TABLE_NAME]} {
dict set retval [dict get $row TABLE_NAME] $row
}
}
set retval
} result options]
catch {rename $stmt {}}
return -level 0 -options $options $result
}
# The 'columns' method returns a dictionary describing the tables
# in the database
method columns {table {pattern %}} {
# Make sure that the type map is initialized
my typemap
# Query the columns from the database
set stmt [::tdbc::odbc::columnsStatement create \
Stmt::[incr statementSeq] [self] $table $pattern]
set status [catch {
set retval {}
$stmt foreach -as dicts origrow {
# Map the type, precision, scale and nullable indicators
# to tdbc's notation
set row {}
dict for {key value} $origrow {
dict set row [string tolower $key] $value
}
if {[dict exists $row column_name]} {
if {[dict exists $typemap \
[dict get $row data_type]]} {
dict set row type \
[dict get $typemap \
[dict get $row data_type]]
} else {
dict set row type [dict get $row type_name]
}
if {[dict exists $row column_size]} {
dict set row precision \
[dict get $row column_size]
}
if {[dict exists $row decimal_digits]} {
dict set row scale \
[dict get $row decimal_digits]
}
if {![dict exists $row nullable]} {
dict set row nullable \
[expr {!![string trim [dict get $row is_nullable]]}]
}
dict set retval [dict get $row column_name] $row
}
}
set retval
} result options]
catch {rename $stmt {}}
return -level 0 -options $options $result
}
# The 'primarykeys' method returns a dictionary describing the primary
# keys of a table
method primarykeys {tableName} {
set stmt [::tdbc::odbc::primarykeysStatement create \
Stmt::[incr statementSeq] [self] $tableName]
set status [catch {
set retval {}
$stmt foreach -as dicts row {
foreach {odbcKey tdbcKey} {
TABLE_CAT tableCatalog
TABLE_SCHEM tableSchema
TABLE_NAME tableName
COLUMN_NAME columnName
KEY_SEQ ordinalPosition
PK_NAME constraintName
} {
if {[dict exists $row $odbcKey]} {
dict set row $tdbcKey [dict get $row $odbcKey]
dict unset row $odbcKey
}
}
lappend retval $row
}
set retval
} result options]
catch {rename $stmt {}}
return -level 0 -options $options $result
}
# The 'foreignkeys' method returns a dictionary describing the foreign
# keys of a table
method foreignkeys {args} {
set stmt [::tdbc::odbc::foreignkeysStatement create \
Stmt::[incr statementSeq] [self] {*}$args]
set status [catch {
set fkseq 0
set retval {}
$stmt foreach -as dicts row {
foreach {odbcKey tdbcKey} {
PKTABLE_CAT primaryCatalog
PKTABLE_SCHEM primarySchema
PKTABLE_NAME primaryTable
PKCOLUMN_NAME primaryColumn
FKTABLE_CAT foreignCatalog
FKTABLE_SCHEM foreignSchema
FKTABLE_NAME foreignTable
FKCOLUMN_NAME foreignColumn
UPDATE_RULE updateRule
DELETE_RULE deleteRule
DEFERRABILITY deferrable
KEY_SEQ ordinalPosition
FK_NAME foreignConstraintName
} {
if {[dict exists $row $odbcKey]} {
dict set row $tdbcKey [dict get $row $odbcKey]
dict unset row $odbcKey
}
}
# Horrible kludge: If the driver doesn't report FK_NAME,
# make one up.
if {![dict exists $row foreignConstraintName]} {
if {![dict exists $row ordinalPosition]
|| [dict get $row ordinalPosition] == 1} {
set fkname ?[dict get $row foreignTable]?[incr fkseq]
}
dict set row foreignConstraintName $fkname
}
lappend retval $row
}
set retval
} result options]
catch {rename $stmt {}}
return -level 0 -options $options $result
}
# The 'prepareCall' method gives a portable interface to prepare
# calls to stored procedures. It delegates to 'prepare' to do the
# actual work.
method preparecall {call} {
regexp {^[[:space:]]*(?:([A-Za-z_][A-Za-z_0-9]*)[[:space:]]*=)?(.*)} \
$call -> varName rest
if {$varName eq {}} {
my prepare \\{CALL $rest\\}
} else {
my prepare \\{:$varName=CALL $rest\\}
}
if 0 {
# Kevin thinks this is going to be
if {![regexp -expanded {
^\s* # leading whitespace
(?::([[:alpha:]_][[:alnum:]_]*)\s*=\s*) # possible variable name
(?:(?:([[:alpha:]_][[:alnum:]_]*)\s*[.]\s*)? # catalog
([[:alpha:]_][[:alnum:]_]*)\s*[.]\s*)? # schema
([[:alpha:]_][[:alnum:]_]*)\s* # procedure
(.*)$ # argument list
} $call -> varName catalog schema procedure arglist]} {
return -code error \
-errorCode [list TDBC \
SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION \
42000 ODBC -1] \
"Syntax error in stored procedure call"
} else {
my PrepareCall $varName $catalog $schema $procedure $arglist
}
# at least if making all parameters 'inout' doesn't work.
}
}
# The 'typemap' method returns the type map
method typemap {} {
if {![info exists typemap]} {
set typemap $::tdbc::odbc::sqltypes
set typesStmt [tdbc::odbc::typesStatement new [self]]
$typesStmt foreach row {
set typeNum [dict get $row DATA_TYPE]
if {![dict exists $typemap $typeNum]} {
dict set typemap $typeNum [string tolower \
[dict get $row TYPE_NAME]]
}
switch -exact -- $typeNum {
-9 {
[self] HasWvarchar 1
}
-5 {
[self] HasBigint 1
}
}
}
rename $typesStmt {}
}
return $typemap
}
# The 'begintransaction', 'commit' and 'rollback' methods are
# implemented in C.
}
#-------------------------------------------------------------------------------
#
# tdbc::odbc::statement --
#
# The class 'tdbc::odbc::statement' models one statement against a
# database accessed through an ODBC connection
#
#-------------------------------------------------------------------------------
::oo::class create ::tdbc::odbc::statement {
superclass ::tdbc::statement
# The constructor is implemented in C. It accepts the handle to
# the connection and the SQL code for the statement to prepare.
# It creates a subordinate namespace to hold the statement's
# active result sets, and then delegates to the 'init' method,
# written in C, to do the actual work of preparing the statement.
# The 'resultSetCreate' method forwards to the result set constructor
forward resultSetCreate ::tdbc::odbc::resultset create
# The 'params' method describes the parameters to the statement
method params {} {
set typemap [[my connection] typemap]
set result {}
foreach {name flags typeNum precision scale nullable} [my ParamList] {
set lst [dict create \
name $name \
direction [lindex {unknown in out inout} \
[expr {($flags & 0x06) >> 1}]] \
type [dict get $typemap $typeNum] \
precision $precision \
scale $scale]
if {$nullable in {0 1}} {
dict set list nullable $nullable
}
dict set result $name $lst
}
return $result
}
# Methods implemented in C:
# init statement ?dictionary?
# Does the heavy lifting for the constructor
# connection
# Returns the connection handle to which this statement belongs
# paramtype paramname ?direction? type ?precision ?scale??
# Declares the type of a parameter in the statement
}
#------------------------------------------------------------------------------
#
# tdbc::odbc::tablesStatement --
#
# The class 'tdbc::odbc::tablesStatement' represents the special
# statement that queries the tables in a database through an ODBC
# connection.
#
#------------------------------------------------------------------------------
oo::class create ::tdbc::odbc::tablesStatement {
superclass ::tdbc::statement
# The constructor is written in C. It accepts the handle to the
# connection and a pattern to match table names. It works in all
# ways like the constructor of the 'statement' class except that
# its 'init' method sets up to enumerate tables and not run a SQL
# query.
# The 'resultSetCreate' method forwards to the result set constructor
forward resultSetCreate ::tdbc::odbc::resultset create
}
#------------------------------------------------------------------------------
#
# tdbc::odbc::columnsStatement --
#
# The class 'tdbc::odbc::tablesStatement' represents the special
# statement that queries the columns of a table or view
# in a database through an ODBC connection.
#
#------------------------------------------------------------------------------
oo::class create ::tdbc::odbc::columnsStatement {
superclass ::tdbc::statement
# The constructor is written in C. It accepts the handle to the
# connection, a table name, and a pattern to match column
# names. It works in all ways like the constructor of the
# 'statement' class except that its 'init' method sets up to
# enumerate tables and not run a SQL query.
# The 'resultSetCreate' class forwards to the constructor of the
# result set
forward resultSetCreate ::tdbc::odbc::resultset create
}
#------------------------------------------------------------------------------
#
# tdbc::odbc::primarykeysStatement --
#
# The class 'tdbc::odbc::primarykeysStatement' represents the special
# statement that queries the primary keys on a table through an ODBC
# connection.
#
#------------------------------------------------------------------------------
oo::class create ::tdbc::odbc::primarykeysStatement {
superclass ::tdbc::statement
# The constructor is written in C. It accepts the handle to the
# connection and a table name. It works in all
# ways like the constructor of the 'statement' class except that
# its 'init' method sets up to enumerate primary keys and not run a SQL
# query.
# The 'resultSetCreate' method forwards to the result set constructor
forward resultSetCreate ::tdbc::odbc::resultset create
}
#------------------------------------------------------------------------------
#
# tdbc::odbc::foreignkeysStatement --
#
# The class 'tdbc::odbc::foreignkeysStatement' represents the special
# statement that queries the foreign keys on a table through an ODBC
# connection.
#
#------------------------------------------------------------------------------
oo::class create ::tdbc::odbc::foreignkeysStatement {
superclass ::tdbc::statement
# The constructor is written in C. It accepts the handle to the
# connection and the -primary and -foreign options. It works in all
# ways like the constructor of the 'statement' class except that
# its 'init' method sets up to enumerate foreign keys and not run a SQL
# query.
# The 'resultSetCreate' method forwards to the result set constructor
forward resultSetCreate ::tdbc::odbc::resultset create
}
#------------------------------------------------------------------------------
#
# tdbc::odbc::typesStatement --
#
# The class 'tdbc::odbc::typesStatement' represents the special
# statement that queries the types available in a database through
# an ODBC connection.
#
#------------------------------------------------------------------------------
oo::class create ::tdbc::odbc::typesStatement {
superclass ::tdbc::statement
# The constructor is written in C. It accepts the handle to the
# connection, and (optionally) a data type number. It works in all
# ways like the constructor of the 'statement' class except that
# its 'init' method sets up to enumerate types and not run a SQL
# query.
# The 'resultSetCreate' method forwards to the constructor of result sets
forward resultSetCreate ::tdbc::odbc::resultset create
# The C code contains a variant implementation of the 'init' method.
}
#------------------------------------------------------------------------------
#
# tdbc::odbc::resultset --
#
# The class 'tdbc::odbc::resultset' models the result set that is
# produced by executing a statement against an ODBC database.
#
#------------------------------------------------------------------------------
::oo::class create ::tdbc::odbc::resultset {
superclass ::tdbc::resultset
# Methods implemented in C include:
# constructor statement ?dictionary?
# -- Executes the statement against the database, optionally providing
# a dictionary of substituted parameters (default is to get params
# from variables in the caller's scope).
# columns
# -- Returns a list of the names of the columns in the result.
# nextdict
# -- Stores the next row of the result set in the given variable in
# the caller's scope as a dictionary whose keys are
# column names and whose values are column values.
# nextlist
# -- Stores the next row of the result set in the given variable in
# the caller's scope as a list of cells.
# rowcount
# -- Returns a count of rows affected by the statement, or -1
# if the count of rows has not been determined.
}