sqlanywhere / sqlanydb

Python driver for SAP Sybase SQL Anywhere
Other
43 stars 20 forks source link

Pack fail with big number with argument out of range #27

Open EDRossi opened 2 years ago

EDRossi commented 2 years ago

trying to use a Numeric(11) the package fail when trying to pack

sqlanydb.py line 430

        size = param.value.buffer_size
        buffer = create_string_buffer(value)
    else:
        buffer = **create_string_buffer(pack(fmt, value))**
        size = length = calcsize(fmt)
    param.value.buffer = cast(buffer, POINTER(c_char))

image

i am using flask and sqlalchemy

EDRossi commented 2 years ago

i tryed to use bigint ending with the same result

hynek commented 8 months ago

This is btw not just some ORM problem. I've just run into the same problem with raw SQL and had to transform the numbers into strings first:

  File "/Users/hynek/Work/mailbox-usage-svc/src/mailbox_usage_svc/adapters/repositories.py", line 70, in update_mailbox
    self.cursor.execute(
  File "/Users/hynek/Work/mailbox-usage-svc/.venv/lib/python3.12/site-packages/sqlanydb.py", line 840, in execute
    self.executemany(operation, [parameters])
  File "/Users/hynek/Work/mailbox-usage-svc/.venv/lib/python3.12/site-packages/sqlanydb.py", line 814, in executemany
    parms = [bind(k, col)
             ^^^^^^^^^^^^
  File "/Users/hynek/Work/mailbox-usage-svc/.venv/lib/python3.12/site-packages/sqlanydb.py", line 803, in bind
    (self.assign)(param, col)
  File "/Users/hynek/Work/mailbox-usage-svc/.venv/lib/python3.12/site-packages/sqlanydb.py", line 437, in assign
    buffer = create_string_buffer(pack(fmt, value))
                                  ^^^^^^^^^^^^^^^^^
struct.error: 'i' format requires -2147483648 <= number <= 2147483647

The type of the field is bigint.

@DanCummins-SAP any chance of this being addressed? Not being able to insert big numbers into a database is kinda big deal.

DanCummins-SAP commented 8 months ago

@DanCummins-SAP any chance of this being addressed? Not being able to insert big numbers into a database is kinda big deal.

Hi Hynek, Thanks for the report, we have added it to our backlog. Dan

hynek commented 7 months ago

This is fixed in 1.0.14.