예제 #1
0
def DisplayJoin():
    env = SliceEnv()
    left_name = input("Input the first database's name(For example:CustDB): ")
    right_name = input("Input the second database's name(For example:SalesDB): ")
    leftDB = env.open(left_name)
    rightDB = env.open(right_name)
    rightDB.join(leftDB)
    env.close(left_name)
    env.close(right_name)
    print('Join OK!')
예제 #2
0
def DisplayJoin():
    env = SliceEnv()
    left_name = input("Input the first database's name(For example:CustDB): ")
    right_name = input(
        "Input the second database's name(For example:SalesDB): ")
    leftDB = env.open(left_name)
    rightDB = env.open(right_name)
    rightDB.join(leftDB)
    env.close(left_name)
    env.close(right_name)
    print('Join OK!')
예제 #3
0
def RunQuery():
    query = input("Input a Query: ")
    select_index = query.find('SELECT')
    from_index = query.find('FROM')
    where_index = query.find('WHERE')
    if select_index == -1 or from_index == -1 or where_index == -1:
        return 'Input Wrong!'
    display_list = query[select_index + 6:from_index - 1].strip().split(',')
    target_database = query[from_index + 5:where_index - 1].strip()
    condition = query[where_index + 5:]
    less_index = condition.find('(')
    greater_index = condition.find(')')
    if less_index == -1 and greater_index == -1:
        condition_list = [
            item.strip() for item in condition.strip().split(',')
        ]
    else:
        new_condition = condition[:less_index] + condition[
            less_index + 1:greater_index] + condition[greater_index + 1:]
        condition_list = [
            item.strip() for item in new_condition.strip().split(',')
        ]
    col_name, operator, literal = condition_list[0], condition_list[
        1], condition_list[2]
    col_list = [item for item in display_list]
    col_list.append(col_name)
    env = SliceEnv()
    sliceDB = env.open(target_database)
    result = sliceDB.run_query(col_list, col_name, operator, literal)
    for item in result:
        item_str = ''
        for each in item:
            item_str += str(each) + '    '
        print(item_str)
예제 #4
0
파일: RunQuery.py 프로젝트: LarryShang/git
def RunQuery():
    query = input("Input a Query: ")
    select_index = query.find('SELECT')
    from_index = query.find('FROM')
    where_index = query.find('WHERE')
    if select_index==-1 or from_index==-1 or where_index==-1:
        return 'Input Wrong!'
    display_list = query[select_index+6:from_index-1].strip().split(',')
    target_database = query[from_index+5:where_index-1].strip()
    condition = query[where_index+5:]
    less_index = condition.find('(')
    greater_index = condition.find(')')
    if less_index==-1 and greater_index==-1:
        condition_list = [item.strip() for item in condition.strip().split(',')]
    else:
        new_condition = condition[:less_index]+condition[less_index+1:greater_index]+condition[greater_index+1:]
        condition_list = [item.strip() for item in new_condition.strip().split(',')]
    col_name,operator,literal = condition_list[0],condition_list[1],condition_list[2]
    col_list = [item for item in display_list]
    col_list.append(col_name)
    env = SliceEnv()
    sliceDB = env.open(target_database)
    result = sliceDB.run_query(col_list,col_name,operator,literal)
    for item in result:
        item_str = ''
        for each in item:
            item_str += str(each)+'    '
        print(item_str)
예제 #5
0
def DeleteRecord():
    env = SliceEnv()
    db_name = input("Input the table's name(For example:CustDB): ")
    sliceDB = env.open(db_name)
    index_col = sliceDB.db_index_col
    key_value = input("The key of the table "+db_name+" is "+index_col+", input the key value: ")
    value_list = sliceDB.delete(key_value)
    print(value_list)
    env.close(db_name)
예제 #6
0
def DeleteRecord():
    env = SliceEnv()
    db_name = input("Input the table's name(For example:CustDB): ")
    sliceDB = env.open(db_name)
    index_col = sliceDB.db_index_col
    key_value = input("The key of the table " + db_name + " is " + index_col +
                      ", input the key value: ")
    value_list = sliceDB.delete(key_value)
    print(value_list)
    env.close(db_name)
예제 #7
0
def UpdateRecord():
    env = SliceEnv()
    db_name = input("Input the table's name(For example:CustDB): ")
    sliceDB = env.open(db_name)
    sliceRecord = sliceDB.createRecord()
    fields = []
    for item in sliceDB.db_schema:
        fields.append(item.get_field_name())
    for field in fields:
        value = input('Input "' + field + '" value:')
        #         print(value)
        if value:
            sliceRecord.setString(field, value)
    sliceDB.set(sliceRecord)
    env.close(db_name)
    print('Update OK')
예제 #8
0
파일: AddRecord.py 프로젝트: LarryShang/git
def AddRecord():
    env = SliceEnv()
    db_name = input("Input the database's name(For example:CustDB):")
    sliceDB = env.open(db_name)
    sliceRecord = sliceDB.createRecord()
    while 1:
        field = input('Input the field name(For example:cust),Press Enter to quit input: ')
        if field:
            value = input("Input the value: ")
            sliceRecord.setString(field,value)
        else:
            break
    sliceDB.set(sliceRecord)
    env.close(db_name)
    print('Add OK')
    
예제 #9
0
def AddRecord():
    env = SliceEnv()
    db_name = input("Input the database's name(For example:CustDB):")
    sliceDB = env.open(db_name)
    sliceRecord = sliceDB.createRecord()
    while 1:
        field = input(
            'Input the field name(For example:cust),Press Enter to quit input: '
        )
        if field:
            value = input("Input the value: ")
            sliceRecord.setString(field, value)
        else:
            break
    sliceDB.set(sliceRecord)
    env.close(db_name)
    print('Add OK')
예제 #10
0
def Bulkload():
    env = SliceEnv()
    db_name = input("Input the database's name(For example:CustDB): ")
    sliceDB = env.open(db_name)
    bulkfile = input("Input the bulk file's name(For example:CustDB): ")
    sliceDB.load(bulkfile)