Chilkat Online Tools

ListUniqueProblems SQL Server Example

AWS Device Farm

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(max)
    -- This example requires the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @authAws int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.AuthAws', @authAws OUT

    EXEC sp_OASetProperty @authAws, 'AccessKey', 'AWS_ACCESS_KEY'
    EXEC sp_OASetProperty @authAws, 'SecretKey', 'AWS_SECRET_KEY'

    -- Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    EXEC sp_OASetProperty @authAws, 'Region', 'us-west-2'
    EXEC sp_OASetProperty @authAws, 'ServiceName', 'devicefarm'
    -- SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    EXEC sp_OAMethod @rest, 'SetAuthAws', @success OUT, @authAws

    -- URL: https://devicefarm.us-west-2.amazonaws.com/
    -- Use the same region as specified above.
    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'devicefarm.us-west-2.amazonaws.com', 443, 1, 1
    IF @success <> 1
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
        PRINT 'ConnectFailReason: ' + @iTmp0
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @authAws
        RETURN
      END

    -- The following code creates the JSON request body.
    -- The JSON created by this code is shown below.

    -- Use this online tool to generate code from sample JSON:
    -- Generate Code to Create JSON

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'arn', 'string'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'nextToken', 'string'

    -- The JSON request body created by the above code:

    -- {
    --   "arn": "string",
    --   "nextToken": "string"
    -- }

    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/x-amz-json-1.1'
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'X-Amz-Target', 'DeviceFarm_20150623.ListUniqueProblems'

    DECLARE @sbRequestBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody
    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @rest, 'FullRequestSb', @success OUT, 'POST', '/', @sbRequestBody, @sbResponseBody
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @authAws
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END
    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @respStatusCode OUT

    PRINT 'response status code = ' + @respStatusCode
    IF @respStatusCode <> 200
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @rest, 'ResponseHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Response Body:'
        EXEC sp_OAMethod @sbResponseBody, 'GetAsString', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @authAws
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody

    -- The following code parses the JSON response.
    -- A sample JSON response is shown below the sample code.

    -- Use this online tool to generate parsing code from sample JSON:
    -- Generate Parsing Code from JSON

    DECLARE @message nvarchar(max)

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @Arn nvarchar(max)

    DECLARE @Availability nvarchar(max)

    DECLARE @Carrier nvarchar(max)

    DECLARE @Architecture nvarchar(max)

    DECLARE @Clock int

    DECLARE @Frequency nvarchar(max)

    DECLARE @FleetName nvarchar(max)

    DECLARE @FleetType nvarchar(max)

    DECLARE @FormFactor nvarchar(max)

    DECLARE @HeapSize int

    DECLARE @Image nvarchar(max)

    DECLARE @Manufacturer nvarchar(max)

    DECLARE @Memory int

    DECLARE @Model nvarchar(max)

    DECLARE @ModelId nvarchar(max)

    DECLARE @Name nvarchar(max)

    DECLARE @Os nvarchar(max)

    DECLARE @Platform nvarchar(max)

    DECLARE @Radio nvarchar(max)

    DECLARE @RemoteAccessEnabled int

    DECLARE @RemoteDebugEnabled int

    DECLARE @Height int

    DECLARE @Width int

    DECLARE @jobArn nvarchar(max)

    DECLARE @jobName nvarchar(max)

    DECLARE @result nvarchar(max)

    DECLARE @runArn nvarchar(max)

    DECLARE @runName nvarchar(max)

    DECLARE @suiteArn nvarchar(max)

    DECLARE @suiteName nvarchar(max)

    DECLARE @testArn nvarchar(max)

    DECLARE @testName nvarchar(max)

    DECLARE @k int

    DECLARE @count_k int

    DECLARE @arn nvarchar(max)

    DECLARE @deviceArn nvarchar(max)

    DECLARE @instanceProfileArn nvarchar(max)

    DECLARE @Description nvarchar(max)

    DECLARE @instanceProfileName nvarchar(max)

    DECLARE @PackageCleanup int

    DECLARE @RebootAfterUse int

    DECLARE @status nvarchar(max)

    DECLARE @udid nvarchar(max)

    DECLARE @json1 int

    DECLARE @i1 int

    DECLARE @count_i1 int

    DECLARE @strVal nvarchar(max)

    DECLARE @nextToken nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @nextToken OUT, 'nextToken'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'uniqueProblems.string'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @message OUT, 'uniqueProblems.string[i].message'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'uniqueProblems.string[i].problems'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @Arn OUT, 'uniqueProblems.string[i].problems[j].device.arn'
            EXEC sp_OAMethod @jResp, 'StringOf', @Availability OUT, 'uniqueProblems.string[i].problems[j].device.availability'
            EXEC sp_OAMethod @jResp, 'StringOf', @Carrier OUT, 'uniqueProblems.string[i].problems[j].device.carrier'
            EXEC sp_OAMethod @jResp, 'StringOf', @Architecture OUT, 'uniqueProblems.string[i].problems[j].device.cpu.architecture'
            EXEC sp_OAMethod @jResp, 'IntOf', @Clock OUT, 'uniqueProblems.string[i].problems[j].device.cpu.clock'
            EXEC sp_OAMethod @jResp, 'StringOf', @Frequency OUT, 'uniqueProblems.string[i].problems[j].device.cpu.frequency'
            EXEC sp_OAMethod @jResp, 'StringOf', @FleetName OUT, 'uniqueProblems.string[i].problems[j].device.fleetName'
            EXEC sp_OAMethod @jResp, 'StringOf', @FleetType OUT, 'uniqueProblems.string[i].problems[j].device.fleetType'
            EXEC sp_OAMethod @jResp, 'StringOf', @FormFactor OUT, 'uniqueProblems.string[i].problems[j].device.formFactor'
            EXEC sp_OAMethod @jResp, 'IntOf', @HeapSize OUT, 'uniqueProblems.string[i].problems[j].device.heapSize'
            EXEC sp_OAMethod @jResp, 'StringOf', @Image OUT, 'uniqueProblems.string[i].problems[j].device.image'
            EXEC sp_OAMethod @jResp, 'StringOf', @Manufacturer OUT, 'uniqueProblems.string[i].problems[j].device.manufacturer'
            EXEC sp_OAMethod @jResp, 'IntOf', @Memory OUT, 'uniqueProblems.string[i].problems[j].device.memory'
            EXEC sp_OAMethod @jResp, 'StringOf', @Model OUT, 'uniqueProblems.string[i].problems[j].device.model'
            EXEC sp_OAMethod @jResp, 'StringOf', @ModelId OUT, 'uniqueProblems.string[i].problems[j].device.modelId'
            EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'uniqueProblems.string[i].problems[j].device.name'
            EXEC sp_OAMethod @jResp, 'StringOf', @Os OUT, 'uniqueProblems.string[i].problems[j].device.os'
            EXEC sp_OAMethod @jResp, 'StringOf', @Platform OUT, 'uniqueProblems.string[i].problems[j].device.platform'
            EXEC sp_OAMethod @jResp, 'StringOf', @Radio OUT, 'uniqueProblems.string[i].problems[j].device.radio'
            EXEC sp_OAMethod @jResp, 'IntOf', @RemoteAccessEnabled OUT, 'uniqueProblems.string[i].problems[j].device.remoteAccessEnabled'
            EXEC sp_OAMethod @jResp, 'IntOf', @RemoteDebugEnabled OUT, 'uniqueProblems.string[i].problems[j].device.remoteDebugEnabled'
            EXEC sp_OAMethod @jResp, 'IntOf', @Height OUT, 'uniqueProblems.string[i].problems[j].device.resolution.height'
            EXEC sp_OAMethod @jResp, 'IntOf', @Width OUT, 'uniqueProblems.string[i].problems[j].device.resolution.width'
            EXEC sp_OAMethod @jResp, 'StringOf', @jobArn OUT, 'uniqueProblems.string[i].problems[j].job.arn'
            EXEC sp_OAMethod @jResp, 'StringOf', @jobName OUT, 'uniqueProblems.string[i].problems[j].job.name'
            EXEC sp_OAMethod @jResp, 'StringOf', @message OUT, 'uniqueProblems.string[i].problems[j].message'
            EXEC sp_OAMethod @jResp, 'StringOf', @result OUT, 'uniqueProblems.string[i].problems[j].result'
            EXEC sp_OAMethod @jResp, 'StringOf', @runArn OUT, 'uniqueProblems.string[i].problems[j].run.arn'
            EXEC sp_OAMethod @jResp, 'StringOf', @runName OUT, 'uniqueProblems.string[i].problems[j].run.name'
            EXEC sp_OAMethod @jResp, 'StringOf', @suiteArn OUT, 'uniqueProblems.string[i].problems[j].suite.arn'
            EXEC sp_OAMethod @jResp, 'StringOf', @suiteName OUT, 'uniqueProblems.string[i].problems[j].suite.name'
            EXEC sp_OAMethod @jResp, 'StringOf', @testArn OUT, 'uniqueProblems.string[i].problems[j].test.arn'
            EXEC sp_OAMethod @jResp, 'StringOf', @testName OUT, 'uniqueProblems.string[i].problems[j].test.name'
            SELECT @k = 0
            EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_k OUT, 'uniqueProblems.string[i].problems[j].device.instances'
            WHILE @k < @count_k
              BEGIN
                EXEC sp_OASetProperty @jResp, 'K', @k
                EXEC sp_OAMethod @jResp, 'StringOf', @arn OUT, 'uniqueProblems.string[i].problems[j].device.instances[k].arn'
                EXEC sp_OAMethod @jResp, 'StringOf', @deviceArn OUT, 'uniqueProblems.string[i].problems[j].device.instances[k].deviceArn'
                EXEC sp_OAMethod @jResp, 'StringOf', @instanceProfileArn OUT, 'uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.arn'
                EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.description'
                EXEC sp_OAMethod @jResp, 'StringOf', @instanceProfileName OUT, 'uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.name'
                EXEC sp_OAMethod @jResp, 'IntOf', @PackageCleanup OUT, 'uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.packageCleanup'
                EXEC sp_OAMethod @jResp, 'IntOf', @RebootAfterUse OUT, 'uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.rebootAfterUse'
                EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'uniqueProblems.string[i].problems[j].device.instances[k].status'
                EXEC sp_OAMethod @jResp, 'StringOf', @udid OUT, 'uniqueProblems.string[i].problems[j].device.instances[k].udid'

                EXEC sp_OAMethod @jResp, 'ObjectOf', @json1 OUT, 'uniqueProblems.string[i].problems[j].device.instances[k]'
                SELECT @i1 = 0
                EXEC sp_OAMethod @json1, 'SizeOfArray', @count_i1 OUT, 'instanceProfile.excludeAppPackagesFromCleanup'
                WHILE @i1 < @count_i1
                  BEGIN
                    EXEC sp_OASetProperty @json1, 'I', @i1
                    EXEC sp_OAMethod @json1, 'StringOf', @strVal OUT, 'instanceProfile.excludeAppPackagesFromCleanup[i]'
                    SELECT @i1 = @i1 + 1
                  END
                EXEC @hr = sp_OADestroy @json1

                EXEC sp_OAMethod @jResp, 'ObjectOf', @json1 OUT, 'uniqueProblems.string[i].problems[j].device.instances[k]'
                SELECT @i1 = 0
                EXEC sp_OAMethod @json1, 'SizeOfArray', @count_i1 OUT, 'labels'
                WHILE @i1 < @count_i1
                  BEGIN
                    EXEC sp_OASetProperty @json1, 'I', @i1
                    EXEC sp_OAMethod @json1, 'StringOf', @strVal OUT, 'labels[i]'
                    SELECT @i1 = @i1 + 1
                  END
                EXEC @hr = sp_OADestroy @json1

                SELECT @k = @k + 1
              END
            SELECT @j = @j + 1
          END
        SELECT @i = @i + 1
      END

    -- A sample JSON response body parsed by the above code:

    -- {
    --   "nextToken": "string",
    --   "uniqueProblems": {
    --     "string": [
    --       {
    --         "message": "string",
    --         "problems": [
    --           {
    --             "device": {
    --               "arn": "string",
    --               "availability": "string",
    --               "carrier": "string",
    --               "cpu": {
    --                 "architecture": "string",
    --                 "clock": number,
    --                 "frequency": "string"
    --               },
    --               "fleetName": "string",
    --               "fleetType": "string",
    --               "formFactor": "string",
    --               "heapSize": number,
    --               "image": "string",
    --               "instances": [
    --                 {
    --                   "arn": "string",
    --                   "deviceArn": "string",
    --                   "instanceProfile": {
    --                     "arn": "string",
    --                     "description": "string",
    --                     "excludeAppPackagesFromCleanup": [
    --                       "string"
    --                     ],
    --                     "name": "string",
    --                     "packageCleanup": boolean,
    --                     "rebootAfterUse": boolean
    --                   },
    --                   "labels": [
    --                     "string"
    --                   ],
    --                   "status": "string",
    --                   "udid": "string"
    --                 }
    --               ],
    --               "manufacturer": "string",
    --               "memory": number,
    --               "model": "string",
    --               "modelId": "string",
    --               "name": "string",
    --               "os": "string",
    --               "platform": "string",
    --               "radio": "string",
    --               "remoteAccessEnabled": boolean,
    --               "remoteDebugEnabled": boolean,
    --               "resolution": {
    --                 "height": number,
    --                 "width": number
    --               }
    --             },
    --             "job": {
    --               "arn": "string",
    --               "name": "string"
    --             },
    --             "message": "string",
    --             "result": "string",
    --             "run": {
    --               "arn": "string",
    --               "name": "string"
    --             },
    --             "suite": {
    --               "arn": "string",
    --               "name": "string"
    --             },
    --             "test": {
    --               "arn": "string",
    --               "name": "string"
    --             }
    --           }
    --         ]
    --       }
    --     ]
    --   }
    -- }

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @authAws
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbRequestBody
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO