jakesylvestre / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

A string returned by SELECT behaves strange when used with format() #375

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. SELECT somestring FROM sometable WHERE somecondition
2. "{:80.80s}".format(somestring) returns blank line
3. print(somestring) shows the string
4. Repeating step 2 now works

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

Expect repeating calls to format() to work the same. 
In this case format only works after string was altered or printed

What version of the product are you using? On what operating system?
OS: Windows 7
Database: MSSQL
Reproduced on two different installations:
SETUP 1:
   python-3.3.4.amd64.msi
   pyodbc-3.0.7.win-amd64-py3.3.exe
SETUP 2:
   Python 3.3.5rc1
   pyodbc-3.0.7.win32-py3.3.exe

I reproduced the problem both from IDLE and stand-alone script.

Please provide any additional information below.

My IDLE session:

>>> import pyodbc
>>> dbh = pyodbc.connect(driver='{SQL Server}', server='someserver', 
database='somedb', uid=secretuid, pwd=secretpwd)
>>> dbc=dbh.cursor()
>>> dbc.execute('select message_txt from ecampaign where campaign_id = ?', 
1190788)
<pyodbc.Cursor object at 0x032A86B0>
>>> for row in dbc:
    val = row.message_txt

>>> "{:40.40s}".format(val)
'                                        '
>>> "{:40.40s}".format(val)
'                                        '
>>> val[:40]
'The following is information about new p'
>>> "{:40.40s}".format(val)
'The following is information about new p'
>>> "{:40.40s}".format(val)
'The following is information about new p'
>>> 

Also any other string operations on val, including "{:s}".format(val) works and 
triggers subsequent formats to work.

>>> len(val)
4240
>>> type(val)
<class 'str'>

Original issue reported on code.google.com by Shompol@gmail.com on 10 Jul 2014 at 10:24