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

Problems on comparing binary types (bit from MySQL) #491

Closed
NathanPB opened this issue Feb 10, 2019 · 3 comments
Closed

Problems on comparing binary types (bit from MySQL) #491

NathanPB opened this issue Feb 10, 2019 · 3 comments
Assignees
Labels
Milestone

Comments

@NathanPB
Copy link

Hello everyone, I'm not sure if this is a bug or just me being dumb again.
Well, I have the following table:

create table Permissions (
  guild varchar(32),
  role varchar(32),
  permission varchar(128) not null,
  type bit(1) not null default 0,

  foreign key(guild) references Guilds(id)
);

... and I need to select the entries where type is 1.
I'm trying

transaction {
                    return@transaction Database.PERMISSIONS.run {
                        slice(permission)
                        .select {
                            ((guild eq this@PermGroup.guild?.id) and
                            (role eq this@PermGroup.role?.id)) and
                            (type eq byteArrayOf(1)).also { println(it) }
                        }.map { it[permission] }
                    }
                }

but I got no results, then I added the .also { println(it) } statement to see the query and I got the following:
permissions.guild IS NULL and permissions.role IS NULL and permissions.type = [B@2e877764.

I think the ByteArray just isn't being serialized, and I honestly don't know how to deal with it.

Kotlin 1.3.21
Exposed 0.12.1
MySQL Connector 5.1.6
MySQL 5.7.23

@Tapac
Copy link
Contributor

Tapac commented Feb 11, 2019

Could you specify how do you map type column in Exposed?

@NathanPB
Copy link
Author

NathanPB commented Feb 11, 2019

Could you specify how do you map type column in Exposed?

its binary(1).default(byteArrayOf(0))

@Tapac
Copy link
Contributor

Tapac commented Mar 9, 2019

@NathanPB, first of all in exposed binary column type will be represented as VARBINARY not BIT, so your case with BIT(1) is similar to boolean` column type.
But there is indeed a problem with representing and comparing byteArray values which will be fixed in the next release (0.13.1)

@Tapac Tapac closed this as completed Mar 9, 2019
@Tapac Tapac added the bug label Mar 9, 2019
@Tapac Tapac self-assigned this Mar 9, 2019
@Tapac Tapac added this to the 0.13.1 milestone Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants