I have create the below a RHEL Machine that was setup using an oracle.
Also returning the data needed to be done a little different than on windows.
print("Start database connection 1")
-- Connect to the database
local oracle_server = "<ServerName>"
local oracle_user = "<OracleUser>"
local oracle_pwd = "<UserPassword>"
local oracle_service = "<OracleServiceName>"
local oracle_port = "1521"
local oracle_database= "CA_UIM"
local database_driver ="Oracle in OraClient12Home1"
function getRow(dataTable, rowNum, isNIS)
local realRow
if (isNIS) then
realRow = dataTable[rowNum]
else
realRow = {}
for key, val in pairs(dataTable[rowNum]) do
realRow[key] = val
realRow[string.lower(key)] = val
realRow[string.upper(key)] = val
end
end
return realRow
end
if oracle_pwd ~= "" then
-- Build connection string
local cs = "Provider=Oracle;Data Source="..oracle_server..";Database="..oracle_database..";User ID="..oracle_user..";Password="..oracle_pwd..";ServiceName="..oracle_service..";Port="..oracle_port..";"
print (cs)
local rc = database.open(cs,false)
print(rc)
if rc == NIME_OK then
local rs = database.query ("Select * from CA_UIM.cm_computer_system order by CS_ID")
printf ("Number of QoS objects: %d",#rs)
for I=1,#rs do
nextRow = getRow(rs, I, false)
print("For Row " .. I .. " NAME is " .. nextRow.NAME .. " and CA_ID is " .. nextRow.CS_ID)
end
for i=1,#rs do
print("Name Column has: " .. rs[i].NAME) -- .. ", CS_ID Column has: " .. rs[i].CS_ID)
end
else
print ("Failed to open database using the provided connection string!")
end
database.close()
end