2 Replies Latest reply on Nov 2, 2006 4:32 AM by Newsgroup_User

    Session struct object to database.

    Level 7
      How do i store the entire session struct object to database.
      is there anyway i can covert complex vars to simple ??

      lke example to store an image, we use cfcontent .
      How do i achieve the same for complex vars like struct, query obj etc ?


        • 1. Re: Session struct object to database.
          monkey_woo_too Level 1
          1. You cannot save 'complex values' you can save strings
          2. You can convert 'complex values' to strings by serialising them
          3. You can serialise 'complex values' in CF by using WDDX
          4. So, use <cfwddx> or one of the WDDX functions to convert your value and write the result into a varchar field.
          5. Then use cfwddx or similar to convert the varchar back into a complex value when you need to read it back.

          I know the pedants out there will take issue with my over simplification here, but...

          http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-c20.htm
          • 2. Re: Session struct object to database.
            Level 7
            Many thanks,

            Basically i wanted to have "Save shopping cart" functionality where i am
            using array of structs (session.arBasket) to store cart items in session.. i
            am using a variable session.arBasket which is an object of cart.cfc
            component.

            The following code suggested by you helped me out.

            Thank You again :)

            <cfset session.arBasket = arraynew(1)>
            <cfset session.arBasket[1] = structNew()>
            <cfset session.arBasket[1].fname = "Srikanth">
            <cfset session.arBasket[1].Lname = "Madishetti">
            <cfset session.arBasket[2] = structNew()>
            <cfset session.arBasket[2].fname = "Sukumar">
            <cfset session.arBasket[2].Lname = "Madishetti">
            <cfwddx action="CFML2WDDX" input="#session.arBasket#" output="string">
            <!--- query to save output="string" of CFML2WDDX to database --->
            <!--- query to retrieve wddx packet stored in database --->
            <cfwddx action="WDDX2CFML" input="#string#" output="struct">
            <cfdump var="#struct#">

            "monkey woo too" <webforumsuser@macromedia.com> wrote in message
            news:eickob$d58$1@forums.macromedia.com...
            > 1. You cannot save 'complex values' you can save strings
            > 2. You can convert 'complex values' to strings by serialising them
            > 3. You can serialise 'complex values' in CF by using WDDX
            > 4. So, use <cfwddx> or one of the WDDX functions to convert your value
            and
            > write the result into a varchar field.
            > 5. Then use cfwddx or similar to convert the varchar back into a complex
            value
            > when you need to read it back.
            >
            > I know the pedants out there will take issue with my over simplification
            here,
            > but...
            >
            > http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-c20.htm
            >
            >