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
(SQL Server) MaxMind IPv4 Geolocation LookupDemonstrates how to lookup Geolocation data for an IPv4 address using the MaxMind GeoIP2 Precision Web Service.
-- 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.