Thursday 14 May 2009

Import csv job

Here is an import job for importing tuples from a csv file:


static void importJob(Args _args)
{
    FileIOPermission        permission;
    AsciiIo                 file;
    Filename                fileName = @"c:\test\test.csv";
    CustTable               custTable;
    container               line;
    #define.fieldDelimiter(";")
    #define.recordDelimiter("\n")
    #define.read("r")
    ttsBegin;
    permission  = new FileIOPermission(fileName, #read);
    permission.assert();
 
    file = new AsciiIo(fileName, #read);
    file.inFieldDelimiter(#fieldDelimiter);
    file.inRecordDelimiter(#recordDelimiter);
 
    if(!file || file.status() != IO_Status::Ok)
    {
        throw error(strFmt("@SYS76826", file));
    }
 
    while(file.status() == IO_Status::Ok)
    {
        line = file.read();
     
        custTable.AccountNum = conPeek(line, 1);
        custTable.insert();
    }
    ttsCommit;
     


}
Happy hacking

No comments: