2023年7月13日发(作者:)
UniDAC使用说明
整理:兵临成下 QQ:383530895
UniDAC官方网址:/
一、连接数据库Connecting to Database
1、 通用连接属性
Provider
第一个就应该设置的属性,指定要连接的数据库类型,根据指定的数据库连接类型不同其它的设置也会发生相应的变化;
Username and Password
登录数据的有效用户名和密码;
Server
通常将此设成要连接数据库所在的计算机名或IP地址,如果将此属性设置为空,对于MySQL, InterBase连接数据库方式, UniDAC 将试图连接本地(Localhost)。
Oracle:
客户端模式下,指定的Server名称一定要出现在中,且有效,设置效果如下:
with UniConnection1 do
begin
ProviderName := 'Oracle';
Server := 'ORCL';
Username := 'username';
Password := 'password';
end;
直连模式(Direct mode)下:在此模式下,运行软件的计算机可以不安装Oracle客户端而连接Oracle数据库,但要做以下设置:
1) 设置直连模式
2) 设置Server
指定Server格式:Host:Port:SID.
注:客户端模式和直连模式的设置不能混淆,否则无法执行。两种格式严格区分。
效果如下:
with UniConnection1 do
begin
ProviderName := 'Oracle';
Server := '192.168.1.113:1521:ORCL';
Username := ' Username ';
Password := ' Password 3';
end;
SQL Server:
指定要连接的数据库所在的网络IP,且有效,如果采用的不是默认端口(1433),Server应该这样设置:HostName,PortNumber.
Database
这个属性只对SQL Server, MySQL, PostgreSQL, InterBase, and SQLite 连接方式有效,
Port
指定TCP/IP协议访问的有效端口
MySQL – 默认端口 3306
PostgreSQL -默认端口5432
二、UniDAC(版本:2.7)连接数据库必要文件或局限需求
1、Oracle连接
Oracle在采用直连模式将受到以下限制:
特别要注意的是(包括:应用TUniLoader): 1)、应用直连模式,本地执行程序的客户机必须要安装TCP/IP协议
2)、注意防火墙
3)、数据库的triggers、check constraints、clustered tables、loading of remote objects、user-defined types将得不到支持
4)、available, like OBJECT, ARRAY, REF, XML, BINARY_DOUBLE, BINARY_FLOAT这些类型将变为不可用
5)、TUniLoader的应用版本应高于Oracle client 8.17
以下是英文原文:
triggers are not supported
check constraints are not supported
referential integrity constraints are not supported
clustered tables are not supported
loading of remote objects is not supported
user-defined types are not supported
LOBs must be specified after all scalar columns
LONGs must be specified last
You cannot use TUniLoader in a threaded OCI environment with Oracle client 8.17 or
lower.
Connect using the TCP/IP network protocol only.
Some types are not available, like OBJECT, ARRAY, REF, XML, BINARY_DOUBLE,
BINARY_FLOAT.
Certain problems may occur when using firewalls.
NLS conversion on the client side is not supported.
Transparent Application Failover is not supported.
Statement caching is not available.
OS authentication and changing expired passwords features are not available.
The DES authentication is used.
Oracle Advanced Security is not supported.
We do not guarantee stability of multithreaded applications. It is highly recommended to
use the separate TUniConnection component for each thread when using UniDAC from
different threads.
2、 SQL Server连接
1) 提供连接支持
服务端: SQL Server 2005 (including Compact and Express editions), SQL
Server 2000, SQL Server 7, and MSDE.
客户端: SQL OLE DB and SQL Native Client.
2) 环境需求
MDAC(Microsoft Data Access Components)版本不低于2.5
3、 My SQL连接
My SQL提供的连接也包括直连和客户端连接方式,默认采用的是直连方式,如果要更改连接方式,在应用程序分发时要带上
二、Delphi与各数据库数据类型比较
Delphi数据类型与各数据库数据类型对比如下表,如有具体说明见表中脚注:
Delphi Type
Oracle Types
SQL Server Types
MySQL Types
[1]
InterBase
Types
PostgreSQL
SQLite TyTypes
NUMBER(p,
ftSmallint
0)[2]
(p < 5)
SMALLINT
TINYINT(M)
TINYINT
(M > 1) SMALLINT
SMALLINT
SMALLINTSMALLINT
TINYINT(M)
UNSIGNED
(M > 1)
-
SMALLINT
UNSIGNED
YEAR
MEDIUMINT
MEDIUMINT
INTEGER
UNSIGNED
INT
BIT
INT
UNSIGNED
BIGINT
BIGINT
UNSIGNED
ftWord
-
TINYINT
-
-
ftInteger
NUMBER(p,
0)[2]
(4 < p < 10)INT
INTEGER
INTEGER
INT
NUMBER(p,
ftLargeint
0)[2] BIGINT
(9 < p < 19)
BIGINT
BIGINT
BIGINT
ftFloat
NUMBER(p, NUMBER(p, DECIMAL([3] DECIMAL(p, DECIMALs)[2] DECIMAL(p, s)[3]
[3]s)[3] s)[3]
s) REAL
BINARY FLOAT FLOAT FLOAT
FLOAT DOUBLE
FLOAT(FLOAT) REAL
DOUBLE DOUBLE
DOUBLE
PRECISION
BINARY PRECISION
PRECISIODOUBLE
ftBCD
NUMBER(p, DECIMAL(p, DECIMAL(p,
[3] DECIMAL(p, s)s)[2] s)[3] s)[3]
(p < 15) and (s < DECIMAL[3]
DECIMAL[(p < 15) and (p < 15) and (p < 15)
5)
(s < 5)
(s < 5)
and (s < 5)
ftFMTBcd
NUMBER(p, DECIMAL(p, DECIMAL(p,
s)[2] DECIMAL(p, s) s)[3] s)[3]
(14 < p < 39) (14 < p < 39) and (14 < p < 39) (14 < p < DECIMAL[3]
DECIMAL[and> (4 < s < 39)
(4 < s < 39)
ftCurrency
-
MONEY
SMALLMONEY
ftBoolean
-
BIT
VARCHAR2
NVARCHAR2
VARCHAR
CHAR
NCHAR
[5]ftString
RAW CHAR
INTERVAL DAY VARCHAR
TO SECOND
INTERVAL DAY
TO MONTH
ROWID
UROWID
ftWideString
See note [7]
NCHAR
NVARCHAR
LONG
ftMemo
Also see note
TEXT
[8]
NTEXT[9]
ftWideMemo
See note[10]
NTEXT[11]
ftOraClob
CLOB
NCLOB
-
ftBlob
LONG RAW
IMAGE
and 19) and
(4 < s < 39)
(4 < s < 19)
-
-
MONEY
MONEY
TINYINT[4]
BOOL[4] BOOLEAN
BOOLEAN
BOOLEAN
BOOLEAN[4]
CHAR
VARCHAR
ENUM CHAR CHAR CHAR
SET VARCHAR
VARCHAR
VARCHAR
BINARY[6]
VARBINARY[6]
See note [7]
See note See note See no[7]
[7]
[7]
TINYTEXT
TEXT TEXT
MEDIUMTEXT
BLOB TEXT
TEXT
CLOB
LONGTEXT
See See See See
note[10]
note[10]
note[10]
note[10]-
-
-
-
TINYBLOB BLOB
BLOB BINARY
BYTEA
BLOB MEDIUMBLOB
LONGBLOB
Spatial
Data Types
ftOraBlob
ftBytes
BLOB
-
-
BINARY
TIMESTAMP
-
BINARY
-
-
LARGE
OBJECT
-
-
-
ftVarBytes
RAW
VARBINARY
CHAR
VARCHAR
VARBINARY
-
(CHARSET =
OCTETS)
DATE
DATETIME
TIME
DATE
DATE
BINARY
VARBINAR
ftDate
-
-
DATE
-
DATE
ftDateTime
DATE
ftTime
-
TIMESTAMTIMESTAMP
TIMESTAMP
DATETIMETIME
TIME
TIME
TIMESTAMP
TIMESTAMP
ftTimeStamp
WITH
TIMEZONE
ftCursor
ftGuid
ftVariant
NOT
SUPPORTED
BFILE
OBJECT
XML
-
-
-
-
-
REF CURSOR
-
-
-
SQL_VARIANT
CURSOR
XML
TABLE
-
-
-
-
-
REFCURSOR
-
-
-
-
-
UNIQUEIDENTIFIER
-
-
-
-
-
[1] – 如果FieldsAsString 选项被设置 True,则除BLOB和TEXT数据类型外,全部做为ftString来处理
[2] – Oracle NUMBER数据类型与Delphi数据类型对应方式:
if scale equals zero, provider checks values of the specific options to choose the correct Delphi
type in the following order:
1.1 field precision is less or equal Precision Smallint (default is 4) - uses ftSmallint;
1.2 field precision is less or equal Precision Integer (default is 9) - uses ftInteger;
1.3 field precision is less or equal Precision LargeInt (default is 18) - uses ftLargeint;
if scale is greater than zero, the appropriate Delphi type is chosen using the following sequence of
rules:.
2.1 field precision is less or equal PrecisionFloat (default is 0) - uses ftFloat; 2.2 EnableBCD is True and field precision, scale is less or equal PrecisionBCD (default is 14,4) -
uses ftBCD;
2.3 EnableFMTBCD is True and field precision, scale is less or equal PrecisionFMTBCD (default
is 38,38) - uses ftFMTBCD;
2.4 uses ftFloat.
[3] - The appropriate Delphi type is chosen using the following sequence of rules:
EnableBCD is True and field precision, scale is less or equal 14,4 - uses ftBCD;
EnableFMTBCD is True - uses ftFMTBCD;
uses ftFloat.
[4] - If the EnableBoolean option is True
[5] - If the RawAsString option is True
[6] - If the BinaryAsString is True
[7] - If the UseUnicode option is True, all server types mapped to ftString will be mapped to
ftWideString.
[8] - If the LongStrings option is False, and the field length is greater than 255, all server types
mapped to ftString will be mapped to ftMemo.
[9] - For all Delphi versions prior to BDS 2006.
[10] - If the UseUnicode option is True, in BDS 2006 and later versions all server types mapped to
ftMemo will be mapped to ftWideMemo.
[11] - For BDS 2006 and higher IDE versions.
三、UniDAC更新数据
1、数据自动更新
TUniTable、TUniQuery和TUniStoredProc是用来检索和编辑数据的UniDAC控件,
四、主从关系表
五、存储过程
1、TUniConnection, TUniSQL, TUniQuery, TUniStoredProc均可以执行存储过程。
TUniConnection:
是一种最简单的执行存储过程的控件,但他有很多限制。TUniConnection不能具有SQL、存储过程名和参数,不支持输出参数也不支持存储执行的预准备。当然,如果只是运行一个既没有返回也没有输出参数设置,那TUniConnection是一个不错的选择。
TUniSQL:
TUniSQL是一个被分离出的小控件,执行SQL语句但不返回结果集。它没有数据存储,但要消耗一些内存,但比TUniQuery和TUniStoredProc的执行速度快。
TUniQuery:
TUniQuery除具有TUniSQL的执行功能外,还能返回结果集。
TUniStoredProc:
TUniStoredProc是专门用来执行存储过程的一个控件,可以返回结果集、输出参数、执行准备以及通过CreateProcCall方法初始化等。
2、 参数类型
UniDAC支持四种参数类型:input, output, input/output, result
六、事务处理
TUniConnection通过StartTransaction, Commit, Rollback等方法来控制本地事务,判断一个事务是否开启用InTransaction。
七、控件详解
1、TUniConnection
建立和控件数据连接的控件,能访问的数据库包括:Oracle, SQL Server, MySQL, InterBase,
Firebird, 和PostgreSQL.
虽然UniDAC对不同的数据库提供了统一的访问接口,但是对个别数据库还是要进行一些特殊的设置,这些设置是一个字符串列表,你可以按以下代码进行设置:
['CharLength'] := '1';
1、 Oracle
发布者:admin,转转请注明出处:http://www.yc00.com/news/1689245322a225576.html
评论列表(0条)