DescribeTable Objective-C Example
#import <CkoRest.h>
#import <CkoAuthAws.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <NSString.h>
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoRest *rest = [[CkoRest alloc] init];
BOOL success;
CkoAuthAws *authAws = [[CkoAuthAws alloc] init];
authAws.AccessKey = @"AWS_ACCESS_KEY";
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.)
authAws.Region = @"us-west-2";
authAws.ServiceName = @"redshift-data";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];
// URL: https://redshift-data.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"redshift-data.us-west-2.amazonaws.com" port: [NSNumber numberWithInt: 443] tls: YES autoReconnect: YES];
if (success != YES) {
NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
NSLog(@"%@",rest.LastErrorText);
return;
}
// 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
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"ClusterIdentifier" value: @"string"];
[json UpdateString: @"ConnectedDatabase" value: @"string"];
[json UpdateString: @"Database" value: @"string"];
[json UpdateString: @"DbUser" value: @"string"];
[json UpdateInt: @"MaxResults" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"NextToken" value: @"string"];
[json UpdateString: @"Schema" value: @"string"];
[json UpdateString: @"SecretArn" value: @"string"];
[json UpdateString: @"Table" value: @"string"];
// The JSON request body created by the above code:
// {
// "ClusterIdentifier": "string",
// "ConnectedDatabase": "string",
// "Database": "string",
// "DbUser": "string",
// "MaxResults": number,
// "NextToken": "string",
// "Schema": "string",
// "SecretArn": "string",
// "Table": "string"
// }
[rest AddHeader: @"Content-Type" value: @"application/x-amz-json-1.1"];
[rest AddHeader: @"X-Amz-Target" value: @"RedshiftData.DescribeTable"];
CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestSb: @"POST" uriPath: @"/" requestBody: sbRequestBody responseBody: sbResponseBody];
if (success != YES) {
NSLog(@"%@",rest.LastErrorText);
return;
}
int respStatusCode = [rest.ResponseStatusCode intValue];
NSLog(@"%@%d",@"response status code = ",respStatusCode);
if (respStatusCode != 200) {
NSLog(@"%@",@"Response Header:");
NSLog(@"%@",rest.ResponseHeader);
NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[sbResponseBody GetAsString]);
return;
}
CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: 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
NSString *columnDefault = 0;
int isCaseSensitive;
int isCurrency;
int isSigned;
NSString *label = 0;
int length;
NSString *name = 0;
int nullable;
int precision;
int scale;
NSString *schemaName = 0;
NSString *tableName = 0;
NSString *typeName = 0;
NSString *NextToken = [jResp StringOf: @"NextToken"];
NSString *TableName = [jResp StringOf: @"TableName"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"ColumnList"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
columnDefault = [jResp StringOf: @"ColumnList[i].columnDefault"];
isCaseSensitive = [[jResp IntOf: @"ColumnList[i].isCaseSensitive"] intValue];
isCurrency = [[jResp IntOf: @"ColumnList[i].isCurrency"] intValue];
isSigned = [[jResp IntOf: @"ColumnList[i].isSigned"] intValue];
label = [jResp StringOf: @"ColumnList[i].label"];
length = [[jResp IntOf: @"ColumnList[i].length"] intValue];
name = [jResp StringOf: @"ColumnList[i].name"];
nullable = [[jResp IntOf: @"ColumnList[i].nullable"] intValue];
precision = [[jResp IntOf: @"ColumnList[i].precision"] intValue];
scale = [[jResp IntOf: @"ColumnList[i].scale"] intValue];
schemaName = [jResp StringOf: @"ColumnList[i].schemaName"];
tableName = [jResp StringOf: @"ColumnList[i].tableName"];
typeName = [jResp StringOf: @"ColumnList[i].typeName"];
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "ColumnList": [
// {
// "columnDefault": "string",
// "isCaseSensitive": boolean,
// "isCurrency": boolean,
// "isSigned": boolean,
// "label": "string",
// "length": number,
// "name": "string",
// "nullable": number,
// "precision": number,
// "scale": number,
// "schemaName": "string",
// "tableName": "string",
// "typeName": "string"
// }
// ],
// "NextToken": "string",
// "TableName": "string"
// }