Skip to content

Commit a781279

Browse files
committed
fix scalar functions
1 parent f876c75 commit a781279

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

‎mysql.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ Agent.prototype._update = function(item) {
802802
};
803803

804804
Agent.prototype._select = function(item) {
805-
return { name: item.name, query: item.condition.toQuery(item.query) + item.condition.toString(this.id), params: null, first: item.condition._take === 1 };
805+
return { name: item.name, query: item.condition.toQuery(item.query) + item.condition.toString(this.id), params: null, first: item.condition._take === 1, datatype: item.datatype };
806806
};
807807

808808
Agent.prototype._delete = function(item) {
@@ -927,7 +927,7 @@ Agent.prototype.count = function(name, table, column) {
927927
column = '*';
928928

929929
var condition = new SqlBuilder();
930-
self.command.push({ type: 'query', query: 'SELECT COUNT(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn' });
930+
self.command.push({ type: 'query', query: 'SELECT COUNT(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn', datatype: 1 });
931931
return condition;
932932
};
933933

@@ -939,7 +939,7 @@ Agent.prototype.max = function(name, table, column) {
939939
}
940940

941941
var condition = new SqlBuilder();
942-
self.command.push({ type: 'query', query: 'SELECT MAX(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn' });
942+
self.command.push({ type: 'query', query: 'SELECT MAX(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn', datatype: 1 });
943943
return condition;
944944
};
945945

@@ -951,7 +951,7 @@ Agent.prototype.min = function(name, table, column) {
951951
}
952952

953953
var condition = new SqlBuilder();
954-
self.command.push({ type: 'query', query: 'SELECT MAX(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn' });
954+
self.command.push({ type: 'query', query: 'SELECT MAX(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn', datatype: 1 });
955955
return condition;
956956
};
957957

@@ -963,7 +963,7 @@ Agent.prototype.avg = function(name, table, column) {
963963
}
964964

965965
var condition = new SqlBuilder();
966-
self.command.push({ type: 'query', query: 'SELECT AVG(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn' });
966+
self.command.push({ type: 'query', query: 'SELECT AVG(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn', datatype: 1 });
967967
return condition;
968968
};
969969

@@ -1220,7 +1220,7 @@ Agent.prototype._prepare = function(callback) {
12201220

12211221
if (current.first && current.column) {
12221222
if (rows.length > 0)
1223-
self.results[current.name] = current.column === 'sqlagentcolumn_e' ? true : rows[0][current.column];
1223+
self.results[current.name] = current.column === 'sqlagentcolumn_e' ? true : current.datatype === 1 ? parseFloat(rows[0][current.column] || 0) : rows[0][current.column];
12241224
} else if (current.first)
12251225
self.results[current.name] = rows instanceof Array ? rows[0] : rows;
12261226
else

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
"type": "git",
1212
"url": "https://github.com/petersirka/node-sqlagent.git"
1313
},
14-
"version": "1.6.0"
14+
"version": "1.7.0"
1515
}

‎pg.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ Agent.prototype._prepare = function(callback) {
12561256

12571257
if (current.first && current.column) {
12581258
if (rows.length > 0)
1259-
self.results[current.name] = current.column === 'sqlagentcolumn_e' ? true : current.datatype === 1 ? parseInt(rows[0][current.column]) : rows[0][current.column];
1259+
self.results[current.name] = current.column === 'sqlagentcolumn_e' ? true : current.datatype === 1 ? parseFloat(rows[0][current.column] || 0) : rows[0][current.column];
12601260
} else if (current.first)
12611261
self.results[current.name] = rows instanceof Array ? rows[0] : rows;
12621262
else

‎sqlserver.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ Agent.prototype._update = function(item) {
853853
};
854854

855855
Agent.prototype._select = function(item) {
856-
return { name: item.name, query: item.condition.toQuery(item.query) + item.condition.toString(this.id), params: null, first: item.condition._take === 1 };
856+
return { name: item.name, query: item.condition.toQuery(item.query) + item.condition.toString(this.id), params: null, first: item.condition._take === 1, datatype: item.datatype };
857857
};
858858

859859
Agent.prototype._delete = function(item) {
@@ -978,7 +978,7 @@ Agent.prototype.count = function(name, table, column) {
978978
column = '*';
979979

980980
var condition = new SqlBuilder();
981-
self.command.push({ type: 'query', query: 'SELECT COUNT(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn' });
981+
self.command.push({ type: 'query', query: 'SELECT COUNT(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn', datatype: 1 });
982982
return condition;
983983
};
984984

@@ -990,7 +990,7 @@ Agent.prototype.max = function(name, table, column) {
990990
}
991991

992992
var condition = new SqlBuilder();
993-
self.command.push({ type: 'query', query: 'SELECT MAX(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn' });
993+
self.command.push({ type: 'query', query: 'SELECT MAX(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn', datatype: 1 });
994994
return condition;
995995
};
996996

@@ -1002,7 +1002,7 @@ Agent.prototype.min = function(name, table, column) {
10021002
}
10031003

10041004
var condition = new SqlBuilder();
1005-
self.command.push({ type: 'query', query: 'SELECT MAX(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn' });
1005+
self.command.push({ type: 'query', query: 'SELECT MAX(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn', datatype: 1 });
10061006
return condition;
10071007
};
10081008

@@ -1014,7 +1014,7 @@ Agent.prototype.avg = function(name, table, column) {
10141014
}
10151015

10161016
var condition = new SqlBuilder();
1017-
self.command.push({ type: 'query', query: 'SELECT AVG(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn' });
1017+
self.command.push({ type: 'query', query: 'SELECT AVG(' + column + ') as sqlagentcolumn FROM ' + table, name: name, condition: condition, first: true, column: 'sqlagentcolumn', datatype: 1 });
10181018
return condition;
10191019
};
10201020

@@ -1268,7 +1268,7 @@ Agent.prototype._prepare = function(callback) {
12681268

12691269
if (current.first && current.column) {
12701270
if (rows.length > 0)
1271-
self.results[current.name] = current.column === 'sqlagentcolumn_e' ? true : rows[0][current.column];
1271+
self.results[current.name] = current.column === 'sqlagentcolumn_e' ? true : current.datatype === 1 ? parseFloat(rows[0][current.column] || 0) : rows[0][current.column];
12721272
}
12731273
else if (current.first)
12741274
self.results[current.name] = rows instanceof Array ? rows[0] : rows;

0 commit comments

Comments
 (0)