예제 #1
0
파일: pilot.py 프로젝트: 7aitsev/db_2017
def populate(db, count):
    try:
        # check whether "Rating" has rows and if not, populate the table in an ineractive mode
        next.rating_rows = common.select_all_rows(db, rating.select_all_query)
        if 0 == len(next.rating_rows):
            inserted_rows_count = common.populate_interactive(db, rating)
            if 0 >= inserted_rows_count:
                print '"Rating" does not have records'
                return -1
            next.rating_rows = common.select_all_rows(db,
                                                      rating.select_all_query)
        # fetch all records from "Person" and decide populate the table or not
        next.person_rows = common.select_all_rows(db, person.select_all_query)
        next.person_rows_len = len(next.person_rows)
        rows = common.fetch_unused_rows(db, sys.modules[__name__], count)
        person_rows_count = len(rows)
        if person_rows_count < count:
            print 'Unused rows in "Person": {}'.format(person_rows_count)
            rv = common.populate_interactive(db, person)
            person_rows_count += rv
            if person_rows_count < count:
                print '"Person" does not have enough records'
                return -1
            next.i = 0
            next.person_rows = common.select_all_rows(db,
                                                      person.select_all_query)
            next.person_rows_len = len(next.person_rows)
            rows = common.fetch_unused_rows(db, sys.modules[__name__], count)
    except pg_driver.Error as e:
        print e.pgerror
        return -1
    return common.insert_rows(db, sys.modules[__name__], rows)
예제 #2
0
def populate(db, count):
    if limit < count:
        print 'The number of rows must be in [1,{}]'.format(limit)
        return -1
    import csv
    with open(filepath, 'r') as csvfile:
        next.reader = csv.reader(csvfile)
        keys = next.reader.next()  # skip the header
        rows = common.fetch_unused_rows(db, sys.modules[__name__], count)
        return common.insert_rows(db, sys.modules[__name__], rows)
예제 #3
0
def populate(db, count):
    try:
        next.route_rows = common.check_availability(
            db, route, select_all_from_route_and_airport_query)
        next.pilot_rows = common.check_availability(db, pilot)
        next.plane_rows = common.check_availability(db, plane)
    except pg_driver.Error as e:
        print e.pgerror
        db.rollback()
        return -1
    rows = common.fetch_unused_rows(db, sys.modules[__name__], count)
    return common.insert_rows(db, sys.modules[__name__], rows)
예제 #4
0
def populate(db, count):
    try:
        # check whether "Airport has rows and if not, populate the table in an interactive mode
        next.airport_rows = common.select_all_rows(db,
                                                   airport.select_all_query)
        if 0 == len(next.airport_rows):
            print '"Airports" is empty'
            rv = common.populate_interactive(db, airport)
            if 0 >= rv:
                print 'Not enough rows in "Airport" to fulfil the operation'
                return -1
            next.airport_rows = common.select_all_rows(
                db, airport.select_all_query)
    except pg_driver.Error as e:
        print e.pgerror
        return -1

    # assume "Airport" has some data
    rows = common.fetch_unused_rows(db, sys.modules[__name__], count)
    return common.insert_rows(db, sys.modules[__name__], rows)
예제 #5
0
def populate(db, count):
    try:
        next.person_rows = common.check_availability(db, person)
        next.flight_rows = common.check_availability(db, flight, select_all_from_flight_and_plane_query)
    except pg_driver.Error as e:
        print e.pgerror
        db.rollback()
        return -1

    total_seats_count = 0
    try:
        c = db.cursor()
        c.execute(select_total_capacity_query)
        total_seats_count = c.fetchall()
    except pg_driver.Error as e:
        db.rollback()
        return -1
    if 0 == total_seats_count or count > total_seats_count:
        print 'Total seats count: {}\tRequested number of tickets ({}) is too big' \
            .format(total_seats_count, count)
        return -1

    rows = common.fetch_unused_rows(db, sys.modules[__name__], count)
    return common.insert_rows(db, sys.modules[__name__], rows)
예제 #6
0
def populate(db, count):
    if limit < count:
        print 'The number of rows must be in [1,{}]'.format(limit)
        return -1
    rows = common.fetch_unused_rows(db, sys.modules[__name__], count)
    return common.insert_rows(db, sys.modules[__name__], rows)