2 Replies Latest reply: Jul 31, 2014 3:56 AM by Anders Johansson RSS

    Connector handling more then one table

      Hello. I'm a little unsure if I posted this question in the right section, but all categories under connectors were about specific connectors.

       

      I'm a fair bit into the development of a connector and can handle one table at a time in it. I've also managed to create two tables in the QVX-file like this.

       

      for(int i=0; i<2; i++) {

           MTables.Add(new QvxTable {

                TableName = "table"+i,

                GetRows = getRows,

                Fields = Fields[i]

           });

      }

       

      (Btw how do I change to preformated for code examples?)

       

      The above code will produce two tables in the QVX file. However they will both contain the same data since the delegate is the same.

      Creating a specific delegate for each table is not an option since I don't know how many tables I'll get from the source, and neither do I know what they will contain on beforehand.

       

      How can I associate my delegate getRows with the right table? Is it possible to access the object calling the delegate? This post (http://stackoverflow.com/questions/5409580/action-delegate-how-to-get-the-instance-that-call-the-method) suggest that it is possible but I'm pretty green on C# and delegates in particular and can't really make use of it.

       

      If I could get the name of the QvxTable object calling getRows() I would probably be able to use something like this in the getRows function:

       

      // Assume we have the following property in MyQvxConnection

      public Dictionary<string, MyTable> DictionaryOfTables

       

      // Also assume that MyTable have the method getData() that returns an IEnumerable

       

      // In getRows()

      foreach (MyRow rowData in DictionaryOfTables[CallingTable.TableName].getData())

       

      Any directions and ideas are appreciated

        • Re: Connector handling more then one table
          prabhu appu

          Hi

           

          Any One have idea on this. I'm also facing the same issue...

           

          Regards,

          Prabhu Appu

            • Re: Connector handling more then one table

              Hello Prabhu,

               

              I solved it by assigning a function pointer to the property GetRows of QvxTable:

              QvxTable table = new QvxTable {

                        TableName = "table",

                        Fields = Fields

                   });

              table.GetRows = mapRows(sourceContext, table);

              MTables.Add(table);

               

              mapRows() is a function returning an anonymous function which comply to the signature of QvxTable.GetRows property.

              You can add arguments to QvxTable as necessary (to describe the context) and they will be available in the scope of the anonymous function. In the example below I need an object describing the source data and an argument containing an instance of the target table

               

              Private QlikView.Qvx.QvxLibrary.QvxTable.GetRowsHandler mapRows(IPodioApplication app, QvxTable table)

                  {

                      return () =>

                      {

                          // Implement context based stuffz

                          return new List<QvxDataRow>();

                      };

                  }

              }


              You may find syntax error in the example, but VS should detect that