January 19, 2017

Script Component Variable Limitation Using Blob

Its' been awhile since my last post. I have been very busy working on new technologies and platforms such as Cassandra, PostgreSql, Elastic Search and Maven projects, not too mention Kafka, so when the opportunity came to generate a ragged right file format I said 'HELL YEA', so he is the problem concatenate a encrypted string into a single row and insert that into a table, after some quick searches and ingenuity I build the below code and the task got done and bury, but everything is not as simple as it seems, the output is inserted into a varchar(max) so initially I used dt_text but not error and not data inserted after much scratching my head "This should work" I change the the type to dt_image as the blob type get a binary array and BOOOMMMM data.
enjoy.
public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        char cquoute = (char)31;
        char cdelimite = (char)30;
        String quote = cquoute.ToString();
        String delimite = quote + cdelimite.ToString() + quote;

        StringBuilder RawData = new StringBuilder();

        RawData.Append(quote + (Row.customerAddressId.ToString()) + delimite);
        RawData.Append((!Row.AddressName_IsNull ? Row.AddressName : "NULL") + delimite);
        RawData.Append((!Row.CompanyName_IsNull ? Row.CompanyName : "NULL") + delimite);
        RawData.Append((!Row.Address1_IsNull ? Row.Address1 : "NULL") + delimite);
        RawData.Append((!Row.Address2_IsNull ? Row.Address2 : "NULL") + delimite);
        RawData.Append((!Row.City_IsNull ? Row.City : "NULL") + delimite);
        RawData.Append((!Row.StateName_IsNull ? Row.StateName : "NULL") + delimite);
        RawData.Append((!Row.Zip_IsNull ? Row.Zip : "NULL") + delimite);
        RawData.Append((!Row.CountryName_IsNull ? Row.CountryName : "NULL") + delimite);
        RawData.Append((!Row.FirstName_IsNull ? Row.FirstName : "NULL") + delimite);
        RawData.Append((!Row.LastName_IsNull ? Row.LastName : "NULL") + delimite);
        RawData.Append((!Row.Phone_IsNull ? Row.Phone : "NULL") + delimite);
        RawData.Append((!Row.IsDefaultBilling_IsNull ? Row.IsDefaultBilling.ToString() : "False") + delimite);
        RawData.Append((!Row.IsDefaultShipping_IsNull ? Row.IsDefaultShipping.ToString() : "False") + delimite);
        RawData.Append((!Row.IsAPO_IsNull ? Row.IsAPO.ToString() : "False") + delimite);
        RawData.Append((!Row.AddressUuid_IsNull ? Row.AddressUuid : "NULL") + delimite);
        RawData.Append((!Row.ModifiedDate_IsNull ? Row.ModifiedDate.ToString() : "NULL") + quote);

        Output0Buffer.AddRow();
        Output0Buffer.customerid = (int) Row.CustomerId;
        Output0Buffer.addressid = (int)Row.customerAddressId;
        Output0Buffer.RawData.AddBlobData(Encoding.UTF8.GetBytes(RawData.ToString()));

No comments:

Post a Comment

Contact Form

Name

Email *

Message *