Comparing version 3.0.0-rc.0 to 3.0.0
@@ -224,3 +224,3 @@ 'use strict'; | ||
if (opts.logger.query) | ||
opts.logger.query(`BULK: (${this.prepare.id}) ${opts.logger.logParam ? this.displaySql() : this.sql}`); | ||
opts.logger.query(`BULK: (${this.prepare.id}) sql: ${opts.logger.logParam ? this.displaySql() : this.sql}`); | ||
const parameterCount = this.prepare.parameters.length; | ||
@@ -227,0 +227,0 @@ this.rowIdx = 0; |
@@ -14,4 +14,4 @@ 'use strict'; | ||
class ColumnDef { | ||
constructor(packet, info, opts, binary) { | ||
this._parse = new StringParser(packet); | ||
constructor(packet, info) { | ||
this._stringParser = new StringParser(packet); | ||
if (info.serverCapabilities & Capabilities.MARIADB_CLIENT_EXTENDED_TYPE_INFO) { | ||
@@ -47,3 +47,5 @@ const subPacket = packet.subPacketLengthEncoded(); | ||
this.type = FieldType.TYPES[this.columnType]; | ||
} | ||
__parser(binary, opts) { | ||
// set reader function read(packet, index, nullBitmap, opts) | ||
@@ -55,7 +57,6 @@ // this permit for multi-row result-set to avoid resolving type parsing each data. | ||
if (this.signed()) { | ||
this._read = (packet, index, nullBitmap) => (isNullBitmap(index, nullBitmap) ? null : packet.readInt8()); | ||
return (packet, index, nullBitmap, opts) => (isNullBitmap(index, nullBitmap) ? null : packet.readInt8()); | ||
} else { | ||
this._read = (packet, index, nullBitmap) => (isNullBitmap(index, nullBitmap) ? null : packet.readUInt8()); | ||
return (packet, index, nullBitmap, opts) => (isNullBitmap(index, nullBitmap) ? null : packet.readUInt8()); | ||
} | ||
break; | ||
@@ -65,11 +66,10 @@ case FieldType.YEAR: | ||
if (this.signed()) { | ||
this._read = (packet, index, nullBitmap) => (isNullBitmap(index, nullBitmap) ? null : packet.readInt16()); | ||
return (packet, index, nullBitmap, opts) => (isNullBitmap(index, nullBitmap) ? null : packet.readInt16()); | ||
} else { | ||
this._read = (packet, index, nullBitmap) => (isNullBitmap(index, nullBitmap) ? null : packet.readUInt16()); | ||
return (packet, index, nullBitmap, opts) => (isNullBitmap(index, nullBitmap) ? null : packet.readUInt16()); | ||
} | ||
break; | ||
case FieldType.INT24: | ||
if (this.signed()) { | ||
this._read = (packet, index, nullBitmap) => { | ||
return (packet, index, nullBitmap, opts) => { | ||
if (isNullBitmap(index, nullBitmap)) { | ||
@@ -83,3 +83,3 @@ return null; | ||
} else { | ||
this._read = (packet, index, nullBitmap) => { | ||
return (packet, index, nullBitmap, opts) => { | ||
if (isNullBitmap(index, nullBitmap)) { | ||
@@ -93,22 +93,18 @@ return null; | ||
} | ||
break; | ||
case FieldType.INT: | ||
if (this.signed()) { | ||
this._read = (packet, index, nullBitmap) => (isNullBitmap(index, nullBitmap) ? null : packet.readInt32()); | ||
return (packet, index, nullBitmap, opts) => (isNullBitmap(index, nullBitmap) ? null : packet.readInt32()); | ||
} else { | ||
this._read = (packet, index, nullBitmap) => (isNullBitmap(index, nullBitmap) ? null : packet.readUInt32()); | ||
return (packet, index, nullBitmap, opts) => (isNullBitmap(index, nullBitmap) ? null : packet.readUInt32()); | ||
} | ||
break; | ||
case FieldType.FLOAT: | ||
this._read = (packet, index, nullBitmap) => (isNullBitmap(index, nullBitmap) ? null : packet.readFloat()); | ||
break; | ||
return (packet, index, nullBitmap, opts) => (isNullBitmap(index, nullBitmap) ? null : packet.readFloat()); | ||
case FieldType.DOUBLE: | ||
this._read = (packet, index, nullBitmap) => (isNullBitmap(index, nullBitmap) ? null : packet.readDouble()); | ||
break; | ||
return (packet, index, nullBitmap, opts) => (isNullBitmap(index, nullBitmap) ? null : packet.readDouble()); | ||
case FieldType.BIGINT: | ||
this._read = (packet, index, nullBitmap, opts) => { | ||
return (packet, index, nullBitmap, opts) => { | ||
if (isNullBitmap(index, nullBitmap)) return null; | ||
@@ -124,7 +120,19 @@ const val = this.signed() ? packet.readBigInt64() : packet.readBigUInt64(); | ||
}; | ||
break; | ||
case FieldType.DATE: | ||
return (packet, index, nullBitmap, opts) => | ||
isNullBitmap(index, nullBitmap) ? null : packet.readBinaryDate(opts); | ||
case FieldType.DATETIME: | ||
case FieldType.TIMESTAMP: | ||
return (packet, index, nullBitmap, opts) => | ||
isNullBitmap(index, nullBitmap) ? null : packet.readBinaryDateTime(opts, this); | ||
case FieldType.TIME: | ||
return (packet, index, nullBitmap, opts) => | ||
isNullBitmap(index, nullBitmap) ? null : packet.readBinaryTime(); | ||
case FieldType.DECIMAL: | ||
case FieldType.NEWDECIMAL: | ||
this._read = (packet, index, nullBitmap, opts) => { | ||
return (packet, index, nullBitmap, opts) => { | ||
if (isNullBitmap(index, nullBitmap)) return null; | ||
@@ -140,77 +148,45 @@ const valDec = packet.readDecimalLengthEncoded(); | ||
}; | ||
break; | ||
case FieldType.DATE: | ||
this._read = (packet, index, nullBitmap, opts) => | ||
isNullBitmap(index, nullBitmap) ? null : packet.readBinaryDate(opts); | ||
break; | ||
case FieldType.DATETIME: | ||
case FieldType.TIMESTAMP: | ||
this._read = (packet, index, nullBitmap, opts) => | ||
isNullBitmap(index, nullBitmap) ? null : packet.readBinaryDateTime(opts, this); | ||
break; | ||
case FieldType.TIME: | ||
this._read = (packet, index, nullBitmap) => | ||
isNullBitmap(index, nullBitmap) ? null : packet.readBinaryTime(); | ||
break; | ||
case FieldType.GEOMETRY: | ||
this._read = (packet, index, nullBitmap) => { | ||
let defaultVal = this.__getDefaultGeomVal(); | ||
return (packet, index, nullBitmap, opts) => { | ||
if (isNullBitmap(index, nullBitmap)) { | ||
if (this.dataTypeName) { | ||
switch (this.dataTypeName) { | ||
case 'point': | ||
return { type: 'Point' }; | ||
case 'linestring': | ||
return { type: 'LineString' }; | ||
case 'polygon': | ||
return { type: 'Polygon' }; | ||
case 'multipoint': | ||
return { type: 'MultiPoint' }; | ||
case 'multilinestring': | ||
return { type: 'MultiLineString' }; | ||
case 'multipolygon': | ||
return { type: 'MultiPolygon' }; | ||
default: | ||
return { type: this.dataTypeName }; | ||
} | ||
} | ||
return null; | ||
return defaultVal; | ||
} | ||
return packet.readGeometry(this.dataTypeName); | ||
return packet.readGeometry(defaultVal); | ||
}; | ||
break; | ||
case FieldType.JSON: | ||
//for mysql only => parse string as JSON object | ||
this._read = (packet, index, nullBitmap) => | ||
isNullBitmap(index, nullBitmap) ? null : JSON.parse(packet.readStringLength()); | ||
break; | ||
return (packet, index, nullBitmap, opts) => | ||
isNullBitmap(index, nullBitmap) ? null : JSON.parse(packet.readStringLengthEncoded()); | ||
case FieldType.BIT: | ||
if (this.columnLength === 1 && opts.bitOneIsBoolean) { | ||
return (packet, index, nullBitmap, opts) => | ||
isNullBitmap(index, nullBitmap) ? null : packet.readBufferLengthEncoded()[0] === 1; | ||
} | ||
return (packet, index, nullBitmap, opts) => | ||
isNullBitmap(index, nullBitmap) ? null : packet.readBufferLengthEncoded(); | ||
default: | ||
if (this.dataTypeFormat && this.dataTypeFormat === 'json' && opts.autoJsonMap) { | ||
this._read = (packet, index, nullBitmap) => | ||
isNullBitmap(index, nullBitmap) ? null : JSON.parse(packet.readStringLength()); | ||
break; | ||
return (packet, index, nullBitmap, opts) => | ||
isNullBitmap(index, nullBitmap) ? null : JSON.parse(packet.readStringLengthEncoded()); | ||
} | ||
if (this.collation.index === 63) { | ||
this._read = (packet, index, nullBitmap) => | ||
return (packet, index, nullBitmap, opts) => | ||
isNullBitmap(index, nullBitmap) ? null : packet.readBufferLengthEncoded(); | ||
break; | ||
} | ||
if (this.isSet()) { | ||
this._read = (packet, index, nullBitmap) => { | ||
return (packet, index, nullBitmap, opts) => { | ||
if (isNullBitmap(index, nullBitmap)) return null; | ||
const string = packet.readStringLength(); | ||
const string = packet.readStringLengthEncoded(); | ||
return string == null ? null : string === '' ? [] : string.split(','); | ||
}; | ||
break; | ||
} | ||
this._read = (packet, index, nullBitmap) => | ||
isNullBitmap(index, nullBitmap) ? null : packet.readStringLength(); | ||
break; | ||
return (packet, index, nullBitmap, opts) => | ||
isNullBitmap(index, nullBitmap) ? null : packet.readStringLengthEncoded(); | ||
} | ||
@@ -224,12 +200,10 @@ } else { | ||
case FieldType.YEAR: | ||
this._read = (packet) => packet.readIntLengthEncoded(); | ||
break; | ||
return (packet, index, nullBitmap, opts) => packet.readIntLengthEncoded(); | ||
case FieldType.FLOAT: | ||
case FieldType.DOUBLE: | ||
this._read = (packet) => packet.readFloatLengthCoded(); | ||
break; | ||
return (packet, index, nullBitmap, opts) => packet.readFloatLengthCoded(); | ||
case FieldType.BIGINT: | ||
this._read = (packet, index, nullBitmap, opts) => { | ||
return (packet, index, nullBitmap, opts) => { | ||
const val = packet.readBigIntLengthEncoded(); | ||
@@ -244,7 +218,6 @@ if (val != null && (opts.bigIntAsNumber || opts.supportBigNumbers)) { | ||
}; | ||
break; | ||
case FieldType.DECIMAL: | ||
case FieldType.NEWDECIMAL: | ||
this._read = (packet, index, nullBitmap, opts) => { | ||
return (packet, index, nullBitmap, opts) => { | ||
const valDec = packet.readDecimalLengthEncoded(); | ||
@@ -259,6 +232,5 @@ if (valDec != null && (opts.decimalAsNumber || opts.supportBigNumbers)) { | ||
}; | ||
break; | ||
case FieldType.DATE: | ||
this._read = (packet, index, nullBitmap, opts) => { | ||
return (packet, index, nullBitmap, opts) => { | ||
if (opts.dateStrings) { | ||
@@ -269,7 +241,6 @@ return packet.readAsciiStringLengthEncoded(); | ||
}; | ||
break; | ||
case FieldType.DATETIME: | ||
case FieldType.TIMESTAMP: | ||
this._read = (packet, index, nullBitmap, opts) => { | ||
return (packet, index, nullBitmap, opts) => { | ||
if (opts.dateStrings) { | ||
@@ -280,36 +251,39 @@ return packet.readAsciiStringLengthEncoded(); | ||
}; | ||
break; | ||
case FieldType.TIME: | ||
this._read = (packet) => packet.readAsciiStringLengthEncoded(); | ||
break; | ||
return (packet, index, nullBitmap, opts) => packet.readAsciiStringLengthEncoded(); | ||
case FieldType.GEOMETRY: | ||
this._read = (packet) => packet.readGeometry(this.dataTypeName); | ||
break; | ||
let defaultVal = this.__getDefaultGeomVal(); | ||
return (packet, index, nullBitmap, opts) => packet.readGeometry(defaultVal); | ||
case FieldType.JSON: | ||
//for mysql only => parse string as JSON object | ||
this._read = (packet) => JSON.parse(packet.readStringLength()); | ||
break; | ||
return (packet, index, nullBitmap, opts) => JSON.parse(packet.readStringLengthEncoded()); | ||
case FieldType.BIT: | ||
if (this.columnLength === 1 && opts.bitOneIsBoolean) { | ||
return (packet, index, nullBitmap, opts) => { | ||
const val = packet.readBufferLengthEncoded(); | ||
return val == null ? null : val[0] === 1; | ||
}; | ||
} | ||
return (packet, index, nullBitmap, opts) => packet.readBufferLengthEncoded(); | ||
default: | ||
if (this.dataTypeFormat && this.dataTypeFormat === 'json' && opts.autoJsonMap) { | ||
this._read = (packet) => JSON.parse(packet.readStringLength()); | ||
break; | ||
return (packet, index, nullBitmap, opts) => JSON.parse(packet.readStringLengthEncoded()); | ||
} | ||
if (this.collation.index === 63) { | ||
this._read = (packet) => packet.readBufferLengthEncoded(); | ||
break; | ||
return (packet, index, nullBitmap, opts) => packet.readBufferLengthEncoded(); | ||
} | ||
if (this.isSet()) { | ||
this._read = (packet) => { | ||
const string = packet.readStringLength(); | ||
return (packet, index, nullBitmap, opts) => { | ||
const string = packet.readStringLengthEncoded(); | ||
return string == null ? null : string === '' ? [] : string.split(','); | ||
}; | ||
break; | ||
} | ||
this._read = (packet) => packet.readStringLength(); | ||
return (packet, index, nullBitmap, opts) => packet.readStringLengthEncoded(); | ||
} | ||
@@ -319,24 +293,45 @@ } | ||
__getDefaultGeomVal() { | ||
if (this.dataTypeName) { | ||
switch (this.dataTypeName) { | ||
case 'point': | ||
return { type: 'Point' }; | ||
case 'linestring': | ||
return { type: 'LineString' }; | ||
case 'polygon': | ||
return { type: 'Polygon' }; | ||
case 'multipoint': | ||
return { type: 'MultiPoint' }; | ||
case 'multilinestring': | ||
return { type: 'MultiLineString' }; | ||
case 'multipolygon': | ||
return { type: 'MultiPolygon' }; | ||
default: | ||
return { type: this.dataTypeName }; | ||
} | ||
} | ||
return null; | ||
} | ||
db() { | ||
return this._parse.packet.readString(this._parse.dbOffset, this._parse.dbLength); | ||
return this._stringParser.packet.readString(this._stringParser.dbOffset, this._stringParser.dbLength); | ||
} | ||
schema() { | ||
return this._parse.packet.readString(this._parse.dbOffset, this._parse.dbLength); | ||
return this._stringParser.packet.readString(this._stringParser.dbOffset, this._stringParser.dbLength); | ||
} | ||
table() { | ||
return this._parse.packet.readString(this._parse.tableOffset, this._parse.tableLength); | ||
return this._stringParser.packet.readString(this._stringParser.tableOffset, this._stringParser.tableLength); | ||
} | ||
orgTable() { | ||
return this._parse.packet.readString(this._parse.orgTableOffset, this._parse.orgTableLength); | ||
return this._stringParser.packet.readString(this._stringParser.orgTableOffset, this._stringParser.orgTableLength); | ||
} | ||
name() { | ||
return this._parse.packet.readString(this._parse.nameOffset, this._parse.nameLength); | ||
return this._stringParser.packet.readString(this._stringParser.nameOffset, this._stringParser.nameLength); | ||
} | ||
orgName() { | ||
return this._parse.packet.readString(this._parse.orgNameOffset, this._parse.orgNameLength); | ||
return this._stringParser.packet.readString(this._stringParser.orgNameOffset, this._stringParser.orgNameLength); | ||
} | ||
@@ -343,0 +338,0 @@ |
@@ -109,3 +109,3 @@ 'use strict'; | ||
static parseOkPacket(packet, out, opts, info) { | ||
parseOkPacket(packet, out, opts, info) { | ||
packet.skip(1); //skip header | ||
@@ -133,4 +133,4 @@ | ||
const subSubPacket = subPacket.subPacketLengthEncoded(); | ||
const variable = subSubPacket.readStringLength(); | ||
const value = subSubPacket.readStringLength(); | ||
const variable = subSubPacket.readStringLengthEncoded(); | ||
const value = subSubPacket.readStringLengthEncoded(); | ||
@@ -154,3 +154,3 @@ switch (variable) { | ||
const subSubPacket2 = subPacket.subPacketLengthEncoded(); | ||
info.database = subSubPacket2.readStringLength(); | ||
info.database = subSubPacket2.readStringLengthEncoded(); | ||
break; | ||
@@ -157,0 +157,0 @@ } |
@@ -10,3 +10,3 @@ 'use strict'; | ||
static castWrapper(column, packet, index, nullBitmap, opts) { | ||
column.string = () => (isNullBitmap(index, nullBitmap) ? null : packet.readStringLength()); | ||
column.string = () => (isNullBitmap(index, nullBitmap) ? null : packet.readStringLengthEncoded()); | ||
column.buffer = () => (isNullBitmap(index, nullBitmap) ? null : packet.readBufferLengthEncoded()); | ||
@@ -25,24 +25,33 @@ column.float = () => (isNullBitmap(index, nullBitmap) ? null : packet.readFloat()); | ||
column.geometry = () => { | ||
if (isNullBitmap(index, nullBitmap)) { | ||
if (column.dataTypeName) { | ||
switch (column.dataTypeName) { | ||
case 'point': | ||
return { type: 'Point' }; | ||
case 'linestring': | ||
return { type: 'LineString' }; | ||
case 'polygon': | ||
return { type: 'Polygon' }; | ||
case 'multipoint': | ||
return { type: 'MultiPoint' }; | ||
case 'multilinestring': | ||
return { type: 'MultiLineString' }; | ||
case 'multipolygon': | ||
return { type: 'MultiPolygon' }; | ||
default: | ||
return { type: column.dataTypeName }; | ||
} | ||
let defaultVal = null; | ||
if (column.dataTypeName) { | ||
switch (column.dataTypeName) { | ||
case 'point': | ||
defaultVal = { type: 'Point' }; | ||
break; | ||
case 'linestring': | ||
defaultVal = { type: 'LineString' }; | ||
break; | ||
case 'polygon': | ||
defaultVal = { type: 'Polygon' }; | ||
break; | ||
case 'multipoint': | ||
defaultVal = { type: 'MultiPoint' }; | ||
break; | ||
case 'multilinestring': | ||
defaultVal = { type: 'MultiLineString' }; | ||
break; | ||
case 'multipolygon': | ||
defaultVal = { type: 'MultiPolygon' }; | ||
break; | ||
default: | ||
defaultVal = { type: column.dataTypeName }; | ||
break; | ||
} | ||
return null; | ||
} | ||
return column.readGeometry(); | ||
if (isNullBitmap(index, nullBitmap)) { | ||
return defaultVal; | ||
} | ||
return column.readGeometry(defaultVal); | ||
}; | ||
@@ -49,0 +58,0 @@ } |
@@ -5,3 +5,3 @@ 'use strict'; | ||
static castWrapper(column, packet, index, nullBitmap, opts) { | ||
column.string = () => packet.readStringLength(); | ||
column.string = () => packet.readStringLengthEncoded(); | ||
column.buffer = () => packet.readBufferLengthEncoded(); | ||
@@ -16,3 +16,36 @@ column.float = () => packet.readFloatLengthCoded(); | ||
column.datetime = () => packet.readDateTime(opts); | ||
column.geometry = () => column.readGeometry(); | ||
column.geometry = () => { | ||
let defaultVal = null; | ||
if (column.dataTypeName) { | ||
switch (column.dataTypeName) { | ||
case 'point': | ||
defaultVal = { type: 'Point' }; | ||
break; | ||
case 'linestring': | ||
defaultVal = { type: 'LineString' }; | ||
break; | ||
case 'polygon': | ||
defaultVal = { type: 'Polygon' }; | ||
break; | ||
case 'multipoint': | ||
defaultVal = { type: 'MultiPoint' }; | ||
break; | ||
case 'multilinestring': | ||
defaultVal = { type: 'MultiLineString' }; | ||
break; | ||
case 'multipolygon': | ||
defaultVal = { type: 'MultiPolygon' }; | ||
break; | ||
default: | ||
defaultVal = { type: column.dataTypeName }; | ||
break; | ||
} | ||
} | ||
if (isNullBitmap(index, nullBitmap)) { | ||
return defaultVal; | ||
} | ||
return column.readGeometry(defaultVal); | ||
}; | ||
} | ||
@@ -19,0 +52,0 @@ } |
@@ -58,3 +58,5 @@ 'use strict'; | ||
if (opts.logger.query) | ||
opts.logger.query(`EXECUTE: (${this.prepare.id}) ${opts.logger.logParam ? this.displaySql() : this.sql}`); | ||
opts.logger.query( | ||
`EXECUTE: (${this.prepare.id}) sql: ${opts.logger.logParam ? this.displaySql() : this.sql}` | ||
); | ||
if (!this.longDataStep) { | ||
@@ -73,3 +75,3 @@ this.longDataStep = true; | ||
if (opts.logger.query) | ||
opts.logger.query(`EXECUTE: (${this.prepare.id}) ${opts.logger.logParam ? this.displaySql() : this.sql}`); | ||
opts.logger.query(`EXECUTE: (${this.prepare.id}) sql: ${opts.logger.logParam ? this.displaySql() : this.sql}`); | ||
this.sendComStmtExecute(out, info); | ||
@@ -90,3 +92,3 @@ } | ||
this.throwNewError( | ||
`Parameter at position ${this.values.length} is not set\\n${this.displaySql()}`, | ||
`Parameter at position ${this.values.length} is not set\\nsql: ${this.displaySql()}`, | ||
false, | ||
@@ -109,3 +111,3 @@ info, | ||
this.throwNewError(errMsg + '\n' + this.displaySql(), false, info, 'HY000', Errors.ER_PARAMETER_UNDEFINED); | ||
this.throwNewError(errMsg + '\nsql: ' + this.displaySql(), false, info, 'HY000', Errors.ER_PARAMETER_UNDEFINED); | ||
return false; | ||
@@ -112,0 +114,0 @@ } |
@@ -82,5 +82,2 @@ 'use strict'; | ||
this._columnCount = packet.readUnsignedLength(); | ||
this._getValue = this.opts.typeCast | ||
? this.readCastValue | ||
: (column, packet, index, nullBitmap, opts) => column._read(packet, index, nullBitmap, opts); | ||
@@ -112,3 +109,3 @@ this._rows.push([]); | ||
readOKPacket(packet, out, opts, info) { | ||
const okPacket = Command.parseOkPacket(packet, out, this.opts, info); | ||
const okPacket = this.parseOkPacket(packet, out, this.opts, info); | ||
this._rows.push(okPacket); | ||
@@ -172,3 +169,3 @@ | ||
this.columnNo--; | ||
this._columnsPrepare.push(new ColumnDefinition(packet.clone(), info, this.opts, this.binary)); | ||
this._columnsPrepare.push(new ColumnDefinition(packet.clone(), info)); | ||
if (this.columnNo === 0) { | ||
@@ -189,3 +186,3 @@ if (info.eofDeprecated) { | ||
this.parameterNo--; | ||
this._parameterPrepare.push(new ColumnDefinition(packet.clone(), info, this.opts, this.binary)); | ||
this._parameterPrepare.push(new ColumnDefinition(packet.clone(), info)); | ||
if (this.parameterNo === 0) { | ||
@@ -217,5 +214,3 @@ if (info.eofDeprecated) { | ||
readColumn(packet, out, opts, info) { | ||
if (this._columns.length !== this._columnCount) { | ||
this._columns.push(new ColumnDefinition(packet.clone(), info, this.opts, this.binary)); | ||
} | ||
this._columns.push(new ColumnDefinition(packet.clone(), info)); | ||
@@ -237,2 +232,13 @@ // last column | ||
setParser() { | ||
this._parseFonction = new Array(this._columnCount); | ||
if (this.opts.typeCast) { | ||
for (let i = 0; i < this._columnCount; i++) { | ||
this._parseFonction[i] = this.readCastValue.bind(this, this._columns[i]); | ||
} | ||
} else { | ||
for (let i = 0; i < this._columnCount; i++) { | ||
this._parseFonction[i] = this._columns[i].__parser(this.binary, this.opts); | ||
} | ||
} | ||
if (this.opts.rowsAsArray) { | ||
@@ -242,4 +248,4 @@ this.parseRow = this.parseRowAsArray; | ||
this.tableHeader = new Array(this._columnCount); | ||
this.parseRow = this.binary ? this.parseRowStdBinary : this.parseRowStdText; | ||
if (this.opts.nestTables) { | ||
this.parseRow = this.parseRowStd; | ||
if (typeof this.opts.nestTables === 'string') { | ||
@@ -258,3 +264,2 @@ for (let i = 0; i < this._columnCount; i++) { | ||
} else { | ||
this.parseRow = this.parseRowStd; | ||
for (let i = 0; i < this._columnCount; i++) { | ||
@@ -468,3 +473,3 @@ this.tableHeader[i] = this._columns[i].name(); | ||
for (let i = 0; i < this._columnCount; i++) { | ||
row[i] = this._getValue(columns[i], packet, i, nullBitMap, this.opts); | ||
row[i] = this._parseFonction[i].call(null, packet, i, nullBitMap, this.opts); | ||
} | ||
@@ -479,4 +484,4 @@ return row; | ||
if (!row[this.tableHeader[i][0]]) row[this.tableHeader[i][0]] = {}; | ||
row[this.tableHeader[i][0]][this.tableHeader[i][1]] = this._getValue( | ||
columns[i], | ||
row[this.tableHeader[i][0]][this.tableHeader[i][1]] = this._parseFonction[i].call( | ||
null, | ||
packet, | ||
@@ -491,7 +496,6 @@ i, | ||
parseRowStd(columns, packet) { | ||
parseRowStdText(columns, packet) { | ||
const row = {}; | ||
const nullBitMap = this.binary ? BinaryDecoder.newRow(packet, columns) : null; | ||
for (let i = 0; i < this._columnCount; i++) { | ||
row[this.tableHeader[i]] = this._getValue(columns[i], packet, i, nullBitMap, this.opts); | ||
row[this.tableHeader[i]] = this._parseFonction[i].call(null, packet, i, null, this.opts); | ||
} | ||
@@ -501,2 +505,11 @@ return row; | ||
parseRowStdBinary(columns, packet) { | ||
const row = {}; | ||
const nullBitMap = BinaryDecoder.newRow(packet, columns); | ||
for (let i = 0; i < this._columnCount; i++) { | ||
row[this.tableHeader[i]] = this._parseFonction[i].call(null, packet, i, nullBitMap, this.opts); | ||
} | ||
return row; | ||
} | ||
readCastValue(column, packet, index, nullBitmap, opts) { | ||
@@ -508,3 +521,3 @@ if (this.binary) { | ||
} | ||
return opts.typeCast(column, column._read.bind(column, packet, index, nullBitmap, opts)); | ||
return opts.typeCast(column, column.__parser(this.binary, opts).bind(column, packet, index, nullBitmap, opts)); | ||
} | ||
@@ -528,3 +541,3 @@ | ||
info, | ||
'45034', | ||
'HY000', | ||
this.sql | ||
@@ -531,0 +544,0 @@ ); |
@@ -95,6 +95,6 @@ 'use strict'; | ||
if (this.sql.length > this.opts.debugLen) { | ||
return 'sql: ' + this.sql.substring(0, this.opts.debugLen) + '...'; | ||
return this.sql.substring(0, this.opts.debugLen) + '...'; | ||
} | ||
} | ||
return 'sql: ' + this.sql; | ||
return this.sql; | ||
} | ||
@@ -101,0 +101,0 @@ } |
@@ -56,3 +56,3 @@ 'use strict'; | ||
this.initSql = opts.initSql; | ||
this.connectTimeout = opts.connectTimeout === undefined ? 10000 : opts.connectTimeout; | ||
this.connectTimeout = opts.connectTimeout === undefined ? 1000 : opts.connectTimeout; | ||
this.connectAttributes = opts.connectAttributes || false; | ||
@@ -122,2 +122,3 @@ this.compress = opts.compress || false; | ||
this.autoJsonMap = opts.autoJsonMap === undefined ? true : opts.autoJsonMap; | ||
this.bitOneIsBoolean = opts.bitOneIsBoolean === undefined ? true : opts.bitOneIsBoolean; | ||
this.arrayParenthesis = opts.arrayParenthesis || false; | ||
@@ -242,2 +243,3 @@ this.permitSetMultiParamEntries = opts.permitSetMultiParamEntries || false; | ||
if (opts.ssl && (opts.ssl == 'true' || opts.ssl == 'false')) opts.ssl = opts.ssl == 'true'; | ||
if (opts.bitOneIsBoolean) opts.bitOneIsBoolean = opts.bitOneIsBoolean == 'true'; | ||
return opts; | ||
@@ -244,0 +246,0 @@ } |
@@ -17,3 +17,3 @@ 'use strict'; | ||
readStringLength() { | ||
readStringLengthEncoded() { | ||
const len = this.readUnsignedLength(); | ||
@@ -20,0 +20,0 @@ if (len === null) return null; |
@@ -16,3 +16,3 @@ 'use strict'; | ||
readStringLength() { | ||
readStringLengthEncoded() { | ||
const len = this.readUnsignedLength(); | ||
@@ -19,0 +19,0 @@ if (len === null) return null; |
@@ -25,24 +25,6 @@ 'use strict'; | ||
readGeometry(dataTypeName) { | ||
readGeometry(defaultVal) { | ||
const geoBuf = this.readBufferLengthEncoded(); | ||
if (geoBuf === null || geoBuf.length === 0) { | ||
if (dataTypeName) { | ||
switch (dataTypeName) { | ||
case 'point': | ||
return { type: 'Point' }; | ||
case 'linestring': | ||
return { type: 'LineString' }; | ||
case 'polygon': | ||
return { type: 'Polygon' }; | ||
case 'multipoint': | ||
return { type: 'MultiPoint' }; | ||
case 'multilinestring': | ||
return { type: 'MultiLineString' }; | ||
case 'multipolygon': | ||
return { type: 'MultiPolygon' }; | ||
default: | ||
return { type: dataTypeName }; | ||
} | ||
} | ||
return null; | ||
return defaultVal; | ||
} | ||
@@ -276,2 +258,6 @@ let geoPos = 4; | ||
readStringLengthEncoded() { | ||
throw new Error('code is normally superseded by Node encoder or Iconv depending on charset used'); | ||
} | ||
readBigIntLengthEncoded() { | ||
@@ -278,0 +264,0 @@ const len = this.readUnsignedLength(); |
@@ -363,5 +363,9 @@ const Errors = require('../misc/errors'); | ||
module.exports.validateFileName = function (sql, parameters, fileName) { | ||
// in case of windows, file name in query are escaped | ||
// so for example LOAD DATA LOCAL INFILE 'C:\\Temp\\myFile.txt' ... | ||
// but server return 'C:\Temp\myFile.txt' | ||
// so with regex escaped, must test LOAD DATA LOCAL INFILE 'C:\\\\Temp\\\\myFile.txt' | ||
let queryValidator = new RegExp( | ||
"^(\\s*\\/\\*([^\\*]|\\*[^\\/])*\\*\\/)*\\s*LOAD\\s+DATA\\s+((LOW_PRIORITY|CONCURRENT)\\s+)?LOCAL\\s+INFILE\\s+'" + | ||
fileName + | ||
fileName.replace(/\\/g, '\\\\\\\\').replace('.', '\\.') + | ||
"'", | ||
@@ -378,3 +382,6 @@ 'i' | ||
if (queryValidator.test(sql) && parameters.length > 0) { | ||
return parameters[0].toLowerCase() === fileName.toLowerCase(); | ||
if (Array.isArray(parameters)) { | ||
return parameters[0].toLowerCase() === fileName.toLowerCase(); | ||
} | ||
return parameters.toLowerCase() === fileName.toLowerCase(); | ||
} | ||
@@ -381,0 +388,0 @@ } |
@@ -296,4 +296,4 @@ 'use strict'; | ||
*/ | ||
async _doAcquire() { | ||
if (!this._hasIdleConnection() || this.#closed) throw null; | ||
_doAcquire() { | ||
if (!this._hasIdleConnection() || this.#closed) return Promise.reject(); | ||
@@ -304,9 +304,13 @@ const conn = this.#idleConnections.shift(); | ||
if (this.#opts.minDelayValidation <= 0 || Date.now() - conn.lastUse > this.#opts.minDelayValidation) { | ||
try { | ||
await new Promise(conn.ping.bind(conn, this.#opts.pingTimeout)); | ||
if (this.#opts.leakDetectionTimeout > 0) this._checkLeak(conn); | ||
return conn; | ||
} catch (err) { | ||
//eat | ||
} | ||
return new Promise(conn.ping.bind(conn, this.#opts.pingTimeout)).then( | ||
() => { | ||
if (this.#opts.leakDetectionTimeout > 0) this._checkLeak(conn); | ||
return Promise.resolve(conn); | ||
}, | ||
() => { | ||
delete this.#activeConnections[conn.threadId]; | ||
this.emit('validateSize'); | ||
return this._doAcquire(); | ||
} | ||
); | ||
} else { | ||
@@ -316,8 +320,5 @@ //just check connection state | ||
if (this.#opts.leakDetectionTimeout > 0) this._checkLeak(conn); | ||
return conn; | ||
return Promise.resolve(conn); | ||
} | ||
} | ||
delete this.#activeConnections[conn.threadId]; | ||
this.emit('validateSize'); | ||
return this._doAcquire(); | ||
} | ||
@@ -324,0 +325,0 @@ |
{ | ||
"name": "mariadb", | ||
"version": "3.0.0-rc.0", | ||
"version": "3.0.0", | ||
"description": "fast mariadb/mysql connector.", | ||
@@ -49,28 +49,28 @@ "main": "promise.js", | ||
"@alloc/quick-lru": "^5.2.0", | ||
"@types/geojson": "^7946.0.7", | ||
"@types/node": "^14.14.28", | ||
"denque": "^1.5.0", | ||
"@types/geojson": "^7946.0.8", | ||
"@types/node": "^17.0.10", | ||
"denque": "^2.0.1", | ||
"iconv-lite": "^0.6.3", | ||
"moment-timezone": "^0.5.33", | ||
"moment-timezone": "^0.5.34", | ||
"please-upgrade-node": "^3.2.0" | ||
}, | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^5.0.0", | ||
"@typescript-eslint/parser": "^5.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.10.0", | ||
"@typescript-eslint/parser": "^5.10.0", | ||
"benchmark": "^2.1.4", | ||
"chai": "^4.3.4", | ||
"codecov": "^3.8.2", | ||
"colors": "^1.4.0", | ||
"chalk": "^4.1.2", | ||
"dom-parser": "^0.1.6", | ||
"error-stack-parser": "^2.0.6", | ||
"eslint": "^8.0.0", | ||
"eslint": "^8.7.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-markdown": "^2.2.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"mocha": "^8.4.0", | ||
"eslint-plugin-markdown": "^2.2.1", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"mocha": "^9.2.0", | ||
"mocha-lcov-reporter": "^1.3.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.3.2", | ||
"typescript": "^4.1.5", | ||
"winston": "^3.3.3" | ||
"prettier": "^2.5.1", | ||
"typescript": "^4.5.5", | ||
"winston": "^3.4.0" | ||
}, | ||
@@ -77,0 +77,0 @@ "bugs": { |
@@ -102,33 +102,7 @@ <p align="center"> | ||
``` | ||
Using ECMAScript < 2017: | ||
example: | ||
```js | ||
const mariadb = require('mariadb'); | ||
const pool = mariadb.createPool({host: process.env.DB_HOST, user: process.env.DB_USER, connectionLimit: 5}); | ||
pool.getConnection() | ||
.then(conn => { | ||
conn.query("SELECT 1 as val") | ||
.then(rows => { // rows: [ {val: 1}, meta: ... ] | ||
return conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]); | ||
}) | ||
.then(res => { // res: { affectedRows: 1, insertId: 1, warningStatus: 0 } | ||
conn.release(); // release to pool | ||
}) | ||
.catch(err => { | ||
conn.release(); // release to pool | ||
}) | ||
}).catch(err => { | ||
//not connected | ||
}); | ||
``` | ||
Using ECMAScript 2017: | ||
```js | ||
const mariadb = require('mariadb'); | ||
const pool = mariadb.createPool({host: process.env.DB_HOST, user: process.env.DB_USER, connectionLimit: 5}); | ||
async function asyncFunction() { | ||
@@ -145,4 +119,2 @@ let conn; | ||
} catch (err) { | ||
throw err; | ||
} finally { | ||
@@ -149,0 +121,0 @@ if (conn) conn.release(); //release to pool |
@@ -746,2 +746,4 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
getConnection(pattern?: string, selector?: string): Promise<PoolConnection>; | ||
on(ev: 'remove', callback: (nodekey: string) => void): PoolCluster; | ||
} | ||
@@ -748,0 +750,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
13554
0
506952
69
138
+ Added@types/node@17.0.45(transitive)
+ Addeddenque@2.1.0(transitive)
- Removed@types/node@14.18.63(transitive)
- Removeddenque@1.5.1(transitive)
Updated@types/geojson@^7946.0.8
Updated@types/node@^17.0.10
Updateddenque@^2.0.1
Updatedmoment-timezone@^0.5.34