0

I am trying to do a little bit of math in in a sqlite call. I have two columns that I want to add their value then check to see if they are less than a value that I input.

    c = self.db.cursor()
    c.execute("BEGIN EXCLUSIVE TRANSACTION");
    c.execute("SELECT ID as id,task FROM tube WHERE state=0 OR (state=1 & ts+ttr<? ) ORDER BY ID ASC LIMIT 1", (time.time(),))
    task = c.fetchone()
    print task
    if task != None:
        ts = time.time();
        c.execute("UPDATE tube SET state=1,ts=? WHERE ID=?", (ts, task['id']))
        task['ts'] = ts
    else:
        task = None

    self.db.commit()
    return task

From what I can tell its not doing this operation. It still returns a row but not based on the logic I am providing.

8
  • you should post more python code Commented Sep 11, 2013 at 12:42
  • @FoxMaSk added more code for u Commented Sep 11, 2013 at 12:46
  • do you use Bottle or Flask ? to try to understand what could be returned by c.fetchone() and then if it's possible to modify it on the fly by adding ts to it. Commented Sep 11, 2013 at 12:53
  • @FoxMaSk i am not use ethier just torando Commented Sep 11, 2013 at 12:55
  • so what's look like the def fetchone() ? as I dont see yet a known ORM that provides this function Commented Sep 11, 2013 at 13:01

1 Answer 1

4

You are using the bitwise and operator & where you probably want a logical AND.

The bitwise operators have higher precedence that the comparisons (=, <), while the logical ones have lower. Therefore state=1 & ts+ttr<? is very different from state=1 AND ts+ttr<?

Sign up to request clarification or add additional context in comments.

1 Comment

I think i see what you mean Its been while since i wrote sql

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.