Skip to content

Commit

Permalink
use NULL as constant instead of null
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
  • Loading branch information
Pierre Tardy committed Mar 11, 2014
1 parent f242dc4 commit 9d27b7b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 deletions.
5 changes: 3 additions & 2 deletions master/buildbot/db/__init__.py
Expand Up @@ -13,5 +13,6 @@
#
# Copyright Buildbot Team Members

# a null constant to use in sqlalchemy whereclauses e.g. (tbl.c.results == null)
null = None
# a NULL constant to use in sqlalchemy whereclauses e.g. (tbl.c.results == NULL)
# so that pep8 is happy
NULL = None
6 changes: 3 additions & 3 deletions master/buildbot/db/buildrequests.py
Expand Up @@ -17,7 +17,7 @@
import sqlalchemy as sa

from buildbot.db import base
from buildbot.db import null
from buildbot.db import NULL
from buildbot.util import datetime2epoch
from buildbot.util import epoch2datetime
from twisted.internet import reactor
Expand Down Expand Up @@ -83,11 +83,11 @@ def thd(conn):
if isinstance(claimed, bool):
if not claimed:
q = q.where(
(claims_tbl.c.claimed_at == null) &
(claims_tbl.c.claimed_at == NULL) &
(reqs_tbl.c.complete == 0))
else:
q = q.where(
(claims_tbl.c.claimed_at != null))
(claims_tbl.c.claimed_at != NULL))
else:
q = q.where(
(claims_tbl.c.masterid == claimed))
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/db/builds.py
Expand Up @@ -16,7 +16,7 @@
import sqlalchemy as sa

from buildbot.db import base
from buildbot.db import null
from buildbot.db import NULL
from buildbot.util import epoch2datetime
from buildbot.util import json
from twisted.internet import reactor
Expand Down Expand Up @@ -111,7 +111,7 @@ def thd(conn):
tbl = self.db.model.builds
q = tbl.update()
q = q.where(tbl.c.masterid == masterid)
q = q.where(tbl.c.results == None)
q = q.where(tbl.c.results == NULL)

conn.execute(q,
complete_at=_reactor.seconds(),
Expand Down
8 changes: 4 additions & 4 deletions master/buildbot/db/buildsets.py
Expand Up @@ -20,7 +20,7 @@
import sqlalchemy as sa

from buildbot.db import base
from buildbot.db import null
from buildbot.db import NULL
from buildbot.util import datetime2epoch
from buildbot.util import epoch2datetime
from buildbot.util import json
Expand Down Expand Up @@ -128,7 +128,7 @@ def thd(conn):

q = tbl.update(whereclause=(
(tbl.c.id == bsid) &
((tbl.c.complete == null) | (tbl.c.complete != 1))))
((tbl.c.complete == NULL) | (tbl.c.complete != 1))))
res = conn.execute(q,
complete=1,
results=results,
Expand Down Expand Up @@ -158,7 +158,7 @@ def thd(conn):
q = q.where(bs_tbl.c.complete != 0)
else:
q = q.where((bs_tbl.c.complete == 0) |
(bs_tbl.c.complete == null))
(bs_tbl.c.complete == NULL))
res = conn.execute(q)
return [self._thd_row2dict(conn, row) for row in res.fetchall()]
return self.db.pool.do(thd)
Expand All @@ -181,7 +181,7 @@ def thd(conn):
q = q.where(bs_tbl.c.complete != 0)
else:
q = q.where((bs_tbl.c.complete == 0) |
(bs_tbl.c.complete == null))
(bs_tbl.c.complete == NULL))
if branch:
q = q.where(ss_tbl.c.branch == branch)
if repository:
Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/db/changesources.py
Expand Up @@ -16,7 +16,7 @@
import sqlalchemy as sa

from buildbot.db import base
from buildbot.db import null
from buildbot.db import NULL
from twisted.internet import defer


Expand Down Expand Up @@ -87,9 +87,9 @@ def thd(conn):
if masterid is not None:
wc = (cs_mst_tbl.c.masterid == masterid)
elif active:
wc = (cs_mst_tbl.c.masterid != null)
wc = (cs_mst_tbl.c.masterid != NULL)
elif active is not None:
wc = (cs_mst_tbl.c.masterid == null)
wc = (cs_mst_tbl.c.masterid == NULL)

q = sa.select([cs_tbl.c.id, cs_tbl.c.name,
cs_mst_tbl.c.masterid],
Expand Down
Expand Up @@ -16,7 +16,7 @@
import migrate
import sqlalchemy as sa

from buildbot.db import null
from buildbot.db import NULL
from buildbot.util import sautils


Expand All @@ -33,7 +33,7 @@ def migrate_claims(migrate_engine, metadata, buildrequests, objects,
buildrequests.c.claimed_by_name.label("name"),
sa.literal_column("'BuildMaster'").label("class_name"),
],
whereclause=buildrequests.c.claimed_by_name != null,
whereclause=buildrequests.c.claimed_by_name != NULL,
distinct=True)

# this doesn't seem to work without str() -- verified in sqla 0.6.0 - 0.7.1
Expand All @@ -51,7 +51,7 @@ def migrate_claims(migrate_engine, metadata, buildrequests, objects,
objects.c.id.label('objectid'),
buildrequests.c.claimed_at,
], from_obj=[join],
whereclause=buildrequests.c.claimed_by_name != null)
whereclause=buildrequests.c.claimed_by_name != NULL)
migrate_engine.execute(
str(sautils.InsertFromSelect(buildrequest_claims, claims)))

Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/db/schedulers.py
Expand Up @@ -17,7 +17,7 @@
import sqlalchemy.exc

from buildbot.db import base
from buildbot.db import null
from buildbot.db import NULL
from twisted.internet import defer


Expand Down Expand Up @@ -161,9 +161,9 @@ def thd(conn):
if masterid is not None:
wc = (sch_mst_tbl.c.masterid == masterid)
elif active:
wc = (sch_mst_tbl.c.masterid != null)
wc = (sch_mst_tbl.c.masterid != NULL)
elif active is not None:
wc = (sch_mst_tbl.c.masterid == null)
wc = (sch_mst_tbl.c.masterid == NULL)

q = sa.select([sch_tbl.c.id, sch_tbl.c.name,
sch_mst_tbl.c.masterid],
Expand Down
6 changes: 3 additions & 3 deletions master/docs/developer/database.rst
Expand Up @@ -1508,13 +1508,13 @@ object, ``conn``.
.. note::

SQLAlchemy requires the use of a syntax that is forbidden by pep8.
If in where clauses you need to select rows where a value is null,
If in where clauses you need to select rows where a value is NULL,
you need to write (`tbl.c.value == None`). This form is forbidden by pep8
which requires the use of `is None` instead of `== None`. As sqlalchemy is using operator
overloading to implement pythonic SQL statements, and `is` operator is not overloadable,
we need to keep the `==` operators. In order to solve this issue, buildbot
uses `buildbot.db.null` constant, which is `None`.
So instead of writting `tbl.c.value == None`, please write `tbl.c.value == null`)
uses `buildbot.db.NULL` constant, which is `None`.
So instead of writting `tbl.c.value == None`, please write `tbl.c.value == NULL`)


.. py:class:: DBThreadPool
Expand Down

0 comments on commit 9d27b7b

Please sign in to comment.