Git Product home page Git Product logo

Comments (10)

TimelordUK avatar TimelordUK commented on September 24, 2024

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.

patriksimek avatar patriksimek commented on September 24, 2024

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.

TimelordUK avatar TimelordUK commented on September 24, 2024

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.

patriksimek avatar patriksimek commented on September 24, 2024

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.

TimelordUK avatar TimelordUK commented on September 24, 2024

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.

TimelordUK avatar TimelordUK commented on September 24, 2024

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.

patriksimek avatar patriksimek commented on September 24, 2024

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.

TimelordUK avatar TimelordUK commented on September 24, 2024

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.

TimelordUK avatar TimelordUK commented on September 24, 2024

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.

TimelordUK avatar TimelordUK commented on September 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.