rfid mysql查询到python

2024-09-27 01:29:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用Rfid的老php系统。我们有一个转换Rfid代码的sql查询。我将PHP系统改为odoo11这里是SQL查询

UPDATE members set member_id=100000*floor(fob_id/65536)+(fob_id%65536)

它基本上是fob id乘以100000再除以65536 但后来他们发现,如果离岸价以7或9结尾,我想是计算错误了,所以地板部分总是四舍五入,除以它们后,剩余部分加上百分比。(我想是这样的)

如何在Python中获得与上述查询相同的结果(pythonversion3.5)

这是我的密码

@api.onchange('barcode2')
def _onchange_barcode2(self):
    self.barcode = (self.barcode2)
    a = (self.barcode2) * 100000 
    fob = (math.floor(a)) /65536 +(self.barcode2)%65536
    self.memberid = fob

我有一个rfid号码0005225306,这应该是07947962,但与上述代码我得到8021146。你知道吗

我使用的%运算符正确吗?如果我在使用MySQLUPDATE members set member_id=100000*floor(fob_id/65536)+(fob_id%65536)的旧PHP系统中输入0005225306,它将给出正确的值07947962。你知道吗

知道为什么我的python代码没有得到相同的值吗?你知道吗


Tags: 代码selfidsql系统rfidmemberphp
1条回答
网友
1楼 · 发布于 2024-09-27 01:29:03

我不知道你的barcode*字段和它们的数据类型,但是在解析它们时会很在意。这些计算的顺序很重要:

@api.onchange('barcode2')
def _onchange_barcode2(self):
    # let's suppose the barcode fields are strings
    # because of leading zeros
    self.barcode = self.barcode2
    try:
        barcode_int = int(self.barcode2)
        fob = math.floor(barcode_int / 65536)
        fob = int((fob * 100000) + barcode_int % 65536)
        # let's suppose memberid is a char field
        self.memberid = '{:08d}'.format(fob)
    except:
        # handle parse problems eg. Odoo Warning

相关问题 更多 >

    热门问题