Comments (10)
to confirm
function nullBinary() {
var msnodesql = require('node-sqlserver-v8');
msnodesql.open(connStr, function(err, conn) {
if (err) return console.error(err);
conn.query("declare @bin binary(4) = ?; select @bin as bin", [new Buffer(0)], function(err, res) {
console.error(err);
console.error(res);
});
});
}
i.e. you are saying passing in new Buffer(0) does not work? when i run the above, i do not see this error. Running with null, agreed it does fail and this is because actually the driver tries to decode type from params rather than column meta data which would be more reliable, but that is a pretty big change to make and is consistent with previous behavior.
can you confirm what you are expecting to see when new Buffer(0) is sent in?
i see
Debugger listening on port 16763
null
{ bin: <Buffer 00 00 00 00> }
from node-sqlserver-v8.
I made some tests and realised that the problem is that new Buffer(0)
is a valid value and should not be converted to null. The workaround I used to use was a bug and should be no longer used.
var msnodesql = require('msnodesqlv8');
msnodesql.open(connectionString, function(err, conn) {
if (err) return console.error(err);
conn.query("declare @bin varbinary(max) = ?; insert into varbintest(bin) values (@bin); select @bin as bin", [new Buffer(0)], function(err, res) {
console.log(res);
});
});
This code inserts one row to table varbintest
with value 0x
and returns it back as a result.
[ { bin: <Buffer > } ]
I have no idea how to resolve this without knowing the parameter's type.
from node-sqlserver-v8.
can you see if the following is any help. I only support varBinary at the moment through this way of binding, but it can be extended. The idea is to tell the c++ driver explicitly what the type is rather than it trying to guess. In this way we can pass a null of type varbinary, I added the test to the params suite.
open(function(conn) {
var tm = conn.tableMgr();
conn.query("declare @bin binary(4) = ?; select @bin as bin", [tm.sqlTypes.asVarBinary(null)], function (err, res) {
console.log(res[0]['bin'] == null);
console.error(err);
console.error(res);
});
});
from node-sqlserver-v8.
I absolutely preffer this way of passing arguments. Automatic type guess is a nice feature until you need to explitily set something.
The code looks unnecessarily verbose to me. Creating a table manager to cast types seems like overkill to me. Some ideas:
var msnodesql = require('msnodesqlv8');
msnodesql.open(connectionString, function(conn) {
conn.query("select @bin", [msnodesql.VarBinary(null)], function(err, res) {});
// or
conn.query("select @bin", [msnodesql.cast(null, "VarBinary")], function(err, res) {});
})
from node-sqlserver-v8.
agreed, your API is more elegant. I like both methods, I would probably say the first would be my preference. I will take a look and get back to you when I have something.
from node-sqlserver-v8.
OK, I added some new methods.
let me know if you think the names etc should be changed. I have added a new test suite userbind.js
sql.Double(d)
sql.BigInt(i)
sql.VarBinary(null)
sql.Integer(i)
sql.WVarChar(str)
sql.SSTimeStampOffset(utcDate)
once things look OK I will update the documentation.
I removed the first attempt as previously discussed.
from node-sqlserver-v8.
I would prefer naming according to type. So it would be nice to have all those functions available.
sql.Bit(value)
sql.BigInt(value)
sql.Decimal(value, [precision], [scale]) -- optional precision and scale definition
sql.Float(value)
sql.Int(value)
sql.Money(value)
sql.Numeric(value, [precision], [scale]) -- optional precision and scale definition
sql.SmallInt(value)
sql.SmallMoney(value)
sql.Real(value)
sql.TinyInt(value)
sql.Char(value, [length]) -- optional length definition
sql.NChar(value, [length]) -- optional length definition
sql.Text(value)
sql.NText(value)
sql.VarChar(value, [length]) -- optional length definition
sql.NVarChar(value, [length]) -- optional length definition
sql.Xml(value)
sql.UniqueIdentifier(value)
sql.Time(value, [scale]) -- optional scale definition
sql.Date(value)
sql.DateTime(value)
sql.DateTime2(value, [scale]) -- optional scale definition
sql.DateTimeOffset(value, [scale]) -- optional scale definition
sql.SmallDateTime(value)
sql.Binary(value)
sql.VarBinary(value, [length]) -- optional length definition
sql.Image(value)
sql.UDT(value)
sql.Geography(value)
sql.Geometry(value)
sql.Variant(value)
from node-sqlserver-v8.
OK, I am still working on this, it will probably be available within the next week. I will add a base set of unit tests but we will only know the limitations through use. Ill keep you posted with progress.
from node-sqlserver-v8.
I did have a go at adding quite a few of these into the API with some tests. If you still need them, take a look else they will be there for others. The null into varbinary is available which is what kicked off this discussion.
from node-sqlserver-v8.
I will assume this is implemented ok now. For further problems with user binding please raise a specific test covering that type and I will take a look. The specific user binding mentioned is now available. Therefore I'll close this issue.
from node-sqlserver-v8.
Related Issues (20)
- Cannot use without 'require'? HOT 1
- Module not found: Can't resolve '../build/Release/sqlserverv8' HOT 10
- Module did not self-register: sqlserverv8.node HOT 7
- npm install --save msnodesqlv8 fails MSBuild.exe failed with exit code: 1 HOT 5
- import { SqlClient } from "msnodesqlv8/types"; Cannot find module 'msnodesqlv8/types' or its corresponding type declarations HOT 1
- Unable to initialize msnodesql during Hot Module Reload (HMR) HOT 2
- Security vulnerability detected in latest HOT 1
- uncaughtException: Cannot read properties of null (reading 'query') HOT 3
- `ConcreteColumnType.parseSS` method tampers with plain date strings HOT 3
- Cannot find module '../build/Release/sqlserverv8.node' - Windows 10 / node.js v20.11.0/v21.6.1 HOT 1
- npm install results in LNK1127: library is corrupt HOT 1
- Uncaught Exception: static Sybase = new ServerDialect("Sybase")
- Cannot find module 'msnodesqlv8/types' or its corresponding type declarations. HOT 1
- [Question] What is the authentication detail if set trustedConnection to be true? HOT 2
- Missing binaries for Electron v28 and v29 HOT 6
- Unable to find dialect at msnodesqlv8/lib/sequelize HOT 7
- Execute system stored procedure HOT 3
- Handling of queries that return BIGINT HOT 3
- Segmentation Fault after a few minutes of running .... HOT 1
- Cannot find module 'msnodesqlv8/types' or its corresponding type declarations. HOT 2
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-sqlserver-v8.