Exemple #1
0
 def set_info_by_command(self, command_string):
     """
     run sql command for inser
     :param command_string:
     :return:
     """
     try:
         mycursor.execute(command_string)
         mydb.commit()
     except mysql.connector.Error as err:
         print("set_info_by_command:Something went wrong: {}" + err.msg)
         crash_window("Cant connect update data on database")
Exemple #2
0
 def get_info_by_command(self, command_string):
     """
     run sql command
     :param command_string:
     :return:
     """
     myresult = ""
     try:
         mycursor.execute(command_string)
         myresult = mycursor.fetchall()
     except mysql.connector.Error as err:
         print("get_info_by_command:Something went wrong: {}" + err.msg)
         crash_window("Cant connect run commands on database")
     return myresult
Exemple #3
0
 def set_user_config(self, db_name, user_name):
     """
     Set database and provileges for user.
     :param db_name:  string got from file
     :param user_name: got from file
     """
     try:
         cmd = "GRANT ALL PRIVILEGES ON " + db_name + ".* TO '" + user_name + "'@'localhost' WITH GRANT OPTION;"
         mycursor.execute(cmd)
         cmd = "GRANT FILE ON *.* to '" + user_name + "'@'localhost';"
         mycursor.execute(cmd)
         cmd = "USE " + db_name + ";"
         mycursor.execute(cmd)
     except mysql.connector.Error as err:
         print("set_user_config:Command skipped: " + err.msg)
         crash_window("Cant set user configurations to database")
         return "Error while setting users PRIVILEGES:" + err.msg, Conventions.CRASHING_MODE
     return Conventions.WORKING_MODE
Exemple #4
0
 def connect(self):
     """
     connect the SQL:
 connect to server
     :return:
     """
     global mydb, mycursor
     # get settings for connection
     try:
         mydb = mysql.connector.connect(host=settings_info["ip"],
                                        user=settings_info["user_name"],
                                        password=settings_info["password"],
                                        port=settings_info["port"],
                                        allow_local_infile=True)
         mycursor = mydb.cursor()
         self.set_user_config(settings_info["database"],
                              settings_info["user_name"])
     except mysql.connector.Error as err:
         print("Something went wrong: {}".format(err))
         crash_window("Cant connect to database")