diff --git a/pydal/adapters/db2.py b/pydal/adapters/db2.py index e0dfe348c..d5f157164 100644 --- a/pydal/adapters/db2.py +++ b/pydal/adapters/db2.py @@ -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: diff --git a/pydal/adapters/firebird.py b/pydal/adapters/firebird.py index 2615e6165..8e078874c 100644 --- a/pydal/adapters/firebird.py +++ b/pydal/adapters/firebird.py @@ -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 diff --git a/pydal/adapters/google.py b/pydal/adapters/google.py index 7701b345c..ddddd1da7 100644 --- a/pydal/adapters/google.py +++ b/pydal/adapters/google.py @@ -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): @@ -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=""): diff --git a/pydal/adapters/mongo.py b/pydal/adapters/mongo.py index 1274a44e7..cea419c6d 100644 --- a/pydal/adapters/mongo.py +++ b/pydal/adapters/mongo.py @@ -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 " @@ -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: diff --git a/pydal/adapters/mssql.py b/pydal/adapters/mssql.py index d61e6780f..f58418341 100644 --- a/pydal/adapters/mssql.py +++ b/pydal/adapters/mssql.py @@ -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") @@ -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") diff --git a/pydal/adapters/oracle.py b/pydal/adapters/oracle.py index 4eea1cf14..91b4104e3 100644 --- a/pydal/adapters/oracle.py +++ b/pydal/adapters/oracle.py @@ -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: diff --git a/pydal/adapters/postgres.py b/pydal/adapters/postgres.py index 4ddb5fa3b..5768e7e8d 100644 --- a/pydal/adapters/postgres.py +++ b/pydal/adapters/postgres.py @@ -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 diff --git a/pydal/adapters/sap.py b/pydal/adapters/sap.py index 8530c435c..60db38afe 100644 --- a/pydal/adapters/sap.py +++ b/pydal/adapters/sap.py @@ -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) diff --git a/pydal/adapters/snowflake.py b/pydal/adapters/snowflake.py index f0e12fde6..480f27328 100644 --- a/pydal/adapters/snowflake.py +++ b/pydal/adapters/snowflake.py @@ -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 diff --git a/pydal/base.py b/pydal/base.py index b64d01be6..7a6e40799 100644 --- a/pydal/base.py +++ b/pydal/base.py @@ -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) diff --git a/pydal/contrib/imap_adapter.py b/pydal/contrib/imap_adapter.py index 36db63e36..44ab52d52 100644 --- a/pydal/contrib/imap_adapter.py +++ b/pydal/contrib/imap_adapter.py @@ -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], } diff --git a/pydal/helpers/classes.py b/pydal/helpers/classes.py index ddd2798d6..743d9fc26 100644 --- a/pydal/helpers/classes.py +++ b/pydal/helpers/classes.py @@ -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: @@ -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) @@ -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("