返回首页

gbase数据、南大通用产品文档:GBase8s类定义

更新日期:2024年09月11日

以下示例中的 charattrUDT 是 C 不透明类型的类,它必须实现 SQLData 接口:
import java.sql.*;
import com.gbasedbt.jdbc.*;
/*
* C struct of charattr_udt:
*
* typedef struct charattr_type
* {
* char chr1[4+1];
* mi_boolean bold; // mi_boolean (1 byte)
* mi_smallint fontsize; // mi_smallint (2 bytes)
* }
* charattr;
*
* typedef charattr charattr_udt;
*
*/
public class charattrUDT implements SQLData
{
private String sql_type = "charattr_udt";
// an ASCII character/a multibyte character, and is null-terminated.
public String chr1;
// Is the character in boldface?

GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 188 -

public boolean bold;
// font size of the character
public short fontsize;

public charattrUDT() { }

public charattrUDT(String chr1, boolean bold, short fontsize)
{
this.chr1 = chr1;
this.bold = bold;
this.fontsize = fontsize;
}

public String getSQLTypeName()
{
return sql_type;
}
// reads a stream of data values and builds a Java object
public void readSQL(SQLInput stream, String type) throws SQLException
{
sql_type = type;
chr1 = ((IfmxUDTSQLInput)stream).readString(5);
bold = stream.readBoolean();
fontsize = stream.readShort();
}
// writes a sequence of values from a Java object to a stream
public void writeSQL(SQLOutput stream) throws SQLException
{
((IfmxUDTSQLOutput)stream).writeString(chr1, 5);
stream.writeBoolean(bold);
stream.writeShort(fontsize);
}
// overides Object.equals()
public boolean equals(Object b)
{
return (chr1.equals(((charattrUDT)b).chr1) &&
bold == ((charattrUDT)b).bold &&

GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 189 -

fontsize == ((charattrUDT)b).fontsize);
}

public String toString()
{
return "chr1=" + chr1 + " bold=" + bold + " fontsize=" + fontsize;
}
}
在 JDBC 应用程序中,自定义类型映射必须将 SQL 类型名 charattr_udt 映射
到 charattrUDT 类:
java.util.Map customtypemap = conn.getTypeMap();
if (customtypemap == null)
{
System.out.println("\n***ERROR: typemap is null!");
return;
}
customtypemap.put("charattr_udt", Class.forName("charattrUDT"));

decround() 函数将 decimal 类型数值四舍五入到小数数位。
语法
void decround(d, s)
dec_t *d;
mint s;
d
指向 decround() 函数四舍五入其值的 decimal 结构的指针。
s
decround() 对 d 四舍五入的小数数字的数目。请使用 s 参数的整数值。

用法
四舍五入因子为 5x10-s-1。
要四舍五入一个值,
decround() 函数对正数值加上舍入因子,
或从负数值减去此因子。然后,它截断至 s 位,如下表所示。
四舍五入之前的值
s 的值
四舍五入的值

函数说明
返回date (1 = 周日, 2 = 周一, ..., 7 = 周六)对应的工作日索引。
示例
示例1:“2020-08-30”是周日,返回对应的工作日索引为1。
gbase> SELECT DAYOFWEEK('2020-08-30') FROM dual;
+-------------------------+
| DAYOFWEEK('2020-08-30') |
+-------------------------+
|
1 |
+-------------------------+
1 row in set