File size: 3,533 Bytes
00b00eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# 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)