Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

SQL Server Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(SQL Server) MaxMind IPv4 Geolocation Lookup

Demonstrates how to lookup Geolocation data for an IPv4 address using the MaxMind GeoIP2 Precision Web Service.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example requires the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OASetProperty @http, 'Login', 'MAXMIND_ACCOUNT_ID'
    EXEC sp_OASetProperty @http, 'Password', 'MAXMIND_LICENSE_KEY'
    EXEC sp_OASetProperty @http, 'Accept', 'application/json'

    -- Lookup an IPv4 address: 149.250.207.170  (this was a randomly chosen address)
    DECLARE @jsonStr nvarchar(4000)
    EXEC sp_OAMethod @http, 'QuickGetStr', @jsonStr OUT, 'https://geoip.maxmind.com/geoip/v2.1/country/149.250.207.170'
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        RETURN
      END

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OASetProperty @json, 'EmitCompact', 0
    DECLARE @success int
    EXEC sp_OAMethod @json, 'Load', @success OUT, @jsonStr

    EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

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

    -- {
    --   "continent": {
    --     "code": "EU",
    --     "geoname_id": 6255148,
    --     "names": {
    --       "ja": "?????",
    --       "pt-BR": "Europa",
    --       "ru": "??????",
    --       "zh-CN": "??",
    --       "de": "Europa",
    --       "en": "Europe",
    --       "es": "Europa",
    --       "fr": "Europe"
    --     }
    --   },
    --   "country": {
    --     "is_in_european_union": true,
    --     "iso_code": "DE",
    --     "geoname_id": 2921044,
    --     "names": {
    --       "fr": "Allemagne",
    --       "ja": "????????",
    --       "pt-BR": "Alemanha",
    --       "ru": "????????",
    --       "zh-CN": "??",
    --       "de": "Deutschland",
    --       "en": "Germany",
    --       "es": "Alemania"
    --     }
    --   },
    --   "maxmind": {
    --     "queries_remaining": 49999
    --   },
    --   "registered_country": {
    --     "is_in_european_union": true,
    --     "iso_code": "DE",
    --     "geoname_id": 2921044,
    --     "names": {
    --       "es": "Alemania",
    --       "fr": "Allemagne",
    --       "ja": "????????",
    --       "pt-BR": "Alemanha",
    --       "ru": "????????",
    --       "zh-CN": "??",
    --       "de": "Deutschland",
    --       "en": "Germany"
    --     }
    --   },
    --   "traits": {
    --     "ip_address": "149.250.207.170"
    --   }
    -- }
    -- 
    -- 
    DECLARE @continentCode nvarchar(4000)

    DECLARE @continentGeoname_id int

    DECLARE @continentNamesJa nvarchar(4000)

    DECLARE @continentNamesPt_BR nvarchar(4000)

    DECLARE @continentNamesRu nvarchar(4000)

    DECLARE @continentNamesZh_CN nvarchar(4000)

    DECLARE @continentNamesDe nvarchar(4000)

    DECLARE @continentNamesEn nvarchar(4000)

    DECLARE @continentNamesEs nvarchar(4000)

    DECLARE @continentNamesFr nvarchar(4000)

    DECLARE @countryIs_in_european_union int

    DECLARE @countryIso_code nvarchar(4000)

    DECLARE @countryGeoname_id int

    DECLARE @countryNamesFr nvarchar(4000)

    DECLARE @countryNamesJa nvarchar(4000)

    DECLARE @countryNamesPt_BR nvarchar(4000)

    DECLARE @countryNamesRu nvarchar(4000)

    DECLARE @countryNamesZh_CN nvarchar(4000)

    DECLARE @countryNamesDe nvarchar(4000)

    DECLARE @countryNamesEn nvarchar(4000)

    DECLARE @countryNamesEs nvarchar(4000)

    DECLARE @maxmindQueries_remaining int

    DECLARE @registered_countryIs_in_european_union int

    DECLARE @registered_countryIso_code nvarchar(4000)

    DECLARE @registered_countryGeoname_id int

    DECLARE @registered_countryNamesEs nvarchar(4000)

    DECLARE @registered_countryNamesFr nvarchar(4000)

    DECLARE @registered_countryNamesJa nvarchar(4000)

    DECLARE @registered_countryNamesPt_BR nvarchar(4000)

    DECLARE @registered_countryNamesRu nvarchar(4000)

    DECLARE @registered_countryNamesZh_CN nvarchar(4000)

    DECLARE @registered_countryNamesDe nvarchar(4000)

    DECLARE @registered_countryNamesEn nvarchar(4000)

    DECLARE @traitsIp_address nvarchar(4000)

    EXEC sp_OAMethod @json, 'StringOf', @continentCode OUT, 'continent.code'
    EXEC sp_OAMethod @json, 'IntOf', @continentGeoname_id OUT, 'continent.geoname_id'
    EXEC sp_OAMethod @json, 'StringOf', @continentNamesJa OUT, 'continent.names.ja'
    EXEC sp_OAMethod @json, 'StringOf', @continentNamesPt_BR OUT, 'continent.names.pt-BR'
    EXEC sp_OAMethod @json, 'StringOf', @continentNamesRu OUT, 'continent.names.ru'
    EXEC sp_OAMethod @json, 'StringOf', @continentNamesZh_CN OUT, 'continent.names.zh-CN'
    EXEC sp_OAMethod @json, 'StringOf', @continentNamesDe OUT, 'continent.names.de'
    EXEC sp_OAMethod @json, 'StringOf', @continentNamesEn OUT, 'continent.names.en'
    EXEC sp_OAMethod @json, 'StringOf', @continentNamesEs OUT, 'continent.names.es'
    EXEC sp_OAMethod @json, 'StringOf', @continentNamesFr OUT, 'continent.names.fr'
    EXEC sp_OAMethod @json, 'BoolOf', @countryIs_in_european_union OUT, 'country.is_in_european_union'
    EXEC sp_OAMethod @json, 'StringOf', @countryIso_code OUT, 'country.iso_code'
    EXEC sp_OAMethod @json, 'IntOf', @countryGeoname_id OUT, 'country.geoname_id'
    EXEC sp_OAMethod @json, 'StringOf', @countryNamesFr OUT, 'country.names.fr'
    EXEC sp_OAMethod @json, 'StringOf', @countryNamesJa OUT, 'country.names.ja'
    EXEC sp_OAMethod @json, 'StringOf', @countryNamesPt_BR OUT, 'country.names.pt-BR'
    EXEC sp_OAMethod @json, 'StringOf', @countryNamesRu OUT, 'country.names.ru'
    EXEC sp_OAMethod @json, 'StringOf', @countryNamesZh_CN OUT, 'country.names.zh-CN'
    EXEC sp_OAMethod @json, 'StringOf', @countryNamesDe OUT, 'country.names.de'
    EXEC sp_OAMethod @json, 'StringOf', @countryNamesEn OUT, 'country.names.en'
    EXEC sp_OAMethod @json, 'StringOf', @countryNamesEs OUT, 'country.names.es'
    EXEC sp_OAMethod @json, 'IntOf', @maxmindQueries_remaining OUT, 'maxmind.queries_remaining'
    EXEC sp_OAMethod @json, 'BoolOf', @registered_countryIs_in_european_union OUT, 'registered_country.is_in_european_union'
    EXEC sp_OAMethod @json, 'StringOf', @registered_countryIso_code OUT, 'registered_country.iso_code'
    EXEC sp_OAMethod @json, 'IntOf', @registered_countryGeoname_id OUT, 'registered_country.geoname_id'
    EXEC sp_OAMethod @json, 'StringOf', @registered_countryNamesEs OUT, 'registered_country.names.es'
    EXEC sp_OAMethod @json, 'StringOf', @registered_countryNamesFr OUT, 'registered_country.names.fr'
    EXEC sp_OAMethod @json, 'StringOf', @registered_countryNamesJa OUT, 'registered_country.names.ja'
    EXEC sp_OAMethod @json, 'StringOf', @registered_countryNamesPt_BR OUT, 'registered_country.names.pt-BR'
    EXEC sp_OAMethod @json, 'StringOf', @registered_countryNamesRu OUT, 'registered_country.names.ru'
    EXEC sp_OAMethod @json, 'StringOf', @registered_countryNamesZh_CN OUT, 'registered_country.names.zh-CN'
    EXEC sp_OAMethod @json, 'StringOf', @registered_countryNamesDe OUT, 'registered_country.names.de'
    EXEC sp_OAMethod @json, 'StringOf', @registered_countryNamesEn OUT, 'registered_country.names.en'
    EXEC sp_OAMethod @json, 'StringOf', @traitsIp_address OUT, 'traits.ip_address'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.