Menu

#71 [Python] Fetchone get numeric data's type is not correct

open
nobody
None
5
2012-02-01
2012-02-01
Jira Trac
No

# Brief:
## Use fetchone method to get numeric data from db, including float,double,numeric and monetary, but the return data type is string.
# Test Steps:
## insert a double data 1.1 into table
## select the data and check it
# Result:
## Expect result is 1.1
## Actual result is '1.1'
# Code reference:
{noformat}
import CUBRIDdb
import unittest

class FetchoneTest(unittest.TestCase):
def test_numeric(self):
print test_num
self.con = CUBRIDdb.connect(CUBRID:localhost:33000:demodb, dba,)
self.cur = self.con.cursor()
sqlCreate = create table numeric_db(c_int int, c_short short,c_numeric numeric,c_float float,c_double double,c_monetary monetary)
self.cur.execute(sqlCreate)
data1 = 1.1
sqlInsert = insert into numeric_db(c_double) values ( +'%s'%data1 +)
self.cur.execute(sqlInsert)
sqlSelect = select * from numeric_db
self.cur.execute(sqlSelect)
data2 = self.cur.fetchone()
self.assertEquals(data1, data2[4])

if __name__ == '__main__':
unittest.main()
{noformat}

Discussion

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.