Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 2019 14:34
    willmorgan commented on 889cbf1
  • Jan 31 2019 13:15
    gsamal commented on 889cbf1
  • Jan 31 2019 13:10
    dhensby closed #797
  • Jan 31 2019 13:10
    dhensby commented #797
  • Jan 31 2019 13:07
    dhensby closed #795
  • Jan 31 2019 13:07
    dhensby commented #795
  • Jan 31 2019 12:58
    gsamal commented #789
  • Jan 31 2019 11:50
    cesco69 opened #797
  • Jan 31 2019 10:22

    dhensby on master

    Update changelog for v5 Merge pull request #796 from dh… (compare)

  • Jan 31 2019 10:22
    dhensby closed #796
  • Jan 31 2019 09:53
    dhensby commented #789
  • Jan 31 2019 09:52
    dhensby commented #778
  • Jan 31 2019 09:51
    dhensby review_requested #796
  • Jan 31 2019 09:51
    dhensby opened #796
  • Jan 31 2019 06:45
    suckerp commented #795
  • Jan 31 2019 02:58
    liumorgan starred tediousjs/node-mssql
  • Jan 31 2019 02:15
    zhoukk starred tediousjs/node-mssql
  • Jan 30 2019 22:22
    vjpr edited #795
  • Jan 30 2019 22:22
    vjpr edited #795
  • Jan 30 2019 22:22
    vjpr opened #795
David Gasperoni
@mcdado
Either omit the callback and use the promise, or embrace callback hell
Daniel Hensby
@dhensby
@mn567 yes, they are wrong - issue #844 , fix #846 - fixed in v6 docs
dhaneshhs
@dhaneshhs
is there any sql query generator which works well with mssql which support easy way of generating INSERT query as i have more than 30 columns to be inserted to the table
Daniel Hensby
@dhensby
dhaneshhs
@dhaneshhs
Thanks @dhensby
TK
@tonnykayage
Mssql inducing memory leaks when i run a benchmark at 10k concurrency, Memory increases overtime until i'm out of memory.
_g[conn].request().query(preparedQuery, function (err, records) {
_g[conn].on('error', errdb => {
reject(_t.i(1005, configurations.errors, errdb));
Logger.log("error", "tmsmssql", "SYS", _t.i(1005, configurations.errors, errdb));
return;
});
if (err) {
reject(_t.i(1003, configurations.errors, JSON.stringify(err)));
} else {
if (records.rowsAffected[0] > 0) {
if (op === 'INSERT' || op === 'UPDATE' || op === 'DELETE') {
resolve(_t.i(200, null, records));
} else {
resolve(_t.i(200, null, records.recordset));
}
} else {
reject(_t.i(1004, configurations.errors));
}
}
});
Igor Savin
@kibertoad
Which mmsql version are you running?
TK
@tonnykayage
Mssql 5.1.0 @kibertoad
Taldrit
@Taldrit
I have a problem with the tutorial. I tried the ConnectionPool and always got the message that .on() is not a function and then I commented that out and tried it without, but now I get the error Already connecting to database. What did I do wrong?
const mssql = require('mssql');
let config = {...}; // that one is correct, I tested it with a pure simple query
const sqlPool = new mssql.ConnectionPool(config, err => {
console.log(err);
}).connect();
sqlPool.on('error', err => {
log(err);
});
const sqlQuery = queryString => {
return sqlPool.then(pool => {
pool.request().query(queryString)
}).then(result => {
console.dir(result);
})
};
sqlQuery("SELECT * FROM users");
David Gasperoni
@mcdado
If you pass a callback to ConnectionPool, it will not return a promise

Instead of this

