I am doing local development for SAP CAP with Nodejs project in VSCODE. I am connected to XSA Server. I am trying to create hana database user in XSA environment. I want to first check if the list of users that my app will create is already existing or not. For that, I am trying to execute a select query with where clause. Its a prepared statement, which i am trying to execute with execBatch(array). Below is the code.
let arr = [["POC_ADMIN_DEMO_USER_7"],["POC_ADMIN_DEMO_USER_1"]]
const checkuserexiststatement = await xsaDbConn.preparePromisified("SELECT USER_NAME FROM USERS WHERE USER_NAME = ?")
let readuserresult = await checkuserexiststatement.execBatch(arr)
console.table(readuserresult)
The execution of the query fails with the following error -
Error
Error: SQL command would generate a result set at
C:\Users\Documents\XSA\SAC_POC\cap_njs\cap_njs\user_management.js.createUsers
(C:\Users\Documents\XSA\SAC_POC\cap_njs\cap_njs\user_management.js:59:60)
I want to know if select query/statement supports execBatch() functionality in Hana as the same select statement works without any placeholder that is when the value of the user_name is provided directly in the where clause and exec() used instead of execBatch(), Or is it that I am missing some point here?
execBatch() - returns no of rows affected as a result of the query executed. Select query returns a result set (if any) or else an empty array in Node.js.
Therefore execBatch() is not compatible with Select query because execBatch() is used for batch execution and selection is one shot instead of batch.
Related
I am using the new scripting feature of Big Query to declare a variable and then am using that variable in a standard SQL query.
The structure of the query is :
DECLARE {name of variable} {data type};
SET {name of variable} = {Value}'
(A SQL QUERY THEN FOLLOWS USING THE ABOVE VARIABLE)
I understand that this is now a script a no longer a typical query, and thus when I run it, it runs as a sequence of executable tasks. But is there anyway in the script to explicitly state that I only want to output the resulting table of the SQL query as opposed to both the result of declaring the variable and SQL query?
What BQ Outputs
Depending on how you "capture" the output, if you are sending a query from Python/Java/CLI, then the last SELECT statement in script is the only output that you receive with the API.
Please also note that each "output" that you see come with a cost/bytes-billed, which is another reason for them to be visible at all time.
Update:
If you need to capture the output of SELECT statement to a table, depending on your intention, you may use:
CREATE OR REPLACE TABLE <your_destination_table> AS SELECT ...
or
INSERT INTO TABLE <your_destination_table> SELECT ...
I am using SELECT UpdateDate FROM dbo.log command in a execute sql task. I'm fairly new to this so please bear with me. I want to store the value as a variable then pass that into the where clause of a subsequent data flow. My questions are:
What is the correct way to setup the Execute SQL Task. In General I have the OLE DB Connection and direct input with the query above. Result Set is set to Single row and then I am storing this to a variable I have created called User:: UpdateDate. For some reason this doesn't work?
I then want to call this date in a data flow. ie. SELECT * FROM Users WHERE RecordDate > User::UpdateDate. I believe the syntax is different for this.
I would really appreciate some help with this. Many thanks in advance
In your Execute SQL Task Editor, configure the Parameter Mapping as shown below, obviously use your own variable, in this example I'm using PackageStartTime.
Then in your SQL statement, use below:
SELECT * FROM Users WHERE RecordDate > ?
To save value from a SQL Statement, you will need to set the Result Set to single row and configure result set as shown in the example below:
Execute SQL Task with ResultSet
First of all, create a variable of type System.Date example: #[User::UpdateDate].
Add an Execute SQL Task select the OLEDB connection and use the following command as SQL Statement:
SELECT TOP 1 UpdateDate FROM dbo.log
Set the ResultSet property to Single Row and in the ResultSet Tab add a Row with the following values:
ResultName = 0 (which means the first column)
VariableName = #[User::UpdateDate]
Additional Information
SSIS Basics: Using the Execute SQL Task to Generate Result Sets
OLEDB Source with parameterized SQL Command
Inside the Data Flow Task, add an OLEDB Source, select the Access Mode to SQL Command. And write the following command:
SELECT * FROM Users WHERE RecordDate > ?
Click on the Parameters button and map the variable #[User::UpdateDate] as the first parameter.
Additional Information
Map Query Parameters to Variables in a Data Flow Component
Parameterized OLEDB source query
I am currently using a function in SQL Server to get the max-value of a certain column. I Need this value to generate a specific number of dummy files to insert flowfiles that are created later on.
Is there a way of calling this function via a nifi-processor?
By using ExecuteSQL I Always get error like unable to execute SQL select query or the column "ab" was not found, when using select ab.functionname() (ab is the loginname of the db)
In SQL Server I can just use select ab.functionname() and get the desired results.
If there is no possible way of calling this function, is there another way to create #flowfiles dummyfiles to reserve this place for them in the DB so that no one else could insert or use this ids (not autoincremt, because it is not possible) while the flowfiles are getting processed?
I tried using $flowfile.count and the Counterprocessor, but this did not solve the Problem.
It should look like: INSERT INTO table (id,nr) values (max(id)+1,anynumber) for every flowfiles, unfortunately the ExecuteSQL is not able to do this.
Think this conversation can help you:
https://community.hortonworks.com/questions/26170/does-executesql-processor-allow-to-execute-stored.html
Gist:
You can use ExecuteScript or ExecuteProcess to call appropriate script. For example for ExecuteProcess just call sqlplus command. Choose type of command "sqlplus". In command arguments set something like: user_id/password#dbname #"script_path/someScript.sql". In someScript.sql you put something like:
execute spname(param)
You can write your own processor :) Of course it's more difficulty and often unnecessary
I am using SAS Enterprise Guide (EG) 6.1 and want to know what are the indexes of our Oracle tables. Is there a way to write a program to get this information?
I tried to do:
LIBNAME DW ORACLE USER='username' PASSWORD='password' PATH='path.world' SCHEMA='schema';
DATA _NULL_ ;
dsid = OPEN(DW.some_table) ;
isIndexed = ATTRN(dsid,"ISINDEX") ;
PUT isIndexed = ;
RUN ;
some_table is the name of (my table), but I get an error:
ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase.
ERROR 557-185: Variable some_table is not an object.
Reference: https://communities.sas.com/t5/ODS-and-Base-Reporting/check-if-index-exists/td-p/1966
OPEN takes a string or a value that resolves to a string. So you need
dsid= OPEN('dw.some_dataset');
I don't know if you can use that with Oracle or not, and I don't know whether ATTRN will be useful for this particular purpose or not. These all work well with SAS datasets, but it's up to the libname engine (and whatever middleware it uses) to implement the functionality that ATTRN would use.
For example, I don't use Oracle but I do have SQL Server tables with indexes, and I can run the above code on them; the code appears to work (it doesn't show errors) but it shows the tables as being unindexed, when they clearly are.
Your best bet is to connect using pass-through (CONNECT TO ...) instead of libname, and then you can run native Oracle syntax rather than using SAS.
I have having an issue with a SQL execution where I am getting an error message
-2147217843 Login Failed for user.
I am able to successfully open the connection to the database and execute select count(*) queries.
I am getting this error when I include fields.
In a separate application that uses the same fields I am able to retrieve the same data so seems to rule out column permissions.
The query coming back with no error is:-
SELECT tbl_PersonalDetails.SystemID
FROM tbl_PersonalDetails
WHERE tbl_PersonalDetails.Title IS NOT NULL
And tbl_PersonalDetails.HospitalNumber IS NOT NULL
AND tbl_PersonalDetails.SiteID = 1
The query coming back with the error is:-
SELECT DISTINCT tbl_PersonalDetails.Title,tbl_PersonalDetails.HospitalNumber
FROM tbl_PersonalDetails
WHERE tbl_PersonalDetails.SiteID = 1
ORDER BY tbl_PersonalDetails.Title,tbl_PersonalDetails.HospitalNumber ASC
This is not specific to these particular queries, in the first query where we are just doing a count I always get a count back with no issue, when I try to request fields such as in the second I always get the Login Error.
Your problem isn't in the SQL queries you've posted. They would either all fail or all succeed based on the information given.
Your problem is your calling/client code. Sounds like you're using Classic ASP ("recordset....adodb connection").
Double check that your ASP code is using the proper connection strings.
To prove this, run any of these queries in SQL Server Management Studio. Connect using the credentials that your connection string contains.