powerbasic程序用ado连接oracle数据库对number数据类型的取值
在使用 PowerBASIC 语言,通过 ADO 的 OraOLEDB 驱动访问 Oracle 数据库时,发现对于 NUMBER 类型的字段的值,使用字符串形式转换后,总是为空。 经过调试,发现在 PowerBASIC 中将返回的值认成了“14” ,即不明数据类型。 要取出该值,使用通常的做法是不行的。成功的方法如下: 首先,定义%VT_DECIMAL = 14 然后,对取出的值,判断其内部数据结构,并根据不同情况进行分别处理,代码如下: SELECT CASE VARIANTVT (vValue)CASE %VT_EMPTYsValue = ““CASE %VT_NULLsValue = ““ CASE %VT_BSTRsValue = VARIANT$(vValue)CASE %VT_DATE type 7CALL DbDateFromVariantDate (vValue) TO sValueCASE %VT_DECIMAL %VT_DECIMAL=14 = “16 byte fixed point“ 10-05-08 jet is giving me a type 3 from ptmn.mdb table = I4 handled below.CALL VtDecimalToString (vValue) TO sValue KNOWN NUMERIC TYPES OTHER THAN DECIMAL I2, I4, R4, R8, CY, I1, UI1, UI2, UI4, I8, UI8 INT UINT 2 3 4 5 6 16 17 18 19 20 21 22 23CASE %VT_BOOL added this handler 11-5-08sValue = IIF$(ISTRUE VARIANT#(vvalue), “1“, “0“) KNOWN NUMERIC TYPESCASE %VT_I2, %VT_I4, %VT_R4, %VT_R8, %VT_CY, %VT_I1, %VT_UI1,_%VT_UI2, %VT_UI4, %VT_I8, %VT_UI8, %VT_INT, %VT_UINTSValue = AT$(VARIANT#(vValue)) if we get an unexpected type, we want to know about it so we can add an explicit handler for it.CASE ELSEsValue = USING$ (“UNKNOWN TYPE # AT_$(VARIANT_#(VALUE)) IS & “, _VARIANTVT(vvalue), AT$(VARIANT#(vValue))) END SELECT 请注意其中标红的部分。其中,调用了一个名为 VtDecimalToString 方法。 该方法定义如下: FUNCTION VtDecimalToString (vDec AS VARIANT) AS STRINGLOCAL S AS STRING, hr AS LONGhr = VarBstrFromDec(vDec, %LOCALE_USER_DEFAULT, 0, S)FUNCTION = ACODE$(S) END FUNCTION 不难看出,其中的 VarBstrFromDec 是关键,意思是把可变数据类型变量中的浮点值变为字 符串。详情请参考 FUNCTION DbDatefromVariantDate (vDate AS VARIANT) AS STRINGLOCAL ST AS SYSTEMTIMELOCAL szDF AS ASCIIZ * 48, szDate AS ASCIIZ * 48LOCAL szTF AS ASCIIZ * 48, szTime AS ASCIIZ * 48LOCAL vbTime AS DOUBLEvbTime = VARIANT#(vDate)VariantTimeToSystemTime vbTime, St always at the dateszDf = “yyyy - MM - dd“GetDateat BYVAL %NULL, BYVAL %NULL ,st, szDf, szDate, SIZEOF (szDate) only add the time string if presentIF FRAC (vbTime) THENszTF = “HH : mm : ss“ HH= 24 hour, hh= 12 hourGetTimeat BYVAL %NULL, BYVAL %NULL ,st, szTF, szTime, SIZEOF (szTime)FUNCTION = szDate & $SPC & szTimeELSEFUNCTION = szDateEND IF END FUNCTION