@@ -58,6 +58,7 @@ NJS_NAPI_METHOD_DECL_ASYNC(njsConnection_getStatementInfo);
5858NJS_NAPI_METHOD_DECL_SYNC (njsConnection_getStmtCacheSize );
5959NJS_NAPI_METHOD_DECL_SYNC (njsConnection_getTag );
6060NJS_NAPI_METHOD_DECL_SYNC (njsConnection_getTransactionInProgress );
61+ NJS_NAPI_METHOD_DECL_SYNC (njsConnection_getWarning );
6162NJS_NAPI_METHOD_DECL_SYNC (njsConnection_isHealthy );
6263NJS_NAPI_METHOD_DECL_ASYNC (njsConnection_ping );
6364NJS_NAPI_METHOD_DECL_ASYNC (njsConnection_rollback );
@@ -175,6 +176,8 @@ static const napi_property_descriptor njsClassProperties[] = {
175176 NULL },
176177 { "getTransactionInProgress" , NULL , njsConnection_getTransactionInProgress ,
177178 NULL , NULL , NULL , napi_default , NULL },
179+ { "getWarning" , NULL , njsConnection_getWarning , NULL , NULL , NULL ,
180+ napi_default , NULL },
178181 { "isHealthy" , NULL , njsConnection_isHealthy , NULL , NULL , NULL ,
179182 napi_default , NULL },
180183 { "ping" , NULL , njsConnection_ping , NULL , NULL , NULL , napi_default ,
@@ -483,6 +486,9 @@ static bool njsConnection_connectAsync(njsBaton *baton)
483486 & baton -> dpiConnHandle ) < 0 )
484487 return njsBaton_setErrorDPI (baton );
485488
489+ // handle warnings if any
490+ dpiContext_getError (baton -> globals -> context , & baton -> warningInfo );
491+
486492 return true;
487493}
488494
@@ -496,6 +502,11 @@ static bool njsConnection_connectPostAsync(njsBaton *baton, napi_env env,
496502{
497503 njsConnection * conn = (njsConnection * ) baton -> callingInstance ;
498504
505+ // process warnings if any
506+ if (baton -> warningInfo .isWarning ) {
507+ conn -> warningInfo = baton -> warningInfo ;
508+ }
509+
499510 // transfer the ODPI-C connection handle to the new object
500511 conn -> handle = baton -> dpiConnHandle ;
501512 baton -> dpiConnHandle = NULL ;
@@ -662,6 +673,9 @@ static bool njsConnection_executeAsync(njsBaton *baton)
662673 if (dpiStmt_execute (baton -> dpiStmtHandle , mode , & baton -> numQueryVars ) < 0 )
663674 return njsBaton_setErrorDPI (baton );
664675
676+ // handle warnings if any
677+ dpiContext_getError (baton -> globals -> context , & baton -> warningInfo );
678+
665679 // for queries, initialize query variables
666680 if (baton -> numQueryVars > 0 ) {
667681
@@ -698,7 +712,7 @@ static bool njsConnection_executeAsync(njsBaton *baton)
698712static bool njsConnection_executePostAsync (njsBaton * baton , napi_env env ,
699713 napi_value * result )
700714{
701- napi_value resultSet , rowsAffected , outBinds , lastRowid ;
715+ napi_value resultSet , rowsAffected , outBinds , lastRowid , error ;
702716 napi_value implicitResults ;
703717 uint32_t rowidValueLength ;
704718 const char * rowidValue ;
@@ -711,6 +725,14 @@ static bool njsConnection_executePostAsync(njsBaton *baton, napi_env env,
711725 // create result object
712726 NJS_CHECK_NAPI (env , napi_create_object (env , result ))
713727
728+ // process warnings if any
729+ if (baton -> warningInfo .isWarning ) {
730+ if (!njsUtils_getError (env , & baton -> warningInfo , NULL , & error ))
731+ return false;
732+ NJS_CHECK_NAPI (env , napi_set_named_property (env , * result , "warning" ,
733+ error ))
734+ }
735+
714736 // handle queries
715737 if (baton -> queryVars ) {
716738
@@ -1700,6 +1722,25 @@ NJS_NAPI_METHOD_IMPL_SYNC(njsConnection_getTransactionInProgress, 0, NULL)
17001722}
17011723
17021724
1725+ //-----------------------------------------------------------------------------
1726+ // njsConnection_getWarning()
1727+ // Get the warning set on connection object. This is set at connection
1728+ // creation time. The only warning expected is password-will-expire-soon
1729+ //-----------------------------------------------------------------------------
1730+ NJS_NAPI_METHOD_IMPL_SYNC (njsConnection_getWarning , 0 , NULL )
1731+ {
1732+ njsConnection * conn = (njsConnection * ) callingInstance ;
1733+
1734+ if (conn -> handle ) {
1735+ if (conn -> warningInfo .isWarning ) {
1736+ if (!njsUtils_getError (env , & conn -> warningInfo , NULL , returnValue ))
1737+ return njsUtils_throwErrorDPI (env , globals );
1738+ }
1739+ }
1740+ return true;
1741+ }
1742+
1743+
17031744//-----------------------------------------------------------------------------
17041745// njsConnection_newFromBaton()
17051746// Called when a connection is being created from the baton.
@@ -1727,6 +1768,10 @@ bool njsConnection_newFromBaton(njsBaton *baton, napi_env env,
17271768 baton -> tagLength = 0 ;
17281769 }
17291770
1771+ // transfer any warning information to the connection
1772+ if (baton -> warningInfo .isWarning ) {
1773+ conn -> warningInfo = baton -> warningInfo ;
1774+ }
17301775 return true;
17311776}
17321777
0 commit comments