返回首页

gbase数据、南大通用产品文档:GBase8a

更新日期:2024年09月11日

GBaseDataReader 成员
公共属性
属 性
描 述
YieldCount
获取当前行的列数。
HasRows
获取一个数值指明GBaseDataReader
是否包含一行或多行。
IsClosed
获得一个值指明GBaseDataReader 是
否关闭。
Item
重载函数。
根据给定的列索引,
返回指

GBase 8a 程序员手册ADO.NET 篇


- 206 -

南大通用数据技术股份有限公司
属 性
描 述
定列的原始列值。
RecordsAffected
得到由SQL 语句更改的,
插入的,
或者
删除的行数。
公共方法
方 法
描 述
Close
关闭GBaseDataReader 对象。
Equals (继承于Object)
判断指定的对象是否等于当前的对象。

GetBoolean
获取指定列的Boolean 值。
GetByte
获取指定列的字节值。
GetBytes
获取指定列的字节数组值。
GetChar
获取指定列的单个字符值。
GetChars
获取指定列的字符数组值。
GetDataTypeName
获取指定列的数据类型的字符串。
GetDateTime
获取指定列的DateTime 类型值。
GetDecimal
获取指定列的Decimal 值。
GetDouble
获取指定列的双精度浮点数值。
GetFieldType
获取指定列的数据类型对象。
GetFloat
获取指定列的单精度浮点数值类型。
GetInt16
获取指定列的16 位有符号整数值。
GetInt32
获取指定列的32 位有符号整数值。
GetInt64
获取指定列的64 位有符号整数值。
GetGBaseDateTime
获取指定列的GBaseDateTime 值。
GetName
获得指定列的名字。
GetOrdinal
通过给定的列名,获得列序号。
GetSchemaTable
返回描述GBaseDataReader 列元数据
的DataTable。
GetString
得到指定列的String 值。
GetTimeSpan
得到指定列的TimeSpan 值。
GetType (继承于 Object)
获取当前实例的类型。



GBase 8a 程序员手册ADO.NET 篇
南大通用数据技术股份有限公司

- 207 -
方 法
描 述
GetUInt16
获取指定列的16 位无符号整数值。
GetUInt32
获取指定列的32 位无符号整数值。
GetUInt64
获取指定列的64 位无符号整数值。
GetValue
获取指定列的原类型数值,返回
Object。
GetValues
获得当前行中所有属性,
返回属性的数
量。
IsDBNull
获得一个值,判断指定列的值是否为
空。
NextResult
当获取多条SQL 语句对应的结果集时,
此方法获取下一个结果集。
Read
使数据读取器读取下一条记录。
ToString (继承于 Object)
返回类的完全限定名。

SQL 代码的示例在整个出版物中出现。
除非另有说明,
代码不特定于任何单个的 GBase 8s
应用程序开发工具。
如果示例中仅列出 SQL 语句,那么它们将不用分号定界。例如:您可能看到以下示例中
的代码:
CONNECT TO stores_demo
...

DELETE FROM customer
WHERE customer_num = 121
...

COMMIT WORK

GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 4 -
DISCONNECT CURRENT
要将此 SQL 代码用于特定产品,必须应用该产品的语法规则。例如,如果使用的是 SQL
API,那么必须在每条语句的开头使用 EXEC SQL,并在每条语句的结尾使用分号(或其
他合适的定界符)。 如果使用的是 DB–Access,那么必须用分号将多条语句隔开。
提示: 代码示例中的省略点表示在整个应用程序中将添加更多的代码,但是不必显示它以描述
正在讨论的概念。
有关使用特定应用程序开发工具或 SQL API 的 SQL 语句的详细指导,
请参阅您的产品文
档。

2 入门
这些主题提供 GBase 8s JDBC Driver 和 JDBC API 的概述。

代表一个GBase 数据库中的事务。这个类不能被继承。对于该类型的所有
成员,参考GBaseTransaction 成员。

继承层次
System.Object
|__ System.MarshalByRefObject
|__ System.Data.Common.DbTransaction
|__ GBase.Data.GBaseClient.GBaseTransaction

