Copying a rowset from table to a rowset message - peoplesoft

I am having an issue copying a rowset (that is populated from a table) to a rowset type message.
This is what I have (took out a lot of tries that failed many times)
Local Message &MSG;
Local Rowset &HDR_RS, &LN_RS;
&MSG = CreateMessage(Operation.TEST_SC_ASYNC_IB);
&HDR_RS = CreateRowset(Record.FUND_TBL);
&HDR_RS.Fill();
My goal is to add the HDR_RS rowset that is filled to the Message
This is the solution:
&MSG = CreateMessage(Operation.TEST_SC_ASYNC_IB);
&HDR_RS = CreateRowset(Record.FUND_TBL);
&HDR_RS.Fill();
&MSG.CopyRowset(&HDR_RS);
%IntBroker.Publish(&MSG);

Related

Unable to write dataframe in R as Update-Statement to Postgis/PostgresSQL

I have the following dataframe:
library(rpostgis)
library(RPostgreSQL)
library(glue)
df<-data.frame(elevation=c(450,900),
id=c(1,2))
Now I try to upload this to a table in my PostgreSQL/Postgis database. My connection (dbConnect) is working for "SELECT"-Statements properly. However, I tried two ways of updating a database table with this dataframe and both failed.
First:
pgInsert(postgis,name="fields",data.obj=df,overwrite = FALSE, partial.match = TRUE,
row.names = FALSE,upsert.using = TRUE,df.geom=NULL)
2 out of 2 columns of the data frame match database table columns and will be formatted for database insert.
Error: x must be character or SQL
I do not know what the error is trying to tell me as both the values in the dataframe and table are set to integer.
Second:
sql<-glue_sql("UPDATE fields SET elevation ={df$elevation} WHERE
+ id = {df$id};", .con = postgis)
> sql
<SQL> UPDATE fields SET elevation =450 WHERE
id = 1;
<SQL> UPDATE fields SET elevation =900 WHERE
id = 2;
dbSendStatement(postgis,sql)
<PostgreSQLResult>
In both cases no data is transferred to the database and I do not see any Error logs within the database.
Any hint on how to solve this problem?
It is a mistake from my site, I got glue_sql wrong. To correctly update the database with every query created by glue_sql you have to loop through the created object like the following example:
for(i in 1:max(NROW(sql))){
dbSendStatement(postgis,sql[i])
}

How to validate/debug trigger statement after it is loaded

There are two tables ... the 'master' (tblFile) holds record details of files that have been processed by some java code .. the PK is the file name. A column of interest in this table is the 'status' column (VALID or INVALID).
In the subordinate table (tblAnomaly) there are many records that hold the anomalies from processing each file .. this table has a FK as the file name from tblFile ... and along with other columns of relevant data there is a boolean type column which acts as an acceptance flag of the anomaly. NULL is accept .. # is not.
The user manually works their way through the list of anomalies presented in a swing ListPane and checks off the anomalies as they address the issue in the source file. When all the anomalies have been dealt with i need the status of the file in tblFile to change to VALID so that it can be imported into a database.
Here is the trigger i have settled on having designed the statements individually via an SQL editor .. however, i do not know how to validate/debug the trigger statement after it is loaded to the database, so cannot work out why it does not work ... no action and no feedback!!
CREATE TRIGGER
updateFileStatus
AFTER UPDATE ON tblAnomaly
WHEN 0 = (SELECT COUNT(*) FROM tblAnomaly WHERE tblAnomaly.file_name = tblFile.file_name AND tblAnomaly.accept = '#')
BEGIN
UPDATE tblFile
SET tblFile.file_status = 'VALID'
WHERE tblFile.file_name = tblAnomaly.file_name;
END;
So i worked it out! .. here is the solution that works.
CREATE TRIGGER
updateFileStatus
AFTER UPDATE ON tblAnomaly
WHEN 0 = (SELECT COUNT(*)
FROM tblAnomaly
WHERE file_name = old.file_name
AND accept = '#')
BEGIN
UPDATE tblFile
SET file_status = 'VALID'
WHERE file_name = old.file_name;
END;

delete query in ssis package with 2 or more parameters in execute SQl Task

I am new to SSIS I want to execute delete query in my SSIS package thorough Execute Sql Task having 2 or more parameters. If I use 1 parameter it's working fine but if more than 1 than error. I don't want to use SP's and please help me as I am stuck from a long time.
General
TimeOut = 0
Typeconversionmode - Allowed
Result Set - None
ConnectonType - OLE DB
Connection = MyConnection
SqlSource = DirectInput
SqlStatment="delete from tblStgPaymentProcessingACH where id=? and paymentid=?"
BypassPrepare = True
Variables
Name = ID , Scope = MyJOB, DataType=int64, Value=2
Name = PMTID , Scope = MyJOB, DataType=int64, Value=101161419602
Parameter Mapping
User::ID, Direction = input, datatype = LONG, ParameterName = 0, ParamtereSize = 0
User::PMTID, Direction = input, datatype = LONG, ParameterName = 1, ParamtereSize = 0
Database DataTypes
Column
ID - INT
Paymentid - Bigint
Getting Error
[Execute SQL Task] Error: Executing the query "delete from mytable
where id=..." failed with the following error: "An error occurred while extracting the result into a variable of type (DBTYPE_I4)". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

Error binding parameter 0 - probably unsupported type

I am creating an SQL db and trying to iterate over an excel file and put all the data in to the SQL table as follows but I keep getting an annoying error. I have looked at the data types and still can't get my head around it please let me know if anyone spots what the problem is my code is:
import sqlite3
from openpyxl import load_workbook
#wb = load_workbook(r"LeaguePlayers.xlsx")
#read workbook to get data
wb = load_workbook(filename = r"LeaguePlayers.xlsx", use_iterators = True)
ws = wb.get_sheet_by_name(name = 'Sheet1')
#ws = wb.worksheets
conn = sqlite3.connect("players.db") # or use :memory: to put it in RAM
cursor = conn.cursor()
# create a table
cursor.execute("""CREATE TABLE players
(player TEXT,
team TEXT,
points INTEGER,
cost REAL,
position TEXT)
""")
#Iterate through worksheet and print cell contents
for row in ws.iter_rows():
for cell in row:
cursor.execute("INSERT INTO players VALUES (?,?,?,?,?)", row)
conn.commit()
#----------------------------------------
# display SQL data
#----------------------------------------
c.execute('SELECT * FROM players')
for row in c:
print (row)
The error i get says:
cursor.execute("INSERT INTO players VALUES (?,?,?,?,?)", row)
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
I really think you need to do some kind of introduction to Python.
You are making two elementary mistakes: looping of the cells in a row but passing the row to the query; passing a complex object as opposed to a native Python type such as an integer or string.
Something like the following is what you want:
player = [cell.value for cell in row]
cursor.execute(query, player)
Note, that execute takes a sequence (tuple or list) as the second argument.

How to display the highest value from a column in a sqlite database in lua corona

I'm creating a game and when it finishes it stores it in a database (code below that adds it)
-- open SQLite database, if it doesn't exist, create database
local path = system.pathForFile("leaderboards.sqlite", system.DocumentsDirectory)
db = sqlite3.open( path )
print(path)
-- setup the table if it doesn't exist
local tablesetup = "CREATE TABLE IF NOT EXISTS leaderboards (id INTEGER PRIMARY KEY, score INDEXED);"
db:exec( tablesetup )
print(tablesetup)
-- save student data to database
local tablefill = "INSERT INTO leaderboards VALUES (NULL,'" .. score .. "');"
print(tablefill)
db:exec( tablefill )
-- close database
db:close()
print("db closed")
Then I want at the top of the screen to display the highest score so this is my display function
local function highScore()
-- open database
local path = system.pathForFile("leaderboards.sqlite", system.DocumentsDirectory)
db = sqlite3.open( path )
print(path)
--print all the table contents
local sql = "SELECT MAX(score) FROM leaderboards"
local val = db:exec(sql)
local t = display.newText("Best: "..val, 300, -20, nil, 28)
print(val)
t:setTextColor(255,255,255)
db:close()
end
Right now on the screen it is just saying 0 and not the high score or any screen. The values are being entered in the database but my sql statement isn't displaying it.
The simplest method is
local val
for x in db:urows "SELECT MAX(score) FROM leaderboards" do val = x end
Or
local sql = "SELECT MAX(score) FROM leaderboards"
for val in db:urows(sql)
local t = display.newText("Best: "..val, 300, -20, nil, 28)
print(val)
t:setTextColor(255,255,255)
end
See the urows documentation here.
From the docs:
db:exec
db:exec(sql[,func[,udata]])
db:execute(sql[,func[,udata]])
Compiles and executes the SQL statement(s) given in string sql. The
statements are simply executed one after the other and not stored. The
function returns sqlite3.OK on success or else a numerical error code
(see Numerical error and result codes).
If one or more of the SQL statements are queries, then the callback
function specified in func is invoked once for each row of the query
result (if func is nil, no callback is invoked). The callback receives
four arguments: udata (the third parameter of the db:exec() call), the
number of columns in the row, a table with the column values and
another table with the column names. The callback function should
return 0. If the callback returns a non-zero value then the query is
aborted, all subsequent SQL statements are skipped and db:exec()
returns sqlite3.ABORT.
In your code, the local val receives sqlite3.OK, which probably equals 0. You need to provide a callback function to receive row data, for example
local function maxscorecb(udata, ncols, colvals, colnames)
--Assuming that it's always one row and value
udata[1] = colvals[1]
return 0
end
--print all the table contents
local sql = "SELECT MAX(score) FROM leaderboards"
local scoretab = {}
local val = db:exec(sql, maxscorecb, scoretab)
local t = display.newText("Best: "..scoretab[1], 300, -20, nil, 28)
print(val)
t:setTextColor(255,255,255)
db:close()
P.S. Haven't tested it, just based on reading the docs.

Resources