// 更新系 def execute(self, query, param=None): with self.connection.cursor() as cur: cur.execute(query, parameters=param) self.connection.commit()
// 1件取得 def fetchone(self, query, param=None): with self.connection.cursor() as cur: cur.execute(query, parameters=param) return cur.fetchone()
// 全件取得 def fetchall(self, query, param=None): with self.connection.cursor() as cur: cur.execute(query, parameters=param) return cur.fetchall()
// 逐次取得 def fetchmany(self, query, param=None, size=1000): with self.connection.cursor() as cur: cur.execute(query, parameters=param) with True: rows = cur.fetchmany() if not rows: break for row in rows: yield row
def close(self): self.connection.close()
if__name__ == '__main__': host = 'https://xxxx.xxx' with HiveConnector(host, 10000, 'test_db') as hc: query = 'SELECT * FROM access_logs WHERE log_date=%s' result = hc.fetchall(query, ('20210101',)) print(result)