Hi! Met some strange behavior when using Sequel with mysql2 driver for 
MariaDB server.

My server says:

mysql> select version()\G
*************************** 1. row ***************************
version(): 10.2.12-MariaDB-10.2.12+maria~jessie
1 row in set (0.00 sec)

I can use Sequel with Mysql2 driver for the most of trivial operations 
(connect, select, insert, transactions).
But some Sequel features guarded with predicates that check the server 
version. For example `#supports_cte?` returns true for `db.server_version 
>= 100200` only in case of mariadb.
Ok. It does matter. But when I use mysql driver on the client to connect to 
remote MariaDB server (version 10.2.12-MariaDB-10.2.12+maria~jessie) 
Sequel::Database#server_info returns 50505 instead of 100212
I have found the code and it looks a bit 
strange: 
https://github.com/jeremyevans/sequel/blob/40d00b287cd7a99bcf812bc414562b57cabf4436/lib/sequel/adapters/mysql2.rb#L81-L83

1) `synchronize(server){|conn| conn.server_info[:id]}` returns 50505, 
`super()` - 100212
2) `super` is incorrect call since 
Sequel::MySQL::DatabaseMethods#server_version doesn't accept arguments.

The script that demonstrates this issue:

```
require 'bundler/inline'

gemfile(false) do
  source 'https://rubygems.org'

  gem 'mysql2'
  gem 'sequel'
  gem 'rspec'
end

require 'rspec'
require 'rspec/autorun'
require 'sequel'

RSpec.describe Sequel::Mysql2::Database, '#server_version' do
  subject(:server_version) { database.server_version }

  let(:database) { Sequel.connect(uri) }

  context 'when comes from Sequel::Mysql2::Database' do
    let(:uri) { 'mysql2://[email protected]/sequel_test' }

    it { is_expected.to eq 50505 }
  end

  context 'when comes from Sequel::MySQL::DatabaseMethods' do
    before do
      require 'sequel/adapters/mysql2'

      Sequel::Mysql2::Database.define_method(:server_version) do
        super()
      end
    end

    let(:uri) { 'mysql2://[email protected]/sequel_test' }

    it { is_expected.to eq 100212 }
  end
end
```

Best regards!

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to