react-native-mssql
react-native-mssql copied to clipboard
Can Update but can't Select rows
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
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 ?
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.
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
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.
I've just tested many types and found that (timestamp) columns causes the same issue