Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    To get the id of a record after operation add

    After a successful add i need to get hold of the id (primary key) of the added record. As the sql (generated by S.GWT) shows, the server try to return record with id= 56, but the references to the other records (inner joins) lead to no record returned to client side. Is there a way to write the data source to not involve the other tables? ..by sql-templating or something else? Jointype = "outer" will lead to other problems where this ds is also used.

    the involved data source:
    Code:
    <DataSource 
    	schema="dbo"
    	dbName="MSSQL"
    	tableName="lor_lotteries"
    	ID="lotteries"
    	dataSourceVersion="1"
    	serverType="sql"
    	title = "Lotteri"
    	useAnsiJoins="true"
    >
    	<fields>
     		<field name="id" primaryKey="true" detail="true" type="sequence" foreignKey="financial_last_registration.lottery_id"></field>
     		<field name="contractor_id" type="integer" detail="true" foreignKey="contractor.id"></field>
     		<field name="organization_id" type="integer" detail="true" foreignKey="organization.id"></field>
    		<field name="authorization_ref_journal" type="text" length="20" title="Godkjenning i 360"/>
    		<field name="type" type="integer" foreignKey="lottery_types.id" hidden="true"/>
    		<field name="typeOfBingo" title="Type bingo" includeFrom="lottery_types.name"/>
    		<field name="contractor_orgno" type="text" includeFrom="contractor.orgno" detail="true" />
    		<field name="contractor_navn" title="Entreprenør" type="text" includeFrom="contractor.navn" />
    		<field name="contractor_postnrSted" title="Entreprenørs adresse" type="text" includeFrom="contractor.postnrSted" detail="true" />
    		<field name="organization_navn" title="Organisasjon" type="text" includeFrom="organization.navn" />
    		<field name="last_reg_date" title="Siste regnskap" type="date" includeFrom="financial_last_registration.registration_timestamp"  />
    		<field name="last_approved_date" title="Regnskap godkjent" type="date" includeFrom="financial_last_registration.approved_timestamp" />
    		<field name="deleted" type="boolean"  detail="true"></field> 
    		<field name="valid_from" title="Gyldig fra" type="date"/>
    		<field name="valid_to" title="Gyldig til" type="date"/>		
    		<field name="venue_id" type="integer" detail="true" foreignKey="venue.id" joinType="outer"></field>
    		<field name="venue_name" type="text" includeFrom="venue.navn" detail="true"/>
    		<field name="venue_adress" type="text" includeFrom="venue.postnrSted" detail="true"/>
    		<field name="venue_orgno" type="text" includeFrom="venue.orgno" detail="true"/>
    	</fields>
    </DataSource>
    sql from the console:
    Code:
    SELECT lor_lotteries.authorization_ref_journal, lor_lotteries.contractor_id, lor_lotteries.deleted, lor_lotteries.id, lor_lotteries.organization_id, lor_lotteries.type, lor_lotteries.valid_from, lor_lotteries.valid_to, lor_lotteries.venue_id, lor_lottery_types.name AS typeOfBingo, lor_contractors.orgno AS contractor_orgno, view_grunndata_er.navn AS contractor_navn, view_grunndata_er.postnrSted AS contractor_postnrSted, view_grunndata_er_2.navn AS organization_navn, view_financial_last_registration.registration_timestamp AS last_reg_date, view_financial_last_registration.approved_timestamp AS last_approved_date, view_grunndata_er_3.navn AS venue_name, view_grunndata_er_3.postnrSted AS venue_adress, lor_venues.orgno AS venue_orgno 
    FROM lor_lotteries 
    JOIN lor_lottery_types ON lor_lotteries.type = lor_lottery_types.id 
    JOIN lor_contractors ON lor_lotteries.contractor_id = lor_contractors.id 
    JOIN view_grunndata_er ON lor_contractors.orgno = view_grunndata_er.orgnr 
    JOIN lor_organizations ON lor_lotteries.organization_id = lor_organizations.id 
    JOIN view_grunndata_er_2 ON lor_organizations.orgno = view_grunndata_er_2.orgnr 
    JOIN view_financial_last_registration ON lor_lotteries.id = view_financial_last_registration.lottery_id 
    LEFT OUTER JOIN lor_venues ON lor_lotteries.venue_id = lor_venues.id 
    JOIN view_grunndata_er_3 ON lor_venues.orgno = view_grunndata_er_3.orgnr 
    WHERE (lor_lotteries.id=56)
    response as shown in the RPC tab in the Developer Console :
    Code:
    [
        {
            data:[
            ], 
            invalidateCache:false, 
            isDSResponse:true, 
            operationType:"add", 
            queueStatus:0, 
            status:0
        }
    ]

    SmartClient Version: v8.3p_2013-05-05/PowerEdition Deployment (built 2013-05-05)

    Firefox 23.0.1
    Last edited by Sindre; 26 Aug 2013, 03:36.

    #2
    You can set operationBinding.cacheSyncOperation to the operationId of another operationBinding that performs whatever SQL you need to return the appropriate added record.

    Comment


      #3
      Thanks. Your answer resulted in this atempt to alter the joins.
      Code:
      	<operationBindings>
      	<operationBinding operationType="add" cacheSyncOperation="getId">
      	</operationBinding>
      		<operationBinding operationType="fetch" operationId="getId">
      			<tableClause> lor_lotteries 
      JOIN lor_lottery_types ON lor_lotteries.type = lor_lottery_types.id 
      JOIN lor_contractors ON lor_lotteries.contractor_id = lor_contractors.id 
      JOIN view_grunndata_er ON lor_contractors.orgno = view_grunndata_er.orgnr 
      LEFT OUTER JOIN lor_organizations ON lor_lotteries.organization_id = lor_organizations.id 
      JOIN view_grunndata_er_2 ON lor_organizations.orgno = view_grunndata_er_2.orgnr 
      JOIN view_financial_last_registration ON lor_lotteries.id = view_financial_last_registration.lottery_id 
      LEFT OUTER JOIN lor_venues ON lor_lotteries.venue_id = lor_venues.id 
      JOIN view_grunndata_er_3 ON lor_venues.orgno = view_grunndata_er_3.orgnr </tableClause>
      		</operationBinding>
      	</operationBindings>
      But the <tableClause> did not override the content in the sql. It just added it to it. 16 joins instead of 8. So I got this "bug-feeling".

      I have now a solution where i use customSQL to ovveride the comlete expression.

      Comment


        #4
        If you feel you may have foud a bug where the tableClause doesn't successfully override, feel free to submit a minimal, ready-to-run testcase and we'll take a look.

        Comment

        Working...
        X