So I debugged a bit more using a where EVENTS.IP_ADDRESS.eq("4.2.2.1") 
condition and identified an issue in my 
Binding's set(BindingSetStatementContext<String> ctx) method.

Here's how I originally defined that method:

  @Override
  public void set(BindingSetStatementContext<String> ctx) throws SQLException {
    ctx.statement().setString(ctx.index(), 
Objects.toString(ctx.convert(converter()).value(), null));
  }


I need to provide a String representation of the value to 
ctx.statement.setString(). The string value I ultimately want to provide is 
"4.2.2.1". However, 
using Objects.toString(ctx.convert(converter()).value(), null) produces a 
string like "[B@329910d0". This kind of string is what you get when calling 
toString() on a byte[].

I felt like I didn't need to involve the converter at all since the ctx 
already has the String value I want to pass to setString, so I just did 
this:

@Override
public void set(BindingSetStatementContext<String> ctx) throws SQLException {
  ctx.statement().setString(ctx.index(), ctx.value());
}


So now my where conditions are working with this Binding. Here's the 
updated state of it with more overridden methods simply throwing 
SQLFeatureNotSupportExceptions:

package com.example;


import java.sql.*;
import org.jooq.*;

public class Inet6AtonBinding implements Binding<byte[], String> {

  @Override
  public Converter<byte[], String> converter() {
    return new Converter<byte[], String>() {
      @Override
      public String from(byte[] bytes) {
        return new String(bytes);
      }

      @Override
      public byte[] to(String string) {
        return string.getBytes();
      }

      @Override
      public Class<byte[]> fromType() {
        return byte[].class;
      }

      @Override
      public Class<String> toType() {
        return String.class;
      }
    };
  }

  @Override
  public void sql(BindingSQLContext<String> ctx) throws SQLException {
    ctx.render().sql("INET6_ATON(?)");
  }

  @Override
  public void register(BindingRegisterContext<String> ctx) throws SQLException {
    throw new SQLFeatureNotSupportedException();
  }

  @Override
  public void set(BindingSetStatementContext<String> ctx) throws SQLException {
    ctx.statement().setString(ctx.index(), ctx.value());
  }

  @Override
  public void get(BindingGetResultSetContext<String> ctx) throws SQLException {
    throw new SQLFeatureNotSupportedException();
  }

  @Override
  public void get(BindingGetStatementContext<String> ctx) throws SQLException {
    throw new SQLFeatureNotSupportedException();
  }

  @Override
  public void set(BindingSetSQLOutputContext<String> ctx) throws SQLException {
    throw new SQLFeatureNotSupportedException();
  }

  @Override
  public void get(BindingGetSQLInputContext<String> ctx) throws SQLException {
    throw new SQLFeatureNotSupportedException();
  }
}


Interested to hear any feedback about my choice to throw exceptions for 
most of the overridden methods and my approach of not using the converter 
at all.

On Wednesday, June 26, 2019 at 12:09:37 AM UTC-7, Lukas Eder wrote:
>
>
>
> On Wed, Jun 26, 2019 at 3:31 AM John Bai <[email protected] <javascript:>> 
> wrote:
>
>>
>> When I pretty print the SQL from a select with a 
>> .where(EVENTS.IP_ADDRESS.eq("4.2.2.1")) following these instructions, I see 
>> this:
>>
>> where (
>>   `events`.`ip_address` = INET6_ATON(?)
>> )
>>
>> What do I need to change in order to get this working? Thanks!
>>
>
>
> That looks like what I understood you wanted. What's not working about 
> this? 
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/1aa3f828-5db3-479a-bd84-02c80818922e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to