Xbase++
Xbase++
Google Cloud SQL - Get Instance Information
See more Google Cloud SQL Examples
Demonstrates how to get information about your Cloud SQL instances, including instance summary information, usage data, operation logs, and database logs.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oSbToken
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cV_type
LOCAL cIpAddress
LOCAL cKind
LOCAL cState
LOCAL cDatabaseVersion
LOCAL cSettingsTier
LOCAL cSettingsKind
LOCAL cSettingsPricingPlan
LOCAL cSettingsReplicationType
LOCAL cSettingsActivationPolicy
LOCAL nSettingsIpConfigurationIpv4Enabled
LOCAL cSettingsLocationPreferenceZone
LOCAL cSettingsLocationPreferenceKind
LOCAL cSettingsDataDiskType
LOCAL cSettingsBackupConfigurationStartTime
LOCAL cSettingsBackupConfigurationKind
LOCAL nSettingsBackupConfigurationEnabled
LOCAL nSettingsBackupConfigurationPointInTimeEnabled
LOCAL cSettingsSettingsVersion
LOCAL cSettingsStorageAutoResizeLimit
LOCAL nSettingsStorageAutoResize
LOCAL cSettingsDataDiskSizeGb
LOCAL cEtag
LOCAL cServerCaCertKind
LOCAL cServerCaCertCertSerialNumber
LOCAL cServerCaCertCert
LOCAL cServerCaCertCommonName
LOCAL cServerCaCertSha1Fingerprint
LOCAL cServerCaCertInstance
LOCAL cServerCaCertCreateTime
LOCAL cServerCaCertExpirationTime
LOCAL cInstanceType
LOCAL cProject
LOCAL cServiceAccountEmailAddress
LOCAL cBackendType
LOCAL cSelfLink
LOCAL cConnectionName
LOCAL cName
LOCAL cRegion
LOCAL cGceZone
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// In this example, Get Google Cloud SQL OAuth2 Access Token,
// the service account access token was saved to a text file. This example fetches the access token from the file..
oSbToken := CreateObject("Chilkat.StringBuilder")
oSbToken:LoadFile("qa_data/tokens/google_cloud_sql_access_token.txt", "utf-8")
oHttp := CreateObject("Chilkat.Http")
// Implements the following CURL command:
// curl -X GET \
// -H "Authorization: Bearer access-token" \
// https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Causes the "Authorization: Bearer "$(gcloud auth print-access-token)" header to be added.
oHttp:AuthToken := oSbToken:GetAsString()
// Replace "project-id" with your actual Google project ID.
// Replace "instance-id" with your database instance ID, which is the name of your database. (For example, when I created my test database I named it "chilkat", and therefore my instance-id is "chilkat".)
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id", oSbResponseBody)
IF (nSuccess == 0)
? oHttp:LastErrorText
oSbToken:destroy()
oHttp:destroy()
oSbResponseBody:destroy()
RETURN
ENDIF
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode == 401)
? "It may be that your access token expired."
? "Try refreshing the access token by re-fetching it."
ENDIF
IF (nRespStatusCode >= 400)
? "Response Header:"
? oHttp:LastHeader
? "Failed."
oSbToken:destroy()
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
RETURN
ENDIF
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "kind": "sql#instance",
// "state": "RUNNABLE",
// "databaseVersion": "MYSQL_5_7",
// "settings": {
// "authorizedGaeApplications": [
// ],
// "tier": "db-f1-micro",
// "kind": "sql#settings",
// "pricingPlan": "PER_USE",
// "replicationType": "SYNCHRONOUS",
// "activationPolicy": "ALWAYS",
// "ipConfiguration": {
// "authorizedNetworks": [
// ],
// "ipv4Enabled": true
// },
// "locationPreference": {
// "zone": "asia-east1-a",
// "kind": "sql#locationPreference"
// },
// "dataDiskType": "PD_SSD",
// "backupConfiguration": {
// "startTime": "08:00",
// "kind": "sql#backupConfiguration",
// "enabled": true,
// "pointInTimeEnabled": true
// },
// "settingsVersion": "13",
// "storageAutoResizeLimit": "0",
// "storageAutoResize": true,
// "dataDiskSizeGb": "10"
// },
// "etag": "etag-id",
// "ipAddresses": [
// {
// "type": "PRIMARY",
// "ipAddress": "10.0.0.1"
// }
// ],
// "serverCaCert": {
// "kind": "sql#sslCert",
// "certSerialNumber": "0",
// "cert": "certificate-id",
// "commonName": "C=US,O=Google\\, Inc,CN=Google Cloud SQL Server CA,dnQualifier=dn-qualifier-id",
// "sha1Fingerprint": "sha-id",
// "instance": "instance-id",
// "createTime": "2019-06-28T22:46:35.052Z",
// "expirationTime": "2029-06-25T22:47:35.052Z"
// },
// "instanceType": "CLOUD_SQL_INSTANCE",
// "project": "project-id",
// "serviceAccountEmailAddress": "service-acct-id@gcp-sa-cloud-sql.iam.gserviceaccount.com",
// "backendType": "SECOND_GEN",
// "selfLink": "https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id",
// "connectionName": "project-id:region:instance-id",
// "name": "instance-id",
// "region": "asia-east1",
// "gceZone": "asia-east1-a"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
cKind := oJResp:StringOf("kind")
cState := oJResp:StringOf("state")
cDatabaseVersion := oJResp:StringOf("databaseVersion")
cSettingsTier := oJResp:StringOf("settings.tier")
cSettingsKind := oJResp:StringOf("settings.kind")
cSettingsPricingPlan := oJResp:StringOf("settings.pricingPlan")
cSettingsReplicationType := oJResp:StringOf("settings.replicationType")
cSettingsActivationPolicy := oJResp:StringOf("settings.activationPolicy")
nSettingsIpConfigurationIpv4Enabled := oJResp:BoolOf("settings.ipConfiguration.ipv4Enabled")
cSettingsLocationPreferenceZone := oJResp:StringOf("settings.locationPreference.zone")
cSettingsLocationPreferenceKind := oJResp:StringOf("settings.locationPreference.kind")
cSettingsDataDiskType := oJResp:StringOf("settings.dataDiskType")
cSettingsBackupConfigurationStartTime := oJResp:StringOf("settings.backupConfiguration.startTime")
cSettingsBackupConfigurationKind := oJResp:StringOf("settings.backupConfiguration.kind")
nSettingsBackupConfigurationEnabled := oJResp:BoolOf("settings.backupConfiguration.enabled")
nSettingsBackupConfigurationPointInTimeEnabled := oJResp:BoolOf("settings.backupConfiguration.pointInTimeEnabled")
cSettingsSettingsVersion := oJResp:StringOf("settings.settingsVersion")
cSettingsStorageAutoResizeLimit := oJResp:StringOf("settings.storageAutoResizeLimit")
nSettingsStorageAutoResize := oJResp:BoolOf("settings.storageAutoResize")
cSettingsDataDiskSizeGb := oJResp:StringOf("settings.dataDiskSizeGb")
cEtag := oJResp:StringOf("etag")
cServerCaCertKind := oJResp:StringOf("serverCaCert.kind")
cServerCaCertCertSerialNumber := oJResp:StringOf("serverCaCert.certSerialNumber")
cServerCaCertCert := oJResp:StringOf("serverCaCert.cert")
cServerCaCertCommonName := oJResp:StringOf("serverCaCert.commonName")
cServerCaCertSha1Fingerprint := oJResp:StringOf("serverCaCert.sha1Fingerprint")
cServerCaCertInstance := oJResp:StringOf("serverCaCert.instance")
cServerCaCertCreateTime := oJResp:StringOf("serverCaCert.createTime")
cServerCaCertExpirationTime := oJResp:StringOf("serverCaCert.expirationTime")
cInstanceType := oJResp:StringOf("instanceType")
cProject := oJResp:StringOf("project")
cServiceAccountEmailAddress := oJResp:StringOf("serviceAccountEmailAddress")
cBackendType := oJResp:StringOf("backendType")
cSelfLink := oJResp:StringOf("selfLink")
cConnectionName := oJResp:StringOf("connectionName")
cName := oJResp:StringOf("name")
cRegion := oJResp:StringOf("region")
cGceZone := oJResp:StringOf("gceZone")
i := 0
nCount_i := oJResp:SizeOfArray("settings.authorizedGaeApplications")
DO WHILE i < nCount_i
oJResp:I := i
i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("settings.ipConfiguration.authorizedNetworks")
DO WHILE i < nCount_i
oJResp:I := i
i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("ipAddresses")
DO WHILE i < nCount_i
oJResp:I := i
cV_type := oJResp:StringOf("ipAddresses[i].type")
cIpAddress := oJResp:StringOf("ipAddresses[i].ipAddress")
i := i + 1
ENDDO
oSbToken:destroy()
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()