teradatasql
Version:
Teradata SQL Driver for Node.js
100 lines • 4.69 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const teradatasql = __importStar(require("teradatasql"));
function byte(s, encoding) {
return Uint8Array.from(Buffer.from(s, encoding));
}
const con = teradatasql.connect({ host: "whomooz", user: "guest", password: "please" });
try {
const cur = con.cursor();
try {
const aao = [
["BYTEINT", 1n],
["SMALLINT", 2n],
["INTEGER", 3n],
["BIGINT", 4n],
["FLOAT", "5"],
["NUMBER", "6"],
["DECIMAL(18)", "7"],
["DECIMAL(38)", "8"],
["PERIOD(DATE)", "0009-09-09,0909-09-09"],
["PERIOD(TIME)", "10:10:10.101000,10:10:10.101010"],
["PERIOD(TIME WITH TIME ZONE)", "11:11:11.111110+11:11,11:11:11.111111+11:11"],
["PERIOD(TIMESTAMP)", "1212-01-12 12:12:12.121212,1212-02-12 12:12:12.121212"],
["PERIOD(TIMESTAMP WITH TIME ZONE)", "1313-01-13 13:13:13.131313+13:13,1313-02-13 13:13:13.131313+13:13"],
["INTERVAL YEAR(4)", "-1414"],
["INTERVAL YEAR(4) TO MONTH", "-1515-11"],
["INTERVAL MONTH(4)", "-1616"],
["INTERVAL DAY(4)", "-1717"],
["INTERVAL DAY(4) TO HOUR", "-1818 18"],
["INTERVAL DAY(4) TO MINUTE", "-1919 19:19"],
["INTERVAL DAY(4) TO SECOND", "-2020 20:20:20.202020"],
["INTERVAL HOUR(4)", "-2121"],
["INTERVAL HOUR(4) TO MINUTE", "-2222:22"],
["INTERVAL HOUR(4) TO SECOND", "-2323:23:23.232323"],
["INTERVAL MINUTE(4)", "-2424"],
["INTERVAL MINUTE(4) TO SECOND", "-2525:25.252525"],
["INTERVAL SECOND(4)", "-2626.262626"],
["BYTE(2)", byte("27")],
["CHAR(2)", "28"],
];
console.log(" teradata_parameter bind type Result from TYPE function Round-trip data value");
console.log(" -------------------------------- ----------------------------------- ---------------------");
for (let n = 0; n < aao.length; n++) {
const ao = aao[n];
const sDataType = ao[0];
const oValue = ao[1];
cur.execute("{fn teradata_parameter(1," + sDataType + ")}select trim(type(?))", [null]);
const row = cur.fetchone();
const sTypeFuncResult = row ? row[0] : "";
let oOutput;
if (sDataType.startsWith("PERIOD")) {
cur.execute("create volatile table volatiletable (c1 " + sDataType + ") no primary index on commit preserve rows");
cur.execute("{fn teradata_parameter(1," + sDataType + ")}insert into volatiletable values (?)", [oValue]);
cur.execute("select * from volatiletable");
const row = cur.fetchone();
oOutput = row ? row[0] : null;
cur.execute("drop table volatiletable");
}
else if (sDataType.startsWith("BYTE(")) {
oOutput = 'byte("' + Buffer.from(oValue).toString() + '")';
}
else {
cur.execute("{fn teradata_parameter(1," + sDataType + ")}select ?", [oValue]);
const row = cur.fetchone();
oOutput = row ? row[0] : null;
}
console.log(`${(n + 1).toString().padEnd(2)} ${sDataType.padEnd(33)} ${sTypeFuncResult.padEnd(36)} ${oOutput}`);
}
}
finally {
cur.close();
}
}
finally {
con.close();
}
//# sourceMappingURL=ParamDataTypes.js.map