Comments (7)
Just like you've enclosed the ${table}
with braces, the user_id
needs to be enclosed.
const table = 'test';
const user_id = 'abab==';
const input_parameter = 'USER_ID';
-const query = `SELECT * FROM [uat].[dbo].[${table}] WITH(NOLOCK) WHERE ${user_id} = @${input_parameter}`;
+const query = `SELECT * FROM [uat].[dbo].[${table}] WITH(NOLOCK) WHERE [${user_id}] = @${input_parameter}`;
from node-mssql.
But now its giving invalid column name error for all queries,
RequestError: Invalid column name 'abab=='
RequestError: Invalid column name '160000007137377767'
from node-mssql.
I'm afraid that the issues are for bugs with the library and not query writing support.
I can't help you with your query, especially as I don't have any of the actual context.
Here are docs for database identifiers (column names, etc): https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers?view=sql-server-ver16
from node-mssql.
Sorry for opening this as an issue, I can't seem to find the workaround for this in docs or any communities :')
I should have write the question better, the variable im passing is in double quote, hence why the solution you gave return that error.
However managed to resolve this, by single quote the user_id variable in query:
const query = `SELECT * FROM [uat].[dbo].[${table}] WITH(NOLOCK) WHERE '${user_id}' = @${input_parameter}`;
Thank you for your help btw! 😄
from node-mssql.
I'm not sure that is doing what you expect it to do - that's a literal value comparison. A bit like doing SELECT * FROM table WHERE 1 = 1
- it's not referencing a column.
from node-mssql.
Actually you're right, I tried with other string variable yesterday and it still returns true.
I tried using LIKE operator as below, and it seems giving the same error:
SELECT * FROM [uat].[dbo].[${table}] WITH(NOLOCK) WHERE USER_KEY LIKE ${user_id}
RequestError: Incorrect syntax near '='.
Perhaps, is there any other way you can suggest me to try. I tried to remove double quote and assign single quote globally and it still not resolving the issue:
user_id = user_id.replace(/\"/g, "'") // not working
user_id = `'${user_id}'`; // giving literal value comparison
from node-mssql.
I managed to resolve this already, seems like i confused with my own logic to do the query.
It should be:
const table = 'test';
const userId = 'sample==';
const input_parameter = 'USER_ID';
const data = {[input_parameter]: userId }
const query = `SELECT * FROM [uat].[dbo].[${table}] WITH(NOLOCK) WHERE ${input_parameter} = @${input_parameter}`;
let dbRequest = new sql.Request(pool);
for (const key in data) {
dbRequest.input(key, data[key]);
}
then do the dbRequest.query(query)
now it works as expected, sorry for the confusion :')
from node-mssql.
Related Issues (20)
- How to connect to SQL Server using tedious (Windows Authentication) HOT 1
- Issue connecting to MSSQL DB in Linux environment HOT 3
- How to use the user-defined data types?
- you have a typo in your readme sql.query`some query` HOT 1
- ConnectionError: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified HOT 1
- Potential impact of disabling connection validation when released from the pool HOT 1
- The "config.server" property is required and must be of type string. HOT 1
- @azure/core-rest-pipeline breaking support for node.js 14 HOT 2
- Does node-mssql support multiSubnetFailover? HOT 9
- Suspected memory leak when streaming data HOT 4
- arrayRowMode returns a function for the column type HOT 6
- Problem with Persian/Arabic characters when using input() HOT 4
- Testing library-using code in Jest results in SyntaxError: Unexpected token 'export' HOT 1
- Request timeouts in mssql/msnodesqlv8 when using default Pool size HOT 4
- Bulk Insert row lock not supported HOT 1
- Committing a transaction early, within a transaction ? HOT 4
- [Question] Does node-mssql support Kerberos authentication HOT 1
- ConnectionError: Connection not yet open. HOT 1
- How to bind a multidimensional array HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-mssql.