[DB-SIG] Re: Returning floats in DCOracle2

Alexei Ustyuzhaninov alust@UralskyGSM.com
Mon, 16 Dec 2002 20:08:37 +0500


Yes, you are right. The matter was in the decimal separator. Setting it 
manually to "." resolves the problem. Thank you for the help.

bash-2.04$ cat test.py
import DCOracle2
db = DCOracle2.connect("x/y@z")
c = db.cursor()
c.execute("ALTER SESSION SET NLS_NUMERIC_CHARACTERS='. '")
c.execute("SELECT 0.5 FROM DUAL")
print c.fetchone()

bash-2.04$ python test.py
[0.5]

Matthew T. Kromer wrote:
> The problem may have to do with a mismatch between the C locale's=20
> sscanf() function for parsing numbers, and Oracle's numeric formatting=20
> environment setting.  This might come from the difference between trying=20
> to parse "0.5" using "," as the decimal separator or vice versa ("0,5"=20
> with ".").
> 
> The reason DCOracle2's C layer handles numbers as strings is old, and no=20
> longer valid (it used to cause problems under Linux to initialize in=20
> Object mode).  At some point in time I'll rip out all of the string /=20
> number conversion (which usses sscanf()) and replace it with various=20
> OCINumber calls.
> 
> Alternatively, there might be a compiler problem.
> 
> I was unable to reproduce the problem myself.
> 
> 
> jno wrote:
> 
>>could not reproduce:
>>
>>[jno@hypnos jno]$ python                                               =20
>>Python 2.1.3 (#2, Jul 24 2002, 11:13:04) [C] on hp-uxB
>>Type "copyright", "credits" or "license" for more information.
>> =20
>>
>>>>>import DCOracle
>>>>>d =3D DCOracle.Connect('xxx/xxx@xxx')
>>>>>c =3D d.cursor()
>>>>>c.execute('select 0.5 from dual')
>>>>>r=3Dc.fetchall()
>>>>>c.close()
>>>>>print r
>>>>>       =20
>>>>>
>>[(0.5,)]
>> =20
>>
>>[jno@hypnos jno]$ uname -a
>>HP-UX hypnos B.11.00 U 9000/800 654339382 unlimited-user license
>>[jno@hypnos jno]$=20
>>
>>well, it is NOT DCO2, Py 2.2.2 and HP-UX 11.11 ;-)
>>
>>-jno
>>
>>=F7 =F0=D4=CE, 29.11.2002, =D7 12:57, Alexei Ustyuzhaninov =CE=C1=D0=C9=D3=
> =C1=CC:
>> =20
>>
>>>Hi!
>>>
>>>I have ran into a silly problem with DCOracle2. It returns wrong float=20
>>>numbers from SELECT statement.
>>>
>>>bash-2.04$ cat test.py
>>>import DCOracle2
>>>db =3D DCOracle2.connect("x/y@z")
>>>c =3D db.cursor()
>>>c.execute("SELECT 0.5 FROM DUAL")
>>>print c.fetchone()
>>>
>>>bash-2.04$ python test.py
>>>[3.6097722056218853]
>>>
>>>Unfortunately 0.5 is somewhat different from 3.6097722056218853.
>>>The environment is:
>>>HP-UX 11.11
>>>python 2.2.2
>>>DCOracle2 1.2
>>>
>>>Could somebody give me a tip on the problem please?

-- 
Best regards,
Alexei Ustyuzhaninov