Ejemplo n.º 1
0
def execute_sql(table_foreverstrong):
    import os
    from sql_helper import create_database, update_database, create_index
    import sqlite3 as sq3

    db_name = 'blockchain.db'
    db_is_new = not os.path.exists(db_name)

    #connect to the database
    conn = sq3.connect(db_name)  # or use :memory: to put it in RAM
    cur = conn.cursor()

    if db_is_new:
        print('Creating a new DB.')
        create_database(cur)
        create_index(cur)
        update_database(cur, table_foreverstrong)
    else:
        update_database(cur, table_foreverstrong)
    conn.commit()
    conn.close()
Ejemplo n.º 2
0
def execute_sql(table_block, table_txn):
    import sqlite3
    import os
    from sql_helper import create_database, update_database

    # Check if the DB already exists in the operating system
    dbname = 'blockchaindb.sqlite'
    db_is_new = not os.path.exists(dbname)

    # Connect to the SQLITE database
    conn = sqlite3.connect(dbname)
    csr = conn.cursor()

    # Create a new database if none exists
    if db_is_new:
        print('creating a new database')
        create_database(csr)
        update_database(csr, table_block, table_txn)
    else:
        update_database(csr, table_block, table_txn)

    # commit the data and close SQL connection
    conn.commit()
    conn.close()