Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not rollback transaction when encountering 'duplicate field name' error #113

Closed
koendeschacht opened this issue Jun 5, 2020 · 1 comment

Comments

@koendeschacht
Copy link
Contributor

koendeschacht commented Jun 5, 2020

Hi,

First of all thanks for all the hard work on this package!

When running an query that returns two columns with the same name, the software throws an error 'duplicate field name'. When I catch this error and try to rollback the transaction, the software throws another (uncaught) error, which crashes the program. Tested with version 2.4.0

Test case:

create table test1
(
    my_col int
);

create table test2
(
    my_col int
)
import mariadb from 'mariadb'

async function test () {
  loadEnvFiles('backend')
  let connection = await mariadb.createConnection(myConfiguration)
  await connection.beginTransaction()
  try {
    let results = await connection.query('SELECT * FROM test1 INNER JOIN test2 on test1.my_col=test2.my_col')
    console.log('Got results', results)
  } catch (error) {
    try {
       await connection.rollback()
    } catch (rollbackError) {
      console.log('Got rollbackError', rollbackError)
    }
    console.log('Got error', error)
  }
}

test()

This results in the output:

/home/koen/zelfstandige/give-a-day/site/backend/node_modules/mariadb/lib/cmd/common-text-cmd.js:256
      row[this.tableHeader[i]] = this._getValue(i, columns[i], this.opts, connOpts, packet);
                                                          ^

TypeError: Cannot read property '0' of null
    at Query.parseRowStd (/home/koen/zelfstandige/give-a-day/site/backend/node_modules/mariadb/lib/cmd/common-text-cmd.js:256:59)
    at Query.readResultSetRow (/home/koen/zelfstandige/give-a-day/site/backend/node_modules/mariadb/lib/cmd/resultset.js:435:22)
    at PacketInputStream.receivePacketBasic (/home/koen/zelfstandige/give-a-day/site/backend/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/koen/zelfstandige/give-a-day/site/backend/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:302:12)
    at readableAddChunk (_stream_readable.js:278:9)
    at Socket.Readable.push (_stream_readable.js:217:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)

I expect that the error is printed in the log statement console.log('Got error', error)

Thanks!

@rusher
Copy link
Collaborator

rusher commented Jun 8, 2020

Allright, this will be corrected by 7291295.

Thanks for clear test case 👌!

@rusher rusher closed this as completed Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants