返回首页

gbase数据、南大通用产品文档:GBase8sifx_int8cvasc() 函数

更新日期:2024年09月11日

ifx_int8cvasc() 函数将 C char 类型中保存作为可打印的字符的值转换为 int8 类
型数值。
语法

mint ifx_int8cvasc(strng_val, len, int8_val)

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 722 -

char *strng_val
mint len;
ifx_int8_t *int8_val;
strng_val
指向字符串的指针。
len
strng_val 字符串的长度。
int8_val
指向 ifx_int8cvasc() 放置转换的结果处的 int8 结构的指针。

用法
字符串 strng_val 可包含下列符号:
开头的符号,或为正(+)或为负(-)。
在 e 或 E 前面的指数。您可在该指数前面加符号,或为正(+)或为负(-)。

strng_val 字符串在小数点分隔符的右边不包含小数点分隔符或数字。ifx_int8cvasc()
函数截断小数点分隔符右边的小数点分隔符和任何数字。
ifx_int8cvasc() 函数忽略该字符串
中开头的空格。
当您使用非缺省的语言环境(US English 之外的一种)时,ifx_int8cvasc() 支持
strng_val 字符串中的非 ASCII 字符。

返回代码
0
转换成功。
-1213
字符串有非数值的字符。
-1284
操作导致溢出或下溢。

示例
demo 目录中的文件 int8cvasc.ec 包含下列样例程序。
/*

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 723 -

* ifx_in8cvasc.ec *
The following program converts three strings to INT8
types and displays the values stored in each field of
the INT8 structures.
*/

#include

EXEC SQL include "int8.h";

