Skip to content

Refactoring code of parsing geometry #302

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

Merged
merged 1 commit into from
Oct 14, 2012
Merged

Refactoring code of parsing geometry #302

merged 1 commit into from
Oct 14, 2012

Conversation

croquiscom
Copy link

(Continuation of #301 request)

I think about a way to parse a geometry value more naturally, but it does not seem so good and useful for other part.

// pseudo code

Parser.prototype.readUInt32 = function () {
  var value = this._byteOrder ? this._buffer.readUInt32LE(_offset) : this._buffer.readUInt32BE(_offset);
  _offset += 4;
  return value;
}

Parser.prototype.parseGeometry = function() {
  var length = this.parseLengthCodedNumber();
  var end = this._offset + length;
  var result = null;

  this._offset += 4; // skip four bytes
  this._byteOrder = this.readUInt8();
  var wkbType = this.readUInt32();
  var x = this.readUInt32();
  var y = this.readUInt32();
  result = {x:x, y:y};

  this._offset = end;
  return result;
}

It seems that parsing WKBGeometry type is different work from parsing MySQL packet.

So, I just move the code from RowDataPacket.js to Parser.js as only a function.

How about this patch?

felixge added a commit that referenced this pull request Oct 14, 2012
Refactoring code of parsing geometry
@felixge felixge merged commit 9752b7a into mysqljs:master Oct 14, 2012
@felixge
Copy link
Collaborator

felixge commented Oct 14, 2012

Yeah, this is better. I'll try to make this nicer once I refactor the parser to use buffy.

@felixge
Copy link
Collaborator

felixge commented Oct 14, 2012

Thanks!

dveeden pushed a commit to dveeden/mysql that referenced this pull request Jan 31, 2023
According to the database/sql/driver documentation, ErrBadConn should only
be used when the database was not affected. The driver restarts the same
query on a different connection, then.
The mysql driver did not follow this advice, so queries were repeated if
ErrBadConn is returned but a query succeeded.

This is fixed by changing most ErrBadConn errors to ErrInvalidConn.

The only valid returns of ErrBadConn are at the beginning of a database
interaction when no data was sent to the database yet.

Those valid cases are located the following funcs before attempting to write
to the network or if 0 bytes were written:

* Begin
* BeginTx
* Exec
* ExecContext
* Prepare
* PrepareContext
* Query
* QueryContext

Commit and Rollback could arguably also be on that list, but are left out as
some engines like MyISAM are not supporting transactions.

Tests in b/packets_test.go were changed because they simulate a read not
preceded by a write to the db. This cannot happen as the client has to send
the query first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants