Spaces:
Sleeping
Sleeping
| # import sqlite3 | |
| # # Connect to SQLite database (or create it if it doesn't exist) | |
| # conn = sqlite3.connect('imp_db.db') | |
| # # Enable foreign key support | |
| # conn.execute('PRAGMA foreign_keys = ON;') | |
| # # Create a cursor object | |
| # c = conn.cursor() | |
| # # SQL queries to create tables | |
| # create_mmo_users_table = """ | |
| # CREATE TABLE IF NOT EXISTS mmo_users ( | |
| # emp_id TEXT PRIMARY KEY , | |
| # emp_nam TEXT NOT NULL, | |
| # emp_typ TEXT NOT NULL, | |
| # pswrd_key TEXT NOT NULL, | |
| # pswrd_flag INTEGER NOT NULL DEFAULT 0, | |
| # crte_dt_tm TEXT DEFAULT (datetime('now')), | |
| # crte_by_uid TEXT NOT NULL, | |
| # updt_dt_tm TEXT DEFAULT (datetime('now')), | |
| # updt_by_uid TEXT | |
| # ); | |
| # """ | |
| # create_mmo_projects_table = """ | |
| # CREATE TABLE IF NOT EXISTS mmo_projects ( | |
| # prj_id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| # prj_ownr_id TEXT NOT NULL, | |
| # prj_nam TEXT NOT NULL, | |
| # alwd_emp_id TEXT, | |
| # meta_data_agrgt TEXT, | |
| # crte_dt_tm TEXT DEFAULT (datetime('now')), | |
| # crte_by_uid TEXT NOT NULL, | |
| # updt_dt_tm TEXT DEFAULT (datetime('now')), | |
| # updt_by_uid TEXT, | |
| # FOREIGN KEY (prj_ownr_id) REFERENCES mmo_users(emp_id) | |
| # ); | |
| # """ | |
| # create_mmo_project_meta_data_table = """ | |
| # CREATE TABLE IF NOT EXISTS mmo_project_meta_data ( | |
| # prj_guid INTEGER PRIMARY KEY AUTOINCREMENT, | |
| # prj_id INTEGER NOT NULL, | |
| # page_nam TEXT NOT NULL, | |
| # file_nam TEXT NOT NULL, | |
| # pkl_obj BLOB, | |
| # dshbrd_ts TEXT, | |
| # crte_dt_tm TEXT DEFAULT (datetime('now')), | |
| # crte_by_uid TEXT NOT NULL, | |
| # updt_dt_tm TEXT DEFAULT (datetime('now')), | |
| # updt_by_uid TEXT, | |
| # FOREIGN KEY (prj_id) REFERENCES mmo_projects(prj_id) | |
| # ); | |
| # """ | |
| # # Execute the queries to create tables | |
| # c.execute(create_mmo_users_table) | |
| # c.execute(create_mmo_projects_table) | |
| # c.execute(create_mmo_project_meta_data_table) | |
| # # Commit changes and close the connection | |
| # conn.commit() | |
| # conn.close() | |
| import sqlite3 | |
| def add_user_to_db(db_path, user_id, name, user_type, pswrd_key): | |
| """ | |
| Adds a user to the mmo_users table in the SQLite database. | |
| Parameters: | |
| - db_path (str): The path to the SQLite database file. | |
| - user_id (str): The ID of the user. | |
| - name (str): The name of the user. | |
| - user_type (str): The type of the user. | |
| - pswrd_key (str): The password key for the user. | |
| """ | |
| try: | |
| # Connect to the SQLite database | |
| conn = sqlite3.connect(db_path) | |
| cursor = conn.cursor() | |
| # SQL query to insert a new user | |
| insert_query = """ | |
| INSERT INTO mmo_users (emp_id, emp_nam, emp_typ, pswrd_key,crte_by_uid) | |
| VALUES (?, ?, ?, ?,?) | |
| """ | |
| # Execute the query with parameters | |
| cursor.execute(insert_query, (user_id, name, user_type, pswrd_key, user_id)) | |
| # Commit the transaction | |
| conn.commit() | |
| print(f"User {name} added successfully.") | |
| except sqlite3.Error as e: | |
| print(f"Error adding user to the database: {e}") | |
| finally: | |
| # Close the database connection | |
| conn.close() | |
| # Define the database path and user details | |
| db_path = r'db\imp_db.db' # Update this path to your actual database path | |
| user_id = 'e162284' | |
| name = 'admin' | |
| user_type = 'admin' | |
| pswrd_key = '$2b$12$wP7R0usvKWtr4X06qwGWvOFQCkzOZAzSVRAoDv/68x6GS4rHK5mDm' | |
| # Add the user to the database | |
| add_user_to_db(db_path, user_id, name, user_type, pswrd_key) | |