3 Replies Latest reply on Jun 10, 2013 11:37 AM by Kutir Mobility

    Insert data in db using hash

      Hi All,

      I want to insert the data from the model class to oracle db, i can insert the hard coded values as shown below.

      Please guide me to do the actual value coming from the Rhodes application..

       

      def create(create_hash)

         @conn.exec("INSERT INTO product VALUES('Nokia 7610','Nokia','123','333','33')")

        @conn.commit

      end

       

      Also please help me to understand the architecture of passing data from Rhodes--> RhoConnect and vice-versa. (Means to say how and in which form data is transferred and parsed?)

        • Re: Insert data in db using hash
          Kutir Mobility

          Hi Ankur Srivastava,

          The architecture of passing data from Rhodes--> RhoConnect and vice-versa.

          For example,

          We have product model in  rhodes and rhoconnect.

          When we click sync button it syncrinize product model with product source adapter using SyncEngine API.

          SyncEngine API is used to synchronize data for the Rhodes model and handle updates between the Rhodes application and the RhoConnect server.

          It has dosync and dosync_source.

          dosync - Start a synchronization with the RhoConnect server.

          dosync_source - Start a synchronization with the RhoConnect server for a given source id . eg: pass product model data to rhoconnect and vice-versa.

          Rhodes Controller:

           

          def create

          @product = Product.create(@params['product'])

          SyncEngine.dosync_source(Product.get_source_id.to_i, false) #sync by source id

          end

          Rhoconnect - product.rb:

          def create(create_hash)

              res = RestClient.post(@base,:product => create_hash)

          end

           

           

          Thanks

          Surendran S

          Kutir Mobility

            • Re: Insert data in db using hash

              Thanks Surendran for explaining me the architecture.

               

              I am really strucked in inserting the data in oracle using RhoConnect.

              I got the idea and able to pass the data to the dummy webserver of Product tutorial.

               

              I want to insert it in oracle db. I have tried the below:

               

              def create(create_hash)

                @Product_name = "#{create_hash['name']}"

                @Product_brand = "#{create_hash['brand']}"

                @Product_price = "#{create_hash['price']}"

                @Product_sku = "#{create_hash['sku']}"

                @Product_quantity = "#{create_hash['quantity']}"

               

                @conn.exec("INSERT INTO product VALUES(@Product_name,@Product_brand,@Product_price,@Product_sku,@Product_quantity)")

                @conn.commit

              end

               

               

              Please guide me !!

              Thanks in advance.