ibmdb / node-ibm_db

IBM DB2 and IBM Informix bindings for node
MIT License
188 stars 151 forks source link

Providing extended client information #970

Closed Elaldradrain closed 3 months ago

Elaldradrain commented 6 months ago

Is your feature request related to a problem? Please describe. I need a way to track workloads for nodejs services. For java service its possible to set client infomation using the following documentation: https://www.ibm.com/docs/en/db2-for-zos/12?topic=jies-providing-extended-client-information-data-source-client-info-properties

Describe the solution you'd like I would like a way of setting client information using the ibm_db driver for nodejs.

bimalkjha commented 6 months ago

@Elaldradrain The extended client information is saved on Db2 for z/OS in special registers. You can set client information for non-Java clients by setting the value of special registers CURRENT CLIENT_USERID and CURRENT CLIENT_WRKSTNNAME. I think this documentation can provide you detailed info about it: https://www.ibm.com/docs/en/db2-for-zos/11?topic=registers-general-rules-special#db2z_rules4specialregisters__chgregvals

For non-Java clients, you can set special registers using two methods: 1) By setting corresponding connection level attribues (SQLSetConnectAttr) and 2) By setting special register values in db2dsdriver.cfg file.

Currently, ibm_db has support for few connection level attributes only, but you can set client info using db2dsdriver.cfg file. To set CURRENT CLIENT_USERID and CURRENT CLIENT_WRKSTNNAME special register, you need to create a .../ibm_db/installer/clidriver/cfg/db2dsdriver.cfg file and specify special register as below:

<configuration>
    <databases>
        <database name="sample" host="hotelfvt02.torolab.ibm.com" port="21169">
            <specialregisters>                  
                <parameter name="CURRENT CLINET_USERID" value="B Jha"/>
                <parameter name="CURRENT CLINET_WRKSTNNAME" value="hotelfvt02"/>
            </specialregisters>
        </database>
        <database name="sample2" host="hotelfvt02.torolab.ibm.com" port="21169">
        </database>
    </databases>
</configuration>

I would also suggest to check "General Rules for Special Registers" here: https://www.ibm.com/docs/en/db2-for-zos/11?topic=registers-general-rules-special and https://www.ibm.com/docs/en/db2/11.1?topic=applications-application-compatibility-db2-zos too. Thanks.

Elaldradrain commented 5 months ago

Thank you very much for this very detailed reply!

I'm still missing one feature which I hope you can clarify for me. I need to change the client user dynamically on runtime, but I can't find any api for it. With dotnet I could do the following

Dim sqlconn As D2Connection = new DB2Connection()
sqlconn = new DB2Connection(szconnect_X)
sqlconn.Open()
sqlconn.ClientUser = "foobar"

The SQLSetConnectAttr you mentioned doesn't seem to be exposed by the nodejs clidriver wrapper.

Elaldradrain commented 4 months ago

Thank you very much! I've just read the commit and it looks just like what we need.

I'll be testing it asap. If you prefer, you can close this issue now. Otherwise I'll report back to let you know if it solves all our needs :). For now im installing with git+https://git@github.com/ibmdb/node-ibm_db.git#master.

bimalkjha commented 3 months ago

Added support in latest release. Hence, closing the issue now. Thanks.