Last active
October 24, 2023 00:02
-
-
Save maxux/aa0f9b29994b9503afa65377593d3e0f to your computer and use it in GitHub Desktop.
SQLite3 MySQL Gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
db = sqlite3.connect("power-buffer.sqlite3") | |
cursor = db.cursor() | |
buffer = [] | |
print("[+] fetching rows") | |
cursor.execute("SELECT * FROM power") | |
batch = 16384 | |
total = 0 | |
index = 0 | |
with open("output.sql", "w") as f: | |
print("[+] start transaction") | |
f.write("START TRANSACTION;\n") | |
print("[+] writing queries") | |
for row in cursor.fetchall(): | |
buffer.append("(FROM_UNIXTIME(%s), %d, %d)" % (row[0], row[1], row[2])) | |
index += 1 | |
if index == batch: | |
f.write("INSERT IGNORE INTO power (timestamp, value, phase) VALUES ") | |
f.write(",".join(buffer) + ";\n") | |
buffer = [] | |
total += index | |
index = 0 | |
print(total) | |
print("[+] cleaning buffer") | |
f.write("INSERT INTO power (timestamp, value, phase) VALUES ") | |
f.write(",".join(buffer) + ";\n") | |
print("[+] end transaction") | |
f.write("COMMIT;\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment