Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value transfered to next row when Null #23

Open
RomainDGrey opened this issue Jul 15, 2023 · 5 comments
Open

Value transfered to next row when Null #23

RomainDGrey opened this issue Jul 15, 2023 · 5 comments

Comments

@RomainDGrey
Copy link

RomainDGrey commented Jul 15, 2023

Hello all,

When I try to fetchall the result from a select request, some rows, with null values, shows value from previous line.

Context:

  • I am using a HFSQL Database and the driver of the same name, developed by the WinDev company for it.
  • Python3.11
  • pypyodbc version 1.3.6

Example:

import pypyodbc
DB_URI="DRIVER={HFSQL};Server Name=some.server;Server Port=4900; Database=some_database;UID=admin;PWD=some_pass"
conn = pypyodbc.connect(DB_URI)
cursor = conn.cursor()
result = cursor.execute("SELECT CODE from CWS_BASE WHERE id in ('66783')")
result.fetchall()
result = cursor.execute("SELECT CODE from CWS_BASE WHERE id in ('120140', '66783')")
result.fetchall() 

Output:

[('',)]
[('BLOCAGE',), ('BLOCAGE',)]

Is it linked to the driver or is it linked to the parsing feature of pypyodbc ?

@RomainDGrey
Copy link
Author

RomainDGrey commented Jul 15, 2023

After more investigation, it seems that it's not link to the driver as this powershell script sucessfully retrieve the information :

---
(venv) PS C:\Users\R\Documents\projects\test> $result =(new-Object Data.Odbc.OdbcCommand("SELECT CODE from CWS_BASE WHERE id in ('120140','66783')",$conn)).ExecuteReader()
(venv) PS C:\Users\R\Documents\projects\test> while ($result.Read()) {
>>     $value = $result.GetValue(0)
>>     Write-Output $value
>> }
BLOCAGE 

---

How can I check where in pypyodbc where the value is added if it contains nothing ?

@Replect
Copy link

Replect commented Jun 20, 2024

Did you potentially find a solution for this?
I just realized we have the same issue (also HFSQL server, pypodbc version 1.3.6)... doesn't seem like there has been a new version to this library since...

It might happen somewhere within the fetchone function of pypodbc, based on what I've seen.

@RomainDGrey
Copy link
Author

@Replect Test the 1.3.x branch, from what I remember it fixes my issue

@Replect
Copy link

Replect commented Jun 20, 2024

You mean a previous version to 1.3.6?

EDIT: The branch 1.3.x didn't solve the issue. Or is there anything else to replace beside the pypyodbc.py?

@Replect
Copy link

Replect commented Jun 21, 2024

Okay, I didn't see any version of the pypyodbc.py here to fix the issue, but I think we got it resolved via the following adjustment in the pypyodbc.py (version 1.3.6):

At line 1883, replace the following code:

if used_buf_len.value == SQL_NULL_DATA:
    value_list.append(None)
else:
    if raw_data_parts == []:

with this:

if used_buf_len.value <= SQL_NULL_DATA:
    value_list.append(None)
elif used_buf_len.value == 0:
    value_list.append('')
else:
    if raw_data_parts == []:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants