jangbagu / pypyodbc

Automatically exported from code.google.com/p/pypyodbc
0 stars 0 forks source link

Connecting fails on narrow build of Python #22

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Compile Python with default settings (i.e. narrow)
2. Try to connect via ODBC

What is the expected output? What do you see instead?

Narrow builds use "ucs2_buf = lambda s: s" while wide builds have 
"s.encode('utf_16_le')". This seems to cause problems, although I don't know 
why. Trying to connect with a narrow Python ends with the following error:

  File "/home/tpievila/.virtualenvs/reservedusage/lib/python2.7/site-packages/pypyodbc.py", line 2285, in __init__
    self.connect(connectString, autocommit, ansi, timeout, unicode_results, readonly)
  File "/home/tpievila/.virtualenvs/reservedusage/lib/python2.7/site-packages/pypyodbc.py", line 2333, in connect
    check_success(self, ret)
  File "/home/tpievila/.virtualenvs/reservedusage/lib/python2.7/site-packages/pypyodbc.py", line 951, in check_success
    ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi)
  File "/home/tpievila/.virtualenvs/reservedusage/lib/python2.7/site-packages/pypyodbc.py", line 931, in ctrl_err
    raise DatabaseError(state,err_text)
pypyodbc.DatabaseError: (u'\U000d0049\U001000302', u'[\U000d0049\U001000302] 
\udd00\udc5b\U0009006e\U000f0078\U00020044\udf00\udc43\U0004005b\U00090072\U0005
0076\udfc0\udc72\U0001004d\U0001006e\U00050067\udf00\udc72\U00010044\U00010074\u
dc80\udc20\udd00\udc6f\U00030072\udfc0\udc65\U0001006e\U0005006d\U000e0020\udcc0
\udc6f\U00060020\udd00\udc6f\U0004006e\udfc0\udc2c\U000e0061\udfc0\udc64\U000f00
6e\U00040020\U00060065\udd00\udc61\udcc0\udc6c\U00040020\U00090072\U00050076\udf
c0\udc72\U00100073\U00030065\U00060069\U00050069d')

What version of the product are you using? On what operating system?

1.1.5 on Python 2.6/2.7, RHEL6.

Original issue reported on code.google.com by hu...@kapsi.fi on 20 Aug 2013 at 7:23

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Please run the attached pypyodbc, it will print out the buffer of the encoded 
unicode strings, so we can see how to decode the strings.

Please post the outputs and the exceptions.

Original comment by jiangwen...@gmail.com on 25 Aug 2013 at 2:54

Attachments:

GoogleCodeExporter commented 8 years ago
Hello I got the same issue trying to connect to a Oracle Database.
1.1.3 on Python 2.7, CentOS 6.4 64bits

Below the error:
In [2]:  conect = 
pypyodbc.connect('''Driver=FreeTDS;Server=10.1.1.1;port=1433;uid=user;pwd=pass;d
atabase=test''')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-bc4f1e15f4f6> in <module>()
----> 1 conect = 
pypyodbc.connect('''Driver=FreeTDS;Server=10.1.1.1;port=1433;uid=user;pwd=pass;d
atabase=test''')

/tmp/pypyodbc.py in __init__(self, connectString, autocommit, ansi, timeout, 
unicode_results, readonly, **kargs)
   2287         check_success(self, ret)
   2288 
-> 2289         self.connect(connectString, autocommit, ansi, timeout, 
unicode_results, readonly)
   2290 
   2291 

/tmp/pypyodbc.py in connect(self, connectString, autocommit, ansi, timeout, 
unicode_results, readonly)
   2335         else:
   2336             ret = odbc_func(self.dbc_h, 0, c_connectString, len(self.connectString), None, 0, None, SQL_DRIVER_NOPROMPT)
-> 2337         check_success(self, ret)
   2338 
   2339 

/tmp/pypyodbc.py in check_success(ODBC_obj, ret)
    953             ctrl_err(SQL_HANDLE_STMT, ODBC_obj.stmt_h, ret, ODBC_obj.ansi)
    954         elif isinstance(ODBC_obj, Connection):
--> 955             ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi)
    956         else:
    957             ctrl_err(SQL_HANDLE_ENV, ODBC_obj, ret, False)

/tmp/pypyodbc.py in ctrl_err(ht, h, val_ret, ansi)
    911         ret = ODBC_func(ht, h, number_errors, state, \
    912             ADDR(NativeError), Message, 1024, ADDR(Buffer_len))
--> 913         debug = state.raw
    914         print (debug)
    915         if ret == SQL_NO_DATA_FOUND:

AttributeError: 'c_wchar_Array_36' object has no attribute 'raw'

Original comment by dan...@idev.com.br on 2 Sep 2013 at 5:56

GoogleCodeExporter commented 8 years ago
Issue 11 has been merged into this issue.