语法
[Visual Basic]
Public NotInheritable Class GBaseTransaction _
Inherits DbTransaction
[C#]
public sealed class GBaseTransaction : DbTransaction

必要条件



GBase 8a 程序员手册ADO.NET 篇
南大通用数据技术股份有限公司

- 323 -
命名空间:GBase.Data.GBaseClient

线程安全性
这个类型的公共静态成员(在Visual Basic 中为 Shared)对于多线程操作
是保证线程安全的,对于实例不保证线程安全性。

注释
程序通过在GBaseConnection 对象上调用BeginTransaction 来创建一个
GBaseTransaction 对象。
所有后面关于事务的操作
(例如:
提交或者回滚事务)
都在GBaseTransaction 对象上进行。

示例
下面的例子创建了一个GBaseConnection 和一个GBaseTransaction 对象,
还示范了如何使用BeginTransaction、Commit 和Rollback 方法。
[Visual Basic]
Public Sub RunTransaction(gsConnString As String)
Dim gsConnection As New GBaseConnection(gsConnString)
gsConnection.Open()
Dim gsCommand As GBaseCommand = gsConnection.CreateCommand()
Dim gsTrans As GBaseTransaction
' Start a local transaction
gsTrans = gsConnection.BeginTransaction()
' Must assign both transaction object and connection
' to Command object for a pending local transaction
gsCommand.Connection = gsConnection
gsCommand.Transaction = gsTrans
Try
gsCommand.CommandText = "Insert into Region ("_
&"RegionID,"_
&"RegionDescription)VALUES (100, "_
&"Description')"
gsCommand.ExecuteNonQuery()
gsCommand.CommandText = "Insert into Region ("_
&"RegionID, "_

GBase 8a 程序员手册ADO.NET 篇


- 324 -

南大通用数据技术股份有限公司
&"RegionDescription) VALUES (101, "_
&"'Description')"
gsCommand.ExecuteNonQuery()
gsTrans.Commit()
Console.WriteLine("Both records are written to
database.")
Catch e As Exception
Try
gsTrans.Rollback()
Catch ex As GBaseException
If Not gsTrans.Connection Is Nothing Then
Console.WriteLine("An exception of type " &_
ex.GetType().ToString() &_
" was encountered
while
attempting to roll back
the
transaction.")
End If
End Try
Console.WriteLine("An exception of type "& _
e.GetType().ToString()&_
"was encountered while inserting the data.")
Console.WriteLine("Neither record was written to
database.")
Finally
gsConnection.Close()
End Try
End Sub 'RunTransaction

[C#]
public void RunTransaction(string gsConnString)
{
GBaseConnection gsConnection = new
GBaseConnection(gsConnString);
gsConnection.Open();
GBaseCommand gsCommand = gsConnection.CreateCommand();
GBaseTransaction gsTrans;
// Start a local transaction
gsTrans = gsConnection.BeginTransaction();



GBase 8a 程序员手册ADO.NET 篇
南大通用数据技术股份有限公司

- 325 -
// Must assign both transaction object and connection
// to Command object for a pending local transaction
gsCommand.Connection = gsConnection;
gsCommand.Transaction = gsTrans;
try
{
gsCommand.CommandText = "Insert into Region (RegionID,
RegionDescription) VALUES (100, 'Description')";
gsCommand.ExecuteNonQuery();

gsCommand.CommandText = "Insert into Region (RegionID,
RegionDescription) VALUES (101, 'Description')";
gsCommand.ExecuteNonQuery();
gsTrans.Commit();
Console.WriteLine("Both
records
are
written
to
database.");
}
catch(Exception e)
{
try
{
gsTrans.Rollback();
}
catch (GBaseException ex)
{
if (gsTrans.Connection != null)
{
Console.WriteLine("An exception of type " +
ex.GetType() +" was encountered while attempting to roll back the
transaction.");
}
}
Console.WriteLine("An exception of type " + e.GetType() +
" was encountered while inserting
the data.");
Console.WriteLine("Neither record was written to
database.");
}
finally

GBase 8a 程序员手册ADO.NET 篇


- 326 -

南大通用数据技术股份有限公司
{
gsConnection.Close();
}
}