Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Google Cloud SQL - Get Instance InformationDemonstrates how to get information about your Cloud SQL instances, including instance summary information, usage data, operation logs, and database logs. For more information, see https://cloud.google.com/sql/docs/mysql/instance-info
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var sbToken: HCkStringBuilder; http: HCkHttp; success: Boolean; sbResponseBody: HCkStringBuilder; jResp: HCkJsonObject; respStatusCode: Integer; v_type: PWideChar; ipAddress: PWideChar; kind: PWideChar; state: PWideChar; databaseVersion: PWideChar; settingsTier: PWideChar; settingsKind: PWideChar; settingsPricingPlan: PWideChar; settingsReplicationType: PWideChar; settingsActivationPolicy: PWideChar; settingsIpConfigurationIpv4Enabled: Boolean; settingsLocationPreferenceZone: PWideChar; settingsLocationPreferenceKind: PWideChar; settingsDataDiskType: PWideChar; settingsBackupConfigurationStartTime: PWideChar; settingsBackupConfigurationKind: PWideChar; settingsBackupConfigurationEnabled: Boolean; settingsBackupConfigurationPointInTimeEnabled: Boolean; settingsSettingsVersion: PWideChar; settingsStorageAutoResizeLimit: PWideChar; settingsStorageAutoResize: Boolean; settingsDataDiskSizeGb: PWideChar; etag: PWideChar; serverCaCertKind: PWideChar; serverCaCertCertSerialNumber: PWideChar; serverCaCertCert: PWideChar; serverCaCertCommonName: PWideChar; serverCaCertSha1Fingerprint: PWideChar; serverCaCertInstance: PWideChar; serverCaCertCreateTime: PWideChar; serverCaCertExpirationTime: PWideChar; instanceType: PWideChar; project: PWideChar; serviceAccountEmailAddress: PWideChar; backendType: PWideChar; selfLink: PWideChar; connectionName: PWideChar; name: PWideChar; region: PWideChar; gceZone: PWideChar; i: Integer; count_i: Integer; begin // 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.. sbToken := CkStringBuilder_Create(); CkStringBuilder_LoadFile(sbToken,'qa_data/tokens/google_cloud_sql_access_token.txt','utf-8'); http := CkHttp_Create(); // 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. CkHttp_putAuthToken(http,CkStringBuilder__getAsString(sbToken)); // 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".) sbResponseBody := CkStringBuilder_Create(); success := CkHttp_QuickGetSb(http,'https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id',sbResponseBody); if (success = False) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; jResp := CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,False); Memo1.Lines.Add('Response Body:'); Memo1.Lines.Add(CkJsonObject__emit(jResp)); respStatusCode := CkHttp_getLastStatus(http); Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode)); if (respStatusCode = 401) then begin Memo1.Lines.Add('It may be that your access token expired.'); Memo1.Lines.Add('Try refreshing the access token by re-fetching it.'); end; if (respStatusCode >= 400) then begin Memo1.Lines.Add('Response Header:'); Memo1.Lines.Add(CkHttp__lastHeader(http)); Memo1.Lines.Add('Failed.'); Exit; end; // 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 kind := CkJsonObject__stringOf(jResp,'kind'); state := CkJsonObject__stringOf(jResp,'state'); databaseVersion := CkJsonObject__stringOf(jResp,'databaseVersion'); settingsTier := CkJsonObject__stringOf(jResp,'settings.tier'); settingsKind := CkJsonObject__stringOf(jResp,'settings.kind'); settingsPricingPlan := CkJsonObject__stringOf(jResp,'settings.pricingPlan'); settingsReplicationType := CkJsonObject__stringOf(jResp,'settings.replicationType'); settingsActivationPolicy := CkJsonObject__stringOf(jResp,'settings.activationPolicy'); settingsIpConfigurationIpv4Enabled := CkJsonObject_BoolOf(jResp,'settings.ipConfiguration.ipv4Enabled'); settingsLocationPreferenceZone := CkJsonObject__stringOf(jResp,'settings.locationPreference.zone'); settingsLocationPreferenceKind := CkJsonObject__stringOf(jResp,'settings.locationPreference.kind'); settingsDataDiskType := CkJsonObject__stringOf(jResp,'settings.dataDiskType'); settingsBackupConfigurationStartTime := CkJsonObject__stringOf(jResp,'settings.backupConfiguration.startTime'); settingsBackupConfigurationKind := CkJsonObject__stringOf(jResp,'settings.backupConfiguration.kind'); settingsBackupConfigurationEnabled := CkJsonObject_BoolOf(jResp,'settings.backupConfiguration.enabled'); settingsBackupConfigurationPointInTimeEnabled := CkJsonObject_BoolOf(jResp,'settings.backupConfiguration.pointInTimeEnabled'); settingsSettingsVersion := CkJsonObject__stringOf(jResp,'settings.settingsVersion'); settingsStorageAutoResizeLimit := CkJsonObject__stringOf(jResp,'settings.storageAutoResizeLimit'); settingsStorageAutoResize := CkJsonObject_BoolOf(jResp,'settings.storageAutoResize'); settingsDataDiskSizeGb := CkJsonObject__stringOf(jResp,'settings.dataDiskSizeGb'); etag := CkJsonObject__stringOf(jResp,'etag'); serverCaCertKind := CkJsonObject__stringOf(jResp,'serverCaCert.kind'); serverCaCertCertSerialNumber := CkJsonObject__stringOf(jResp,'serverCaCert.certSerialNumber'); serverCaCertCert := CkJsonObject__stringOf(jResp,'serverCaCert.cert'); serverCaCertCommonName := CkJsonObject__stringOf(jResp,'serverCaCert.commonName'); serverCaCertSha1Fingerprint := CkJsonObject__stringOf(jResp,'serverCaCert.sha1Fingerprint'); serverCaCertInstance := CkJsonObject__stringOf(jResp,'serverCaCert.instance'); serverCaCertCreateTime := CkJsonObject__stringOf(jResp,'serverCaCert.createTime'); serverCaCertExpirationTime := CkJsonObject__stringOf(jResp,'serverCaCert.expirationTime'); instanceType := CkJsonObject__stringOf(jResp,'instanceType'); project := CkJsonObject__stringOf(jResp,'project'); serviceAccountEmailAddress := CkJsonObject__stringOf(jResp,'serviceAccountEmailAddress'); backendType := CkJsonObject__stringOf(jResp,'backendType'); selfLink := CkJsonObject__stringOf(jResp,'selfLink'); connectionName := CkJsonObject__stringOf(jResp,'connectionName'); name := CkJsonObject__stringOf(jResp,'name'); region := CkJsonObject__stringOf(jResp,'region'); gceZone := CkJsonObject__stringOf(jResp,'gceZone'); i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'settings.authorizedGaeApplications'); while i < count_i do begin CkJsonObject_putI(jResp,i); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'settings.ipConfiguration.authorizedNetworks'); while i < count_i do begin CkJsonObject_putI(jResp,i); i := i + 1; end; i := 0; count_i := CkJsonObject_SizeOfArray(jResp,'ipAddresses'); while i < count_i do begin CkJsonObject_putI(jResp,i); v_type := CkJsonObject__stringOf(jResp,'ipAddresses[i].type'); ipAddress := CkJsonObject__stringOf(jResp,'ipAddresses[i].ipAddress'); i := i + 1; end; CkStringBuilder_Dispose(sbToken); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.