Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

@sap/hana-client database property not working

0 Kudos
289

Hi all

would like not to inject my db_name in every query

select * from <db_name>."OCRD"

I tried to use the database property in the connection config but it simply doesnt work

Hany suggestion?

Thanks

Nicola

2 REPLIES 2

dominik_jacobs
Participant
0 Kudos
184

can you provide the @sap/hana-client definition.

cause the following definiton works for me

const hana = require('@sap/hana-client');
const connParams = {
....
database: 'db_name'
};

With the definition I can perform selects without specifying the db name each time.

BR

Dom

0 Kudos
184

Yes sure:

As you can see i must set the schema before any statement, if i dont set it the call doesnt work

The version of sap/hana-client is 8.18

const connOptions = {
serverNode: config.config.host + ':' + config.config.host_port,
UID: config.config.user,
PWD: config.config.password,
encrypt: 'false', //Must be set to true when connecting to SAP HANA Cloud
sslValidateCertificate: 'false', //Must be set to false when connecting
};
const connection = hana.createConnection();
connection.connect(connOptions);
sql_files.forEach((e) => {
logger.debug(sql_dir + path.sep + e);
let rows=[]
if (e.toLowerCase().endsWith('.sql') && (e.startsWith('0') || e.startsWith('1') || e.startsWith('2'))) {
let sql_tmp = "";
try{
sql_tmp = fs.readFileSync(sql_dir + path.sep + e, "utf-8")
// logger.info(sql_tmp)
} catch (err) {
logger.info("sql load KO file " + e + ":" + JSON.stringify(err));
}
try {
let sql = 'SET SCHEMA "' + config.config.master_db + '";\n\r' // + sql_tmp
logger.debug(sql)
let stmt = connection.prepare(sql);
rows = stmt.exec([]);
// logger.info("sql insert procedure/view OK " + sql + ":" + JSON.stringify(rows));
sql = sql_tmp
stmt = connection.prepare(sql);
rows = stmt.exec([]);
logger.info("sql insert procedure/view OK " + e + ":" + JSON.stringify(rows));
} catch (err) {
logger.info("sql insert procedure/view KO " + e + ":" + JSON.stringify(err));
return;
}
}
});
connection.disconnect();