mssql.ConnectionPool(config, err => { console.log(err);

Try like this:

mssql.ConnectionPool(config) .then((result) => {}) .catch((reason) => {});

Error handling is in the catch
.catch((reason) => {
    console.error(reason);
});
Taldrit
@Taldrit
grrrr... no I get the error: TypeError: (intermediate value).then is not a function
maybe I need a complete functioning module to adjust to my needs instead of small code samples. Do you have an example that I could use? I search for one that uses one connection for a long time (there maybe many calls to the same database from the same server without any other connections. So 1 connection that stays open for a longer time should be fine). The samples I found and that work all use a single call on a connection inside the connection call. But that way the connection would have to be closed and reopened on every query.
David Gasperoni
@mcdado
I think I know what you mean, personally I created a class that is technically a singleton for each database. Basically the connectionPool is module variable that calling modules access to. Then anytime I want to run requests I listen to the (already happened) on(“connect”) event
John McCallister
@mccallister_ftw_twitter
Hello
Usher Klein
@asherklein
Hi! I'm trying to connect to a SQL Server CE sdf file. Could someone please point me to an example?
I've tried a connection string like this: Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=Northwind.sdf;Persist Security Info=False;
And get the following error: ConnectionError: Failed to connect to Northwind.sdf:1433 - getaddrinfo ENOTFOUND Northwind.sdf
Any help would be greatly appreciated
thbl
@thbl
is there any benefits for using msnodesqlv8 vs using Tedious ?
Daniel Hensby
@dhensby
Msnkdesqlv8 is for people running on windows
kemmottar
@kemmottar
Hi im trying to listen the database's changes with node and mssql module but i fail so hard. Can u recommend a module for this
Jason Luboff
@JLuboff
@kemmottar What do you mean you're trying to listen to the changes?
kemmottar
@kemmottar
I want to see insert,update and delete
In the tables
Jason Luboff
@JLuboff
I would think you'd want to use a trigger or audit for that on the SQL server side. Unless those DML actions are taking place directly in your app in which case you could log it
kemmottar
@kemmottar
Yes i want to see dml actions in my app. How can i log it with node and listen database changos?
Ty for ur hielo
Help
Jason Luboff
@JLuboff
You would need to log them somewhere either before or after the statements are ran. As far as I know, you can't "listen" for DB changes with this module. Perhaps you could create a custom event listener though..
sql.on('myCustomListener, () => doSomething())
As @dhensby is one of the main maintainers, he may have a better idea
Daniel Hensby
@dhensby
I believe this is a feature in the dotnet library, but it's not possible in node. It's down to the drivers and their integration, none of them support this feature at the moment
kemmottar
@kemmottar
@dhensby
Thank u
Luke
@luker2
function generateUpsertQueryString(myListOfObjects: MyDbTableRow[]) {
    return myListOfObjects.map(o => `

-- update existing row if possible
UPDATE dbo.MyDbTable
SET SomeCol1 = '${o.someCol1}',
    SomeCol2 = '${o.someCol1}'
WHERE SomeCol3 = '${o.someCol1}';

-- otherwise insert new row
IF @@ROWCOUNT = 0
    INSERT INTO dbo.MyDbTable
    (
        SomeCol1,
        SomeCol2,
        SomeCol3
    )
    VALUES
    (   
        '${o.someCol1}',
        '${o.someCol2}',
        '${o.someCol3}'
    );
`).join('\n')
}
hey @dhensby / anybody, I typically use mssql's "params" feature to escape strings. In the case above, the function is basically generating a giant query string. I pass the function a list of objects which should be used to update/insert rows into a table. So the function loops thru and generates an "upsert" statement for each item in the list. I foresee sql injection with this approach of using javascript template strings. Otherwise it seems I'd have to come up with a clever way to format all this data into the "params" object. Any ideas/recommendations?
Jason Luboff
@JLuboff
@luker2 According to the docs, template literals should be sanitized
ES6 Tagged template literals
const sql = require('mssql')

sql.connect(config).then(() => {
    return sql.query`select * from mytable where id = ${value}`
}).then(result => {
    console.dir(result)
}).catch(err => {
    // ... error checks
})

sql.on('error', err => {
    // ... error handler
})
All values are automatically sanitized against sql injection. This is because it is rendered as prepared statement, and thus all limitations imposed in MS SQL on parameters apply. e.g. Column names cannot be passed/set in statements using variables.
I have not personnelly tested that though
Luke
@luker2

@JLuboff unrelated, but this seems like some weird syntax:

return sql.query`select * from mytable where id = ${value}`

But thanks, if I understand correctly, I don't need to make any changes to my approach above. I'll run some tests to make sure that's happening.

Jason Luboff
@JLuboff
Ya, thats tagged template literals (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals around the middle of the page it talks about it)... I agree that its an odd looking syntax too hah
Daniel Hensby
@dhensby

@luker2 - the way you're doing it in your original call won't provide safety because it won't cause the automatic parameterisation of the query.

if you mapped it directly into a query call (as suggested by @JLuboff) then it should be safe as it will generate a parameterised query for you.

function generateUpsertQueryString(myListOfObjects: MyDbTableRow[]) {
    return myListOfObjects.map(o => mssql.query`

-- update existing row if possible
UPDATE dbo.MyDbTable
SET SomeCol1 = '${o.someCol1}',
    SomeCol2 = '${o.someCol1}'
WHERE SomeCol3 = '${o.someCol1}';

-- otherwise insert new row
IF @@ROWCOUNT = 0
    INSERT INTO dbo.MyDbTable
    (
        SomeCol1,
        SomeCol2,
        SomeCol3
    )
    VALUES
    (   
        '${o.someCol1}',
        '${o.someCol2}',
        '${o.someCol3}'
    );
`)
}
Luke
@luker2

@dhensby gotcha. Would it ever be easy to expose a standalone function like mysql.escape() ?

https://github.com/mysqljs/mysql#escaping-query-values

Daniel Hensby
@dhensby
no, because the escaping requires connection context and there isn't as simple a way to escape strings because the connection doesn't expose a way to do this nicely like mysql does. the answer is to use parameterised queries