Ejemplo n.º 1
0
	def get_last_id(self, adapter, table, primary_key, list_data):
		# nothing synced for this list
		if not (list_data.last_inserted_id and list_data.status and list_data.inserted_rows and list_data.rows_to_be_inserted):
			last_inserted_id = 0
		elif list_data.last_inserted_id:
			last_inserted_id = list_data.last_inserted_id
		else:
			last_inserted_id = adapter.get_last_inserted_id(table, primary_key, "first")

		return last_inserted_id
Ejemplo n.º 2
0
    def _get_last_inserted_id(self, list_data, table, primary_key):
        # nothing synced for this list
        if not (list_data.last_inserted_id and list_data.status
                and list_data.inserted_rows and list_data.rows_to_be_inserted):
            last_inserted_id = 0
        elif list_data.last_inserted_id:
            last_inserted_id = list_data.last_inserted_id
        else:
            last_inserted_id = adapter.get_last_inserted_id(
                table, primary_key, "first")

        return last_inserted_id
Ejemplo n.º 3
0
	def sync(self, details_id):
		database_data = database_table.find_detail(details_id)
		provider_data = provider_table.find_detail(details_id)
		list_data = lists_table.find_detail(details_id)
		columns_data = columns_table.find_details(details_id)

		adapter.setup(self.get_driver(database_data))

		table = database_data.table
		primary_key = adapter.get_primary_key(table)

		columns = self.get_columns(columns_data)

		if primary_key and adapter.is_valid_connection():
			last_inserted_id = self.get_last_id(adapter, table, primary_key, list_data)
			rows_to_be_inserted = adapter.get_rows_to_be_inserted(table, columns, primary_key, last_inserted_id)
			number_of_rows = len(rows_to_be_inserted)

			if self.status("Completed", list_data) and number_of_rows == 0:
				return True

			provider = Provider(provider_data.provider, provider_data.apikey)
			
			row_chunks = self.split_rows(rows_to_be_inserted, 100)
			header_row = tuple(columns.keys())
			
			self.update_status_running(last_inserted_id, 
				number_of_rows,
				details_id)

			last_id = adapter.get_last_inserted_id(table, 
				primary_key, 
				"last")

			self.sync_users_thread(self.sync_users, 
				provider, 
				list_data.id,
				header_row, 
				row_chunks, 
				last_id, 
				details_id,
				columns)

			return True

		return False