react-native-mssql icon indicating copy to clipboard operation
react-native-mssql copied to clipboard

Can Update but can't Select rows

Open MujtabaFR opened this issue 5 years ago • 4 comments

Hi, I'm using react-native-mssql on react-native 0.59.9 on Android

I'm able to update the rows in my MSSQL database, but when trying to select any rows.. it throws multiple errors.. couldn't find why

  let sqlConfig = {
      server: '192.168.2.107', //ip address of the mssql database
      username: 'sa', //username to login to the database
      password: 'aaaaa', //password to login to the database
      database: 'new', //the name of the database to connect to
      port: 1433, //OPTIONAL, port of the database on the server
      // timeout: 10  //OPTIONAL, login timeout for the server
  };

  MSSQL.connect(sqlConfig)
  .then(() => {
      console.log('Did connect');
      //  let query = 'UPDATE USERS SET Status=2;  // works perfectly
      let query = 'SELECT TOP 1 * FROM USERS';  // not working
      MSSQL.executeQuery(query)
      .then(rows => {
          console.log(rows);
          MSSQL.close();
      })
      .catch(error => {
          console.log('Query error!', 'Querry: ' + query + '\r\nError: ' + JSON.stringify(error));
          console.warn(error);
          MSSQL.close();
      });
  })
  .catch(error => {
      Alert.alert('Connect error!', JSON.stringify(error));
  });

I'm getting these errors

Screen Shot 2019-07-02 at 5 54 04 AM

Did connect
-------------------------------------------
Query error! Querry: SELECT TOP 1 * FROM USERS
Error: {"framesToPop":1,"nativeStackAndroid":[],"userInfo":null,"code":"REACT-NATIVE-MSSQL"}
-------------------------------------------
Error: byte[] cannot be cast to java.lang.Object[]

Could you please provide any help about this issue ?

MujtabaFR avatar Jul 02 '19 02:07 MujtabaFR

Hi,

That error looks to be a problem converting one of the fields in your users table. Specially it looks like you have a byte array field and the plugin isn't able to convert that to something react native can understand. Can you confirm this?

You could bypass this issue by not selecting that particular column, but if you can provide me with the columns data type and I update the plugin to hopefully handle it.

davidstoneham avatar Jul 02 '19 03:07 davidstoneham

What a rapid response and solution @davidstoneham .. thanks it was solved by not selecting a particular column as you mentioned

I found that the cause was the column (Sid)

many thanks again

photo_2019-07-02_06-10-01

MujtabaFR avatar Jul 02 '19 03:07 MujtabaFR

I just happened to be repyling to emails and the github notification came in at the right time. Thanks for the info and great to hear the work around works. I'll take a look at parsing varbinary data types for the plugin.

davidstoneham avatar Jul 02 '19 03:07 davidstoneham

I've just tested many types and found that (timestamp) columns causes the same issue

MujtabaFR avatar Jul 02 '19 03:07 MujtabaFR