Example #1
0
def oracle_data_import(user, passwd, host, database, user_group,
                       file_with_path):
    oracle_file = zCSV.CsvFile(file_with_path)
    oracle_file.del_lines_begin(8)
    print(oracle_file)
    oracle_info = oracle_file.get_oracle_data()
    print(oracle_info)
    read_return = oracle_data_read(
        user, passwd, host, database, ['[AutoNo]', '[Unit Length]'],
        ['[Order Num]', '[Batch Id]'], ['%d', '%d'],
        (int(oracle_info[0]['Order Num']), int(oracle_info[0]['Batch Id'])))
    if read_return:
        print('Batch is already in database')
        return -2
    sql = genSQL.OracleData_SQL().insert_sql_head()
    # print(sql)
    s_values = genSQL.OracleData_SQL().insert_sql_values(
        oracle_info, user, user_group)
    db = dbunit.DBUnit(user, passwd, host, database)
    # print(s_values)
    insert_return = db.write(sql, s_values)
    if insert_return == -1:
        print('Insert Data Error!')
    else:
        print('Insert Data OK!')
    return insert_return
Example #2
0
def df_purlin_dim_import(user, passwd, host, database, csv_file):
    file_ = zCSV.CsvFile(csv_file)
    dims = file_.get_std_dim()
    exit_dims = []
    insert_return = -1
    if dims:
        for dim in dims:
            exit_dim = df_purlin_dim_read(user, passwd, host, database,
                                          ['part_no'], ['draw_no', 'part_no'],
                                          ['%s', '%s'],
                                          (dim['draw_no'], dim['part_no']))
            if exit_dim:
                exit_dims.append(exit_dim)
            else:
                sql = genSQL.PurlinDimSQL().insert_sql_head()
                # print(sql)
                s_values = genSQL.PurlinDimSQL().insert_sql_values(dim)
                db = dbunit.DBUnit(user, passwd, host, database)
                # print(s_values)
                insert_return = db.write(sql, s_values)
                if insert_return == -1:
                    print('Insert Data Error!')
                else:
                    print('Insert Data OK!')
    return exit_dims, insert_return
Example #3
0
def df_std_punch_read(user, passwd, host, database, show_fields, params_name,
                      params_type, params):
    db = dbunit.DBUnit(user, passwd, host, database)
    sql = genSQL.StdPunchSQL().select_sql_head(show_fields, params_name,
                                               params_type)
    # pprint(sql)
    read_return = db.read(sql, params)
    # if read_return:
    #     pprint(read_return)
    return read_return
Example #4
0
def oracle_data_read(user, passwd, host, database, show_fields, params_name,
                     params_type, params):
    db = dbunit.DBUnit(user, passwd, host, database)
    sql = genSQL.OracleData_SQL().select_sql_head(show_fields, params_name,
                                                  params_type)
    # pprint(sql)
    read_return = db.read(sql, params)
    # if read_return:
    #     pprint(read_return)
    return read_return
Example #5
0
def df_project_insert(user, passwd, host, database, values):
    db = dbunit.DBUnit(user, passwd, host, database)
    sql = genSQL.ProjectSQL().insert_sql_head()
    s_values = genSQL.ProjectSQL().insert_sql_value(values)
    print('sql\n', sql)
    print('s_values\n', s_values)

    insert_return = db.write(sql, s_values)
    if insert_return == -1:
        print('Insert Data Error!')
    else:
        print('Insert Data OK!')
    return insert_return
Example #6
0
def df_project_update(user,
                      passwd,
                      host,
                      database,
                      update_fields,
                      update_values,
                      params_name,
                      params_type,
                      params,
                      option=None):
    db = dbunit.DBUnit(user, passwd, host, database)
    if not option:
        sql = genSQL.ProjectSQL().update_sql_head(update_fields, update_values,
                                                  params_name, params_type)
        # write_return = sql
        write_return = db.write(sql, params)
    return write_return
Example #7
0
def df_purlin_dim_insert(user, passwd, host, database, values):
    db = dbunit.DBUnit(user, passwd, host, database)
    sql = genSQL.PurlinDimSQL().insert_sql_head()
    s_values = genSQL.PurlinDimSQL().insert_sql_values(values)
    print('sql\n', sql)
    print('s_values\n', s_values)
Example #8
0
def oracle_data_read_in_auto(user, passwd, host, database, tuple_auto):
    db = dbunit.DBUnit(user, passwd, host, database)
    sql = genSQL.OracleData_SQL().select_sql_in_auto(tuple_auto)
    read_return = db.read(sql, tuple_auto)
    return read_return
Example #9
0
def df_std_punch_insert(user, passwd, host, database, values):
    db = dbunit.DBUnit(user, passwd, host, database)
    sql = genSQL.StdPunchSQL().insert_sql_head()
    s_values = genSQL.StdPunchSQL().insert_sql_values(values)
    print('sql\n', sql)
    print('s_values\n', s_values)