first_project
This commit is contained in:
41
alter_column_to_nvarchar.py
Normal file
41
alter_column_to_nvarchar.py
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
import mysql.connector
|
||||
|
||||
def get_connection_details():
|
||||
details = {}
|
||||
with open('setting.txt', 'r') as f:
|
||||
for line in f:
|
||||
key, value = line.strip().split(':', 1)
|
||||
details[key.strip()] = value.strip()
|
||||
return details
|
||||
|
||||
def alter_columns_to_nvarchar():
|
||||
conn = None
|
||||
try:
|
||||
config = get_connection_details()
|
||||
conn = mysql.connector.connect(
|
||||
host=config.get('Host'),
|
||||
port=config.get('Port'),
|
||||
user=config.get('Username'),
|
||||
password=config.get('Password'),
|
||||
database=config.get('Database')
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
print("Altering 'name' column to NVARCHAR...")
|
||||
cursor.execute("ALTER TABLE extension_data MODIFY name NVARCHAR(255)")
|
||||
print("Altering 'position' column to NVARCHAR...")
|
||||
cursor.execute("ALTER TABLE extension_data MODIFY position NVARCHAR(255)")
|
||||
|
||||
conn.commit()
|
||||
print("Columns 'name' and 'position' altered to NVARCHAR successfully.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
finally:
|
||||
if conn and conn.is_connected():
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
alter_columns_to_nvarchar()
|
Reference in New Issue
Block a user