File size: 4,090 Bytes
78240ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import mysql.connector
import streamlit as st







def check_if_pk_exists(PK,YourTableName,yourPrimaryKeyColumn):


    # Establish a connection
    db_connection = mysql.connector.connect(
       host='svc-469e9a44-2c3e-4c14-a4c6-4c9474675828-dml.aws-virginia-6.svc.singlestore.com',
        
        # In your case your host is local and you are using root assuming you want to deploy the webapp alot will change but start with the db
        user='admin',
        password='zxROkpE7ch8vPiU8aGUosQaykRQI4rUc',
        database='User_profile'
    )


    cursor = db_connection.cursor()



    select_query = f"SELECT * FROM {YourTableName} WHERE {yourPrimaryKeyColumn} = %s"
    cursor.execute(select_query, (PK,))
    existing_row = cursor.fetchone()

    if existing_row:
        # Commit the changes to the database
        db_connection.commit()

    # Close the cursor and connection
        cursor.close()
        db_connection.close()

        return True
    else:
        db_connection.commit()
        cursor.close()
        db_connection.close()
        return False




def insert_into_user_reg(UserID,name,email):


    
    db_connection = mysql.connector.connect(
        host='svc-469e9a44-2c3e-4c14-a4c6-4c9474675828-dml.aws-virginia-6.svc.singlestore.com',
        
        # In your case your host is local and you are using root assuming you want to deploy the webapp alot will change but start with the db
        user='admin',
        password='zxROkpE7ch8vPiU8aGUosQaykRQI4rUc',
        database='User_profile'
    )


    cursor = db_connection.cursor()


    # Define your SQL query for insertion
    insert_query = f""" 
        INSERT INTO Users (UserID, name, email)
        VALUES (%s, %s, %s)
    """

    # Data to be inserted
    data_to_insert = (f"{UserID}", f"{name}", f"{email}")

    # Execute the query
    cursor.execute(insert_query, data_to_insert)

    # Commit the changes to the database
    db_connection.commit()

    # Close the cursor and connection
    cursor.close()
    db_connection.close()


def fk_status_profile_completeness(UID):
    db_connection = mysql.connector.connect(
      host='svc-469e9a44-2c3e-4c14-a4c6-4c9474675828-dml.aws-virginia-6.svc.singlestore.com',
    
        # In your case your host is local and you are using root assuming you want to deploy the webapp alot will change but start with the db
        user='admin',
        password='zxROkpE7ch8vPiU8aGUosQaykRQI4rUc',
        database='User_profile'
    )
    cursor = db_connection.cursor()


    select_query = "SELECT * FROM Ai_personalized_guide_for_users WHERE UserID = %s"
    cursor.execute(select_query, (UID,))
    existing_row = cursor.fetchone()
    if existing_row: 
        db_connection.commit()
        cursor.close()
        db_connection.close()
        return True  #  key exists
    else:
        db_connection.commit()
        cursor.close()
        db_connection.close()
        return False  # key doesn't exist



def insert_into_ai_personalized_guide_for_users(UserID,reading_speed,level_of_understanding,diction):


    
    db_connection = mysql.connector.connect(
        host='svc-469e9a44-2c3e-4c14-a4c6-4c9474675828-dml.aws-virginia-6.svc.singlestore.com',
        
        # In your case your host is local and you are using root assuming you want to deploy the webapp alot will change but start with the db
        user='admin',
        password='zxROkpE7ch8vPiU8aGUosQaykRQI4rUc',
        database='User_profile'
    )


    cursor = db_connection.cursor()


    # Define your SQL query for insertion
    insert_query = f""" 
        INSERT INTO Ai_personalized_guide_for_users (UserID, reading_speed, level_of_understanding,diction)
        VALUES (%s, %s, %s,%s)
    """

    # Data to be inserted
    data_to_insert = (f"{UserID}", f"{reading_speed}", f"{level_of_understanding}",f"{diction}")

    # Execute the query
    cursor.execute(insert_query, data_to_insert)

    # Commit the changes to the database
    db_connection.commit()

    # Close the cursor and connection
    cursor.close()
    db_connection.close()