Skip to content

Commit

Permalink
better IS_NOT_IN_DB and removed long
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Dec 7, 2024
1 parent 3899b29 commit 57bec7d
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion pydal/adapters/db2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def lastrowid(self, table):
if table._rname
else table
)
return long(self.cursor.fetchone()[0])
return int(self.cursor.fetchone()[0])

def rowslice(self, rows, minimum=0, maximum=None):
if maximum is None:
Expand Down
2 changes: 1 addition & 1 deletion pydal/adapters/firebird.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_connection(self):
def lastrowid(self, table):
sequence_name = table._sequence_name
self.execute("SELECT gen_id(%s, 0) FROM rdb$database" % sequence_name)
return long(self.cursor.fetchone()[0])
return int(self.cursor.fetchone()[0])

def create_sequence_and_triggers(self, query, table, **args):
tablename = table._rname
Expand Down
8 changes: 5 additions & 3 deletions pydal/adapters/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,15 @@ def count(self, query, distinct=None, limit=None):
return 0

def delete(self, table, query):
counter = 0
while self.db(query).count() > 0:
docs = list(self.get_docs(table, query))
batch = self._client.batch()
counter = 0
for doc in docs:
batch.delete(doc.reference)
counter += 1
batch.commit()
if counter:
batch.commit()
return counter

def update(self, table, query, update_fields):
Expand All @@ -336,7 +337,8 @@ def update(self, table, query, update_fields):
for doc in docs:
batch.update(doc.reference, {f.name: v for f, v in update_fields})
counter += 1
batch.commit()
if counter:
batch.commit()
return counter

def truncate(self, table, mode=""):
Expand Down
4 changes: 2 additions & 2 deletions pydal/adapters/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def object_id(self, arg=None):
elif isinstance(arg, self.ObjectId):
return arg
elif isinstance(arg, (Row, Reference)):
return self.object_id(long(arg["id"]))
return self.object_id(int(arg["id"]))
elif not isinstance(arg, (int, long)):
raise TypeError(
"object_id argument must be of type ObjectId or an objectid "
Expand Down Expand Up @@ -464,7 +464,7 @@ def insert(self, table, fields, safe=None):

if result.acknowledged:
Oid = result.inserted_id
rid = Reference(long(str(Oid), 16))
rid = Reference(int(str(Oid), 16))
(rid._table, rid._record) = (table, None)
return rid
else:
Expand Down
4 changes: 2 additions & 2 deletions pydal/adapters/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def connector(self):

def lastrowid(self, table):
self.execute("SELECT SCOPE_IDENTITY();")
return long(self.cursor.fetchone()[0])
return int(self.cursor.fetchone()[0])


@adapters.register_for("mssql")
Expand Down Expand Up @@ -174,7 +174,7 @@ def connector(self):
class Vertica(MSSQL1):
def lastrowid(self, table):
self.execute("SELECT SCOPE_IDENTITY();")
return long(self.cursor.fetchone()[0])
return int(self.cursor.fetchone()[0])


@adapters.register_for("sybase")
Expand Down
2 changes: 1 addition & 1 deletion pydal/adapters/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def execute(self, *args, **kwargs):
def lastrowid(self, table):
sequence_name = table._sequence_name
self.execute("SELECT %s.currval FROM dual;" % sequence_name)
return long(self.cursor.fetchone()[0])
return int(self.cursor.fetchone()[0])

def sqlsafe_table(self, tablename, original_tablename=None):
if original_tablename is not None:
Expand Down
4 changes: 2 additions & 2 deletions pydal/adapters/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ def after_connection(self):

def lastrowid(self, table):
if self._last_insert:
return long(self.cursor.fetchone()[0])
return int(self.cursor.fetchone()[0])
sequence_name = table._sequence_name
self.execute("SELECT currval(%s);" % self.adapt(sequence_name))
return long(self.cursor.fetchone()[0])
return int(self.cursor.fetchone()[0])

def _insert(self, table, fields):
self._last_insert = None
Expand Down
2 changes: 1 addition & 1 deletion pydal/adapters/sap.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def connector(self):

def lastrowid(self, table):
self.execute("select %s.NEXTVAL from dual" % table._sequence_name)
return long(self.cursor.fetchone()[0])
return int(self.cursor.fetchone()[0])

def create_sequence_and_triggers(self, query, table, **args):
self.execute("CREATE SEQUENCE %s;" % table._sequence_name)
Expand Down
4 changes: 2 additions & 2 deletions pydal/adapters/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ def connector(self):

def lastrowid(self, table):
if self._last_insert:
return long(self.cursor.fetchone()[0])
return int(self.cursor.fetchone()[0])
sequence_name = table._sequence_name
self.execute("SELECT currval(%s);" % self.adapt(sequence_name))
return long(self.cursor.fetchone()[0])
return int(self.cursor.fetchone()[0])

def _insert(self, table, fields):
self._last_insert = None
Expand Down
2 changes: 1 addition & 1 deletion pydal/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ def represent(self, name, *args, **kwargs):
return self.representers[name](*args, **kwargs)

def export_to_csv_file(self, ofile, *args, **kwargs):
step = long(kwargs.get("max_fetch_rows", 500))
step = int(kwargs.get("max_fetch_rows", 500))
write_colnames = kwargs["write_colnames"] = kwargs.get("write_colnames", True)
for table in self.tables:
ofile.write("TABLE %s\r\n" % table)
Expand Down
2 changes: 1 addition & 1 deletion pydal/contrib/imap_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ def select(self, query, fields, attributes):
if typ == "OK":
fr = {
"message": int(data[0][0].split()[0]),
"uid": long(uid),
"uid": int(uid),
"email": email.message_from_string(data[0][1]),
"raw_message": data[0][1],
}
Expand Down
8 changes: 4 additions & 4 deletions pydal/helpers/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def __allocate(self):

def __getattr__(self, key, default=None):
if key == "id":
return long(self)
return int(self)
if key in self._table:
self.__allocate()
if self._record:
Expand All @@ -222,7 +222,7 @@ def __setattr__(self, key, value):

def __getitem__(self, key):
if key == "id":
return long(self)
return int(self)
self.__allocate()
return self._record.get(key, None)

Expand All @@ -237,9 +237,9 @@ def Reference_unpickler(data):

def Reference_pickler(data):
try:
marshal_dump = marshal.dumps(long(data))
marshal_dump = marshal.dumps(int(data))
except AttributeError:
marshal_dump = "i%s" % struct.pack("<i", long(data))
marshal_dump = "i%s" % struct.pack("<i", int(data))
return (Reference_unpickler, (marshal_dump,))


Expand Down
2 changes: 1 addition & 1 deletion pydal/helpers/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def to_num(num):
result = 0
try:
result = long(num)
result = int(num)
except NameError as e:
result = int(num)
return result
Expand Down
12 changes: 6 additions & 6 deletions pydal/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __int__(self):
return self.get("id")

def __long__(self):
return long(int(self))
return int(int(self))

def __hash__(self):
return id(self)
Expand Down Expand Up @@ -199,7 +199,7 @@ def as_dict(self, datetime_to_str=False, custom_types=None):
elif isinstance(v, Row):
d[k] = v.as_dict()
elif isinstance(v, Reference):
d[k] = long(v)
d[k] = int(v)
elif isinstance(v, decimal.Decimal):
d[k] = float(v)
elif isinstance(v, DT_INST):
Expand Down Expand Up @@ -1123,7 +1123,7 @@ def fix(field, value, id_map, id_offset):
if not value.strip():
value = None
else:
value = long(value)
value = int(value)
elif field.type.startswith("list:string"):
value = bar_decode_string(value)
elif field.type.startswith(list_reference_s):
Expand All @@ -1143,7 +1143,7 @@ def fix(field, value, id_map, id_offset):
pass
elif id_offset and field.type.startswith("reference"):
try:
value = id_offset[field.type[9:].strip()] + long(value)
value = id_offset[field.type[9:].strip()] + int(value)
except KeyError:
pass
return value
Expand Down Expand Up @@ -1187,7 +1187,7 @@ def is_id(colname):
if field.type != "id":
ditems[fieldname] = value
else:
csv_id = long(value)
csv_id = int(value)
except ValueError:
raise RuntimeError("Unable to parse line:%s" % (lineno + 1))
if not (id_map or csv_id is None or id_offset is None or unique_idx):
Expand Down Expand Up @@ -3211,7 +3211,7 @@ def none_exception(value):
elif PY2 and isinstance(value, unicode):
return value.encode("utf8")
elif isinstance(value, Reference):
return long(value)
return int(value)
elif hasattr(value, "isoformat"):
return value.isoformat()[:19].replace("T", " ")
elif isinstance(value, (list, tuple)): # for type='list:..'
Expand Down
4 changes: 2 additions & 2 deletions pydal/parsers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
class BasicParser(Parser):
@for_type("id")
def _id(self, value):
return long(value)
return int(value)

@for_type("integer")
def _integer(self, value):
return long(value)
return int(value)

@for_type("float")
def _float(self, value):
Expand Down
6 changes: 3 additions & 3 deletions pydal/parsers/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class MongoParser(Parser):
@for_type("id")
def _id(self, value):
if isinstance(value, self.adapter.ObjectId):
return long(str(value), 16)
return long(value)
return int(str(value), 16)
return int(value)

@for_type("blob")
def _blob(self, value):
Expand All @@ -27,7 +27,7 @@ def reference_extras(self, field_type):
@for_type("reference")
def _reference(self, value, referee):
if isinstance(value, self.adapter.ObjectId):
value = long(str(value), 16)
value = int(str(value), 16)
if "." not in referee:
value = Reference(value)
value._table, value._record = self.adapter.db[referee], None
Expand Down
16 changes: 8 additions & 8 deletions pydal/representers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def _boolean(self, value):

@for_type("id", adapt=False)
def _id(self, value):
return str(long(value))
return str(int(value))

@for_type("integer", adapt=False)
def _integer(self, value):
return str(long(value))
return str(int(value))

@for_type("decimal", adapt=False)
def _decimal(self, value):
Expand Down Expand Up @@ -137,7 +137,7 @@ def reference_extras(self, field_type):
@for_type("reference", adapt=False)
def _reference(self, value, referenced):
if referenced in self.adapter.db.tables:
return str(long(value))
return str(int(value))
p = referenced.partition(".")
if p[2] != "":
try:
Expand All @@ -147,7 +147,7 @@ def _reference(self, value, referenced):
return repr(value)
elif isinstance(value, (Row, Reference)):
return str(value["id"])
return str(long(value))
return str(int(value))

@for_type("blob", encode=True)
def _blob(self, value):
Expand Down Expand Up @@ -185,15 +185,15 @@ def _repr_list(self, value, field_type):

@for_type("id")
def _id(self, value):
return long(value)
return int(value)

@for_type("integer")
def _integer(self, value):
return long(value)
return int(value)

@for_type("bigint")
def _bigint(self, value):
return long(value)
return int(value)

@for_type("double")
def _double(self, value):
Expand All @@ -203,7 +203,7 @@ def _double(self, value):
def _reference(self, value):
if isinstance(value, (Row, Reference)):
value = value["id"]
return long(value)
return int(value)

@for_type("boolean")
def _boolean(self, value):
Expand Down
2 changes: 1 addition & 1 deletion pydal/representers/couchdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def adapt(self, value):

@for_type("id")
def _id(self, value):
return str(long(value))
return str(int(value))

@for_type("reference", adapt=False)
def _reference(self, value):
Expand Down
8 changes: 4 additions & 4 deletions pydal/representers/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def _json(self, value):
return value

@for_type("blob")
def _json(self, value):
def _blob(self, value):
return base64.b64decode(value)

@for_type("reference")
def _json(self, value):
def _reference(self, value):
return str(value)

@for_type("list:integer")
Expand All @@ -50,6 +50,6 @@ def _list_string(self, value):
@for_type("list:reference")
def _list_reference(self, value):
if not isinstance(value, list):
return long(value)
return str(value)
values = self._represent_list(value)
return list(map(long, values))
return list(map(str, values))
Loading

0 comments on commit 57bec7d

Please sign in to comment.