def load_csv_to_table(table ,schema_file ,csv_file, server, database, config,cred_file='config/dblogin.config',skipfirstrow=1): """Takes csv file, schema file, with sql server connection params and inserts data to a specified table Args: table: table name where csv data will be written schema_file: schema file that has all column names and data type names csv_file: data being loaded server: sql server host name config: which configuration name to pull username and password credentials cred_file: location of db login config file skipfirstrow(optional): if 1 then skip the first row of data (exclude headers) Returns: None """ from files import loop_csv_file from files import get_schema_file with open(cred_file,'rb') as cred: db_info = json.loads(cred.read()) username = db_info[config]['username'] password = db_info[config]['password'] data_list = loop_csv_file(csv_file) connection = mssql_connect(server, database, username, password) schema_list = get_schema_file(schema_file) #skips the first value of data_list which is the header data_list = iter(data_list) if skipfirstrow == 1: next(data_list) process_datarow_to_list(data_list,schema_list,connection,table)
def load_csv_to_table(table, schema_file, csv_file, server, database, config, cred_file='config/dblogin.config', skipfirstrow=1): """Takes csv file, schema file, with sql server connection params and inserts data to a specified table Args: table: table name where csv data will be written schema_file: schema file that has all column names and data type names csv_file: data being loaded server: sql server host name config: which configuration name to pull username and password credentials cred_file: location of db login config file skipfirstrow(optional): if 1 then skip the first row of data (exclude headers) Returns: None """ from files import loop_csv_file from files import get_schema_file with open(cred_file, 'rb') as cred: db_info = json.loads(cred.read()) username = db_info[config]['username'] password = db_info[config]['password'] data_list = loop_csv_file(csv_file) connection = mssql_connect(server, database, username, password) schema_list = get_schema_file(schema_file) #skips the first value of data_list which is the header data_list = iter(data_list) if skipfirstrow == 1: next(data_list) process_datarow_to_list(data_list, schema_list, connection, table)
def load_csv_to_table(table ,schema_file ,csv_file, connection, skipfirstrow=1): """Takes csv file, schema file, with sql server connection params and inserts data to a specified table Args: table: table name where csv data will be written schema_file: schema file that has all column names and data type names csv_file: data being loaded server: sql server host name config: which configuration name to pull username and password credentials cred_file: location of db login config file skipfirstrow(optional): if 1 then skip the first row of data (exclude headers) Returns: None """ data_list = loop_csv_file(csv_file) schema_list = get_schema_file(schema_file) #skips the first value of data_list which is the header data_list = iter(data_list) if skipfirstrow == 1: next(data_list) insert_datarows_to_table(data_list,schema_list,connection,table)