def write(db_name, source, entries): db = sqlite3.connect(db_name) c = db.cursor() # Set version of database database.write_database_version(c) # Delete old tables and indices, then create new one database.drop_tables(c) database.create_tables(c) # Add sources to table database.insert_source( c, source.name, source.shortname, source.version, source.description, source.legal, source.link, source.update_url, source.other, None, ) insert_words(c, entries) database.generate_indices(c) db.commit() db.close()
def write(db_name, source, words): db = sqlite3.connect(db_name) c = db.cursor() database.write_database_version(c) database.drop_tables(c) database.create_tables(c) database.insert_source( c, source.name, source.shortname, source.version, source.description, source.legal, source.link, source.update_url, source.other, None, ) insert_words(c, words) database.generate_indices(c) db.commit() db.close()
def create_db(): global con con = psycopg2.connect(database='postgres', user='******', password='******') con.set_isolation_level(0) database.create_database(con, test_db) con.close() con = database.connect(dbname=test_db) database.create_tables(con)
def write(chinese_sentences, nonchinese_sentences, links, db_name): print("Writing to database file") db = sqlite3.connect(db_name) c = db.cursor() database.write_database_version(c) database.drop_tables(c) database.create_tables(c) database.insert_source( c, source.name, source.shortname, source.version, source.description, source.legal, source.link, source.update_url, source.other, None, ) # Add sentences to tables for key in chinese_sentences: sentence = chinese_sentences[key] database.insert_chinese_sentence( c, sentence.traditional, sentence.simplified, sentence.pinyin, sentence.jyutping, sentence.language, sentence.id, ) for key in nonchinese_sentences: sentence = nonchinese_sentences[key] database.insert_nonchinese_sentence( c, sentence.sentence, sentence.language, sentence.id, ) # Add links for source_sentence_id in links: for target_sentence_id in links[source_sentence_id]: direct = links[source_sentence_id][target_sentence_id] database.insert_sentence_link( c, source_sentence_id, target_sentence_id, 1, direct, ) db.commit() db.close()
def database_initialization(): database.create_tables() UserDatabaseOPS.add_user( "mesut_guneri", "tokmak", "tokmak", "tokmak", "cobanyildizi") # Can Altinigne Insert Into User Table Manually KnotDatabaseOPS.add_knot(1, "First content of the Knitter", 0, 0, "2016-10-29") InteractionDatabaseOPS.add_user_interaction( 1, 10) # ilknur meray: insert into USER_INTERACTION table manually MessageDatabaseOPS.add_message( 'Thanks for database management systems lecture notes!', 1, 2) NotificationDatabaseOPS.insert_relation(1, 1, True) return redirect(url_for('site.login_page'))
async def start(): if MySQL.is_closed(): MySQL.connect() # create tables for database MySQL.create_tables([Dogs])
def write(db_name, source, entries): db = sqlite3.connect(db_name) c = db.cursor() # Set version of database database.write_database_version(c) # Delete old tables and indices, then create new one database.drop_tables(c) database.create_tables(c) # Add sources to table database.insert_source( c, source.name, source.shortname, source.version, source.description, source.legal, source.link, source.update_url, source.other, None, ) for key in entries: for entry in entries[key]: entry_id = database.get_entry_id( c, entry.traditional, entry.simplified, entry.pinyin, entry.jyutping, entry.freq, ) if entry_id == -1: entry_id = database.insert_entry( c, entry.traditional, entry.simplified, entry.pinyin, entry.jyutping, entry.freq, ) if entry_id == -1: logging.error( f"Could not insert word {entry.traditional}, uh oh!") continue for label, definition in entry.definitions: definition_id = database.insert_definition( c, definition, label, entry_id, 1, None) if definition_id == -1: logging.error( f"Could not insert definition {definition} for word {entry.traditional} " "- check if the definition is a duplicate!") continue database.generate_indices(c) db.commit() db.close()
def setup_class(cls): cls.init_database() database.create_tables(models=[TodoItem, Tags, TodoTags])
def startup(): if connection.is_closed(): connection.connect() connection.create_tables([User])
def database_initialization(): database.create_tables() return redirect(url_for('site.login_page'))
def write(db_name, source, entries, sentences, translations): db = sqlite3.connect(db_name) c = db.cursor() # Set version of database database.write_database_version(c) # Delete old tables and indices, then create new one database.drop_tables(c) database.create_tables(c) # Add sources to table database.insert_source( c, source.name, source.shortname, source.version, source.description, source.legal, source.link, source.update_url, source.other, None, ) for entry in entries: entry_id = database.get_entry_id( c, entry.traditional, entry.simplified, entry.pinyin, entry.jyutping, entry.freq, ) if entry_id == -1: entry_id = database.insert_entry( c, entry.traditional, entry.simplified, entry.pinyin, entry.jyutping, entry.freq, ) if entry_id == -1: logging.error(f"Could not insert word {entry.traditional}, uh oh!") continue for label, definition in entry.definitions: definition_id = database.insert_definition( c, definition, label, entry_id, 1, None ) if definition_id == -1: logging.error( f"Could not insert definition {definition} for word {entry.traditional}, uh oh!" ) continue for sentence in sentences: database.insert_chinese_sentence( c, sentence.traditional, sentence.simplified, sentence.pinyin, sentence.jyutping, sentence.language, sentence.id, ) # In CantoDict, a sentence ID and its corresponding translation ID are separated by 500000000 # (See parse_sentence_file()) database.insert_sentence_link( c, sentence.id, sentence.id + 500000000, 1, True, ) for translation in translations: database.insert_nonchinese_sentence( c, translation.sentence, translation.language, translation.id, ) database.generate_indices(c) db.commit() db.close()
def initialize_database(): database.create_tables() database.init_db() database.adminInit() return redirect(url_for('site.home_page'))
"Usage: python3 script.py <output database name> <database 1 filename> <database 2 filename>" ) print("e.g. python3 script.py dict-merged.db dict.db dict-fr.db") sys.exit(1) db = sqlite3.connect(sys.argv[1]) c = db.cursor() # Set version of database database.write_database_version(c) # Delete old tables and indices database.drop_tables(c) # Create new tables database.create_tables(c) # Attach new databases c.execute("ATTACH DATABASE '{}' AS db1".format(sys.argv[2])) c.execute("ATTACH DATABASE '{}' AS db2".format(sys.argv[3])) # Insert from first database c.execute( """INSERT INTO entries(traditional, simplified, pinyin, jyutping, frequency) SELECT traditional, simplified, pinyin,
def write(entries, db_name): db = sqlite3.connect(db_name) c = db.cursor() database.write_database_version(c) database.drop_tables(c) database.create_tables(c) database.insert_source( c, source.name, source.shortname, source.version, source.description, source.legal, source.link, source.update_url, source.other, None, ) entry_id = 0 for key in entries: for entry in entries[key]: entry_id = database.get_entry_id( c, entry.traditional, entry.simplified, entry.pinyin, entry.jyutping if entry.jyutping != "" else entry.fuzzy_jyutping, entry.freq, ) if entry_id == -1: entry_id = database.insert_entry( c, entry.traditional, entry.simplified, entry.pinyin, entry.jyutping if entry.jyutping != "" else entry.fuzzy_jyutping, entry.freq, ) if entry_id == -1: logging.error( f"Could not insert word {entry.traditional}, uh oh!") continue for definition in entry.definitions: definition_id = database.insert_definition( c, definition, "", entry_id, 1, None) if definition_id == -1: logging.error( f"Could not insert definition {definition} for word {entry.traditional}, uh oh!" ) continue database.generate_indices(c) db.commit() db.close()
def startup(): if connection.is_closed(): connection.connect() # Antes de comenzar el servidor: connection.create_tables([User ]) #Crea todas las tablas de nuestro proyecto