Original comment by jiangwen...@gmail.com on 3 Sep 2013 at 11:35

GoogleCodeExporter commented 8 years ago
I get exactly the same output as danilo@idev.com.br

Original comment by cyborg10...@gmail.com on 3 Sep 2013 at 1:45

GoogleCodeExporter commented 8 years ago
Using 1.1.6dev

In [2]: pypyodbc.version
Out[2]: '1.1.6dev'

In [3]:  conect = 
pypyodbc.connect('''Driver=FreeTDS;Server=10.1.1.1;port=1433;uid=user;pwd=pass;d
atabase=test''')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-bc4f1e15f4f6> in <module>()
----> 1 conect = 
pypyodbc.connect('''Driver=FreeTDS;Server=10.1.1.1;port=1433;uid=user;pwd=pass;d
atabase=test''')

/tmp/pypyodbc.pyc in __init__(self, connectString, autocommit, ansi, timeout, 
unicode_results, readonly, **kargs)
   2287         check_success(self, ret)
   2288 
-> 2289         self.connect(connectString, autocommit, ansi, timeout, 
unicode_results, readonly)
   2290 
   2291 

/tmp/pypyodbc.pyc in connect(self, connectString, autocommit, ansi, timeout, 
unicode_results, readonly)
   2335         else:
   2336             ret = odbc_func(self.dbc_h, 0, c_connectString, len(self.connectString), None, 0, None, SQL_DRIVER_NOPROMPT)
-> 2337         check_success(self, ret)
   2338 
   2339 

/tmp/pypyodbc.pyc in check_success(ODBC_obj, ret)
    953             ctrl_err(SQL_HANDLE_STMT, ODBC_obj.stmt_h, ret, ODBC_obj.ansi)
    954         elif isinstance(ODBC_obj, Connection):
--> 955             ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi)
    956         else:
    957             ctrl_err(SQL_HANDLE_ENV, ODBC_obj, ret, False)

/tmp/pypyodbc.pyc in ctrl_err(ht, h, val_ret, ansi)
    911         ret = ODBC_func(ht, h, number_errors, state, \
    912             ADDR(NativeError), Message, 1024, ADDR(Buffer_len))
--> 913         debug = state.raw
    914         print (debug)
    915         if ret == SQL_NO_DATA_FOUND:

AttributeError: 'c_wchar_Array_36' object has no attribute 'raw'

Original comment by dan...@idev.com.br on 3 Sep 2013 at 8:33

GoogleCodeExporter commented 8 years ago
Dear all, please have a try with the attached pypyodbc.py

Original comment by jiangwen...@gmail.com on 6 Sep 2013 at 3:57

Attachments:

GoogleCodeExporter commented 8 years ago
Hello,
Don't return a error now but seems to be a infinite loop.

In [5]: conect = 
pypyodbc.connect('''Driver=FreeTDS;Server=10.0.0.1;port=1433;uid=user;pwd=pass;d
atabase=MYDB''')
08S01

Original comment by dan...@idev.com.br on 6 Sep 2013 at 1:06

GoogleCodeExporter commented 8 years ago
Hi, the infinite loop should be fixed by this update. Please have a try.

Original comment by jiangwen...@gmail.com on 6 Sep 2013 at 1:15

Attachments:

GoogleCodeExporter commented 8 years ago
This revision works for me!  Thanks.  Will it be merged with the trunk?

Original comment by cyborg10...@gmail.com on 6 Sep 2013 at 1:19

GoogleCodeExporter commented 8 years ago
Yes, I will merge it after some more test and see other people's feed back.

You were testing the last version, right?

Original comment by jiangwen...@gmail.com on 6 Sep 2013 at 1:25

GoogleCodeExporter commented 8 years ago
I was using the version in comment 11

Original comment by cyborg10...@gmail.com on 6 Sep 2013 at 1:28

GoogleCodeExporter commented 8 years ago
Hello,

With last version is working, thanks!

Original comment by dan...@idev.com.br on 6 Sep 2013 at 1:36

GoogleCodeExporter commented 8 years ago
But I row name attributes aren't set.

For example:

cursor.execute("SELECT * FROM myTable WHERE 1;")

rows = cursor.fetchall()

for row in rows:
    print row.id

AttributeError: 'Row' object has no attribute 'id'

Instead, I have to do 

for row in rows:
    print row[0]

1
2
3
4
5

..etc..

Original comment by cyborg10...@gmail.com on 9 Sep 2013 at 8:29

GoogleCodeExporter commented 8 years ago
This is not supported by pypyodbc, reason is explained here: 
https://code.google.com/p/pypyodbc/issues/detail?id=10

In stead, pypyodbc offers row['id']

And, version 1.2.0 has been uploaded which contains the fix of this thread.

Original comment by jiangwen...@gmail.com on 21 Sep 2013 at 11:16