Last active
September 19, 2019 19:22
-
-
Save MrEdinLaw/b556b9268696e04b37d0ea370d867b25 to your computer and use it in GitHub Desktop.
Randomization of a table with a backup table on the side, using python and sqlite3
This file contains hidden or 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 | |
sql_config = sqlite3.connect('Tunes.db') | |
sql_con = sql_config.cursor() | |
sql_con.execute("CREATE TABLE IF NOT EXISTS 'temp' (Title TEXT, Length TEXT)") # Create temp table | |
sql_con.execute("DELETE FROM 'temp'") # Clean temp | |
# sql_con.execute("vacuum") # Commit clea | |
sql_con.execute("INSERT INTO 'temp' SELECT * FROM Tunes") # Copy Data to temp | |
sql_con.execute("DELETE FROM 'Tunes'") # Clean Tunes | |
sql_con.execute("INSERT INTO 'Tunes' SELECT * FROM temp ORDER BY RANDOM()") # Copy Randomized data to Tunes | |
sql_con.execute("DROP TABLE IF EXISTS 'temp'") | |
sql_config.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment