예제 #1
0
파일: copy_from.py 프로젝트: Thynix/pyProbe
# No need to commit changes - sequence changes are not transactional.
database = update_db.main()
cur = database.maintenance.cursor()

print("""Filenames to copy from are built from a prefix, the table name,
and a suffix. The prefix should consist of an absolute path and the start
of the filename, and the suffix should consist of the end of the filename,
including any file extension. The table name goes between the prefix and the
suffix. If a file does not exist it will be skipped.
""")
prefix = raw_input('Enter prefix: ')
suffix = raw_input('Enter suffix: ')

logging.warning("Dropping indexes to speed import.")
database.drop_indexes()

for table in database.table_names:
    filename = prefix + table + suffix
    if os.path.exists(filename):
        source_file = open(filename)
        logging.info("Copying from %s to %s" % (filename, table))
        cur.copy_from(source_file, table)
        logging.info("Updating id sequence for %s" % table)
        update_id_sequence(cur, table)

logging.warning("Copy complete. Recreating indexes.")
database.create_indexes()
logging.warning("Analyzing.")
cur.execute("ANALYZE")
database.maintenance.commit()
예제 #2
0
      bandwidth
    WHERE
      ROWID > ?1
    ORDER BY ROWID ASC
    """, (resume_id('bandwidth'),)):

    row = convert_time(row)

    Postgres_add.execute("""
    INSERT INTO
      bandwidth(id, time, duration, htl, KiB)
    VALUES
      (%s, %s, %s, %s, %s)
    """, row)
new_database.add.commit()
update_id_sequence(Postgres_maint, 'bandwidth')

for row in SQLite.execute("""
    SELECT
      ROWID, time, duration, htl, build
    FROM
      build
    WHERE
      ROWID > ?1
    ORDER BY ROWID ASC
    """, (resume_id('build'),)):

    row = convert_time(row)

    Postgres_add.execute("""
    INSERT INTO
예제 #3
0
    WHERE
      ROWID > ?1
    ORDER BY ROWID ASC
    """, (resume_id('bandwidth'), )):

    row = convert_time(row)

    Postgres_add.execute(
        """
    INSERT INTO
      bandwidth(id, time, duration, htl, KiB)
    VALUES
      (%s, %s, %s, %s, %s)
    """, row)
new_database.add.commit()
update_id_sequence(Postgres_maint, 'bandwidth')

for row in SQLite.execute(
        """
    SELECT
      ROWID, time, duration, htl, build
    FROM
      build
    WHERE
      ROWID > ?1
    ORDER BY ROWID ASC
    """, (resume_id('build'), )):

    row = convert_time(row)

    Postgres_add.execute(