Clarity

  • 1.  Gel script -Reading csv file and passing the o/p  to sql script

    Posted Dec 01, 2014 03:05 PM

    Hi All,

    Could you please help on my below issue .

    In this script i am reading csv file then passing the o/p as input to sql script  but from the <gel:out> I am getting the results of the last record in the csv file .My guess here is result variable is holding the last record  from the select statement and its resulting the o/p (<gel:out> of the last record of the csv file.


    I have tested by replacing the select with update statement its working fine .

    <gel:script xmlns:core="jelly:core"

            xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"

            xmlns:xsd="http://www.w3.org/2001/XMLSchema"

            xmlns:files="jelly:com.niku.union.gel.FileTagLibrary"

            xmlns:sql="jelly:sql">

            <gel:setDataSource dbId="Niku"/>

     

        <gel:parameter var="vFileName" default="ok1.csv"/>

     

        <files:readFile fileName="${vFileName}" delimiter="," var="vResourceData" embedded="false"/>

     

            <core:forEach items="${vResourceData.rows}" var="row" begin="0" end="10">

                <core:set var="A" value="${row[0]}"/>

     

               <sql:query escapeText="0" var="result">

                <![CDATA[

                SELECT  u.first_name firstName,

                               u.last_name lastName,

                               u.user_name userName

                FROM    cmn_sec_users u

                WHERE  u.user_name in('${A}')

                ]]>

                </sql:query>           

                 </core:forEach>

              <core:forEach items="${result.rows}" trim="true" var="row">

     

                    <gel:out>${row.firstName}</gel:out>

                    <gel:out>${row.userName}</gel:out>

     

     

            </core:forEach>

     

    </gel:script>

     

    Many thanks .

     

    Regards,

    Udaya kumar k



  • 2.  Re: Gel script -Reading csv file and passing the o/p  to sql script
    Best Answer

    Posted Dec 01, 2014 03:59 PM

    You are only iterating over the last resultset.  Just move your gel:out loop into the sql:query loop.

    Update will work as it is updating each record in the loop and persist the data in the database.

     

     

    <gel:script xmlns:core="jelly:core"
            xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:files="jelly:com.niku.union.gel.FileTagLibrary"
            xmlns:sql="jelly:sql">
        <gel:setDataSource dbId="Niku"/>
    
        <gel:parameter var="vFileName" default="ok1.csv"/>
    
        <files:readFile fileName="${vFileName}" delimiter="," var="vResourceData" embedded="false"/>
    
        <core:forEach items="${vResourceData.rows}" var="row" begin="0" end="10">
            <core:set var="A" value="${row[0]}"/>
    
            <sql:query escapeText="0" var="result">
                <![CDATA[
                SELECT  u.first_name firstName,
                              u.last_name lastName,
                              u.user_name userName
                FROM    cmn_sec_users u
                WHERE  u.user_name in('${A}')
                ]]>
            </sql:query>
    
            <core:forEach items="${result.rows}" trim="true" var="row">
                <gel:out>${row.firstName}</gel:out>
                <gel:out>${row.userName}</gel:out>
            </core:forEach>          
        </core:forEach>
    
    </gel:script>
    
    

     

     

    V/r,

    Gene



  • 3.  Re: Gel script -Reading csv file and passing the o/p  to sql script

    Posted Dec 02, 2014 12:48 AM

    Hi Gene,

     

    Thanks a lot.

    I was an impression that result variable will holds the entire data and  I am unable to fetch the data from result variable.

     

    Regards,

    Udaya kumar k