sqlanywhere / node-sqlanywhere

SAP SQL Anywhere Database Client for Node
Apache License 2.0
39 stars 36 forks source link

Cannot read property '1' of null #28

Closed juniorabranches closed 6 years ago

juniorabranches commented 6 years ago

I come across this error .. "Cannot read property '1' of null" What can it be?

my code:

import {sqlanywhere} from 'sqlanywhere'   var conn_params = {    Server: 'BDINTESIG_ABRANCHES',    DatabaseFile: 'BDINTESIG.db',    Host: 'localhost: 2638',    UserId: 'USER',    Password: 'PASSWORD' };

       var conn = this.sql.createConnection ();               conn.connect (conn_params, function (err) {          if (err) throw err;          conn.exec ('SELECT user FROM tbgersenha WHERE name =?', ['AUTOR'], function (err, result) {            if (err) throw err;                   console.log ('NamShaha:', result [0] .asha);                     conn.disconnect ();          })        });

gperrow-SAP commented 6 years ago

There are a few problems here:

  1. The host parameter should not have spaces in it. The value should be "localhost:2638", or just "localhost" since 2638 is the default port number.
  2. "user" is a reserved word so if you have a column called user in this table, you need to put quotes around it in your select statement: select "user" from tbgersenha ... Otherwise the server thinks you are selecting the name of the current user.
  3. The result array will have a field containing the name of the column, in this case "user". result[0].asha doesn't refer to anything and will return undefined.
juniorabranches commented 6 years ago

Hi, thanks for the reply. but this was deconfiguration of google translator rsrs my code is this:

import {sqlanywhere} from 'sqlanywhere'

var conn_params = { Server: 'BDINTESIG_ABRANCHES', DatabaseFile: 'BDINTESIG.db', Host: 'localhost:2638', UserId: 'JOAO', Password: '123' };

   var conn = this.sql.createConnection ();

   conn.connect (conn_params, function (err) {
     if (err) throw err;
     conn.exec ('SELECT user FROM tbgersenha WHERE name =?', ['JOAO'], function (err, result) {
       if (err) throw err;

       console.log ('Nome:', result [0] .user);

       conn.disconnect ();
     })
   });

Thanks!!

gperrow-SAP commented 6 years ago

OK, so points 1 and 3 of my first response are not relevant. But you still need to make the change in point 2.