20231106 - Tentativa de SQL com JSON e o RecordSet do Access
This commit is contained in:
parent
cb3a46664e
commit
79f5e3db25
@ -8,6 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="System.Data.OleDb" Version="7.0.0" />
|
<PackageReference Include="System.Data.OleDb" Version="7.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
49
Program.cs
49
Program.cs
@ -2,7 +2,11 @@
|
|||||||
using System.Data.OleDb;
|
using System.Data.OleDb;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
@ -10,20 +14,21 @@ class Program
|
|||||||
{
|
{
|
||||||
// URL da API que você deseja chamar
|
// URL da API que você deseja chamar
|
||||||
string apiUrl = "https://api.pipefy.com/graphql";
|
string apiUrl = "https://api.pipefy.com/graphql";
|
||||||
|
string PipefyToken = "eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJQaXBlZnkiLCJpYXQiOjE2OTg4NTYyMjcsImp0aSI6IjM2N2Y4M2NhLWZjODYtNGRhOC04ODEyLTkzODRkZGZkODc0MiIsInN1YiI6MzAyNTM0MzY2LCJ1c2VyIjp7ImlkIjozMDI1MzQzNjYsImVtYWlsIjoiYmFjazVAZW5lcmdpYXNtYXJ0LmNvbS5iciIsImFwcGxpY2F0aW9uIjozMDAyODkyNDgsInNjb3BlcyI6W119LCJpbnRlcmZhY2VfdXVpZCI6bnVsbH0.o13j9c_y3G3HX35qhX4PmkkibGsmlHsk5dL_Bxsr1CKV5Jlgj218kJdEmriS7aHiw0-P7sfs-bu4YcElfuyiqg";
|
||||||
|
string ConnSourcePath = @"C:\Users\contratos\Documents\Giuliano\Pipefy.accdb";
|
||||||
|
string PipefyTokenTableID = "b9t-7uD5";
|
||||||
|
|
||||||
// Crie uma instância HttpClient
|
|
||||||
using (HttpClient httpClient = new HttpClient())
|
// Crie uma instância HttpClient
|
||||||
|
using (HttpClient httpClient = new HttpClient())
|
||||||
{
|
{
|
||||||
// Defina os headers da requisição (opcional)
|
// Defina os headers da requisição (opcional)
|
||||||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
|
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||||
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJQaXBlZnkiLCJpYXQiOjE2OTg4NTYyMjcsImp0aSI6IjM2N2Y4M2NhLWZjODYtNGRhOC04ODEyLTkzODRkZGZkODc0MiIsInN1YiI6MzAyNTM0MzY2LCJ1c2VyIjp7ImlkIjozMDI1MzQzNjYsImVtYWlsIjoiYmFjazVAZW5lcmdpYXNtYXJ0LmNvbS5iciIsImFwcGxpY2F0aW9uIjozMDAyODkyNDgsInNjb3BlcyI6W119LCJpbnRlcmZhY2VfdXVpZCI6bnVsbH0.o13j9c_y3G3HX35qhX4PmkkibGsmlHsk5dL_Bxsr1CKV5Jlgj218kJdEmriS7aHiw0-P7sfs-bu4YcElfuyiqg");
|
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + PipefyToken);
|
||||||
|
|
||||||
// Crie a consulta GraphQL
|
// Crie a consulta GraphQL
|
||||||
string query = /*lang=json,strict*/ @"
|
string query = /*lang=json,strict*/ @"{""query"":""query{\r\n table_records(table_id: \""wzirXS8w\"") {\r\n edges {\r\n node {\r\n id\r\n record_fields{\r\n field{\r\n id\r\n }\r\n value\r\n }\r\n }\r\n }\r\n }\r\n}"",""variables"":{}}";
|
||||||
{
|
|
||||||
""query"":""{\r\n table_records(table_id: \""b9t-7uD5\"") {\r\n edges {\r\n node {\r\n id\r\n record_fields{\r\n value\r\n }\r\n }\r\n }\r\n }\r\n}"",""variables"":{}
|
|
||||||
}";
|
|
||||||
|
|
||||||
// Defina o conteúdo do corpo da requisição
|
// Defina o conteúdo do corpo da requisição
|
||||||
var content = new StringContent(query, System.Text.Encoding.UTF8, "application/json");
|
var content = new StringContent(query, System.Text.Encoding.UTF8, "application/json");
|
||||||
@ -34,11 +39,12 @@ class Program
|
|||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
string responseBody = await response.Content.ReadAsStringAsync();
|
string responseBody = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
Console.WriteLine("Resposta bem-sucedida:");
|
Console.WriteLine("Resposta bem-sucedida:");
|
||||||
Console.WriteLine(responseBody);
|
Console.WriteLine(responseBody);
|
||||||
|
|
||||||
// Agora você pode comparar a resposta JSON com a tabela no banco de dados Access
|
// Agora você pode comparar a resposta JSON com a tabela no banco de dados Access
|
||||||
CompareResponseWithDatabase(responseBody);
|
CompareResponseWithDatabase(responseBody, ConnSourcePath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -46,12 +52,18 @@ class Program
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void CompareResponseWithDatabase(string jsonResponse)
|
static void CompareResponseWithDatabase(string jsonResponse, string ConnSourcePath)
|
||||||
{
|
{
|
||||||
// Defina a string de conexão para o banco de dados Access
|
// Defina a string de conexão para o banco de dados Access
|
||||||
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\contratos\Documents\Giuliano\Pipefy.accdb";
|
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ConnSourcePath;
|
||||||
|
var responseObject = JObject.Parse(jsonResponse);
|
||||||
|
|
||||||
using (OleDbConnection connection = new OleDbConnection(connectionString))
|
var idFromJson = responseObject["data"]["table_records"]["edges"];
|
||||||
|
foreach( var id in idFromJson){
|
||||||
|
var a = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (OleDbConnection connection = new OleDbConnection(connectionString))
|
||||||
{
|
{
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
@ -64,14 +76,15 @@ class Program
|
|||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
// Compare os dados da resposta JSON com os dados da tabela
|
int idFromDatabase = (int)reader["id"];
|
||||||
// Você pode usar a biblioteca Newtonsoft.Json para desserializar o JSON
|
string nomeFromDatabase = (string)reader["nome"];
|
||||||
// e comparar os valores desejados com os valores do banco de dados
|
|
||||||
// Por exemplo:
|
|
||||||
// string valueFromDatabase = reader["NomeDaColuna"].ToString();
|
|
||||||
// string valueFromJSON = JsonConvert.DeserializeObject<YourType>(jsonResponse).YourProperty;
|
|
||||||
|
|
||||||
// Realize as comparações aqui e tome as ações necessárias
|
// Compare os valores do JSON com os valores do banco de dados
|
||||||
|
//if (idFromJson == idFromDatabase && nomeFromJson == nomeFromDatabase)
|
||||||
|
//{
|
||||||
|
// // Realize ação quando houver correspondência
|
||||||
|
// Console.WriteLine("Correspondência encontrada!");
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user