Column type validation?

  • John

    John - 2011-09-02

    Hey guys,

    Let me preface this by saying I submitted feature request 3397693. Thanks for
    addressing that so quickly!

    Now I have a question about Query#validate as it pertains to column types.

    Assume I have the following:

            DbSpec spec = new DbSpec();
            DbSchema schema = spec.addSchema(null);
            DbTable table1 = schema.addTable("table1");
            DbColumn intColumn = table1.addColumn("intColumn", Types.INTEGER, null);
            String query = new InsertQuery(table1)
                    .addColumn(intColumn, "Obviously not an integer")

    In this case, the invocation of validate does not throw a ValidationException,
    which I would have expected, given that I've created an insertion query where
    the type of value I'm inserting for a column is clearly not what the column

    Are my expectations of Column type validation incorrect? Or am I doing
    something stupid?

    Thanks for your help!

  • James Ahlborn

    James Ahlborn - 2011-09-03

    sqlbuilder validation is a very tricky thing. it attempts to be as helpful as
    possible while still attempting to be as flexible as possible. there is
    currently no column value validation, and i don't really think it is possible.
    for instance, "obviously not an integer" could be "a.some_column". obviously,
    that string value is not an integer, but that may actually be a sql reference
    to a column which is an integer value. or, it could be some other textual
    value which the database will resolve to a valid integer value.

    pretty much all the validation in sqlbuilder is around creating valid sql
    statements from a syntactical standpoint (as far as possible given the
    information which sqlbuilder has available). there are many ways you could
    make sqlbuilder validation happy and still generate a useless or invalid sql
    query. there are probably even ways that you could fail sqlbuilder validation
    and have a valid sql query. in both these scenarios, we try to handle as much
    as possible without reducing the flexibility of the library.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks