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

A question about the CHAR field of oracle in the PonyORM #734

Open
lypch opened this issue Nov 27, 2024 · 0 comments
Open

A question about the CHAR field of oracle in the PonyORM #734

lypch opened this issue Nov 27, 2024 · 0 comments

Comments

@lypch
Copy link

lypch commented Nov 27, 2024

I used PonyORM with an Oracle provider and found that it does not support the CHAR type of ORACLE well.

For example, I have a field whose type is CHAR(15). When I fill it up with the value 1234567890 after saving it into this field, the Oracle will add padding space after the value, like '1234567890 '.

If I use other SQL tools to search with this field as the condition, there is no need to add padding space after the value, but PonyORM can not. For example:

# Model definition
class Item(db.Entity):
    _table_ = 'ITEMM'
    fitemno = PrimaryKey(str, 15, autostrip=False)
    fitemtyp = Required(str, 1)

The first case

from pony.orm import db_session, set_sql_debug,select

from oracle_pony.models import Item

@db_session
def test():
    set_sql_debug(True, show_values=True)
    item = '0035931-3'
    query_set = select(x for x in Item if x.fitemno == item)
    for x in query_set:
        print(x)

if __name__ == '__main__':
    test()
# running result: can not find the record
GET CONNECTION
SELECT "x"."FITEMNO", "x"."FITEMTYP"
FROM "ITEMM" "x"
WHERE "x"."FITEMNO" = :p1
{'p1':'0035931-3'}

COMMIT
RELEASE CONNECTION

The second case

from pony.orm import db_session, set_sql_debug,select

from oracle_pony.models import Item

@db_session
def test():
    set_sql_debug(True, show_values=True)
    item = '0035931-3      '
    query_set = select(x for x in Item if x.fitemno == item)
    for x in query_set:
        print(x)

if __name__ == '__main__':
    test()
# running result: can find the record.
GET CONNECTION
SELECT "x"."FITEMNO", "x"."FITEMTYP"
FROM "ITEMM" "x"
WHERE "x"."FITEMNO" = :p1
{'p1':'0035931-3      '}

Item['0035931-3']
COMMIT
RELEASE CONNECTION

and I found if I use textual value, no problem

from pony.orm import db_session, set_sql_debug,select

from oracle_pony.models import Item

@db_session
def test():
    set_sql_debug(True, show_values=True)
    # item = '0035931-3      '
    query_set = select(x for x in Item if x.fitemno == '0035931-3')
    for x in query_set:
        print(x)

if __name__ == '__main__':
    test()
GET CONNECTION
SELECT "x"."FITEMNO", "x"."FITEMTYP"
FROM "ITEMM" "x"
WHERE "x"."FITEMNO" = '0035931-3'

Item['0035931-3']
COMMIT
RELEASE CONNECTION

I want to know how to solve this issue, is there any parameter can solve my question?

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

1 participant