def add_content(self, values, lang_name, insert_type="normal"):
        """
        Adds content to the database. Tries to insert and updates if 
        row already exists.
        """

        # backup database file 
        if insert_type == "from_file":
            try:
                shutil.copy2(self.db_path + "/codedict_db.DB", 
                    self.db_path + "/BACKUP_codedict_db.DB")
            except (shutil.Error, __HOLE__, OSError) as error:
                print "Error while backing up database.", error
                print "Continuing ..."

        try:
            with self._db_instance:
                dict_cursor = self._db_instance.cursor()
                tags_cursor = self._db_instance.cursor()
                #add language to lang db if not exists
                self._db_instance.execute('''
                    INSERT OR IGNORE INTO Languages (language, suffix) VALUES (?, "")
                ''', (lang_name, ))

                for new_row in values:

                    dict_cursor.execute('''
                        INSERT or REPLACE into Dictionary 
                        (id, language, problem, solution)
                        VALUES((SELECT id from Dictionary where problem = ? AND language = 
                        (SELECT language from Languages where language = ?)), 
                        (SELECT language from Languages where language = ?), ?, ?)
                    ''', (new_row[1], lang_name, lang_name, new_row[1], new_row[2]))

                    tags_list = process_input_tags(new_row[0])
                    dict_id = dict_cursor.lastrowid

                    self._db_instance.execute('''
                            DELETE from ItemsToTags where dictID = ? 
                        ''', (dict_id,))

                    for tag in tags_list:
                        tags_cursor.execute('''
                        INSERT OR REPLACE INTO Tags (id, name, language) VALUES (
                            (SELECT id from Tags WHERE name = ? and language = ?), 
                            ?, (SELECT language from Languages where language = ?))
                        ''', (tag.strip(), lang_name, tag.strip(), lang_name))

                        tag_id = tags_cursor.lastrowid
                        
                        self._db_instance.execute('''
                            INSERT OR IGNORE into ItemsToTags (tagID, dictID) VALUES (?, ?)
                        ''', (tag_id, dict_id))

        except sqlite3.Error as error:
            print "A database error has ocurred: ", error
            sys.exit(1)
dataset/ETHPy150Open BastiPaeltz/codedict/source/database.py/Database.add_content