7 Replies Latest reply on Sep 9, 2013 6:03 AM by Alexey Mironov

    cycling rhoconnect after create

    Alexey Mironov

      Hello, Im try to sync with MS SQL Server (I use TinyTds) by Rhoconnect (sync my app log file) -

       

      class TsdLog < SourceAdapter

        def initialize(source)

          @client = TinyTds::Client.new(:username => 'sa', :password => '', :host => '10.39.3.200', :database => 'cp_suite')

          super(source)

        end

       

        def login

        end

       

        def query(params=nil)

        end

       

        def sync

          super

        end

       

        def create(create_hash)

          puts "Call Create Log"

                 

      rez = @client.execute("INSERT INTO [TSD_Log]

            ([UserId]

            ,[DeviceID]

            ,[Date]

            ,[Time]

            ,[Operation]

            ,[Status]

            ,[Comment])

      VALUES

            ('" + create_hash["UserId"].to_s + "',

             '" + create_hash["DeviceID"].to_s + "',

             CONVERT(DATETIME, '" + create_hash["Date"].to_s + "', 126),

             " + create_hash["Time"].to_s + ",

             " + create_hash["Operation"].to_s + ",

             " + "0" + ",

             '" + create_hash["Comment"].to_s + "')")

         

        end

       

        end

       

      INSERT command do whell and my log records add to the TSD_log table, but after thet rho connect cecling with log -

       

      what can i do to stop it?

      When I stay onle puts "some" in create method cycling don't hapend.... Is it TinyTds bag?

        • Re: cycling rhoconnect after create
          Kutir Mobility

          The create method in a RhoConnect source must return the primary key of the row you inserted

           

          Thanks,

          Javier

          Kutir Mobility

            • Re: cycling rhoconnect after create
              Alexey Mironov

              Thenk Javier, how can I return it (i can do some select and buid nested hash)? Can you show some example (return hash name) please....

                • Re: Re: cycling rhoconnect after create
                  Kutir Mobility

                  There is an example of building a RhoConnect application here:

                   

                  The fast way to multiplatform data-aware mobile applications. Part 2.

                   

                  Look for the "create" method and you will see it returns a simple value (not a hash). The way to obtain that value depends on your database server and your table schema. If the primary key in your SQL Server table is of type IDENTITY, I believe TinyTds lets you call "insert" to get the last inserted primary key, which is what you want, so you could just return:

                   

                  rez.insert
                  

                   

                  Javier

                  Kutir Mobility

                    • Re: cycling rhoconnect after create
                      Alexey Mironov

                      Thenk very mach! Im try rez.insert erly but it does not halp becose my TSD_Log table have not any primary key. I add some composite primary key and so was work as well.

                      • Re: cycling rhoconnect after create
                        Alexey Mironov

                        Javier, I have one litle question about Rhoconnect logic: For example -

                        i have table T in me backend and model T in me Rho App. Im aync in by Rhoconnect.

                        1. Insert one record (a) into table T

                        2. Do sync and record a able in model T

                        3. Delete record a from model T in me Rho Mobile App

                        4. Do sync. Rhoconnect generate delete command in T adapter but I dont calling DELETE command. (It is not nided for app logic). And becose record a stil live in table T.

                        5. Do sync and whait what record a in the table T sync to model T, but nobody hapend. Rhoconect not call query in adapter. Why?

                          • Re: cycling rhoconnect after create
                            Kutir Mobility

                            Rhoconnect keeps a local cache in Redis so that it does not have to query your database every time. You can use the poll_interval setting to tweak how long this cache lasts, or even use pass_through if you don't want to keep any data for that model in Redis.

                             

                            Regarding row deletion, if you delete a record in your application but not run a DELETE to your database, the record may reappear in your application if you reset the database and sync again. You should think whether this is desirable or not for your use case but in general, things should be consistent between your application and the DB. If you do not want to use DELETE, you can:

                             

                            - add a column to your table called "deleted" and set it to true when a record is deleted

                            - in your "query" method, only select records where deleted is false

                             

                            That gives you a consistent view between the database and the application, and you still keeping the records in the database if you need them. The mobile app does not need to know about this "deleted" column, the Rhoconnect server together with the database will handle it.

                             

                            Hope that helps,

                            Javier

                            Kutir Mobility

                            1 of 1 people found this helpful