コード例 #1
0
from template.db import Database
from template.query import Query
#from template.config import init

from random import choice, randint, sample, seed
#init()

db = Database()
db.open('./ECS165')

grades_table = db.get_table('Grades')
query = Query(grades_table)

# repopulate with random data
records = {}
seed(3562901)
for i in range(0, 1000):
    key = 92106429 + i
    records[key] = [
        key,
        randint(0, 20),
        randint(0, 20),
        randint(0, 20),
        randint(0, 20)
    ]

# Simulate updates
keys = sorted(list(records.keys()))
for _ in range(10):
    for key in keys:
        for j in range(1, grades_table.num_columns):
コード例 #2
0
from template.db import Database

database = Database()
grades_table = database.create_table('Grades', 5, 0)

# retValue = database.get_table('Grades')
# print(retValue)
# db_length = len(database.tables_directory)
# print(db_length)

sec_grades_table = database.create_table('Grades2', 5, 0)
retNewTable = database.get_table('Grades2')
print(retNewTable)
db_length2 = len(database.tables_directory)
print("Data base length:",db_length2)
print("Table name:",sec_grades_table.name)
print("Table key",sec_grades_table.Table_key)
print("Table columns:",sec_grades_table.num_columns)
print("Table page directory:",sec_grades_table.page_directory)
print("Table index:",sec_grades_table.index)
print("Table record directory:",sec_grades_table.record_directory)
print("Table prange:",sec_grades_table.prange_num)
print("Table free base rid:",sec_grades_table.free_brid)
print("Table free tail rid:",sec_grades_table.free_trid)

print("Before calling drop", len(database.tables_directory))
database.drop_table('Grades')
print("After calling drop", len(database.tables_directory))
コード例 #3
0
from template.db import Database
from template.query import Query
import os
'''
READ ME!!
    Before using this demo, be sure that the Tail_Const is set to a value high enough
    to guaranteed that all updates are contained within the same block.
        config.py -> TAIL_CONST = 4

    This program is meant to run sequentially through all parts starting with an empty ECS165
    directory.
'''
db2 = Database()
db2.open("ECS165")
#db2.open()
print(db2)
g_table = db2.get_table('Grades')
q = Query(g_table)
rec3 = q.select(92106429, 0, [1, 1, 1, 1, 1])[0]
rec4 = q.select(92106430, 0, [1, 1, 1, 1, 1])[0]
print("Rec = ", rec3)
print("Rec2 = ", rec4)
rec3f = q.selectFull(92106429, 0)
rec4f = q.selectFull(92106430, 0)
print("Rec_full = ", rec3f)
print("Rec2_full = ", rec4f)
db2.close()
コード例 #4
0
import os
from time import process_time
from random import choice, randrange
import sys
'''
print(os.getcwd())
os.chdir('~/ECS165/')
#os.chdir('~')
print(os.getcwd())

sys.exit()
'''

# Student Id and 4 grades

db = Database()
db.open('ECS165')
grades_table = db.create_table('Grades', 5, 0)
query = Query(grades_table)
keys = []

# Measuring Insert Performance
query.insert(92106429, 93, 5, 7, 0)
query.insert(92106430, 8, 7, 6, 5)
rec = query.select(92106429, [1,1,1,1,1])[0]
rec2 = query.select(92106430, [1,1,1,1,1])[0]
print(rec)
print(rec2)
#print(rec.rid, rec.key, rec.columns)
#print(rec2.rid, rec2.key, rec2.columns)
#