Giter Club home page Giter Club logo

Comments (7)

abmusse avatar abmusse commented on July 17, 2024

Opened a PR @ idb-connector repo concerning above issue.

Version 1.0.0 of idb-pconnector released supporting username & passwords for connection.

Marking this issue as resolved!

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on July 17, 2024

@dmabupt while creating a test case for the Updated idbp-connector method connect(url, usernmae, password) , I noticed that errors were not being thrown by the idc-connectors's dbconn.conn().

For Example:

    let conn = new Connection();
    
    conn.debug(true);
    dbConn.connect('*LOCAL', 'fake', 'fake');

I would expect an error to be thrown by the underlying dbconn's .conn() but an error is not thrown.

Looking at the output from points out that it dd fail but the error was just not thrown.

SQLConnect(-1): conn obj [18031b410] handler [2]

 **** ERROR *****
SQLSTATE: 08001
Native Error Code: -30082
Authorization failure on distributed database connection attempt. 
``

Looking @ the underlying idb-connector code I think I know why the error was not thrown. 


Before converting the idb-connector to be napi compliant the [void throwErrMsg(int handleType, Isolate* isolate)](https://bitbucket.org/litmis/nodejs-idb-connector/src/6ca9ff8060a012177f002d5833d8ad7f0ed3e58c/src/db2ia/dbconn.h?at=1.0.13&fileviewer=file-view-default#dbconn.h-119) would throw an error at the end.

The but somehow the Napi version of [void throwErrMsg(int handleType, Isolate* isolate)](https://bitbucket.org/litmis/nodejs-idb-connector/src/16bf93548e688b92594d7951b886d661e0ecf0aa/src/db2ia/dbconn.h?at=master&fileviewer=file-view-default#dbconn.h-89) does not throw the java script error at the end.

I suspect adding `Napi::Error::New(env, Napi::String::New(env, errMsg)).ThrowAsJavaScriptException();` to line 90 of dbconn.h would fix this :smiley: .

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on July 17, 2024

Yes, we can skip the isLocal check because connecting without a username & password should only work when using '*LOCAL' anyway.

When using '*LOCAL' and you don't provide username & password, your current user profile info would be used for you.

#!js
  ...
  /**
   * Instantiates a new Connection instance
   */
  newConnection() {
    let me = this,
      {url, username = '', password = ''} = me.database;

    me.conn = new idbp.Connection();
    if (!username && !password) {
      me.conn.connect(url);
    } else {
      me.conn.connect(url, username, password);
    }
  }

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on July 17, 2024

Original comment by Brian Jerome (Bitbucket: bjerome, GitHub: brianmjerome).


In that case I think we can skip checking for isLocal completely, correct?

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on July 17, 2024

@brianmjerome Thanks! I like the implementation using destructing assignment.

Instead of always skipping connecting with username & password if the url is "*LOCAL" I would tweak it to:

#!js
  ...
  /**
   * Instantiates a new Connection instance
   */
  newConnection() {
    let me = this,
      {url, username = '', password = ''} = me.database,
      isLocal = url === '*LOCAL';

    me.conn = new idbp.Connection();
    if (isLocal && !username && !password) {
      me.conn.connect(url);
    } else {
      me.conn.connect(url, username, password);
    }
  }

That way if a username and password is provided & the url is local then an attempt to connect with the username & password is made.

Currently trying to have the idb-pconnector be used as transport option within itoolkit. Looking at the examples, username and passwords are passed along to connect even when using "*LOCAL".

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on July 17, 2024

Original comment by Brian Jerome (Bitbucket: bjerome, GitHub: brianmjerome).


@abmusse
This is what I had originally for Connection supporting user/pwd. Feel free to reference if needed :)

#!javascript
  ...

  /**
   * Constructor to instantiate a new instance of a Connection class given the `poolIndex` and `config`
   * @param poolIndex An identifier for debug purposes
   * @param config Object includes `database`
   */
  constructor(poolIndex, config = {database: {url: '*LOCAL'}}) {
    let me = this,
      {database} = config;

    // Defaults are initialized if `config` does not have all properties defined at instantiation.
    me.database = database || {url: '*LOCAL'};
    ...
    me.newConnection();
    ...
  }

  /**
   * Instantiates a new Connection instance
   */
  newConnection() {
    let me = this,
      {url, username = '', password = ''} = me.database,
      isLocal = url === '*LOCAL';

    me.conn = new idbp.Connection();
    if (isLocal) {
      me.conn.connect(url);
    } else {
      // Username and Password are assumed blank if not specified with non-local URL.
      me.conn.connect(url, username, password);
    }
  }

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on July 17, 2024

Thanks For the Suggestion!

I'm Currently working on an Implementation.

from nodejs-idb-pconnector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.