char string1[] = "-12,555,444,333,786,456";
char string2[] = "480";
char string3[] = "5.2";
main()
{
mint x;
ifx_int8_t num1, num2, num3;
void nullterm(char *, mint);

printf("IFX_INT8CVASC Sample ESQL Program running.\n\n");

if (x = ifx_int8cvasc(string1, strlen(string1), &num1))
{
printf("Error %d in converting string1 to INT8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string2, strlen(string2), &num2))
{
printf("Error %d in converting string2 to INT8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string3, strlen(string3), &num3))
{

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 724 -

printf("Error %d in converting string3 to INT8\n", x);
exit(1);
}

/* Display the exponent, sign value and number of digits in num1. */

ifx_int8toasc(&num1, string1, sizeof(string1));
nullterm(string1, sizeof(string1));
printf("The value of the first INT8 is = %s\n", string1);

/* Display the exponent, sign value and number of digits in num2. */

ifx_int8toasc(&num2, string2, sizeof(string2));
nullterm(string2, sizeof(string2));
printf("The value of the 2nd INT8 is = %s\n", string2);

/* Display the exponent, sign value and number of digits in num3. */
/* Note that the decimal is truncated */

ifx_int8toasc(&num3, string3, sizeof(string3));
nullterm(string3, sizeof(string3));
printf("The value of the 3rd INT8 is = %s\n", string3);

printf("\nIFX_INT8CVASC Sample Program over.\n\n");
exit(0);
}
void nullterm(char *str, mint size)
{
char *end;

end = str + size;
while(*str && *str > ' ' && str <= end)
++str;

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 725 -

*str = '\0';
}
输出

IFX_INT8CVASC Sample ESQL Program running.

The value of the first INT8 is = -12555444333786456
The value of the 2nd INT8 is = 480
The value of the 3rd INT8 is = 5

下列示例说明本部分中讨论的一些任务。
创建智能大对象
此示例说明 创建智能大对象 中展现的那些步骤。

GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 164
-
file = new File("data.dat");
FileInputStream fin = new FileInputStream(file);

byte[] buffer = new byte[200];;

IfxLobDescriptor loDesc = new IfxLobDescriptor(myConn);
IfxLocator loPtr = new IfxLocator();
IfxSmartBlob smb = new IfxSmartBlob(myConn);

// Now create the large object in server. Read the data from the
file
// data.dat and write to the large object.
int loFd = smb.IfxLoCreate(loDesc, smb.LO_RDWR, loPtr);
System.out.println("A smart-blob is created ");
int n = fin.read(buffer);
if (n > 0)
n = smb.IfxLoWrite(loFd, buffer);
System.out.println("Wrote: " + n +" bytes into it");

// Close the large object and release the locator.
smb.IfxLoClose(loFd);
System.out.println("Smart-blob is closed " );
smb.IfxLoRelease(loPtr);
System.out.println("Smart Blob Locator is released ");
将文件 data.dat 的内容写至智能大对象。
将数据插入至智能大对象
下列代码将数据插入至智能大对象:
String s = "insert into large_tab (col1, col2) values (?,?)";
pstmt = myConn.prepareStatement(s);

file = new File("data.dat");
FileInputStream fin = new FileInputStream(file);

byte[] buffer = new byte[200];;

IfxLobDescriptor loDesc = new IfxLobDescriptor(myConn);

GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 165
-
IfxLocator loPtr = new IfxLocator();
IfxSmartBlob smb = new IfxSmartBlob(myConn);

// Create a smart large object in server
int loFd = smb.IfxLoCreate(loDesc, smb.LO_RDWR, loPtr);
System.out.println("A smart-blob has been created ");
int n = fin.read(buffer);
if (n > 0)
n = smb.IfxLoWrite(loFd, buffer);
smb.IfxLoClose(loFd);

System.out.println("Wrote: " + n +" bytes into it");
System.out.println("Smart-blob is closed " );

Blob blb = new IfxBblob(loPtr);
pstmt.setInt(1, 2); // set the Integer column
pstmt.setBlob(2, blb); // set the blob column
pstmt.executeUpdate();
System.out.println("Binding of smart large object to table is
done");

pstmt.close();
smb.IfxLoRelease(loPtr);
System.out.println("Smart Blob Locator is released ");
将文件 data.dat 的内容写至 large_tab 表的 BLOB 列。
从智能大对象检索数据
本主题中的示例说明 访问智能大对象 中的步骤。
下列代码示例展示如何使用 GBase 8s 扩展类来访问智能大对象数据:
byte[] buffer = new byte[200];
System.out.println("Reading data now ...");
try
{
int row = 0;
Statement stmt = myConn.createStatement();
ResultSet rs = stmt.executeQuery("Select * from demo_14");

GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 166
-
while( rs.next() )
{
row++;
String str = rs.getString(1);
InputStream value = rs.getAsciiStream(2);
IfxBblob b = (IfxBblob) rs.getBlob(2);
IfxLocator loPtr = b.getLocator();
IfxSmartBlob smb = new IfxSmartBlob(myConn);
int loFd = smb.IfxLoOpen(loPtr, smb.LO_RDONLY);

System.out.println("The Smart Blob is Opened for reading ..");
int number = smb.IfxLoRead(loFd, buffer, buffer.length);
System.out.println("Read total " + number + " bytes");
smb.IfxLoClose(loFd);
System.out.println("Closed the Smart Blob ..");
smb.IfxLoRelease(loPtr);
System.out.println("Locator is released ..");
}
rs.close();
}
catch(SQLException e)
{
System.out.println("Select Failed ...\n" +e.getMessage());
}
首先,ResultSet.getBlob() 方法取得 BLOB 类型的一个对象。需要强制转型来将返回的对
象转换为 IfxBblob 类型的对象。接下来,IfxBblob.getLocator() 方法从 IfxBblob 对象取得一
个 IfxLocator 对象。在 IfxLocator 对象可用之后,您可实例化一个 IfxSmartBlob 对象,并使
用 IfxLoOpen() 和 IfxLoRead() 方法,来读取智能大对象数据。访存 CLOB 数据是类似的,
但它使用方法ResultSet.getClob()、IfxCblob.getLocator(),等等。
如果使用 getBlob() 或 getClob() 来从 BLOB 类型的列访存数据,则不需要使用前一样例代
码那样的 GBase 8s 扩展来检索实际的 BLOB 内容。您可简单地使
用 Java.Blob.getBinaryStream() 或 Java.Clob.getAsciiStream() 来检索内容。GBase 8s JDBC
Driver 使用与样例代码相同的步骤,为您隐式地从数据库服务器取得内容。此方法比前一
示例中的方法更简单,但不提供读取 BLOB 列内容的那么多选项。

6 与不透明数据类型一起使用

GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 167
-
不透明数据类型是您定义扩展数据库服务器的原子数据类型。数据库服务器不具有有关不
透明数据类型的信息,直到您提供描述它的例程。
扩展数据库服务器频繁需要您创建用户定义的例程
(UDR)来支持此扩展。
UDR 是您创建
的例程,可以在 SQL 语句,数据库服务器或其他 UDR 中调用。UDR 可以是不透明数据
类型的一部分,也可以是单独的。
JDBC 3.0 标准提供 java.sql.SQLInput 和 java.sql.SQLOutput 方法访问不透明数据类型。
这些
接口的定义扩展为完全支持 GBase 8s 固定二进制和可变二进制不透明数据类型。此扩展包
括以下接口:

IfmxUdtSQLInput

IfmxUdtSQLOutput
此外,以下类同样从 JDBC 客户端应用程序在数据库服务器中创建 Java™ 不透明类型和
UDR :

UDTManager

UDTMetaData

UDRManager

UDRMetaData
UDTManager 和 UDRManager 类提供将客户端 Java 类映射为不透明数据类型和 UDR,并
将它们的实例存储在数据库中的基础架构。
此工具只能在客户端 JDBC 中使用。有关服务器端 JDBC 的功能和限制,请参
阅 J/Foundation 开发者指南。
有关不透明数据类型和 UDR 的详细信息,请参阅以下手册:

GBase 8s 用户定义的例程和数据类型开发者指南 描述了有关不透明类型和 UDR
的术语和概念,包括内部数据结构,支持的功能以及隐式和显式强制转换,这些是
您需要在本节中使用的信息。

J/Foundation 开发者指南 描述了在 Java 中编写 UDR 的具体信息。

下面的主题讨论(以字母顺序)GBase
8s 数据库服务器产品以及它们的实用程序使用
的环境变量。
重要: 下列环境变量的描述包括在 UNIX™ 上设置环境变量的语法。