C++: Converting the resultset of a SQL query into JSON - c++

Is there a standard way/well known method to convert the results of a SQL query, using the MySQL client library, or otherwise into JSON so I can directly pass the results to a JS script?
Before the obvious, no, I'm not allowing SQL queries directly from the browser, I'm implementing a specific subset of SQL in a simple API to expose to clients who will be retrieving the results using AJAX, I figured JSON is the best encoding, just wanted to check and see if there was already a well known way of doing this before I wrote my own.
Thanks!

You may take a look at:
http://weblogs.asp.net/thiagosantos/archive/2008/11/17/get-json-from-sql-server.aspx
It provides a recipe to get JSon from SQL.
My the way, I assume that it is MS SQL as you don't specify.
Good Luck

Related

Upload data from API into GCP dataprep

Is it possible to import data from a Restful API directly into data prep?
I think there might be a couple of work arounds...
1: Save the results to a JSON file in a GCS bucket and import from there.
2: Import the results into a Big Query table and then import into data prep from there.
It would be much smoother to just call an API and get a result set, as opposed to having to take an extra step. I just can't find anywhere that explains how to do this.
TIA!
Long story short: there's no real way to directly stream data into Data Prep. Even the new Dataprep Premium Edition expects that you'll have the data in some form of a database--though this does expand your options to Google Sheets, Salesforce, Oracle, Microsoft SQLServer, MySQL and PostgreSQL.
Personally, I've just gotten in the habit of writing directly into BigQuery and/or Firestore-to-BigQuery to get around this sort of thing. It also has the nice side effect of being another type of logging from applications.

Pulling Instagram data into Google Big Query

I am new to development, so I am sorry if this is a really basic question. I am trying to access some of the data available from instagram's API as documented here. https://developers.facebook.com/docs/instagram-api/insights.
I would like some kind of data repository to pull the data into, so I am looking at Google Big Query to see if I can pull in the data. (The ultimate place will be PowerBi so I can publish online)
Looking at the Facebook request code - is it possible to put this into Google Big query to return the data?
I am replacing the 'instagram-business-user-id' with an ID I have generated already - but it feels like perhaps it needs more markup to let Big Query know what language it is in.
Any help would be much appreciated.
GET graph.facebook.com/{instagram-business-user-id}/insights
?metric=impressions,reach,profile_views
&period=day
Looking at the Facebook request code - is it possible to put this into Google Big query to return the data?
Yes it's absolutely possible using bigQuery API or bigQuery CLI
You can use this Psuedo workflow as an example (using BigQuery API):
Create a table in bigQuery with the desired schema for this you also have 2 options:
Save the result in 1 column with the full JSON, This means to the select you need you use JSON_EXTRACT to fetch specific data
Process the JSON in your code and save it in specific columns to simplify the select statement
Call instagram's API
Call bigQuery API or bigQuery CLI to insert the data, This link provides one option how to do this
Call bigQuery API or bigQuery CLI to fetch the data, This link provides one option how to do this

Executing Named Queries in Athena

We want to execute a parameterized query in Athena using the javascript sdk by aws.
Seems Athena's named query may be the way to do, but the documentation seems very cryptic to understand how to go about doing this.
It would be great if someone can help us do the following
What is the recommended way to avoid sql injection in athena?
Create a parameterized query like SELECT c FROM Country c WHERE c.name = :name
Pass the name parameter's value
Execute this query
Edit: this answer was written before Athena supported prepared statements.
Named queries is a weird feature of Athena that is not really useful for anything, unfortunately.
Athena does not support prepared statements like many RDBMSs. There are SQL libraries with support for doing parameter expansion client side – Sequel for Ruby is one I have experience with, unfortunately I can't give you a suggestion for JavaScript.
Escaping in Athena's SQL dialect isn't very complicated, however. In identifiers double quotes need to be escaped as two double quotes and in literal strings single quotes need to be escaped as single quotes. Other datatypes just need to be clean, e.g. only digits for integers.
Also, keep in mind that in Athena, the dangers of SQL injection are different than in an RDBMS: Athena can't delete your data. If you set up your IAM permissions correctly the user can't even drop tables, and even if you for some reason run queries with a user that is allowed to drop tables, tables are just metadata and can easily be set up again.

Does user search query support OR clause for Orgunits?

I'm trying to use the google directory api to get a specific set of users based on their orgUnitPath. I can't seem to get a query working where I do something like orgUnitPath=/OUTest OR orgUnitPath=/LeftOU without having to make two separate api calls. Any advice.
The query does not support OR. Currently two API calls will be necessary.

can xpath be used in outgoing SOAP request (envelope) regardless of SOAP server config?

I'm trying to figure out two things:
Can Xpath be used to query a SOAP-based web services server?
Is this built into the SOAP protocol such that any good SOAP server would handle the requests correctly without having to add custom handling of XPath queries?
The two questions may seem redundant, but I'm breaking them because:
I don't know if what I have in mind makes sense/would be the right use of XPath,
If it does make sense, is it already an understood feature of the SOAP protocol (and thus might explain why I can't find any specific documentation for the Web Service I'm actually dealing with.)
Here is the real-world scenario, if that helps:
I have a calendar database (very simple, MySQL), and I want to update my MS Exchange calendar via EWS. Whenever I push events out from my db to my calendar, two things are true:
The date range will always be the same (the start of the week through the end of the week of when the push happens).
The UID of each event will have an indicator that it was sent out by this specific app.
So, before any events are pushed to the calendar, I would like to delete any events that are within that date range and have the app-indicator in the UID, so that I don't get doubles of calendar items, or worse, old items on my calendar that no longer are right.
Since I'm having trouble finding the right way to do such a query/delete/add all in one request, I was thinking that XPath was the less-proprietary solution. But I'm not even sure where the XPath query would be amended to the request, or even if the best of xml parsers would derive the intended goal.
Sorry this was more long winded then I meant it to be. Short version: can I use XPath within a SOAP request? If so, how?
1 - Can Xpath be used to query a SOAP-based web services server?
Umm. No. XPath is a highly dependent language, it can't do anything on its own. Like CSS, it needs an interpreter and a DOM around to work.
2 - Is this built into the SOAP protocol such that any good SOAP server would handle the requests correctly without having to add custom handling of XPath queries?
No. SOAP is a data exchange protocol built on top of HTTP. It is used to exchange objects (that have been serialized as XML) in a predictable and programmable manner. Even though XPath has a connection to XML, it has no intrinsic connection to SOAP.
I'm afraid I can't give a more specific answer than "probably not", since despite your explanation I have no idea what you are actually trying to do. To get a more specific answer, you would have to show your code (or the pseudo code that reflects your idea).
The SOAP service in question could implement a method that takes the XPath query as input (where the XPath query is just sent as a string parameter to the SOAP method). Then implement logic on the SOAP server that executes the XPath query and deletes the records. BUT this would only be using XPath as a format for the query, it has nothing to do with SOAP being xml! The format of the query parameter could also be SQL.
I have worked with a SOAP method that does a query based on a gml structure (map vector data in xml form). The method took a filter parameter as a string that contained valid gml, and returned the result as another string containing map data in valid gml.